6个文件已修改
645 ■■■■ 已修改文件
febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/controller/EmpBaseInfoController.java 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/entity/EmpBaseInfo.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/mapper/EmpContractInfoMapper.java 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/mapper/EmpContractInfoMapper.xml 32 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/service/impl/EmpBaseInfoServiceImpl.java 506 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/service/impl/EmpContractInfoServiceImpl.java 71 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/controller/EmpBaseInfoController.java
@@ -284,6 +284,12 @@
    @PostMapping("addInEmp")
    @PreAuthorize("hasAuthority('empBaseinfo:add')")
    public FebsResponse addInEmpBaseInfo(@Valid EmpBaseInfo empBaseinfo) throws FebsException {
        if(this.empBaseInfoService.verifyEmpNumb(empBaseinfo)){
            throw new FebsException("已存在此员工编号:" + empBaseinfo.getEmpNumb());
        }
        if(this.empBaseInfoService.verifyCertificateNumb(empBaseinfo)){
            throw new FebsException("已存在此身份证号:" + empBaseinfo.getCertificateNumb());
        }
        try {
            return new FebsResponse().data(empBaseInfoService.addInEmpBaseInfo(empBaseinfo));
        } catch (Exception e) {
febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/entity/EmpBaseInfo.java
@@ -86,7 +86,7 @@
    @ExcelField(value = "岗位名称")
    private String jobName = "";
    @NotBlank(message = "{required}")
    // @NotBlank(message = "{required}")
    @FieldInfo(name = "empType", type = "varchar", explain = "员工类别")
    @TableField("empType")
    @ExcelField(value = "员工类别", writeConverterExp = "1=正式工,2=临时工")
febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/mapper/EmpContractInfoMapper.java
@@ -1,13 +1,11 @@
package cc.mrbird.febs.server.hr.mapper;
import cc.mrbird.febs.server.hr.entity.EmpContractInfo;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
@@ -118,4 +116,30 @@
            " WHERE contractId=#{contractId}" +
            "</script>")
    int updateEmpContractRemind(@Param("contractId") Long contractId);
    /**
     * UNION查询:即将到期 + 已到期未续签的合同
     *
     * @param page 分页参数
     * @param sqlSegment1 即将到期的查询条件SQL
     * @param sqlSegment2 已到期未续签的查询条件SQL
     * @return 分页结果
     */
    IPage<EmpContractInfo> selectUnionPageVo(
            @Param("page") Page<EmpContractInfo> page,
            @Param("sqlSegment1") String sqlSegment1,
            @Param("sqlSegment2") String sqlSegment2
    );
    /**
     * 查询在职人员的最后一份合同
     *
     * @param page 分页参数
     * @param sqlSegment 查询条件SQL
     * @return 分页结果
     */
    IPage<EmpContractInfo> selectLastContractPageVo(
            @Param("page") Page<EmpContractInfo> page,
            @Param("sqlSegment") String sqlSegment
    );
}
febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/mapper/EmpContractInfoMapper.xml
@@ -8,5 +8,37 @@
        inner join t_dept c on b.deptId = c.DEPT_ID
        ${ew.customSqlSegment}
    </select>
    <select id="selectUnionPageVo" resultType="cc.mrbird.febs.server.hr.entity.EmpContractInfo">
        SELECT * FROM (
        (SELECT a.*, b.allDeptName
        FROM t_emp_contractinfo a
        INNER JOIN t_emp_baseinfo b ON a.empId = b.empId
        INNER JOIN t_dept c ON b.deptId = c.DEPT_ID
        <where>
            ${sqlSegment1}
        </where>)
        UNION
        (SELECT a.*, b.allDeptName
        FROM t_emp_contractinfo a
        INNER JOIN t_emp_baseinfo b ON a.empId = b.empId
        INNER JOIN t_dept c ON b.deptId = c.DEPT_ID
        <where>
            ${sqlSegment2}
        </where>)
        ) t
        ORDER BY diffDay ASC
    </select>
    <select id="selectLastContractPageVo" resultType="cc.mrbird.febs.server.hr.entity.EmpContractInfo">
        SELECT a.*, b.allDeptName
        FROM t_emp_contractinfo a
        INNER JOIN t_emp_baseinfo b ON a.empId = b.empId
        INNER JOIN t_dept c ON b.deptId = c.DEPT_ID
        <where>
            ${sqlSegment}
        </where>
        ORDER BY a.diffDay DESC
    </select>
