package com.yida.data.school.smart.config;

import cc.mrbird.febs.common.redis.service.RedisService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yida.data.common.core.entity.constant.StringConstant;
import com.yida.data.common.core.entity.smart.EduSmartWelcomeGuideRoster;
import com.yida.data.common.excel.DefaultExportLargeClient;
import com.yida.data.school.smart.excel.SelectGuidePicExportData;
import com.yida.data.school.smart.service.EduSmartWelcomeGuideRosterService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * smart大文件导出处理类
 *
 * @author ZYJ
 * @date 2023/10/20 15:00
 */
public class ExportGuidePicClient
        extends DefaultExportLargeClient<SelectGuidePicExportData, EduSmartWelcomeGuideRoster, EduSmartWelcomeGuideRosterService> {

    public ExportGuidePicClient(EduSmartWelcomeGuideRosterService eduSmartWelcomeGuideRosterService, RedisService redisService,
                                String exportCacheKey, String uploadUrl) {
        super(eduSmartWelcomeGuideRosterService, redisService, exportCacheKey, uploadUrl);
    }

    @Override
    public Map<String, String> selectExportData(SelectGuidePicExportData selectGuidePicExportData) {
        // 返回数据
        Map<String, String> map = new HashMap<>();
        // 查询指定数据
        List<EduSmartWelcomeGuideRoster> guideRosterList = this.baseService.list(Wrappers.lambdaQuery(new EduSmartWelcomeGuideRoster())
                .eq(EduSmartWelcomeGuideRoster::getGuideId, selectGuidePicExportData.getGuideId()));
        for (EduSmartWelcomeGuideRoster guideRoster : guideRosterList) {
            if (Objects.nonNull(guideRoster)) {
                // 姓名
                String fullName = guideRoster.getFullName();
                if (StrUtil.isEmpty(fullName)) {
                    continue;
                }
                // 身份证号码
                String idNumber = guideRoster.getIdNumber();
                if (StrUtil.isEmpty(idNumber)) {
                    continue;
                }
                String mapKey = fullName + StringConstant.DASH + idNumber + StringConstant.DASH;
                // 身份证正面照片
                if (StrUtil.isNotBlank(guideRoster.getIdCardRight())) {
                    map.put(mapKey + "身份证正面", guideRoster.getIdCardRight());
                }
                // 身份证反面
                if (StrUtil.isNotBlank(guideRoster.getIdCardReverse())) {
                    map.put(mapKey + "身份证反面", guideRoster.getIdCardReverse());
                }
                // 通知书
                if (StrUtil.isNotBlank(guideRoster.getAdmissionLetter())) {
                    map.put(mapKey + "通知书", guideRoster.getAdmissionLetter());
                }
            }
        }
        return map;
    }
}
