package com.sundot.airport.blocked.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.sundot.airport.common.core.domain.entity.SysDictData;
import com.sundot.airport.system.service.ISysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.sundot.airport.common.exception.ServiceException;
import com.sundot.airport.common.utils.DateUtils;
import com.sundot.airport.blocked.mapper.BlockedMissCheckStatisticsMapper;
import com.sundot.airport.blocked.domain.BlockedMissCheckStatistics;
import com.sundot.airport.blocked.service.IBlockedMissCheckStatisticsService;
import com.sundot.airport.system.domain.BasePosition;
import com.sundot.airport.system.service.IBasePositionService;
import com.sundot.airport.common.core.domain.entity.SysUser;
import com.sundot.airport.system.service.ISysUserService;
import com.sundot.airport.common.core.domain.entity.SysDept;
import com.sundot.airport.system.service.ISysDeptService;

/**
 * 漏检统计Service业务层处理
 *
 * @author wangxx
 * @date 2026-04-13
 */
@Service
public class BlockedMissCheckStatisticsServiceImpl implements IBlockedMissCheckStatisticsService {
    @Autowired
    private BlockedMissCheckStatisticsMapper blockedMissCheckStatisticsMapper;

    @Autowired
    private IBasePositionService basePositionService;

    @Autowired
    private ISysUserService sysUserService;

    @Autowired
    private ISysDeptService sysDeptService;

    @Autowired
    private ISysDictDataService sysDictDataService;

    /**
     * 查询漏检统计
     *
     * @param id 漏检统计主键
     * @return 漏检统计
     */
    @Override
    public BlockedMissCheckStatistics selectBlockedMissCheckStatisticsById(Long id) {
        return blockedMissCheckStatisticsMapper.selectBlockedMissCheckStatisticsById(id);
    }

    /**
     * 查询漏检统计列表
     *
     * @param blockedMissCheckStatistics 漏检统计
     * @return 漏检统计
     */
    @Override
    public List<BlockedMissCheckStatistics> selectBlockedMissCheckStatisticsList(BlockedMissCheckStatistics blockedMissCheckStatistics) {
        return blockedMissCheckStatisticsMapper.selectBlockedMissCheckStatisticsList(blockedMissCheckStatistics);
    }

    /**
     * 新增漏检统计
     *
     * @param blockedMissCheckStatistics 漏检统计
     * @return 结果
     */
    @Override
    public int insertBlockedMissCheckStatistics(BlockedMissCheckStatistics blockedMissCheckStatistics) {
        // 根据名称填充ID
        fillIdsByName(blockedMissCheckStatistics);
        blockedMissCheckStatistics.setCreateTime(DateUtils.getNowDate());
        return blockedMissCheckStatisticsMapper.insertBlockedMissCheckStatistics(blockedMissCheckStatistics);
    }

    /**
     * 修改漏检统计
     *
     * @param blockedMissCheckStatistics 漏检统计
     * @return 结果
     */
    @Override
    public int updateBlockedMissCheckStatistics(BlockedMissCheckStatistics blockedMissCheckStatistics) {
        // 根据名称填充ID
        fillIdsByName(blockedMissCheckStatistics);
        blockedMissCheckStatistics.setUpdateTime(DateUtils.getNowDate());
        return blockedMissCheckStatisticsMapper.updateBlockedMissCheckStatistics(blockedMissCheckStatistics);
    }

    /**
     * 批量删除漏检统计
     *
     * @param ids 需要删除的漏检统计主键
     * @return 结果
     */
    @Override
    public int deleteBlockedMissCheckStatisticsByIds(Long[] ids) {
        return blockedMissCheckStatisticsMapper.deleteBlockedMissCheckStatisticsByIds(ids);
    }

    /**
     * 删除漏检统计信息
     *
     * @param id 漏检统计主键
     * @return 结果
     */
    @Override
    public int deleteBlockedMissCheckStatisticsById(Long id) {
        return blockedMissCheckStatisticsMapper.deleteBlockedMissCheckStatisticsById(id);
    }