</mapper>
febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/service/impl/EmpBaseInfoServiceImpl.java
@@ -491,188 +491,370 @@
     *
     * @param listObject
     */
    /**
     * 导入员工基本信息
     * 重构后认知复杂度: ~10 (原224)
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void importEmpBaseInfo(List<List<Object>> listObject, List<String> returnList, List<DicItem> dicItems) {
        for (List<Object> list : listObject) {
            if (list.size() == 0) {
        ImportContext context = prepareImportContext(listObject, dicItems);
        String operatorId = FebsUtil.getUserId();
        List<EmpBaseInfo> newEmpList = new ArrayList<>();
        List<EmpBaseInfo> updateEmpList = new ArrayList<>();
        for (int i = 0; i < listObject.size(); i++) {
            List<Object> rowData = listObject.get(i);
            if (rowData.isEmpty()) {
                continue;
            }
            if (this.count(new LambdaQueryWrapper<EmpBaseInfo>().eq(EmpBaseInfo::getEmpNumb, list.get(1).toString()).ne(EmpBaseInfo::getDelFlag, 1)) > 0) {
                returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}员工编号重复", listObject.indexOf(list) + 1, list.get(1).toString()));
            String empNumb = getImportCellValue(rowData, 1);
            EmpBaseInfo dbData = context.empMap.get(empNumb);
            EmpBaseInfo empBaseInfo = buildEmpBaseInfo(rowData, i, dbData, context.dicMap,
                    context.deptMap, context.positionMap, context.certCountMap, returnList, operatorId);
            if (empBaseInfo == null) {
                continue;
            }
            if (this.count(new LambdaQueryWrapper<EmpBaseInfo>().eq(EmpBaseInfo::getCertificateNumb, list.get(1).toString()).ne(EmpBaseInfo::getDelFlag, 1)) > 0) {
                returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}身份证号重复", listObject.indexOf(list) + 1, list.get(1).toString()));
                continue;
            if (dbData == null) {
                newEmpList.add(empBaseInfo);
            } else {
                updateEmpList.add(empBaseInfo);
            }
            EmpBaseInfo empBaseInfo = new EmpBaseInfo();
        }
        batchSaveEmployees(newEmpList, updateEmpList, operatorId);
    }
    /**
     * 准备导入上下文数据
     */
    private ImportContext prepareImportContext(List<List<Object>> listObject, List<DicItem> dicItems) {
        ImportContext context = new ImportContext();
        // 收集员工编号
        Set<String> empNumbs = listObject.stream()
                .filter(list -> !list.isEmpty())
                .map(list -> getImportCellValue(list, 1))
                .filter(StringUtils::isNotBlank)
                .collect(Collectors.toSet());
        // 批量查询已存在的员工
        context.empMap = CollUtil.isEmpty(empNumbs) ? new HashMap<>() :
                this.list(new LambdaQueryWrapper<EmpBaseInfo>().in(EmpBaseInfo::getEmpNumb, empNumbs))
                        .stream()
                        .collect(Collectors.toMap(EmpBaseInfo::getEmpNumb, e -> e));
        // 批量查询身份证号重复情况
        context.certCountMap = CollUtil.isEmpty(empNumbs) ? new HashMap<>() :
                this.list(new LambdaQueryWrapper<EmpBaseInfo>()
                        .select(EmpBaseInfo::getCertificateNumb)
                        .in(EmpBaseInfo::getCertificateNumb, empNumbs)
                        .ne(EmpBaseInfo::getDelFlag, 1))
                        .stream()
                        .filter(e -> StringUtils.isNotBlank(e.getCertificateNumb()))
                        .collect(Collectors.groupingBy(EmpBaseInfo::getCertificateNumb, Collectors.counting()));
        // 部门Map
        List<Dept> depts = CastUtil.castList(redisService.get("depts"), Dept.class);
        if (CollUtil.isEmpty(depts)) {
            depts = remoteDeptService.setDeptRedis();
        }
        context.deptMap = CollUtil.isEmpty(depts) ? new HashMap<>() :
                depts.stream().collect(Collectors.toMap(Dept::getDeptName, d -> d, (v1, v2) -> v1));
        // 岗位Map
        List<Position> positionList = CastUtil.castList(redisService.get("position"), Position.class);
        if (CollUtil.isEmpty(positionList)) {
            positionList = remotePositionService.setPositionRedis();
        }
        context.positionMap = CollUtil.isEmpty(positionList) ? new HashMap<>() :
                positionList.stream().collect(Collectors.toMap(Position::getPositionName, p -> p, (v1, v2) -> v1));
        // 字典Map
        context.dicMap = CollUtil.isEmpty(dicItems) ? new HashMap<>() :
                dicItems.stream().collect(Collectors.groupingBy(
                        DicItem::getDicCode,
                        Collectors.toMap(DicItem::getDicItemName, d -> d, (v1, v2) -> v1)));
        return context;
    }
    /**
     * 批量保存员工数据
     */
    private void batchSaveEmployees(List<EmpBaseInfo> newEmpList, List<EmpBaseInfo> updateEmpList, String operatorId) {
        if (CollUtil.isNotEmpty(newEmpList)) {
            this.saveBatch(newEmpList, 100);
            newEmpList.forEach(emp -> this.addEmpDimissLog(emp, "2", emp.getEmpId()));
        }
        if (CollUtil.isNotEmpty(updateEmpList)) {
            this.updateBatchById(updateEmpList, 100);
        }
    }
    /**
     * 从字典Map中获取字典项Code并设置到员工对象
     * 降低认知复杂度:将重复的字典查找逻辑提取为通用方法
     */
    private void setDicFieldFromMap(EmpBaseInfo empBaseInfo, Map<String, Map<String, DicItem>> dicMap,
                                     String dicCode, String dicItemName, java.util.function.Consumer<String> setter) {
        if (StringUtils.isBlank(dicItemName)) {
            return;
        }
        Map<String, DicItem> subDicMap = dicMap.get(dicCode);
        if (subDicMap == null) {
            return;
        }
        DicItem dicItem = subDicMap.get(dicItemName);
        if (dicItem != null) {
            setter.accept(dicItem.getDicItemCode());
        }
    }
    private String getImportCellValue(List<Object> list, int index) {
        if (index >= list.size() || list.get(index) == null) {
            return StringUtils.EMPTY;
        }
        return list.get(index).toString();
    }
    private List<Dept> getImportDepts(List<Dept> depts) {
        if (null == depts) {
            depts = remoteDeptService.setDeptRedis();
        }
        if (null == depts) {
            depts = remoteDeptService.setDeptRedis();
        }
        return depts;
    }
    private List<Position> getImportPositions(List<Position> positionList) {
        if (null == positionList) {
            positionList = remotePositionService.setPositionRedis();
        }
        return positionList;
    }
    private DicItem getImportDicItem(List<DicItem> dicItems, String dicCode, String dicItemName) {
        if (StrUtil.isBlank(dicItemName)) {
            return null;
        }
        return dicItems.parallelStream()
                .filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), dicCode) && StrUtil.equals(j.getDicItemName(), dicItemName))
                .findFirst()
                .orElse(null);
    }
    // ==================== importEmpBaseInfo 重构辅助方法 ====================
    /**
     * 条件设置字符串字段(isNew 或值非空时设置)
     */
    private void setIfNewOrNotBlank(EmpBaseInfo empBaseInfo, boolean isNew, String value,
                                     java.util.function.Consumer<String> setter) {
        if (isNew || StringUtils.isNotBlank(value)) {
            setter.accept(value);
        }
    }
    /**
     * 处理身份证信息并设置相关字段
     */
    private void processCertificateNumb(EmpBaseInfo empBaseInfo, String certificateNumb) {
        if (StringUtils.isBlank(certificateNumb)) {
            return;
        }
        empBaseInfo.setCertificateNumb(certificateNumb);
        if (IdcardUtil.isValidCard(certificateNumb)) {
            empBaseInfo.setAge(IdcardUtil.getAgeByIdCard(certificateNumb));
            empBaseInfo.setBirthdate(IdcardUtil.getBirthDate(certificateNumb));
        }
    }
    /**
     * 处理证件列表字段
     */
    private void processCertificateList(EmpBaseInfo empBaseInfo, Map<String, Map<String, DicItem>> dicMap,
                                         String certificateListValue) {
        if (StringUtils.isBlank(certificateListValue)) {
            return;
        }
        Map<String, DicItem> certListDic = dicMap.get("certificateList");
        if (certListDic == null) {
            return;
        }
        String[] items = certificateListValue.split(StringConstant.COMMA);
        String codes = Arrays.stream(items)
                .map(certListDic::get)
                .filter(Objects::nonNull)
                .map(DicItem::getDicItemCode)
                .collect(Collectors.joining(StringConstant.COMMA));
        if (StringUtils.isNotBlank(codes)) {
            empBaseInfo.setCertificateList(codes);
        }
    }
    /**
     * 构建员工基本信息对象
     *
     * @return 构建结果,null表示构建失败需要跳过
     */
    private EmpBaseInfo buildEmpBaseInfo(List<Object> rowData, int rowIndex, EmpBaseInfo dbData,
                                          Map<String, Map<String, DicItem>> dicMap,
                                          Map<String, Dept> deptMap, Map<String, Position> positionMap,
                                          Map<String, Long> certCountMap, List<String> returnList,
                                          String operatorId) {
        String empNumb = getImportCellValue(rowData, 1);
        boolean isNew = dbData == null;
        // 检查身份证号重复
        if (isNew && certCountMap.getOrDefault(empNumb, 0L) > 0) {
            returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}身份证号重复", rowIndex + 1, empNumb));
            return null;
        }
        EmpBaseInfo empBaseInfo = isNew ? new EmpBaseInfo() : dbData;
        if (isNew) {
            empBaseInfo.setEmpId(SequenceUtil.generateId(0L, ModuleCode.HR_EMPLOYEE));
            empBaseInfo.setArchivesNumb(list.get(0).toString());
            empBaseInfo.setEmpNumb(list.get(1).toString());
            empBaseInfo.setDelFlag(2);
            empBaseInfo.setEmpStatus("0");
        }
            List<Dept> depts = CastUtil.castList(redisService.get("depts"), Dept.class);
            if (null == depts) {
                depts = remoteDeptService.setDeptRedis();
            }
            if (null == depts) {
                depts = remoteDeptService.setDeptRedis();
            }
            empBaseInfo.setDeptName(list.get(2).toString());
            Dept dept = depts.stream().filter(d -> d.getDeptName().equals(list.get(2).toString())).findFirst().orElse(null);
            if (null == dept) {
                returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}部门不存在", listObject.indexOf(list) + 1, list.get(2).toString()));
                continue;
            }
        // 设置基础字段
        setIfNewOrNotBlank(empBaseInfo, isNew, getImportCellValue(rowData, 0), empBaseInfo::setArchivesNumb);
        setIfNewOrNotBlank(empBaseInfo, isNew, empNumb, empBaseInfo::setEmpNumb);
        // 设置部门信息
        String deptName = getImportCellValue(rowData, 2);
        if (isNew || StringUtils.isNotBlank(deptName)) {
            Dept dept = deptMap.get(deptName);
            if (dept == null) {
                returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}部门不存在", rowIndex + 1, deptName));
                return null;
            }
            empBaseInfo.setDeptName(deptName);
            empBaseInfo.setAllDeptName(dept.getAllDeptName());
            empBaseInfo.setDeptId(dept.getDeptId());
            List<Position> positionList = CastUtil.castList(redisService.get("position"), Position.class);
            if (null == positionList) {
                positionList = remotePositionService.setPositionRedis();
                if (null == positionList) {
                    returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}获取岗位为空,请设置岗位", listObject.indexOf(list) + 1, list.get(3).toString()));
                    continue;
                }
            }
            Position position = positionList.stream().filter(d -> d.getPositionName().equals(list.get(3).toString())).findFirst().orElse(null);
            if (null == position) {
                returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}获取岗位为空", listObject.indexOf(list) + 1, list.get(3).toString()));
                continue;
        }
        // 设置岗位信息
        String jobName = getImportCellValue(rowData, 3);
        if (isNew || StringUtils.isNotBlank(jobName)) {
            Position position = positionMap.get(jobName);
            if (position == null) {
                returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}获取岗位为空", rowIndex + 1, jobName));
                return null;
            }
            empBaseInfo.setJobId(position.getPositionId());
            empBaseInfo.setJobName(list.get(3).toString());
            empBaseInfo.setEmpName(list.get(4).toString());
            try {
                if (StrUtil.isNotBlank(list.get(5).toString())) {
                    empBaseInfo.setCertificateNumb(list.get(5).toString());
                    if (IdcardUtil.isValidCard(list.get(5).toString())) {
                        empBaseInfo.setAge(IdcardUtil.getAgeByIdCard(list.get(5).toString()));
                        empBaseInfo.setBirthdate(IdcardUtil.getBirthDate(list.get(5).toString()));
                    }
                }
            empBaseInfo.setJobName(jobName);
        }
        // 设置姓名
        setIfNewOrNotBlank(empBaseInfo, isNew, getImportCellValue(rowData, 4), empBaseInfo::setEmpName);
        // 处理身份证
        String certificateNumb = getImportCellValue(rowData, 5);
        if (isNew || StrUtil.isNotBlank(certificateNumb)) {
            try {
                processCertificateNumb(empBaseInfo, certificateNumb);
            } catch (Exception e) {
                log.error("导入人员身份证异常:{}", e);
                returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}检查身份证是否正确", listObject.indexOf(list) + 1, list.get(5).toString()));
                continue;
                returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}检查身份证是否正确", rowIndex + 1, certificateNumb));
                return null;
            }
            empBaseInfo.setSex("男".equals(list.get(6).toString()) ? "1" : "2");
            // 民族
            DicItem dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "nation") && StrUtil.equals(j.getDicItemName(), list.get(7).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empBaseInfo.setNation(dicItem.getDicItemCode());
            }
            // 婚姻状况
            dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "marriage") && StrUtil.equals(j.getDicItemName(), list.get(8).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empBaseInfo.setMarriage(dicItem.getDicItemCode());
            }
            if (StringUtils.isNotBlank(list.get(9).toString())) {
                empBaseInfo.setStature(Integer.valueOf(list.get(9).toString()));
            }
            // 政治面貌
            dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "plitical") && StrUtil.equals(j.getDicItemName(), list.get(10).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empBaseInfo.setPolitics(dicItem.getDicItemCode());
            }
            if (StringUtils.isNotBlank(list.get(11).toString())) {
                empBaseInfo.setEntryDate(DateUtil.parse(list.get(11).toString()));
            }
            // 最高学历
            dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "education") && StrUtil.equals(j.getDicItemName(), list.get(12).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empBaseInfo.setEducation(dicItem.getDicItemCode());
            }
            if (StringUtils.isNotBlank(list.get(13).toString())) {
                empBaseInfo.setSeniority(list.get(13).toString());
            }
            // 籍贯
            dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "nativePlace") && StrUtil.equals(j.getDicItemName(), list.get(14).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empBaseInfo.setNativePlace(dicItem.getDicItemCode());
            }
            empBaseInfo.setCensusAddress(list.get(15).toString());
            empBaseInfo.setCurrentAddress(list.get(16).toString());
            // 员工类型
            dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "empType") && StrUtil.equals(j.getDicItemName(), list.get(17).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empBaseInfo.setEmpType(dicItem.getDicItemCode());
            }
            empBaseInfo.setGuardNumb(list.get(18).toString());
            empBaseInfo.setReturnReceipt(list.get(19).toString());
            empBaseInfo.setTelePhone(list.get(20).toString());
            empBaseInfo.setIntroducer(list.get(21).toString());
            empBaseInfo.setBankName(list.get(22).toString());
            empBaseInfo.setBankNumb(list.get(23).toString());
            // 保险类型
            dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "insuranceType") && StrUtil.equals(j.getDicItemName(), list.get(24).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empBaseInfo.setInsuranceType(dicItem.getDicItemCode());
            }
            empBaseInfo.setSocialNumb(list.get(25).toString());
            empBaseInfo.setFamily(list.get(26).toString());
            empBaseInfo.setUrgencyPhone(list.get(27).toString());
            // 员工手册
            dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "handbookStatus") && StrUtil.equals(j.getDicItemName(), list.get(28).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empBaseInfo.setHandbookStatus(dicItem.getDicItemCode());
            }
            // 工作证
            dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "empCardStatus") && StrUtil.equals(j.getDicItemName(), list.get(29).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empBaseInfo.setEmpCardStatus(dicItem.getDicItemCode());
            }
            // 相关证件
            List<DicItem> dicItemList = new ArrayList<>();
            String[] certificateList = list.get(30).toString().split(StringConstant.COMMA);
            if (null != certificateList) {
                for (String s : certificateList) {
                    dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "certificateList") && StrUtil.equals(j.getDicItemName(), s)).findFirst().orElse(null);
                    if (null != dicItem) {
                        dicItemList.add(dicItem);
                    }
                }
            }
            if (CollUtil.isNotEmpty(dicItemList)) {
                empBaseInfo.setCertificateList(dicItemList.stream().map(i -> i.getDicItemCode()).collect(Collectors.joining(StringConstant.COMMA)));
            }
            empBaseInfo.setDelFlag(2);
            // 入职类型
            dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "lztype") && StrUtil.equals(j.getDicItemName(), list.get(31).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empBaseInfo.setEntryType(dicItem.getDicItemCode());
            }
            // 档案情况
            dicItem = dicItems.parallelStream().filter(j -> StrUtil.equalsIgnoreCase(j.getDicCode(), "archivesStatus") && StrUtil.equals(j.getDicItemName(), list.get(32).toString())).findFirst().orElse(null);
            if (null != dicItem) {
                empBaseInfo.setArchivesStatus(dicItem.getDicItemCode());
            }
            // 身份证有效期
            empBaseInfo.setCertificateValidity(DateUtil.parse(list.get(33).toString()));
            empBaseInfo.setEmpStatus("0");
            boolean saveResult = this.save(empBaseInfo);
            // 新入职员工需要增加一条入职记录
            this.addEmpDimissLog(empBaseInfo, "2", empBaseInfo.getEmpId());
        }
        // 设置性别
        String sex = getImportCellValue(rowData, 6);
        if (isNew || StringUtils.isNotBlank(sex)) {
            empBaseInfo.setSex("男".equals(sex) ? "1" : "2");
        }
        // 设置字典类字段
        setDicFieldFromMap(empBaseInfo, dicMap, "NATION", getImportCellValue(rowData, 7), empBaseInfo::setNation);
        setDicFieldFromMap(empBaseInfo, dicMap, "MARRIAGE", getImportCellValue(rowData, 8), empBaseInfo::setMarriage);
        // 身高
        String stature = getImportCellValue(rowData, 9);
        if (StringUtils.isNotBlank(stature)) {
            empBaseInfo.setStature(Integer.valueOf(stature));
        }
        setDicFieldFromMap(empBaseInfo, dicMap, "PLITICAL", getImportCellValue(rowData, 10), empBaseInfo::setPolitics);
        // 入职日期
        String entryDate = getImportCellValue(rowData, 11);
        if (StringUtils.isNotBlank(entryDate)) {
            empBaseInfo.setEntryDate(DateUtil.parse(entryDate));
        }
        setDicFieldFromMap(empBaseInfo, dicMap, "EDUCATION", getImportCellValue(rowData, 12), empBaseInfo::setEducation);
        // 工龄
        String seniority = getImportCellValue(rowData, 13);
        if (StringUtils.isNotBlank(seniority)) {
            empBaseInfo.setSeniority(seniority);
        }
        setDicFieldFromMap(empBaseInfo, dicMap, "NATIVEPLACE", getImportCellValue(rowData, 14), empBaseInfo::setNativePlace);
        // 地址信息
        setIfNewOrNotBlank(empBaseInfo, isNew, getImportCellValue(rowData, 15), empBaseInfo::setCensusAddress);
        setIfNewOrNotBlank(empBaseInfo, isNew, getImportCellValue(rowData, 16), empBaseInfo::setCurrentAddress);
        setDicFieldFromMap(empBaseInfo, dicMap, "EMPTYPE", getImportCellValue(rowData, 17), empBaseInfo::setEmpType);
        // 其他字段
        setIfNewOrNotBlank(empBaseInfo, isNew, getImportCellValue(rowData, 18), empBaseInfo::setGuardNumb);
        setIfNewOrNotBlank(empBaseInfo, isNew, getImportCellValue(rowData, 19), empBaseInfo::setReturnReceipt);
        setIfNewOrNotBlank(empBaseInfo, isNew, getImportCellValue(rowData, 20), empBaseInfo::setTelePhone);
        setIfNewOrNotBlank(empBaseInfo, isNew, getImportCellValue(rowData, 21), empBaseInfo::setIntroducer);
        setIfNewOrNotBlank(empBaseInfo, isNew, getImportCellValue(rowData, 22), empBaseInfo::setBankName);
        setIfNewOrNotBlank(empBaseInfo, isNew, getImportCellValue(rowData, 23), empBaseInfo::setBankNumb);
        setDicFieldFromMap(empBaseInfo, dicMap, "INSURANCETYPE", getImportCellValue(rowData, 24), empBaseInfo::setInsuranceType);
        setIfNewOrNotBlank(empBaseInfo, isNew, getImportCellValue(rowData, 25), empBaseInfo::setSocialNumb);
        setIfNewOrNotBlank(empBaseInfo, isNew, getImportCellValue(rowData, 26), empBaseInfo::setFamily);
        setIfNewOrNotBlank(empBaseInfo, isNew, getImportCellValue(rowData, 27), empBaseInfo::setUrgencyPhone);
        setDicFieldFromMap(empBaseInfo, dicMap, "handbookStatus", getImportCellValue(rowData, 28), empBaseInfo::setHandbookStatus);
        setDicFieldFromMap(empBaseInfo, dicMap, "empCardStatus", getImportCellValue(rowData, 29), empBaseInfo::setEmpCardStatus);
        // 证件列表
        processCertificateList(empBaseInfo, dicMap, getImportCellValue(rowData, 30));
        setDicFieldFromMap(empBaseInfo, dicMap, "LZTYPE", getImportCellValue(rowData, 31), empBaseInfo::setEntryType);
        setDicFieldFromMap(empBaseInfo, dicMap, "archivesStatus", getImportCellValue(rowData, 32), empBaseInfo::setArchivesStatus);
        // 身份证有效期
        String certificateValidity = getImportCellValue(rowData, 33);
        if (isNew || StringUtils.isNotBlank(certificateValidity)) {
            empBaseInfo.setCertificateValidity(DateUtil.parse(certificateValidity));
        }
        // 设置修改信息
        if (!isNew) {
            empBaseInfo.setModifyTime(new Date());
            empBaseInfo.setModifier(operatorId);
        }
        return empBaseInfo;
    }
    /**
     * 导入上下文数据结构
     */
    private static class ImportContext {
        Map<String, EmpBaseInfo> empMap = new HashMap<>();
        Map<String, Long> certCountMap = new HashMap<>();
        Map<String, Dept> deptMap = new HashMap<>();
        Map<String, Position> positionMap = new HashMap<>();
        Map<String, Map<String, DicItem>> dicMap = new HashMap<>();
    }
    //    @Override
febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/service/impl/EmpContractInfoServiceImpl.java
@@ -27,7 +27,6 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
@@ -273,19 +272,67 @@
    @Override
    public IPage<EmpContractInfo> findRemindContractinfos(QueryRequest request, EmpContractInfo empContractinfo) {
        int diffDay = Integer.parseInt(redisService.get("contract_remind").toString());
        List<String> contractStatus = Lists.newArrayList("1","2");
        QueryWrapper<EmpContractInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("a.DelFlag", empContractinfo.getDelFlag());
        queryWrapper.eq("a.remindFlag", 0);
        queryWrapper.in("a.contractStatus", contractStatus);
        queryWrapper.in("a.empStatus", '0');
        queryWrapper.le("a.diffDay", diffDay);
        queryWrapper.ge("a.endDate", DateUtil.formatDate(new Date()));
        String rightDepts = remoteDeptService.userRightDepts();
        queryWrapper.in("c.dept_Id", remoteDeptService.userRightDepts().split(StringConstant.COMMA));
        /*
         * 原逻辑:仅查询即将到期的合同
         */
        // QueryWrapper<EmpContractInfo> queryWrapper = new QueryWrapper<>();
        // queryWrapper.eq("a.DelFlag", empContractinfo.getDelFlag());
        // queryWrapper.eq("a.remindFlag", 0);
        // queryWrapper.in("a.contractStatus", Lists.newArrayList("1","2"));
        // queryWrapper.in("a.empStatus", '0');
        // queryWrapper.le("a.diffDay", diffDay);
        // queryWrapper.ge("a.endDate", DateUtil.formatDate(new Date()));
        // queryWrapper.in("c.dept_Id", rightDepts.split(StringConstant.COMMA));
        // Page<EmpContractInfo> page = new Page<>(request.getPageNum(), request.getPageSize());
        // SortUtil.handlePageSort(request, page, "diffDay", FebsConstant.ORDER_ASC, true);
        // IPage<EmpContractInfo> iPage = empContractinfoMapper.selectPageVo(page, queryWrapper);
        /*
         * 新逻辑:查询在职人员的最后一份合同
         * 状态1或2:按原条件提醒(未到期、未提醒、在范围内)
         * 状态4:已到期末,系统中无最新合同,直接提醒
         */
        // 处理部门ID,添加引号
        String[] deptIds = rightDepts.split(StringConstant.COMMA);
        StringBuilder quotedDepts = new StringBuilder();
        for (int i = 0; i < deptIds.length; i++) {
            if (i > 0) {
                quotedDepts.append(",");
            }
            quotedDepts.append("'").append(deptIds[i]).append("'");
        }
        // 构建SQL:在职人员的最后一份合同
        // 使用INNER JOIN替代子查询,提高性能
        String today = DateUtil.formatDate(new Date());
        StringBuilder sql = new StringBuilder();
        sql.append("b.empStatus = '0'");  // 员工当前在职
        sql.append(" AND a.DelFlag = ").append(empContractinfo.getDelFlag());
        // 关联子查询获取每个人的最后一份合同
        sql.append(" AND EXISTS (");
        sql.append("SELECT 1 FROM (");
        sql.append("SELECT empId, MAX(beginDate) as maxBeginDate ");
        sql.append("FROM t_emp_contractinfo ");
        sql.append("GROUP BY empId");
        sql.append(") latest ");
        sql.append("WHERE latest.empId = a.empId AND latest.maxBeginDate = a.beginDate");
        sql.append(")");
        // 合同状态判断
        sql.append(" AND ((a.contractStatus IN ('1', '2')");  // 状态1或2
        sql.append(" AND a.remindFlag = 0");
        sql.append(" AND a.diffDay <= ").append(diffDay);
        sql.append(" AND a.endDate >= '").append(today).append("'");
        sql.append(") OR (a.contractStatus = '4'");  // 状态4
        sql.append(" AND a.endDate < '").append(today).append("'");
        sql.append("))");
        sql.append(" AND c.dept_Id IN (").append(quotedDepts).append(")");
        // 查询
        Page<EmpContractInfo> page = new Page<>(request.getPageNum(), request.getPageSize());
        SortUtil.handlePageSort(request, page, "diffDay", FebsConstant.ORDER_ASC, true);
        IPage<EmpContractInfo> iPage = empContractinfoMapper.selectPageVo(page, queryWrapper);
        IPage<EmpContractInfo> iPage = empContractinfoMapper.selectLastContractPageVo(page, sql.toString());
        List<EmpContractInfo> list = iPage.getRecords();
        //设置字典数据
        List<DicItem> dicItems = CastUtil.castList(redisService.get("dicItems"), DicItem.class);