| | |
| | | * |
| | | * @param listObject |
| | | */ |
| | | /** |
| | | * 导入员工基本信息 |
| | | * 重构后认知复杂度: ~10 (原224) |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void importEmpBaseInfo(List<List<Object>> listObject, List<String> returnList, List<DicItem> dicItems) { |
| | | // ========== 优化1:批量预加载员工数据 ========== |
| | | Set<String> empNumbs = new HashSet<>(); |
| | | for (List<Object> list : listObject) { |
| | | if (list.isEmpty()) continue; |
| | | String empNumb = getImportCellValue(list, 1); |
| | | if (StringUtils.isNotBlank(empNumb)) { |
| | | empNumbs.add(empNumb); |
| | | } |
| | | } |
| | | |
| | | // 批量查询已存在的员工,构建Map |
| | | Map<String, EmpBaseInfo> empMap = new HashMap<>(); |
| | | if (CollUtil.isNotEmpty(empNumbs)) { |
| | | List<EmpBaseInfo> existEmps = this.list( |
| | | new LambdaQueryWrapper<EmpBaseInfo>() |
| | | .in(EmpBaseInfo::getEmpNumb, empNumbs) |
| | | ); |
| | | empMap = existEmps.stream() |
| | | .collect(Collectors.toMap(EmpBaseInfo::getEmpNumb, e -> e)); |
| | | } |
| | | |
| | | // 批量查询身份证号重复情况 |
| | | Map<String, Long> certCountMap = new HashMap<>(); |
| | | if (CollUtil.isNotEmpty(empNumbs)) { |
| | | List<EmpBaseInfo> certCheckList = this.list( |
| | | new LambdaQueryWrapper<EmpBaseInfo>() |
| | | .select(EmpBaseInfo::getCertificateNumb) |
| | | .in(EmpBaseInfo::getCertificateNumb, empNumbs) |
| | | .ne(EmpBaseInfo::getDelFlag, 1) |
| | | ); |
| | | certCountMap = certCheckList.stream() |
| | | .filter(e -> StringUtils.isNotBlank(e.getCertificateNumb())) |
| | | .collect(Collectors.groupingBy( |
| | | EmpBaseInfo::getCertificateNumb, |
| | | Collectors.counting() |
| | | )); |
| | | } |
| | | |
| | | // ========== 优化2:部门/岗位数据提前转Map ========== |
| | | List<Dept> depts = CastUtil.castList(redisService.get("depts"), Dept.class); |
| | | if (CollUtil.isEmpty(depts)) { |
| | | depts = remoteDeptService.setDeptRedis(); |
| | | } |
| | | Map<String, Dept> deptMap = new HashMap<>(); |
| | | if (CollUtil.isNotEmpty(depts)) { |
| | | deptMap = depts.stream() |
| | | .collect(Collectors.toMap(Dept::getDeptName, d -> d, (v1, v2) -> v1)); |
| | | } |
| | | |
| | | List<Position> positionList = CastUtil.castList(redisService.get("position"), Position.class); |
| | | if (CollUtil.isEmpty(positionList)) { |
| | | positionList = remotePositionService.setPositionRedis(); |
| | | } |
| | | Map<String, Position> positionMap = new HashMap<>(); |
| | | if (CollUtil.isNotEmpty(positionList)) { |
| | | positionMap = positionList.stream() |
| | | .collect(Collectors.toMap(Position::getPositionName, p -> p, (v1, v2) -> v1)); |
| | | } |
| | | |
| | | // ========== 优化3:字典数据转Map ========== |
| | | Map<String, Map<String, DicItem>> dicMap = new HashMap<>(); |
| | | if (CollUtil.isNotEmpty(dicItems)) { |
| | | dicMap = dicItems.stream() |
| | | .collect(Collectors.groupingBy( |
| | | DicItem::getDicCode, |
| | | Collectors.toMap(DicItem::getDicItemName, d -> d, (v1, v2) -> v1) |
| | | )); |
| | | } |
| | | |
| | | 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> list = listObject.get(i); |
| | | if (list.isEmpty()) { |
| | | List<Object> rowData = listObject.get(i); |
| | | if (rowData.isEmpty()) { |
| | | continue; |
| | | } |
| | | |
| | | String empNumb = getImportCellValue(list, 1); |
| | | String empNumb = getImportCellValue(rowData, 1); |
| | | EmpBaseInfo dbData = context.empMap.get(empNumb); |
| | | |
| | | // ⚡ 从Map获取,不再查询数据库 |
| | | EmpBaseInfo dbData = empMap.get(empNumb); |
| | | boolean isNew = dbData == null; |
| | | EmpBaseInfo empBaseInfo = buildEmpBaseInfo(rowData, i, dbData, context.dicMap, |
| | | context.deptMap, context.positionMap, context.certCountMap, returnList, operatorId); |
| | | |
| | | // ⚡ 从Map检查身份证重复 |
| | | if (isNew && certCountMap.getOrDefault(empNumb, 0L) > 0) { |
| | | returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}身份证号重复", i + 1, empNumb)); |
| | | if (empBaseInfo == null) { |
| | | continue; |
| | | } |
| | | |
| | | EmpBaseInfo empBaseInfo = isNew ? new EmpBaseInfo() : dbData; |
| | | if (isNew) { |
| | | empBaseInfo.setEmpId(SequenceUtil.generateId(0L, ModuleCode.HR_EMPLOYEE)); |
| | | } |
| | | |
| | | String archivesNumb = getImportCellValue(list, 0); |
| | | if (isNew || StringUtils.isNotBlank(archivesNumb)) { |
| | | empBaseInfo.setArchivesNumb(archivesNumb); |
| | | } |
| | | if (isNew || StringUtils.isNotBlank(empNumb)) { |
| | | empBaseInfo.setEmpNumb(empNumb); |
| | | } |
| | | |
| | | String deptName = getImportCellValue(list, 2); |
| | | if (isNew || StringUtils.isNotBlank(deptName)) { |
| | | // ⚡ 使用Map查找 |
| | | Dept dept = deptMap.get(deptName); |
| | | if (null == dept) { |
| | | returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}部门不存在", i + 1, deptName)); |
| | | continue; |
| | | } |
| | | |
| | | empBaseInfo.setDeptName(deptName); |
| | | empBaseInfo.setAllDeptName(dept.getAllDeptName()); |
| | | empBaseInfo.setDeptId(dept.getDeptId()); |
| | | } |
| | | |
| | | String jobName = getImportCellValue(list, 3); |
| | | if (isNew || StringUtils.isNotBlank(jobName)) { |
| | | // ⚡ 使用Map查找 |
| | | Position position = positionMap.get(jobName); |
| | | if (null == position) { |
| | | returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}获取岗位为空", i + 1, jobName)); |
| | | continue; |
| | | } |
| | | empBaseInfo.setJobId(position.getPositionId()); |
| | | empBaseInfo.setJobName(jobName); |
| | | } |
| | | |
| | | String empName = getImportCellValue(list, 4); |
| | | if (isNew || StringUtils.isNotBlank(empName)) { |
| | | empBaseInfo.setEmpName(empName); |
| | | } |
| | | |
| | | String certificateNumb = getImportCellValue(list, 5); |
| | | try { |
| | | if (isNew || StrUtil.isNotBlank(certificateNumb)) { |
| | | empBaseInfo.setCertificateNumb(certificateNumb); |
| | | if (IdcardUtil.isValidCard(certificateNumb)) { |
| | | empBaseInfo.setAge(IdcardUtil.getAgeByIdCard(certificateNumb)); |
| | | empBaseInfo.setBirthdate(IdcardUtil.getBirthDate(certificateNumb)); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("导入人员身份证异常:{}", e); |
| | | returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}检查身份证是否正确", i + 1, certificateNumb)); |
| | | continue; |
| | | } |
| | | |
| | | String sex = getImportCellValue(list, 6); |
| | | if (isNew || StringUtils.isNotBlank(sex)) { |
| | | empBaseInfo.setSex("男".equals(sex) ? "1" : "2"); |
| | | } |
| | | |
| | | // 民族 - 使用字典Map查找 |
| | | String nationName = getImportCellValue(list, 7); |
| | | if (StringUtils.isNotBlank(nationName)) { |
| | | Map<String, DicItem> nationDic = dicMap.get("nation"); |
| | | if (nationDic != null) { |
| | | DicItem dicItem = nationDic.get(nationName); |
| | | if (null != dicItem) { |
| | | empBaseInfo.setNation(dicItem.getDicItemCode()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 婚姻状况 - 使用字典Map查找 |
| | | String marriageName = getImportCellValue(list, 8); |
| | | if (StringUtils.isNotBlank(marriageName)) { |
| | | Map<String, DicItem> marriageDic = dicMap.get("marriage"); |
| | | if (marriageDic != null) { |
| | | DicItem dicItem = marriageDic.get(marriageName); |
| | | if (null != dicItem) { |
| | | empBaseInfo.setMarriage(dicItem.getDicItemCode()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | String stature = getImportCellValue(list, 9); |
| | | if (StringUtils.isNotBlank(stature)) { |
| | | empBaseInfo.setStature(Integer.valueOf(stature)); |
| | | } |
| | | // 政治面貌 - 使用字典Map查找 |
| | | String politicsName = getImportCellValue(list, 10); |
| | | if (StringUtils.isNotBlank(politicsName)) { |
| | | Map<String, DicItem> politicsDic = dicMap.get("plitical"); |
| | | if (politicsDic != null) { |
| | | DicItem dicItem = politicsDic.get(politicsName); |
| | | if (null != dicItem) { |
| | | empBaseInfo.setPolitics(dicItem.getDicItemCode()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | String entryDate = getImportCellValue(list, 11); |
| | | if (StringUtils.isNotBlank(entryDate)) { |
| | | empBaseInfo.setEntryDate(DateUtil.parse(entryDate)); |
| | | } |
| | | |
| | | // 最高学历 - 使用字典Map查找 |
| | | String educationName = getImportCellValue(list, 12); |
| | | if (StringUtils.isNotBlank(educationName)) { |
| | | Map<String, DicItem> educationDic = dicMap.get("education"); |
| | | if (educationDic != null) { |
| | | DicItem dicItem = educationDic.get(educationName); |
| | | if (null != dicItem) { |
| | | empBaseInfo.setEducation(dicItem.getDicItemCode()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | String seniority = getImportCellValue(list, 13); |
| | | if (StringUtils.isNotBlank(seniority)) { |
| | | empBaseInfo.setSeniority(seniority); |
| | | } |
| | | |
| | | // 籍贯 - 使用字典Map查找 |
| | | String nativePlaceName = getImportCellValue(list, 14); |
| | | if (StringUtils.isNotBlank(nativePlaceName)) { |
| | | Map<String, DicItem> nativePlaceDic = dicMap.get("nativePlace"); |
| | | if (nativePlaceDic != null) { |
| | | DicItem dicItem = nativePlaceDic.get(nativePlaceName); |
| | | if (null != dicItem) { |
| | | empBaseInfo.setNativePlace(dicItem.getDicItemCode()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | String censusAddress = getImportCellValue(list, 15); |
| | | if (isNew || StringUtils.isNotBlank(censusAddress)) { |
| | | empBaseInfo.setCensusAddress(censusAddress); |
| | | } |
| | | String currentAddress = getImportCellValue(list, 16); |
| | | if (isNew || StringUtils.isNotBlank(currentAddress)) { |
| | | empBaseInfo.setCurrentAddress(currentAddress); |
| | | } |
| | | // 员工类型 - 使用字典Map查找 |
| | | String empTypeName = getImportCellValue(list, 17); |
| | | if (StringUtils.isNotBlank(empTypeName)) { |
| | | Map<String, DicItem> empTypeDic = dicMap.get("empType"); |
| | | if (empTypeDic != null) { |
| | | DicItem dicItem = empTypeDic.get(empTypeName); |
| | | if (null != dicItem) { |
| | | empBaseInfo.setEmpType(dicItem.getDicItemCode()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | String guardNumb = getImportCellValue(list, 18); |
| | | if (isNew || StringUtils.isNotBlank(guardNumb)) { |
| | | empBaseInfo.setGuardNumb(guardNumb); |
| | | } |
| | | String returnReceipt = getImportCellValue(list, 19); |
| | | if (isNew || StringUtils.isNotBlank(returnReceipt)) { |
| | | empBaseInfo.setReturnReceipt(returnReceipt); |
| | | } |
| | | String telePhone = getImportCellValue(list, 20); |
| | | if (isNew || StringUtils.isNotBlank(telePhone)) { |
| | | empBaseInfo.setTelePhone(telePhone); |
| | | } |
| | | String introducer = getImportCellValue(list, 21); |
| | | if (isNew || StringUtils.isNotBlank(introducer)) { |
| | | empBaseInfo.setIntroducer(introducer); |
| | | } |
| | | String bankName = getImportCellValue(list, 22); |
| | | if (isNew || StringUtils.isNotBlank(bankName)) { |
| | | empBaseInfo.setBankName(bankName); |
| | | } |
| | | String bankNumb = getImportCellValue(list, 23); |
| | | if (isNew || StringUtils.isNotBlank(bankNumb)) { |
| | | empBaseInfo.setBankNumb(bankNumb); |
| | | } |
| | | // 保险类型 - 使用字典Map查找 |
| | | String insuranceTypeName = getImportCellValue(list, 24); |
| | | if (StringUtils.isNotBlank(insuranceTypeName)) { |
| | | Map<String, DicItem> insuranceTypeDic = dicMap.get("insuranceType"); |
| | | if (insuranceTypeDic != null) { |
| | | DicItem dicItem = insuranceTypeDic.get(insuranceTypeName); |
| | | if (null != dicItem) { |
| | | empBaseInfo.setInsuranceType(dicItem.getDicItemCode()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | String socialNumb = getImportCellValue(list, 25); |
| | | if (isNew || StringUtils.isNotBlank(socialNumb)) { |
| | | empBaseInfo.setSocialNumb(socialNumb); |
| | | } |
| | | String family = getImportCellValue(list, 26); |
| | | if (isNew || StringUtils.isNotBlank(family)) { |
| | | empBaseInfo.setFamily(family); |
| | | } |
| | | String urgencyPhone = getImportCellValue(list, 27); |
| | | if (isNew || StringUtils.isNotBlank(urgencyPhone)) { |
| | | empBaseInfo.setUrgencyPhone(urgencyPhone); |
| | | } |
| | | // 员工手册 - 使用字典Map查找 |
| | | String handbookStatusName = getImportCellValue(list, 28); |
| | | if (StringUtils.isNotBlank(handbookStatusName)) { |
| | | Map<String, DicItem> handbookStatusDic = dicMap.get("handbookStatus"); |
| | | if (handbookStatusDic != null) { |
| | | DicItem dicItem = handbookStatusDic.get(handbookStatusName); |
| | | if (null != dicItem) { |
| | | empBaseInfo.setHandbookStatus(dicItem.getDicItemCode()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 工作证 - 使用字典Map查找 |
| | | String empCardStatusName = getImportCellValue(list, 29); |
| | | if (StringUtils.isNotBlank(empCardStatusName)) { |
| | | Map<String, DicItem> empCardStatusDic = dicMap.get("empCardStatus"); |
| | | if (empCardStatusDic != null) { |
| | | DicItem dicItem = empCardStatusDic.get(empCardStatusName); |
| | | if (null != dicItem) { |
| | | empBaseInfo.setEmpCardStatus(dicItem.getDicItemCode()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 相关证件 - 使用字典Map查找 |
| | | List<DicItem> dicItemList = new ArrayList<>(); |
| | | String certificateListValue = getImportCellValue(list, 30); |
| | | String[] certificateList = certificateListValue.split(StringConstant.COMMA); |
| | | if (isNew || StringUtils.isNotBlank(certificateListValue)) { |
| | | Map<String, DicItem> certificateListDic = dicMap.get("certificateList"); |
| | | for (String s : certificateList) { |
| | | if (certificateListDic != null) { |
| | | DicItem dicItem = certificateListDic.get(s); |
| | | if (null != dicItem) { |
| | | dicItemList.add(dicItem); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (CollUtil.isNotEmpty(dicItemList)) { |
| | | empBaseInfo.setCertificateList(dicItemList.stream() |
| | | .map(DicItem::getDicItemCode) |
| | | .collect(Collectors.joining(StringConstant.COMMA))); |
| | | } |
| | | |
| | | |
| | | if (isNew) { |
| | | empBaseInfo.setDelFlag(2); |
| | | } |
| | | // 入职类型 - 使用字典Map查找 |
| | | String lztypeName = getImportCellValue(list, 31); |
| | | if (StringUtils.isNotBlank(lztypeName)) { |
| | | Map<String, DicItem> lztypeDic = dicMap.get("lztype"); |
| | | if (lztypeDic != null) { |
| | | DicItem dicItem = lztypeDic.get(lztypeName); |
| | | if (null != dicItem) { |
| | | empBaseInfo.setEntryType(dicItem.getDicItemCode()); |
| | | } |
| | | } |
| | | } |
| | | // 档案情况 - 使用字典Map查找 |
| | | String archivesStatusName = getImportCellValue(list, 32); |
| | | if (StringUtils.isNotBlank(archivesStatusName)) { |
| | | Map<String, DicItem> archivesStatusDic = dicMap.get("archivesStatus"); |
| | | if (archivesStatusDic != null) { |
| | | DicItem dicItem = archivesStatusDic.get(archivesStatusName); |
| | | if (null != dicItem) { |
| | | empBaseInfo.setArchivesStatus(dicItem.getDicItemCode()); |
| | | } |
| | | } |
| | | } |
| | | // 身份证有效期 |
| | | String certificateValidity = getImportCellValue(list, 33); |
| | | if (isNew || StringUtils.isNotBlank(certificateValidity)) { |
| | | empBaseInfo.setCertificateValidity(DateUtil.parse(certificateValidity)); |
| | | } |
| | | if (isNew) { |
| | | empBaseInfo.setEmpStatus("0"); |
| | | if (dbData == null) { |
| | | newEmpList.add(empBaseInfo); |
| | | } else { |
| | | empBaseInfo.setModifyTime(new Date()); |
| | | empBaseInfo.setModifier(operatorId); |
| | | updateEmpList.add(empBaseInfo); |
| | | } |
| | | } |
| | | |
| | | // ========== 优化4:批量保存/更新 ========== |
| | | 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); |
| | | // 批量添加入职记录 |
| | | for (EmpBaseInfo emp : newEmpList) { |
| | | this.addEmpDimissLog(emp, "2", emp.getEmpId()); |
| | | newEmpList.forEach(emp -> this.addEmpDimissLog(emp, "2", emp.getEmpId())); |
| | | } |
| | | if (CollUtil.isNotEmpty(updateEmpList)) { |
| | | this.updateBatchById(updateEmpList, 100); |
| | | } |
| | | } |
| | | |
| | | 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()); |
| | | } |
| | | } |
| | | |
| | |
| | | .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.setDelFlag(2); |
| | | empBaseInfo.setEmpStatus("0"); |
| | | } |
| | | |
| | | // 设置基础字段 |
| | | 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()); |
| | | } |
| | | |
| | | // 设置岗位信息 |
| | | 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(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("导入员工基本信息异常: 出现位置第{}行, 原因:{}检查身份证是否正确", rowIndex + 1, certificateNumb)); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | // 设置性别 |
| | | 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 |
| | | public void getImage(String empId, HttpServletResponse response) throws Exception { |
| | | EmpBaseInfo empBaseInfo = this.getById(empId); |