    /**
     * 导入漏检统计数据
     *
     * @param list 数据列表
     * @param isUpdateSupport 是否更新支持，如果已存在，则进行更新数据
     * @return 结果
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public String importData(List<BlockedMissCheckStatistics> list, boolean isUpdateSupport) {
        if (CollUtil.isEmpty(list)) {
            throw new ServiceException("导入漏检统计数据不能为空！");
        }

        int successNum = 0;
        int failureNum = 0;
        StringBuilder successMsg = new StringBuilder();
        StringBuilder failureMsg = new StringBuilder();

        for (BlockedMissCheckStatistics data : list) {
            fillIdsByName(data);
            try {
                if (ObjUtil.isNull(data.getReviewDate())) {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】回查日期不能为空");
                    continue;
                }
                if (ObjUtil.isNull(data.getMissCheckTime())) {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】漏检时间不能为空");
                    continue;
                }
                if (ObjUtil.isNull(data.getReviewedUserId()) || ObjUtil.isNull(data.getReviewedUserName())) {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】被回查人不能为空");
                    continue;
                }
                if (ObjUtil.isNull(data.getBrigadeId()) || ObjUtil.isNull(data.getBrigadeName())) {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】大队不能为空");
                    continue;
                }
                if (ObjUtil.isNull(data.getTerminalId()) || ObjUtil.isNull(data.getTerminalName())) {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】航站楼不能为空");
                    continue;
                }
                if (ObjUtil.isNull(data.getAreaId()) || ObjUtil.isNull(data.getAreaName())) {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】区域不能为空");
                    continue;
                }
                if (ObjUtil.isNull(data.getChannelId()) || ObjUtil.isNull(data.getChannelName())) {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】上岗位置不能为空");
                    continue;
                }
                if (ObjUtil.isNull(data.getReviewUserId()) || ObjUtil.isNull(data.getReviewUserName())) {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】回查人不能为空");
                    continue;
                }
                if (ObjUtil.isNull(data.getSupervisorId()) || ObjUtil.isNull(data.getSupervisorName())) {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】分管主管不能为空");
                    continue;
                }
                if (ObjUtil.isNull(data.getTeamLeaderId()) || ObjUtil.isNull(data.getTeamLeaderName())) {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】分管班组长不能为空");
                    continue;
                }
                if (ObjUtil.isNull(data.getMissCheckTimePeriod())) {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】漏检时间段不能为空");
                    continue;
                }
                if (ObjUtil.isNull(data.getMissCheckItem())) {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】漏检物品不能为空");
                    continue;
                }
                if (ObjUtil.isNull(data.getItemLocation())) {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】物品位置不能为空");
                    continue;
                }
                if (ObjUtil.isNull(data.getDifficultyLevel())) {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】难度级别不能为空");
                    continue;
                }
                if (ObjUtil.isNull(data.getDiscriminationType())) {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】判别类型不能为空");
                    continue;
                }
                if (ObjUtil.isNull(data.getIsRecovered())) {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】是否追回不能为空");
                    continue;
                }
                if (ObjUtil.isNull(data.getMachineOperatingYears())) {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】开机年限不能为空");
                    continue;
                }
                if (ObjUtil.isNull(data.getCertificateLevel())) {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】证书级别不能为空");
                    continue;
                }
                if (ObjUtil.isNull(data.getGender())) {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】人员性别不能为空");
                    continue;
                }
                if (ObjUtil.isNull(data.getMissCheckReasonCategory())) {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】漏检原因分类不能为空");
                    continue;
                }
                if (ObjUtil.isNull(data.getMonthlyAssessment())) {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】月考核不能为空");
                    continue;
                }
                if (ObjUtil.isNull(data.getSelfTestHasMissCheck())) {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】本月自测有无漏检不能为空");
                    continue;
                }

                // 查询是否已存在（根据被回查人+回查日期+漏检时间唯一）
                BlockedMissCheckStatistics queryParam = new BlockedMissCheckStatistics();
                queryParam.setReviewedUserId(data.getReviewedUserId());
                queryParam.setReviewDate(data.getReviewDate());
                queryParam.setMissCheckTime(data.getMissCheckTime());
                List<BlockedMissCheckStatistics> existingList = blockedMissCheckStatisticsMapper.selectBlockedMissCheckStatisticsList(queryParam);

                if (CollUtil.isEmpty(existingList)) {
                    // 新增
                    data.setCreateTime(DateUtils.getNowDate());
                    blockedMissCheckStatisticsMapper.insertBlockedMissCheckStatistics(data);
                    successNum++;
                } else if (isUpdateSupport) {
                    // 更新
                    BlockedMissCheckStatistics old = existingList.get(0);
                    data.setId(old.getId());
                    data.setUpdateTime(DateUtils.getNowDate());
                    blockedMissCheckStatisticsMapper.updateBlockedMissCheckStatistics(data);
                    successNum++;
                } else {
                    failureNum++;
                    failureMsg.append("<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】已存在");
                }
            } catch (Exception e) {
                failureNum++;
                String msg = "<br/>" + failureNum + "、被回查人【" + data.getReviewedUserName() + "】、回查日期【" + data.getReviewDate() + "】、漏检时间【" + data.getMissCheckTime() + "】导入失败：";
                failureMsg.append(msg + e.getMessage());
            }
        }

        if (failureNum > 0) {
            failureMsg.insert(0, "很抱歉，导入失败！共 " + failureNum + " 条数据格式不正确，错误如下：");
            throw new ServiceException(failureMsg.toString());
        } else {
            successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successNum + " 条");
        }
        return successMsg.toString();
    }

    /**
     * 检查数据是否重复（被回查人+回查日期+漏检时间）
     *
     * @param blockedMissCheckStatistics 漏检统计数据
     * @return 重复的数据，如果没有重复返回null
     */
    @Override
    public BlockedMissCheckStatistics checkDuplicate(BlockedMissCheckStatistics blockedMissCheckStatistics) {
        if (ObjUtil.isNull(blockedMissCheckStatistics.getReviewedUserId())
                || ObjUtil.isNull(blockedMissCheckStatistics.getReviewDate())
                || ObjUtil.isNull(blockedMissCheckStatistics.getMissCheckTime())) {
            return null;
        }

        BlockedMissCheckStatistics queryParam = new BlockedMissCheckStatistics();
        queryParam.setReviewedUserId(blockedMissCheckStatistics.getReviewedUserId());
        queryParam.setReviewDate(blockedMissCheckStatistics.getReviewDate());
        queryParam.setMissCheckTime(blockedMissCheckStatistics.getMissCheckTime());
        List<BlockedMissCheckStatistics> existingList = blockedMissCheckStatisticsMapper.selectBlockedMissCheckStatisticsList(queryParam);

        if (CollUtil.isNotEmpty(existingList)) {
            return existingList.get(0);
        }
        return null;
    }

    /**
     * 新增或更新漏检统计（如果数据重复则覆盖更新）
     *
     * @param blockedMissCheckStatistics 漏检统计
     * @return 结果
     */
    @Override
    @Transactional
    public int insertOrUpdate(BlockedMissCheckStatistics blockedMissCheckStatistics) {
        // 航站楼+区域+通道 - 通过通道ID查询
        if (ObjUtil.isNotNull(blockedMissCheckStatistics.getChannelId())) {
            BasePosition channel = basePositionService.selectBasePositionById(blockedMissCheckStatistics.getChannelId());
            BasePosition area = basePositionService.selectBasePositionById(channel.getParentId());
            BasePosition terminal = basePositionService.selectBasePositionById(area.getParentId());
            blockedMissCheckStatistics.setChannelName(channel.getName());
            blockedMissCheckStatistics.setAreaId(area.getId());
            blockedMissCheckStatistics.setAreaName(area.getName());
            blockedMissCheckStatistics.setTerminalId(terminal.getId());
            blockedMissCheckStatistics.setTerminalName(terminal.getName());
        }
        // 检查是否重复
        BlockedMissCheckStatistics existing = checkDuplicate(blockedMissCheckStatistics);

        if (existing != null) {
            // 数据已存在，执行更新（覆盖）
            blockedMissCheckStatistics.setId(existing.getId());
            blockedMissCheckStatistics.setUpdateBy(blockedMissCheckStatistics.getUpdateBy() != null
                    ? blockedMissCheckStatistics.getUpdateBy() : blockedMissCheckStatistics.getCreateBy());
            blockedMissCheckStatistics.setUpdateTime(DateUtils.getNowDate());
            return blockedMissCheckStatisticsMapper.updateBlockedMissCheckStatistics(blockedMissCheckStatistics);
        } else {
            // 数据不存在，执行新增
            blockedMissCheckStatistics.setCreateTime(DateUtils.getNowDate());
            return blockedMissCheckStatisticsMapper.insertBlockedMissCheckStatistics(blockedMissCheckStatistics);
        }
    }

    /**
     * 根据名称填充ID字段
     *
     * @param data 漏检统计数据
     */
    private void fillIdsByName(BlockedMissCheckStatistics data) {
        // 1. 大队ID - 通过部门表查询
        if (ObjUtil.isNull(data.getBrigadeId()) && StrUtil.isNotBlank(data.getBrigadeName())) {
            SysDept deptQuery = new SysDept();
            deptQuery.setDeptName(data.getBrigadeName());
            List<SysDept> deptList = sysDeptService.selectDeptList(deptQuery);
            if (CollUtil.isNotEmpty(deptList)) {
                data.setBrigadeId(deptList.get(0).getDeptId());
            }
        }

        // 2. 航站楼ID - 通过位置表查询(level=1)
        if (ObjUtil.isNull(data.getTerminalId()) && StrUtil.isNotBlank(data.getTerminalName())) {
            BasePosition positionQuery = new BasePosition();
            positionQuery.setName(data.getTerminalName());
            positionQuery.setLevel(1);
            List<BasePosition> positionList = basePositionService.selectBasePositionList(positionQuery);
            if (CollUtil.isNotEmpty(positionList)) {
                data.setTerminalId(positionList.get(0).getId());
            }
        }

        // 3. 区域ID - 通过位置表查询(level=2)
        if (ObjUtil.isNull(data.getAreaId()) && StrUtil.isNotBlank(data.getAreaName())) {
            BasePosition positionQuery = new BasePosition();
            positionQuery.setName(data.getAreaName());
            positionQuery.setLevel(2);
            List<BasePosition> positionList = basePositionService.selectBasePositionList(positionQuery);
            if (CollUtil.isNotEmpty(positionList)) {
                data.setAreaId(positionList.get(0).getId());
            }
        }

        // 4. 上岗位置ID - 通过位置表查询(level=3)
        if (ObjUtil.isNull(data.getChannelId()) && StrUtil.isNotBlank(data.getChannelName())) {
            BasePosition positionQuery = new BasePosition();
            positionQuery.setName(data.getChannelName());
            positionQuery.setLevel(3);
            List<BasePosition> positionList = basePositionService.selectBasePositionList(positionQuery);
            if (CollUtil.isNotEmpty(positionList)) {
                data.setChannelId(positionList.get(0).getId());
            }
        }

        // 航站楼+区域+通道 - 通过通道ID查询
        if (ObjUtil.isNotNull(data.getChannelId())) {
            BasePosition channel = basePositionService.selectBasePositionById(data.getChannelId());
            BasePosition area = basePositionService.selectBasePositionById(channel.getParentId());
            BasePosition terminal = basePositionService.selectBasePositionById(area.getParentId());
            data.setChannelName(channel.getName());
            data.setAreaId(area.getId());
            data.setAreaName(area.getName());
            data.setTerminalId(terminal.getId());
            data.setTerminalName(terminal.getName());
        }

        // 5. 被回查人ID - 通过用户昵称查询
        if (ObjUtil.isNull(data.getReviewedUserId()) && StrUtil.isNotBlank(data.getReviewedUserName())) {
            SysUser userQuery = new SysUser();
            userQuery.setNickName(data.getReviewedUserName());
            List<SysUser> userList = sysUserService.selectUserList(userQuery);
            if (CollUtil.isNotEmpty(userList)) {
                data.setReviewedUserId(userList.get(0).getUserId());
            }
        }

        // 6. 回查人ID - 通过用户昵称查询
        if (ObjUtil.isNull(data.getReviewUserId()) && StrUtil.isNotBlank(data.getReviewUserName())) {
            SysUser userQuery = new SysUser();
            userQuery.setNickName(data.getReviewUserName());
            List<SysUser> userList = sysUserService.selectUserList(userQuery);
            if (CollUtil.isNotEmpty(userList)) {
                data.setReviewUserId(userList.get(0).getUserId());
            }
        }

        // 7. 分管主管ID - 通过用户昵称查询
        if (ObjUtil.isNull(data.getSupervisorId()) && StrUtil.isNotBlank(data.getSupervisorName())) {
            SysUser userQuery = new SysUser();
            userQuery.setNickName(data.getSupervisorName());
            List<SysUser> userList = sysUserService.selectUserList(userQuery);
            if (CollUtil.isNotEmpty(userList)) {
                data.setSupervisorId(userList.get(0).getUserId());
            }
        }

        // 8. 代管主管ID - 通过用户昵称查询
        if (ObjUtil.isNull(data.getActingSupervisorId()) && StrUtil.isNotBlank(data.getActingSupervisorName())) {
            SysUser userQuery = new SysUser();
            userQuery.setNickName(data.getActingSupervisorName());
            List<SysUser> userList = sysUserService.selectUserList(userQuery);
            if (CollUtil.isNotEmpty(userList)) {
                data.setActingSupervisorId(userList.get(0).getUserId());
            }
        }

        // 9. 分管班组长ID - 通过用户昵称查询
        if (ObjUtil.isNull(data.getTeamLeaderId()) && StrUtil.isNotBlank(data.getTeamLeaderName())) {
            SysUser userQuery = new SysUser();
            userQuery.setNickName(data.getTeamLeaderName());
            List<SysUser> userList = sysUserService.selectUserList(userQuery);
            if (CollUtil.isNotEmpty(userList)) {
                data.setTeamLeaderId(userList.get(0).getUserId());
            }
        }

        // 判别类型 - 通过漏检统计判断类型字典查询
        if (StrUtil.isNotBlank(data.getDiscriminationType())) {
            SysDictData query = new SysDictData();
            query.setDictType("discrimination_type");
            List<SysDictData> sysDictDataList = sysDictDataService.selectDictDataList(query);
            Map<String, String> sysDictDataMap = sysDictDataList.stream().collect(Collectors.toMap(SysDictData::getDictLabel, SysDictData::getDictValue));
            data.setDiscriminationType(sysDictDataMap.get(data.getDiscriminationType()));
        }

        // 开机年限 - 通过查堵开机年限字典查询
        if (StrUtil.isNotBlank(data.getMachineOperatingYears())) {
            SysDictData query = new SysDictData();
            query.setDictType("blocked_operating_years");
            List<SysDictData> sysDictDataList = sysDictDataService.selectDictDataList(query);
            Map<String, String> sysDictDataMap = sysDictDataList.stream().collect(Collectors.toMap(SysDictData::getDictLabel, SysDictData::getDictValue));
            data.setMachineOperatingYears(sysDictDataMap.get(data.getMachineOperatingYears()));
        }

        // 漏检原因分类 - 通过查堵漏检原因分类字典查询
        if (StrUtil.isNotBlank(data.getMissCheckReasonCategory())) {
            SysDictData query = new SysDictData();
            query.setDictType("blocked_miss_check_reason");
            List<SysDictData> sysDictDataList = sysDictDataService.selectDictDataList(query);
            Map<String, String> sysDictDataMap = sysDictDataList.stream().collect(Collectors.toMap(SysDictData::getDictLabel, SysDictData::getDictValue));
            data.setMissCheckReasonCategory(sysDictDataMap.get(data.getMissCheckReasonCategory()));
        }

        // 月考核 - 通过查堵月考成绩字典查询
        if (StrUtil.isNotBlank(data.getMonthlyAssessment())) {
            SysDictData query = new SysDictData();
            query.setDictType("blocked_monthly_exam_result");
            List<SysDictData> sysDictDataList = sysDictDataService.selectDictDataList(query);
            Map<String, String> sysDictDataMap = sysDictDataList.stream().collect(Collectors.toMap(SysDictData::getDictLabel, SysDictData::getDictValue));
            data.setMonthlyAssessment(sysDictDataMap.get(data.getMonthlyAssessment()));
        }

        // 物品位置 - 通过查堵物品位置字典查询
        if (StrUtil.isNotBlank(data.getItemLocation())) {
            SysDictData query = new SysDictData();
            query.setDictType("blocked_item_position");
            List<SysDictData> sysDictDataList = sysDictDataService.selectDictDataList(query);
            Map<String, String> sysDictDataMap = sysDictDataList.stream().collect(Collectors.toMap(SysDictData::getDictLabel, SysDictData::getDictValue));
            data.setItemLocation(sysDictDataMap.get(data.getItemLocation()));
        }

        // 漏检时间段 - 通过查堵时间段字典查询
        if (StrUtil.isNotBlank(data.getMissCheckTimePeriod())) {
            SysDictData query = new SysDictData();
            query.setDictType("blocked_time_period");
            List<SysDictData> sysDictDataList = sysDictDataService.selectDictDataList(query);
            Map<String, String> sysDictDataMap = sysDictDataList.stream().collect(Collectors.toMap(SysDictData::getDictLabel, SysDictData::getDictValue));
            data.setMissCheckTimePeriod(sysDictDataMap.get(data.getMissCheckTimePeriod()));
        }
    }
}
