From 4e55bd9cee8e44f7a7a0d9185d8323fc7be9193d Mon Sep 17 00:00:00 2001
From: yubo <autumnal_wind@yeah.net>
Date: 星期六, 11 四月 2026 21:14:01 +0800
Subject: [PATCH] fix(hr): 修正员工基础信息字典字段的大小写问题
---
febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/service/impl/EmpBaseInfoServiceImpl.java | 1174 ++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 937 insertions(+), 237 deletions(-)
diff --git a/febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/service/impl/EmpBaseInfoServiceImpl.java b/febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/service/impl/EmpBaseInfoServiceImpl.java
index e78f74a..5168285 100644
--- a/febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/service/impl/EmpBaseInfoServiceImpl.java
+++ b/febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/service/impl/EmpBaseInfoServiceImpl.java
@@ -28,6 +28,7 @@
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -42,6 +43,11 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.time.DayOfWeek;
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.time.temporal.ChronoUnit;
+import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
@@ -95,23 +101,24 @@
Page<EmpBaseInfo> page = new Page<>(request.getPageNum(), request.getPageSize());
SortUtil.handlePageSort(request, page, "entryDate", FebsConstant.ORDER_ASC, true);
IPage<EmpBaseInfo> iPage = empBaseInfoMapper.selectPageVo(page, createQueryWrapper(empBaseInfo));
- //设置部门
+ // 设置部门
// List<EmpBaseInfo> list = setDeptName(iPage.getRecords());
List<EmpBaseInfo> list = iPage.getRecords();
+ List<EmpBaseInfo> newList = new ArrayList<>();
List<DicItem> dicItems = CastUtil.castList(redisService.get("dicItems"), DicItem.class);
list.forEach(p -> {
p.setSexName("1".equals(p.getSex()) ? "男" : "女");
p.setArchivesStatusName("0".equals(p.getArchivesStatus()) ? "未移交" : "已移交");
- p.setEmpCardStatusName("1".equals(p.getEmpCardStatus()) ? "未发" : "已发");
- p.setHandbookStatusName("1".equals(p.getHandbookStatus()) ? "未发" : "已发");
+ p.setEmpCardStatusName("0".equals(p.getEmpCardStatus()) ? "未发" : "已发");
+ p.setHandbookStatusName("0".equals(p.getHandbookStatus()) ? "未发" : "已发");
p.setEmpStatusName("0".equals(p.getEmpStatus()) ? "在职" : "离职");
- //保险类型
+ // 保险类型
p.setInsuranceTypeName(dicItems.stream()
.filter(k -> DicCode.INSURANCETYPE.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getInsuranceType()))
.findFirst()
.map(DicItem::getDicItemName)
.orElse("未知"));
- //员工类别
+ // 员工类别
p.setEmpTypeName(dicItems.stream()
.filter(k -> DicCode.EMPTYPE.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getEmpType()))
.findFirst()
@@ -157,8 +164,23 @@
.findFirst()
.map(DicItem::getDicItemName)
.orElse(""));
- p.setCertificateListName(getCertificateListName(p.getCertificateList(),dicItems));
+ p.setCertificateListName(getCertificateListName(p.getCertificateList(), dicItems));
});
+ // if (StringUtils.isNotBlank(empBaseInfo.getCertificateList())) {
+ // String[] certificates = empBaseInfo.getCertificateList().split(",");
+ // list.forEach(k -> {
+ // String[] dbCertificates = k.getCertificateList().split(",");
+ // for (String certificate : certificates) {
+ // if (Arrays.asList(dbCertificates).contains(certificate)) {
+ // newList.add(k);
+ // break;
+ // }
+ // }
+ // });
+ // iPage.setRecords(newList);
+ // } else {
+ // iPage.setRecords(list);
+ // }
iPage.setRecords(list);
return iPage;
}
@@ -194,12 +216,28 @@
empBaseInfo.setModifier(operatorId);
this.saveOrUpdate(empBaseInfo);
+ addEmpDimissLog(empBaseInfo, operatorId, empId);
+ }
+
+ /**
+ * 增加员工后同步增加入职记录
+ * <p>
+ * date 2021-07-30 09:12
+ *
+ * @param empBaseInfo 员工信息
+ * @param operatorId 操作员Id
+ * @param empId 员工Id
+ * @return void
+ * @author: luoyibo
+ */
+ private void addEmpDimissLog(EmpBaseInfo empBaseInfo, String operatorId, Long empId) {
EmpDimissionLog dimissionLog = new EmpDimissionLog();
dimissionLog.setCloseId(SequenceUtil.generateId(0L, ModuleCode.HR_EMPLOYEE));
dimissionLog.setEmpId(empId);
dimissionLog.setEntryDate(empBaseInfo.getEntryDate());
dimissionLog.setDimissionType("20");
dimissionLog.setRemark(empBaseInfo.getRemark());
+ dimissionLog.setDeptName(empBaseInfo.getAllDeptName());
dimissionLog.setCreator(operatorId);
dimissionLog.setModifier(operatorId);
@@ -257,8 +295,8 @@
List<String> list = new ArrayList<>(Arrays.asList(str));
empBaseInfoMapper.logicDeleteByIds(list, operatorId);
- //同步删除关联数据
- //不良记录
+ // 同步删除关联数据
+ // 不良记录
empBadRecordMapper.logicDelByUserIds(list, operatorId);
empAccidentCasesMapper.logicDelByUserIds(list, operatorId);
empContractInfoMapper.logicDelByUserIds(list, operatorId);
@@ -324,6 +362,10 @@
String operatorId = Optional.of(FebsUtil.getUserId()).orElse("1");
String[] str = ids.split(",");
List<String> list = new ArrayList<>(Arrays.asList(str));
+// for (int i = 0, j = str.length; i < j; i++) {
+// EmpBaseInfo emp = this.getById(str[i]);
+// addEmpDimissLog(emp, operatorId, Long.valueOf(str[i]));
+// }
return empBaseInfoMapper.momentToNormal(list, operatorId) > 0;
}
@@ -349,6 +391,7 @@
public boolean closeEmpArchives(EmpDimissionLog empDimissionLog) {
String operatorId = Optional.of(FebsUtil.getUserId()).orElse("1");
String[] str = empDimissionLog.getEmpIds().split(",");
+ String[] empDeptNames = empDimissionLog.getDeptNames().split(",");
List<String> list = new ArrayList<>(Arrays.asList(str));
String[] strDate = empDimissionLog.getEntryDates().split(",");
@@ -365,6 +408,7 @@
dimissionLog.setReporter(empDimissionLog.getReporter());
dimissionLog.setCreator(operatorId);
dimissionLog.setModifier(operatorId);
+ dimissionLog.setDeptName(empDeptNames[i]);
dimissionLogService.save(dimissionLog);
}
@@ -376,11 +420,11 @@
}
switch (flag) {
case 1:
- //解除合同
+ // 解除合同
empContractInfoMapper.terminateContract(new ArrayList<>(Arrays.asList(empDimissionLog.getEmpIds().split(StringConstant.COMMA))), operatorId);
break;
case 2:
- //禁用账户
+ // 禁用账户
iRemoteUserService.updateStatus(empDimissionLog.getCertificateNumb());
break;
case 3:
@@ -447,183 +491,373 @@
*
* @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) {
- 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()));
- continue;
- }
- EmpBaseInfo empBaseInfo = new EmpBaseInfo();
- empBaseInfo.setEmpId(SequenceUtil.generateId(0L, ModuleCode.HR_EMPLOYEE));
- empBaseInfo.setArchivesNumb(list.get(0).toString());
- empBaseInfo.setEmpNumb(list.get(1).toString());
+ ImportContext context = prepareImportContext(listObject, dicItems);
+ String operatorId = FebsUtil.getUserId();
+ List<EmpBaseInfo> newEmpList = new ArrayList<>();
+ List<EmpBaseInfo> updateEmpList = new ArrayList<>();
- 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()));
+ for (int i = 0; i < listObject.size(); i++) {
+ List<Object> rowData = listObject.get(i);
+ if (rowData.isEmpty()) {
continue;
}
- empBaseInfo.setAllDeptName(dept.getAllDeptName());
+ String empNumb = getImportCellValue(rowData, 1);
+ EmpBaseInfo dbData = context.empMap.get(empNumb);
- 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;
- }
- 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 empBaseInfo = buildEmpBaseInfo(rowData, i, dbData, context.dicMap,
+ context.deptMap, context.positionMap, context.certCountMap, returnList, operatorId);
- } catch (Exception e) {
- log.error("导入人员身份证异常:{}", e);
- returnList.add(StrUtil.format("导入员工基本信息异常: 出现位置第{}行, 原因:{}检查身份证是否正确", listObject.indexOf(list) + 1, list.get(5).toString()));
+ if (empBaseInfo == null) {
continue;
}
-
- 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());
+ if (dbData == null) {
+ newEmpList.add(empBaseInfo);
+ } else {
+ updateEmpList.add(empBaseInfo);
}
+ }
- //婚姻状况
- 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());
- }
+ batchSaveEmployees(newEmpList, updateEmpList, operatorId);
+ }
- 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());
- }
+ /**
+ * 准备导入上下文数据
+ */
+ private ImportContext prepareImportContext(List<List<Object>> listObject, List<DicItem> dicItems) {
+ ImportContext context = new ImportContext();
- if (StringUtils.isNotBlank(list.get(11).toString())) {
- empBaseInfo.setEntryDate(DateUtil.parseDate(list.get(11).toString()));
- }
+ // 收集员工编号
+ Set<String> empNumbs = listObject.stream()
+ .filter(list -> !list.isEmpty())
+ .map(list -> getImportCellValue(list, 1))
+ .filter(StringUtils::isNotBlank)
+ .collect(Collectors.toSet());
- //最高学历
- 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());
- }
+ // 批量查询已存在的员工
+ context.empMap = CollUtil.isEmpty(empNumbs) ? new HashMap<>() :
+ this.list(new LambdaQueryWrapper<EmpBaseInfo>().in(EmpBaseInfo::getEmpNumb, empNumbs))
+ .stream()
+ .collect(Collectors.toMap(EmpBaseInfo::getEmpNumb, e -> e));
- if (StringUtils.isNotBlank(list.get(13).toString())) {
- empBaseInfo.setSeniority(list.get(13).toString());
- }
+ // 批量查询身份证号重复情况
+ 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()));
- //籍贯
- 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());
- }
+ // 部门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));
- 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());
- }
+ // 岗位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));
- 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());
- }
+ // 字典Map
+ context.dicMap = CollUtil.isEmpty(dicItems) ? new HashMap<>() :
+ dicItems.stream().collect(Collectors.groupingBy(
+ DicItem::getDicCode,
+ Collectors.toMap(DicItem::getDicItemName, d -> d, (v1, v2) -> v1)));
- 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());
- }
+ return context;
+ }
- //工作证
- 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.setEmpStatus("0");
- this.save(empBaseInfo);
+ /**
+ * 批量保存员工数据
+ */
+ 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);
}
}
- @Override
+ /**
+ * 从字典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.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);
if (StrUtil.isBlank(empBaseInfo.getImagePath())) {
@@ -632,7 +866,7 @@
String path = properties.getEmpBaseInfoPath() + empBaseInfo.getImagePath();
try (InputStream inputStream = new FileInputStream(path); OutputStream out = response.getOutputStream()) {
- //byte数组用于存放图片字节数据
+ // byte数组用于存放图片字节数据
byte[] buff = new byte[inputStream.available()];
inputStream.read(buff);
@@ -640,7 +874,7 @@
String contentType = empBaseInfo.getImagePath().substring(empBaseInfo.getImagePath().lastIndexOf(".") + 1);
if (contentType.equals("tif")) {
- //设置发送到客户端的响应内容类型
+ // 设置发送到客户端的响应内容类型
response.setContentType("image/tiff");
} else if (contentType.equals("bmp")) {
response.setContentType("application/x-bmp");
@@ -668,26 +902,26 @@
}
String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
List<String> lists = Arrays.asList(split);
- if ("1".equals(number)) { //在职员工
+ if ("1".equals(number)) { // 在职员工
iPage = this.empBaseInfoMapper.zzbaseInfoList(page, index, btime, etime, name, lists);
- } else if ("2".equals(number)) { //新进员工
+ } else if ("2".equals(number)) { // 新进员工
iPage = this.empBaseInfoMapper.xjbaseInfoList(page, index, btime, etime, name, lists);
- } else if ("3".equals(number)) { //正式员工
+ } else if ("3".equals(number)) { // 正式员工
iPage = this.empBaseInfoMapper.zsbaseInfoList(page, index, btime, etime, name, lists);
- } else if ("4".equals(number)) { //临时员工
+ } else if ("4".equals(number)) { // 临时员工
iPage = this.empBaseInfoMapper.lsbaseInfoList(page, index, btime, etime, name, lists);
- } else if ("5".equals(number)) { //超龄员工
+ } else if ("5".equals(number)) { // 超龄员工
iPage = this.empBaseInfoMapper.clbaseInfoList(page, index, btime, etime, name, manOld, womanOld, lists);
- } else if ("6".equals(number)) { //离职员工总数
+ } else if ("6".equals(number)) { // 离职员工总数
iPage = this.empBaseInfoMapper.lzbaseInfoList(page, index, btime, etime, name, lists);
- } else if ("7".equals(number)) { //辞职申请人数
+ } else if ("7".equals(number)) { // 辞职申请人数
iPage = this.empBaseInfoMapper.cjbaseInfoList(page, index, btime, etime, name, lists);
- } else if ("8".equals(number) || "9".equals(number) || "10".equals(number)) { //正常离职人数 ,自动离职人数 ,公司辞退人数
+ } else if ("8".equals(number) || "9".equals(number) || "10".equals(number)) { // 正常离职人数 ,自动离职人数 ,公司辞退人数
iPage = this.empBaseInfoMapper.zcbaseInfoList(page, index, btime, etime, name, number, lists);
- } else if ("11".equals(number)) { //身份证到期
+ } else if ("11".equals(number)) { // 身份证到期
iPage = this.empBaseInfoMapper.sfzbaseInfoList(page, index, btime, etime, name, lists);
}
- //设置部门
+ // 设置部门
List<EmpBaseInfo> list = setDeptName(iPage.getRecords());
List<DicItem> dicItems = CastUtil.castList(redisService.get("dicItems"), DicItem.class);
list.forEach(p -> {
@@ -696,17 +930,22 @@
p.setEmpTypeName("1".equals(p.getEmpType()) ? "正式工" : "临时工");
}
if (StringUtils.isNotBlank(p.getDimissionType())) {
- if ("1".equals(p.getDimissionType())) {
- p.setDimissionTypeName("正常离职");
- } else if ("2".equals(p.getDimissionType())) {
- p.setDimissionTypeName("自动离职");
- } else if ("3".equals(p.getDimissionType())) {
- p.setDimissionTypeName("公司劝退");
- } else if ("4".equals(p.getDimissionType())) {
- p.setDimissionTypeName("公司辞退");
- } else if ("5".equals(p.getDimissionType())) {
- p.setDimissionTypeName("试用期内");
- }
+ // if ("1".equals(p.getDimissionType())) {
+ // p.setDimissionTypeName("正常离职");
+ // } else if ("2".equals(p.getDimissionType())) {
+ // p.setDimissionTypeName("自动离职");
+ // } else if ("3".equals(p.getDimissionType())) {
+ // p.setDimissionTypeName("公司劝退");
+ // } else if ("4".equals(p.getDimissionType())) {
+ // p.setDimissionTypeName("公司辞退");
+ // } else if ("5".equals(p.getDimissionType())) {
+ // p.setDimissionTypeName("试用期内");
+ // }
+ p.setDimissionTypeName(dicItems.stream()
+ .filter(k -> DicCode.IN_OUT_TYPE.equals(k.getDicCode()) && k.getDicItemCode().equals(p.getDimissionType()))
+ .findFirst()
+ .map(DicItem::getDicItemName)
+ .orElse(""));
}
p.setInsuranceTypeName("1".equals(p.getInsuranceType()) ? "(深户)五险一档" : "(非深户)五险一档");
p.setArchivesStatusName("0".equals(p.getArchivesStatus()) ? "未移交" : "已移交");
@@ -751,14 +990,14 @@
IPage<EmpBaseInfo> iPage = null;
String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
List<String> lists = Arrays.asList(split);
- if ("11".equals(number) || "13".equals(number) || "14".equals(number)) { //有效合同 ,新签合同,续签合同
+ if ("11".equals(number) || "13".equals(number) || "14".equals(number)) { // 有效合同 ,新签合同,续签合同
iPage = this.empBaseInfoMapper.yxbaseInfoList(page, index, btime, etime, name, number, lists);
- } else if ("12".equals(number)) { //到期合同
+ } else if ("12".equals(number)) { // 到期合同
iPage = this.empBaseInfoMapper.dqbaseInfoList(page, index, btime, etime, name, lists);
- } else if ("15".equals(number)) { //解除合同
+ } else if ("15".equals(number)) { // 解除合同
iPage = this.empBaseInfoMapper.jcseInfoList(page, index, btime, etime, name, lists);
}
- //设置部门
+ // 设置部门
List<EmpBaseInfo> list = setDeptName(iPage.getRecords());
list.forEach(p -> {
if ("1".equals(p.getContractStatus())) {
@@ -779,7 +1018,7 @@
public IPage<EmpDimissionAttend> empBaseInfoCqList(String index, String btime, String etime, String pageSize, String pageNum, String number, String name) {
Page<EmpDimissionAttend> page = new Page<EmpDimissionAttend>(new Long(pageNum), new Long(pageSize));
IPage<EmpDimissionAttend> iPage = null;
- //q出勤人数 员工加班 员工旷工
+ // q出勤人数 员工加班 员工旷工
String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
List<String> lists = Arrays.asList(split);
iPage = this.empBaseInfoMapper.empBaseInfoCqList(page, index, btime, etime, name, number, lists);
@@ -791,7 +1030,7 @@
public IPage<EmpLeaveInfo> empBaseInfoQjList(String index, String btime, String etime, String pageSize, String pageNum, String number, String name) {
Page<EmpLeaveInfo> page = new Page<EmpLeaveInfo>(new Long(pageNum), new Long(pageSize));
IPage<EmpLeaveInfo> iPage = null;
- //员工请假
+ // 员工请假
String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
List<String> lists = Arrays.asList(split);
iPage = this.empBaseInfoMapper.empBaseInfoQjList(page, index, btime, etime, name, number, lists);
@@ -802,7 +1041,7 @@
public IPage<EmpPhysicalExam> empBaseInfoTjList(String index, String btime, String etime, String pageSize, String pageNum, String number, String name) {
Page<EmpPhysicalExam> page = new Page<EmpPhysicalExam>(new Long(pageNum), new Long(pageSize));
IPage<EmpPhysicalExam> iPage = null;
- //员工体检
+ // 员工体检
String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
List<String> lists = Arrays.asList(split);
iPage = this.empBaseInfoMapper.empBaseInfoTjList(page, index, btime, etime, name, number, lists);
@@ -813,7 +1052,7 @@
public IPage<EmpLaborTrouble> empBaseInfoLzList(String index, String btime, String etime, String pageSize, String pageNum, String number, String name) {
Page<EmpLaborTrouble> page = new Page<EmpLaborTrouble>(new Long(pageNum), new Long(pageSize));
IPage<EmpLaborTrouble> iPage = null;
- //劳资案件
+ // 劳资案件
String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
List<String> lists = Arrays.asList(split);
iPage = this.empBaseInfoMapper.empBaseInfoLzList(page, index, btime, etime, name, number, lists);
@@ -824,7 +1063,7 @@
public IPage<EmpJobChange> empBaseInfoTgList(String index, String btime, String etime, String pageSize, String pageNum, String number, String name) {
Page<EmpJobChange> page = new Page<EmpJobChange>(new Long(pageNum), new Long(pageSize));
IPage<EmpJobChange> iPage = null;
- //调岗
+ // 调岗
String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
List<String> lists = Arrays.asList(split);
iPage = this.empBaseInfoMapper.empBaseInfoTgList(page, index, btime, etime, name, number, lists);
@@ -835,7 +1074,7 @@
public IPage<EmpOccupational> empBaseInfoGsList(String index, String btime, String etime, String pageSize, String pageNum, String number, String name) {
Page<EmpOccupational> page = new Page<EmpOccupational>(new Long(pageNum), new Long(pageSize));
IPage<EmpOccupational> iPage = null;
- //工伤案件
+ // 工伤案件
String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
List<String> lists = Arrays.asList(split);
iPage = this.empBaseInfoMapper.empBaseInfoGsList(page, index, btime, etime, name, number, lists);
@@ -846,7 +1085,7 @@
public IPage<EmpAccidentCases> empBaseInfoYwList(String index, String btime, String etime, String pageSize, String pageNum, String number, String name) {
Page<EmpAccidentCases> page = new Page<EmpAccidentCases>(new Long(pageNum), new Long(pageSize));
IPage<EmpAccidentCases> iPage = null;
- //意外险案件
+ // 意外险案件
String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
List<String> lists = Arrays.asList(split);
iPage = this.empBaseInfoMapper.empBaseInfoYwList(page, index, btime, etime, name, number, lists);
@@ -857,7 +1096,7 @@
public IPage<EmpInsurance> empBaseInfoSbList(String index, String btime, String etime, String pageSize, String pageNum, String number, String name) {
Page<EmpInsurance> page = new Page<EmpInsurance>(new Long(pageNum), new Long(pageSize));
IPage<EmpInsurance> iPage = null;
- //社保
+ // 社保
String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
List<String> lists = Arrays.asList(split);
iPage = this.empBaseInfoMapper.empBaseInfoSbList(page, index, btime, etime, name, number, lists);
@@ -868,7 +1107,7 @@
public IPage<EmpUnemployment> empBaseInfoSyjList(String index, String btime, String etime, String pageSize, String pageNum, String number, String name) {
Page<EmpUnemployment> page = new Page<EmpUnemployment>(new Long(pageNum), new Long(pageSize));
IPage<EmpUnemployment> iPage = null;
- //失业金
+ // 失业金
String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
List<String> lists = Arrays.asList(split);
iPage = this.empBaseInfoMapper.empBaseInfoSyjList(page, index, btime, etime, name, number, lists);
@@ -879,7 +1118,7 @@
public IPage<EmpBadRecord> empBaseInfoBlList(String index, String btime, String etime, String pageSize, String pageNum, String number, String name) {
Page<EmpBadRecord> page = new Page<EmpBadRecord>(new Long(pageNum), new Long(pageSize));
IPage<EmpBadRecord> iPage = null;
- //不良记录
+ // 不良记录
String[] split = remoteDeptService.userRightDepts().split(StringConstant.COMMA);
List<String> lists = Arrays.asList(split);
iPage = this.empBaseInfoMapper.empBaseInfoBlList(page, index, btime, etime, name, number, lists);
@@ -897,56 +1136,56 @@
}
QueryWrapper queryWrapper = new QueryWrapper();
queryWrapper.in("t1.dept_Id", remoteDeptService.userRightDepts().split(StringConstant.COMMA));
- //在职员工,正式员工,临时员工,超龄员工
+ // 在职员工,正式员工,临时员工,超龄员工
Map<String, Object> stringObjectMap = this.baseMapper.countBaseInfoList(index, btime, etime, manOld, womanOld, queryWrapper);
- //正常离职,自动离职,公司辞退 判断条件创建日期
+ // 正常离职,自动离职,公司辞退 判断条件创建日期
Map<String, Object> zclzObjectMap = this.baseMapper.countZcygBaseInfoList(index, btime, etime, queryWrapper);
if (zclzObjectMap != null) {
stringObjectMap.put("zclz", zclzObjectMap.get("zclz").toString());
stringObjectMap.put("zdlz", zclzObjectMap.get("zdlz").toString());
stringObjectMap.put("gsct", zclzObjectMap.get("gsct").toString());
}
- //新进员工 判断条件入职日期
+ // 新进员工 判断条件入职日期
Integer xjygObjectMap = this.baseMapper.countXjygBaseInfoList(index, btime, etime, queryWrapper);
if (xjygObjectMap != null) {
stringObjectMap.put("xjyg", xjygObjectMap);
}
- //离职员工总数
+ // 离职员工总数
Integer empStatus = this.baseMapper.selectCountlz(new QueryWrapper<EmpBaseInfo>()
.eq("t.delFlag", 0).eq("t.empStatus", 1)
.in("t1.dept_Id", remoteDeptService.userRightDepts().split(StringConstant.COMMA)));
if (empStatus != null) {
stringObjectMap.put("lzyg", empStatus);
}
- //解除合同 判断条件离职申请日期
+ // 解除合同 判断条件离职申请日期
Map<String, Object> lzygObjectMap = this.baseMapper.countLzygBaseInfoList(index, btime, etime, queryWrapper);
if (lzygObjectMap != null) {
stringObjectMap.put("jcht", lzygObjectMap.get("jcht").toString());
}
- //辞职申请员工总数 判断条件辞职申请日期
+ // 辞职申请员工总数 判断条件辞职申请日期
Integer czygObjectMap = this.baseMapper.countCzygBaseInfoList(index, btime, etime, queryWrapper);
if (czygObjectMap != null) {
stringObjectMap.put("czyg", czygObjectMap);
}
- //有效合同 判断条件合同签订日期
+ // 有效合同 判断条件合同签订日期
Map<String, Object> yxhtObjectMap = this.baseMapper.countYxhtBaseInfoList(index, btime, etime, queryWrapper);
if (yxhtObjectMap != null) {
stringObjectMap.put("yxht", yxhtObjectMap.get("yxht").toString());
}
- //新签合同,续签合同 判断条件合同签订日期
+ // 新签合同,续签合同 判断条件合同签订日期
Map<String, Object> xqhtObjectMap = this.baseMapper.countXqhtBaseInfoList(index, btime, etime, queryWrapper);
if (yxhtObjectMap != null) {
stringObjectMap.put("xinqht", xqhtObjectMap.get("xinqht").toString());
stringObjectMap.put("xqht", xqhtObjectMap.get("xqht").toString());
}
- //到期合同 判断条件合同结束时间
+ // 到期合同 判断条件合同结束时间
Integer dqhtObjectMap = this.baseMapper.countDqhtBaseInfoList(index, btime, etime, queryWrapper);
if (dqhtObjectMap != null) {
stringObjectMap.put("dqht", dqhtObjectMap);
}
- //出勤人数,员工加班,员工旷工 判断条件考勤月份 本年,本月
+ // 出勤人数,员工加班,员工旷工 判断条件考勤月份 本年,本月
Map<String, Object> cqrsObjectMap = this.baseMapper.countCqrsBaseInfoList(index, btime, etime, queryWrapper);
if (cqrsObjectMap != null) {
stringObjectMap.put("cqrs", cqrsObjectMap.get("cqrs").toString());
@@ -954,55 +1193,74 @@
stringObjectMap.put("ygkg", cqrsObjectMap.get("ygkg").toString());
}
- //员工请假 判断条件到岗时间
+ // 员工请假 判断条件到岗时间
Integer ygqjObjectMap = this.baseMapper.countYgqjBaseInfoList(index, btime, etime, queryWrapper);
if (ygqjObjectMap != null) {
stringObjectMap.put("ygqj", ygqjObjectMap);
}
- //劳资案件 判断条件仲裁日期
+ // 劳资案件 判断条件仲裁日期
Integer lzajObjectMap = this.baseMapper.countLzajBaseInfoList(index, btime, etime, queryWrapper);
if (lzajObjectMap != null) {
stringObjectMap.put("lzaj", lzajObjectMap);
}
- //工伤案件,意外险案件 判断条件受伤日期
+ // 工伤案件,意外险案件 判断条件受伤日期
Map<String, Object> gsajObjectMap = this.baseMapper.countGsajBaseInfoList(index, btime, etime, queryWrapper);
if (gsajObjectMap != null) {
stringObjectMap.put("gsaj", gsajObjectMap.get("gsaj").toString());
stringObjectMap.put("ywxaj", gsajObjectMap.get("ywxaj").toString());
}
- //社保申请 判断条件社保申请日期
+ // 社保申请 判断条件社保申请日期
Integer sbsqObjectMap = this.baseMapper.countSbsqBaseInfoList(index, btime, etime, queryWrapper);
if (sbsqObjectMap != null) {
stringObjectMap.put("sbsq", sbsqObjectMap);
}
- //失业金领取 判断条件失业金申请日期
+ // 失业金领取 判断条件失业金申请日期
Integer syjObjectMap = this.baseMapper.countSyjBaseInfoList(index, btime, etime, queryWrapper);
if (syjObjectMap != null) {
stringObjectMap.put("syj", syjObjectMap);
}
- //员工体检 判断条件体检日期
+ // 员工体检 判断条件体检日期
Integer ygtjObjectMap = this.baseMapper.countYgtjBaseInfoList(index, btime, etime, queryWrapper);
if (ygtjObjectMap != null) {
stringObjectMap.put("ygtj", ygtjObjectMap);
}
- //身份证到期 判断条件身份证有效时间
+ // 身份证到期 判断条件身份证有效时间
Integer sfzObjectMap = this.baseMapper.countSfzBaseInfoList(index, btime, etime, queryWrapper);
if (sfzObjectMap != null) {
stringObjectMap.put("sfz", sfzObjectMap);
}
- //员工调岗 判断条件身份证有效时间
+ // 员工调岗 判断条件身份证有效时间
Integer ygtgObjectMap = this.baseMapper.countYgtgBaseInfoList(index, btime, etime, queryWrapper);
if (ygtgObjectMap != null) {
stringObjectMap.put("ygtg", ygtgObjectMap);
}
- //不良记录 判断条件身份证有效时间
+ // 不良记录 判断条件身份证有效时间
Integer bljlObjectMap = this.baseMapper.countBljlBaseInfoList(index, btime, etime, queryWrapper);
if (bljlObjectMap != null) {
stringObjectMap.put("bljl", bljlObjectMap);
}
+ // 试用提醒 判断条件试用期结束时间
+ EmpBaseInfo empBaseInfo = new EmpBaseInfo();
+ empBaseInfo.setTimeRange(Integer.valueOf(index));
+ Long count = empBaseInfoMapper.selectAlertCount(
+ createProbationAlertQueryWrapper(empBaseInfo)
+ );
+ if (count != null) {
+ stringObjectMap.put("probationCount", count);
+ }
+
+ // 四险提醒 判断条件试用期结束时间
+ empBaseInfo = new EmpBaseInfo();
+ empBaseInfo.setTimeRange(Integer.valueOf(index));
+ QueryRequest queryRequest = new QueryRequest();
+ count = this.countInsuranceAlert(empBaseInfo, queryRequest);
+ if (count != null) {
+ stringObjectMap.put("insuranceCount", count);
+ }
+ // QueryRequest request
return stringObjectMap;
}
@@ -1034,13 +1292,13 @@
private QueryWrapper<EmpBaseInfo> createQueryWrapper(EmpBaseInfo empBaseInfo) {
QueryWrapper<EmpBaseInfo> queryWrapper = new QueryWrapper<>();
- //记录的状态,0-正常 1-删除 2-暂存
+ // 记录的状态,0-正常 1-删除 2-暂存
if (StringUtils.isNotBlank(empBaseInfo.getDelFlag().toString())) {
queryWrapper.eq("a.DelFlag", empBaseInfo.getDelFlag());
} else {
queryWrapper.eq("a.DelFlag", 0);
}
- //人员的状态,0-在职 1-离职 2-退休
+ // 人员的状态,0-在职 1-离职 2-退休
if (StringUtils.isNotBlank(empBaseInfo.getEmpStatus())) {
queryWrapper.in("a.EmpStatus", empBaseInfo.getEmpStatus().split(","));
}
@@ -1138,7 +1396,7 @@
p.in("a.dimissionType", empBaseInfo.getInOutType().split(","));
p.or().in("a.entryType", empBaseInfo.getInOutType().split(","));
});
- //queryWrapper.in("a.dimissionType", empBaseInfo.getDimissionType().split(","));
+ // queryWrapper.in("a.dimissionType", empBaseInfo.getDimissionType().split(","));
}
if (StringUtils.isNotBlank(empBaseInfo.getCertificateList())) {
String[] certificates = empBaseInfo.getCertificateList().split(",");
@@ -1146,8 +1404,8 @@
@Override
public void accept(QueryWrapper<EmpBaseInfo> wrapper) {
for (int i = 0; i < certificates.length; i++) {
- String ageBtn = certificates[i];
- wrapper.or().like("a.certificateList", ageBtn);
+ String ageBtn = "|" + certificates[i] + "|";
+ wrapper.gt("LOCATE('" + ageBtn + "',CONCAT('|',replace( certificateList, ',', '|,|'),'|'))", 0);
}
}
};
@@ -1191,7 +1449,7 @@
@Override
public void exportEmpAll(HttpServletResponse response, EmpBaseInfo empBaseinfo) throws IOException {
- //获取字典
+ // 获取字典
List<DicItem> dicItemList = remoteDicItemService.getAllDicitemsAll();
Map<String, Object> map = new HashMap<>();
@@ -1204,7 +1462,7 @@
});
List<String> sheetNames = new ArrayList<>();
sheetNames.add("基本信息");
- //基本信息
+ // 基本信息
QueryRequest request = new QueryRequest();
request.setPageSize(25535);
request.setPageNum(1);
@@ -1216,7 +1474,7 @@
Page<EmpBaseInfo> page = new Page<>(request.getPageNum(), request.getPageSize());
List<Long> empIds = exportList.stream().map(i -> i.getEmpId()).collect(Collectors.toList());
- //工作经历
+ // 工作经历
IPage<EmpWorkExperience> workExperienceIPage = empWorkExperienceMapper.selectPageVo(page, new QueryWrapper<EmpWorkExperience>().in("a.empId", empIds).ne("a.delFlag", 1));
if (workExperienceIPage.getRecords().size() != 0) {
exportField = FebsUtil.reflectAnnotation(EmpWorkExperience.class);
@@ -1225,7 +1483,7 @@
sheetNames.add("工作经历");
}
- //体检信息
+ // 体检信息
IPage<EmpPhysicalExam> empPhysicalExamIPage = empPhysicalExamMapper.selectPageVo(page, new QueryWrapper<EmpPhysicalExam>().in("a.empId", empIds).ne("a.delFlag", 1));
if (empPhysicalExamIPage.getRecords().size() != 0) {
exportField = FebsUtil.reflectAnnotation(EmpWorkExperience.class);
@@ -1234,7 +1492,7 @@
sheetNames.add("体检信息");
}
- //调岗记录
+ // 调岗记录
IPage<EmpJobChange> jobChangeIPage = empJobChangeMapper.selectPageVoBean(page, new QueryWrapper<EmpJobChange>().in("a.empId", empIds).ne("a.delFlag", 1));
if (jobChangeIPage.getRecords().size() != 0) {
exportField = FebsUtil.reflectAnnotation(EmpJobChange.class);
@@ -1243,7 +1501,7 @@
sheetNames.add("调岗记录");
}
- //合同信息
+ // 合同信息
IPage<EmpContractInfo> empContractInfoIPage = empContractInfoMapper.selectPageVo(page, new QueryWrapper<EmpContractInfo>().in("a.empId", empIds).ne("a.delFlag", 1));
if (empContractInfoIPage.getRecords().size() != 0) {
exportField = FebsUtil.reflectAnnotation(EmpContractInfo.class);
@@ -1252,7 +1510,7 @@
sheetNames.add("合同信息");
}
- //入离职记录
+ // 入离职记录
IPage<EmpDimissionAttend> empDimissionAttendIPage = empDimissionAttendMapper.selectPageVo(page, new QueryWrapper<EmpDimissionAttend>().in("a.empId", empIds).ne("a.delFlag", 1));
if (empDimissionAttendIPage.getRecords().size() != 0) {
exportField = FebsUtil.reflectAnnotation(EmpDimissionAttend.class);
@@ -1261,7 +1519,7 @@
sheetNames.add("入离职记录");
}
- //请假记录
+ // 请假记录
IPage<EmpLeaveInfo> empLeaveInfoIPage = empLeaveInfoMapper.selectPageVo(page, new QueryWrapper<EmpLeaveInfo>().in("a.empId", empIds).ne("a.delFlag", 1));
if (empLeaveInfoIPage.getRecords().size() != 0) {
exportField = FebsUtil.reflectAnnotation(EmpLeaveInfo.class);
@@ -1271,7 +1529,7 @@
}
- //失业金领取
+ // 失业金领取
IPage<EmpUnemployment> empUnemploymentIPage = empUnemploymentMapper.selectPageVo(page, new QueryWrapper<EmpUnemployment>().in("a.empId", empIds).ne("a.delFlag", 1));
if (empUnemploymentIPage.getRecords().size() != 0) {
exportField = FebsUtil.reflectAnnotation(EmpUnemployment.class);
@@ -1280,7 +1538,7 @@
sheetNames.add("失业金领取");
}
- //社保申请
+ // 社保申请
IPage<EmpInsurance> empInsuranceIPage = empInsuranceMapper.selectPageVo(page, new QueryWrapper<EmpInsurance>().in("a.empId", empIds).ne("a.delFlag", 1));
if (empInsuranceIPage.getRecords().size() != 0) {
exportField = FebsUtil.reflectAnnotation(EmpInsurance.class);
@@ -1290,7 +1548,7 @@
}
- //意外险案件
+ // 意外险案件
IPage<EmpAccidentCases> empAccidentCasesIPage = empAccidentCasesMapper.selectPageVo(page, new QueryWrapper<EmpInsurance>().in("a.empId", empIds).ne("a.delFlag", 1));
if (empAccidentCasesIPage.getRecords().size() != 0) {
exportField = FebsUtil.reflectAnnotation(EmpAccidentCases.class);
@@ -1299,7 +1557,7 @@
sheetNames.add("意外险案件");
}
- //工伤案件
+ // 工伤案件
IPage<EmpOccupational> empOccupationalIPage = empOccupationalMapper.selectPageVo(page, new QueryWrapper<EmpOccupational>().in("a.empId", empIds).ne("a.delFlag", 1));
if (empOccupationalIPage.getRecords().size() != 0) {
exportField = FebsUtil.reflectAnnotation(EmpOccupational.class);
@@ -1308,7 +1566,7 @@
sheetNames.add("工伤案件");
}
- //劳资案件
+ // 劳资案件
IPage<EmpLaborTrouble> empLaborTroubleIPage = empLaborTroubleMapper.selectPageVo(page, new QueryWrapper<EmpInsurance>().in("a.empId", empIds).ne("a.delFlag", 1));
if (empLaborTroubleIPage.getRecords().size() != 0) {
exportField = FebsUtil.reflectAnnotation(EmpLaborTrouble.class);
@@ -1318,7 +1576,7 @@
}
- //不良记录
+ // 不良记录
IPage<EmpBadRecord> empBadRecordIPage = empBadRecordMapper.selectPageVo(page, new QueryWrapper<EmpInsurance>().in("a.empId", empIds).ne("a.delFlag", 1));
if (empBadRecordIPage.getRecords().size() != 0) {
exportField = FebsUtil.reflectAnnotation(EmpBadRecord.class);
@@ -1328,7 +1586,7 @@
}
- //备注信息
+ // 备注信息
IPage<EmpRemarkInfo> empRemarkInfoIPage = empRemarkInfoMapper.selectPageVo(page, new QueryWrapper<EmpRemarkInfo>().in("a.empId", empIds).ne("a.delFlag", 1));
if (empRemarkInfoIPage.getRecords().size() != 0) {
exportField = FebsUtil.reflectAnnotation(EmpRemarkInfo.class);
@@ -1379,4 +1637,446 @@
}
return tempName;
}
+
+ @Override
+ public boolean updateSeniority() {
+ return empBaseInfoMapper.updateSeniority() > 0;
+ }
+
+ @Override
+ public boolean updateDeptName() {
+ return empBaseInfoMapper.updateDeptName() > 0;
+ }
+
+ @Override
+ public boolean updateEmpAge(String userId) {
+ List<EmpBaseInfo> empBaseInfoList = new ArrayList<>();
+ if (StringUtils.isNotBlank(userId)) {
+ EmpBaseInfo empBaseInfo = this.getById(userId);
+ empBaseInfoList.add(empBaseInfo);
+ } else {
+ empBaseInfoList = this.list();
+ }
+ if (!empBaseInfoList.isEmpty()) {
+ empBaseInfoList.parallelStream().forEach(p -> {
+ p.setAge(DateUtil.ageOfNow(p.getBirthdate()));
+ this.saveOrUpdate(p);
+ });
+ }
+ return false;
+ }
+
+ @Override
+ public void updateAnnualLeave(String userId) {
+ EmpBaseInfo empBaseInfo = this.getById(userId);
+ int holiday = calculateHoliday(empBaseInfo.getEntryDate(), empBaseInfo.getEmpStatus());
+ empBaseInfo.setAnnualLeave(holiday);
+ baseMapper.update(null, new LambdaUpdateWrapper<EmpBaseInfo>()
+ .set(EmpBaseInfo::getAnnualLeave, holiday)
+ .eq(EmpBaseInfo::getEmpId, empBaseInfo.getEmpId()));
+ }
+
+ @Override
+ public void updateAnnualLeave() {
+ List<EmpBaseInfo> list = this.list();
+ list.parallelStream().forEach(p -> {
+ int holiday = calculateHoliday(p.getEntryDate(), p.getEmpStatus());
+ p.setAnnualLeave(holiday);
+ baseMapper.update(null, new LambdaUpdateWrapper<EmpBaseInfo>()
+ .set(EmpBaseInfo::getAnnualLeave, holiday)
+ .eq(EmpBaseInfo::getEmpId, p.getEmpId()));
+ });
+ }
+
+ @Override
+ public void updateEmpBaseKeyInfo() {
+ List<EmpBaseInfo> list = this.list();
+ list.parallelStream().forEach(p -> {
+ int holiday = calculateHoliday(p.getEntryDate(), p.getEmpStatus());
+ int age = calculateAge(p.getBirthdate());
+
+ baseMapper.update(null, new LambdaUpdateWrapper<EmpBaseInfo>()
+ .set(EmpBaseInfo::getAnnualLeave, holiday)
+ .set(EmpBaseInfo::getAge, age)
+ .eq(EmpBaseInfo::getEmpId, p.getEmpId()));
+ });
+ }
+
+ // region 员工社保档位提醒
+ @Override
+ public IPage<EmpBaseInfo> findInsuranceEmpBaseInfos(QueryRequest request, EmpBaseInfo empBaseInfo) {
+ Page<EmpBaseInfo> page = new Page<>(request.getPageNum(), request.getPageSize());
+ SortUtil.handlePageSort(request, page, "insuranceType", FebsConstant.ORDER_DESC, true);
+
+ // 使用优化后的方法查询社保档位提醒员工
+ List<EmpBaseInfo> alertList = findInsuranceAlertList(empBaseInfo, request);
+ // 手动分页
+ int total = alertList.size();
+ int start = (int) ((page.getCurrent() - 1) * page.getSize());
+ int end = Math.min(start + (int) page.getSize(), total);
+
+ List<EmpBaseInfo> pageList = start < total ? alertList.subList(start, end) : new ArrayList<>();
+
+ List<DicItem> dicItems = CastUtil.castList(redisService.get("dicItems"), DicItem.class);
+ pageList.forEach(item -> {
+ item.setInsuranceTypeName(dicItems.stream()
+ .filter(k -> DicCode.INSURANCETYPE.equals(k.getDicCode()) && k.getDicItemCode().equals(item.getInsuranceType()))
+ .findFirst()
+ .map(DicItem::getDicItemName)
+ .orElse("未知"));
+ item.setSexName(dicItems.stream()
+ .filter(k -> DicCode.SEX.equals(k.getDicCode()) && k.getDicItemCode().equals(item.getSex()))
+ .findFirst()
+ .map(DicItem::getDicItemName)
+ .orElse("未知"));
+ item.setNativePlaceName(dicItems.stream()
+ .filter(k -> DicCode.NATIVEPLACE.equals(k.getDicCode()) && k.getDicItemCode().equals(item.getNativePlace()))
+ .findFirst()
+ .map(DicItem::getDicItemName)
+ .orElse("未知"));
+ item.setEmpTypeName(dicItems.stream()
+ .filter(k -> DicCode.EMPTYPE.equals(k.getDicCode()) && k.getDicItemCode().equals(item.getEmpType()))
+ .findFirst()
+ .map(DicItem::getDicItemName)
+ .orElse("未知"));
+ item.setEducationName(dicItems.stream()
+ .filter(k -> DicCode.EDUCATION.equals(k.getDicCode()) && k.getDicItemCode().equals(item.getEducation()))
+ .findFirst()
+ .map(DicItem::getDicItemName)
+ .orElse("未知"));
+ });
+ // 构建分页结果
+ Page<EmpBaseInfo> resultPage = new Page<>(page.getCurrent(), page.getSize(), total);
+ resultPage.setRecords(pageList);
+ return resultPage;
+ }
+
+ @Override
+ public Long countInsuranceAlert(EmpBaseInfo empBaseInfo, QueryRequest request) {
+ return (long) findInsuranceAlertList(empBaseInfo, request).size();
+ }
+
+ /**
+ * 查询社保档位提醒员工列表
+ * 保险类型:6-(非深户) 四险二档 7-(非深户) 四险一档 10-外参 13-临时工意外险 14-甲方购买
+ * 提醒年龄:男 48 岁,女 39 岁
+ *
+ * @param empBaseInfo 查询条件,timeRange 字段控制时间范围(0-当天 1-本周 2-本月 3-今年)
+ * @return 符合条件的员工列表
+ */
+ private List<EmpBaseInfo> findInsuranceAlertList(EmpBaseInfo empBaseInfo, QueryRequest request) {
+ // 1. 计算时间范围
+ LocalDate[] dateRange = calculateDateRange(empBaseInfo.getTimeRange());
+ LocalDate endDate = dateRange[1];
+
+ // 2. 获取提醒年龄配置
+ int alertWomanAge = getRedisConfigWithDefault("insurance_alert_woman", 39);
+ int alertManAge = getRedisConfigWithDefault("insurance_alert_man", 48);
+
+ // 3. 获取排序参数
+ String sortField = StringUtils.isNotBlank(request.getField()) ? request.getField() : "insuranceType";
+ boolean isAsc = FebsConstant.ORDER_ASC.equals(request.getOrder());
+
+ // 4. 查询符合条件的员工(仅做初步筛选)
+ QueryWrapper<EmpBaseInfo> queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("a.DelFlag", "0")
+ .eq("a.empStatus", "0")
+ .in("a.insuranceType", "6", "7", "10", "13", "14")
+ .isNotNull("a.birthdate")
+ .isNotNull("a.sex");
+ // 如果传入了性别条件,则添加性别筛选
+ if (StringUtils.isNotBlank(empBaseInfo.getSex())) {
+ queryWrapper.eq("a.sex", empBaseInfo.getSex());
+ }
+
+ // 如果传入了社保档位条件,则添加社保档位筛选
+ if (StringUtils.isNotBlank(empBaseInfo.getInsuranceType())) {
+ queryWrapper.eq("a.insuranceType", empBaseInfo.getInsuranceType());
+ }
+ // 添加排序条件
+ queryWrapper.orderBy(true, isAsc, sortField);
+ List<EmpBaseInfo> allList = this.baseMapper.listAll(queryWrapper);
+
+ // 5. 精确筛选:计算每个员工的"生日 + 提醒年龄"日期,判断是否在时间范围内
+ return allList.stream()
+ .filter(emp -> {
+ if (emp.getBirthdate() == null || emp.getSex() == null) {
+ return false;
+ }
+
+ int alertAge = "1".equals(emp.getSex()) ? alertManAge : alertWomanAge;
+ int maxAge = "1".equals(emp.getSex()) ? 50 : 40;
+ LocalDate birthDate = emp.getBirthdate().toInstant()
+ .atZone(ZoneId.systemDefault())
+ .toLocalDate();
+ LocalDate alertDate = birthDate.plusYears(alertAge);
+ LocalDate maxDate = birthDate.plusYears(maxAge);
+
+ return !alertDate.isAfter(endDate) && endDate.isBefore(maxDate);
+ })
+ .collect(Collectors.toList());
+ }
+ //#endregion
+
+ @Override
+ public IPage<EmpBaseInfo> findRetirementEmpBaseInfos(QueryRequest request, EmpBaseInfo empBaseInfo) {
+ Page<EmpBaseInfo> page = new Page<>(request.getPageNum(), request.getPageSize());
+ SortUtil.handlePageSort(request, page, "birthDate", FebsConstant.ORDER_ASC, true);
+
+ // 使用正向计算获取退休提醒列表
+ List<EmpBaseInfo> alertList = findRetirementAlertList(empBaseInfo);
+
+ // 手动分页
+ int total = alertList.size();
+ int start = (int) ((page.getCurrent() - 1) * page.getSize());
+ int end = Math.min(start + (int) page.getSize(), total);
+
+ List<EmpBaseInfo> pageList = start < total ? alertList.subList(start, end) : new ArrayList<>();
+
+ // 设置字典名称
+ List<DicItem> dicItems = CastUtil.castList(redisService.get("dicItems"), DicItem.class);
+ pageList.forEach(item -> {
+ item.setSexName(dicItems.stream()
+ .filter(k -> DicCode.SEX.equals(k.getDicCode()) && k.getDicItemCode().equals(item.getSex()))
+ .findFirst()
+ .map(DicItem::getDicItemName)
+ .orElse("未知"));
+ });
+
+ // 构建分页结果
+ Page<EmpBaseInfo> resultPage = new Page<>(page.getCurrent(), page.getSize(), total);
+ resultPage.setRecords(pageList);
+ return resultPage;
+ }
+
+ @Override
+ public IPage<EmpBaseInfo> findProbationEmpBaseInfos(QueryRequest request, EmpBaseInfo empBaseInfo) {
+ Page<EmpBaseInfo> page = new Page<>(request.getPageNum(), request.getPageSize());
+ SortUtil.handlePageSort(request, page, "probationDate", FebsConstant.ORDER_ASC, true);
+
+ IPage<EmpBaseInfo> iPage = empBaseInfoMapper.selectPageVo(page, createProbationAlertQueryWrapper(empBaseInfo));
+ List<EmpBaseInfo> list = iPage.getRecords();
+ List<DicItem> dicItems = CastUtil.castList(redisService.get("dicItems"), DicItem.class);
+
+ list.forEach(item -> {
+ item.setProbationStatusName(dicItems.stream()
+ .filter(k -> DicCode.PROBATIONS_TATUS.equals(k.getDicCode()) && k.getDicItemCode().equals(item.getProbationStatus()))
+ .findFirst()
+ .map(DicItem::getDicItemName)
+ .orElse("未知"));
+ item.setInsuranceTypeName(dicItems.stream()
+ .filter(k -> DicCode.INSURANCETYPE.equals(k.getDicCode()) && k.getDicItemCode().equals(item.getInsuranceType()))
+ .findFirst()
+ .map(DicItem::getDicItemName)
+ .orElse("未知"));
+ });
+
+ iPage.setRecords(list);
+ return iPage;
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void probationEmpBaseInfo(EmpBaseInfo empBaseInfo) {
+ String operatorId = Optional.of(FebsUtil.getUserId()).orElse("1");
+ LambdaUpdateWrapper<EmpBaseInfo> updateWrapper = new LambdaUpdateWrapper<>();
+ updateWrapper.eq(EmpBaseInfo::getEmpId, empBaseInfo.getEmpId())
+ .set(EmpBaseInfo::getProbationDate, empBaseInfo.getProbationDate())
+ .set(EmpBaseInfo::getProbationStatus, empBaseInfo.getProbationStatus())
+ .set(EmpBaseInfo::getModifier, operatorId)
+ .set(EmpBaseInfo::getModifyTime, new Date());
+
+ this.update(updateWrapper);
+ if (empBaseInfo.getProbationStatus().equals("2")) {
+ // 如果是解骋,需要关闭员工档案
+ EmpDimissionLog dimissionLog = new EmpDimissionLog();
+ dimissionLog.setDimissionDate(empBaseInfo.getProbationDate());
+ dimissionLog.setDimissionType("5");
+ dimissionLog.setEmpIds(empBaseInfo.getEmpId().toString());
+ dimissionLog.setEntryDates(DateUtil.format(empBaseInfo.getEntryDate(), "yyyy-MM-dd"));
+ dimissionLog.setDeptNames(empBaseInfo.getDeptName());
+ dimissionLog.setAfterOperation("1");
+ this.closeEmpArchives(dimissionLog);
+ }
+ }
+
+ /**
+ * 根据设置的参数计算员工的年假
+ *
+ * @param date 入职日期
+ * @param empStatus 人员状态(0-正常 1-离职 2-退休)只计算在职的
+ * @return 年假天数
+ */
+ private int calculateHoliday(Date date, String empStatus) {
+ if (!empStatus.equals("0")) {
+ int holiday = 0;
+ int joinYear = DateUtil.ageOfNow(date);
+ String configValue = redisService.get("annual_leave").toString();
+ String[] values = StrUtil.split(configValue, "|");
+ String[] condition = StrUtil.split(values[0], ",");
+ String[] days = StrUtil.split(values[1], ",");
+ if (condition.length == 2) {
+ int one = Integer.parseInt(condition[0]);
+ int two = Integer.parseInt(condition[1]);
+ if (joinYear >= one && joinYear < two) {
+ holiday = Integer.parseInt(days[0]);
+ } else if (joinYear >= two) {
+ holiday = Integer.parseInt(days[1]);
+ }
+ }
+ return holiday;
+ } else {
+ return 0;
+ }
+ }
+
+ private int calculateAge(Date date) {
+ return DateUtil.ageOfNow(date);
+ }
+
+ private int getRedisConfigWithDefault(String key, int defaultValue) {
+ try {
+ Object value = redisService.get(key);
+ if (value == null) {
+ log.warn("Redis配置 [{}] 不存在,使用默认值:{}");
+ return defaultValue;
+ }
+ return Integer.parseInt(value.toString());
+ } catch (Exception e) {
+ log.warn("Redis配置 [{}] 解析失败,使用默认值:{}");
+ return defaultValue;
+ }
+ }
+
+ /**
+ * 查询退休提醒列表(正向计算)
+ * 使用延迟退休计算逻辑:2025年1月起,男性每4个月延迟1个月,女性每2个月延迟1个月
+ */
+ public List<EmpBaseInfo> findRetirementAlertList(EmpBaseInfo empBaseInfo) {
+ // 1. 计算目标时间范围
+ LocalDate[] dateRange = calculateDateRange(empBaseInfo.getTimeRange());
+ LocalDate startDate = dateRange[0];
+ LocalDate endDate = dateRange[1];
+
+ // 2. 动态计算粗略出生日期范围
+ // 最早出生:男性60岁+最大延迟3年+余量 = startDate - 63年 - 6个月
+ LocalDate roughBirthStart = startDate.minusYears(63).minusMonths(6);
+
+ // 最晚出生:女性50岁退休(最早退休)- 余量 = endDate - 50年 + 6个月
+ // 解释:如果出生日期是 1975-01-01,女性法定退休是 2025-01-01,可能延迟几个月
+ // 所以最晚出生日期应该比 endDate 早约 50年,再留点余量
+ LocalDate roughBirthEnd = endDate.minusYears(50).plusYears(3); // 50岁+可能延迟3年
+
+ // 3. 查询所有在职、未提醒的员工(动态粗略筛选)
+ QueryWrapper<EmpBaseInfo> queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("DelFlag", 0)
+ .eq("empStatus", "0")
+ .eq("retirementReminded", 0)
+ .ge("birthdate", roughBirthStart)
+ .le("birthdate", roughBirthEnd);
+
+ List<EmpBaseInfo> allList = this.baseMapper.selectList(queryWrapper);
+
+ // 3. 逐个计算实际退休时间,筛选在范围内的
+ return allList.stream()
+ .filter(emp -> {
+ LocalDate actualRetirement = calculateActualRetirement(emp);
+ return actualRetirement != null
+ && !actualRetirement.isBefore(startDate)
+ && actualRetirement.isBefore(endDate);
+ })
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * 计算员工的实际退休时间(正向计算)
+ * 方案A:法定退休时间早于2025-01时,按法定年龄退休,不延迟
+ */
+ private LocalDate calculateActualRetirement(EmpBaseInfo emp) {
+ if (emp.getBirthdate() == null || emp.getSex() == null) {
+ return null;
+ }
+
+ LocalDate birthDate = emp.getBirthdate().toInstant()
+ .atZone(java.time.ZoneId.systemDefault())
+ .toLocalDate();
+
+ // 法定退休年龄
+ int legalAge = "1".equals(emp.getSex()) ? 60 : 50;
+ // 延迟除数
+ int delayDivisor = "1".equals(emp.getSex()) ? 4 : 2;
+
+ // 法定退休时间
+ LocalDate legalRetirement = birthDate.plusYears(legalAge);
+
+ // 方案A:法定退休时间早于2025-01,按法定年龄退休
+ LocalDate delayStart = LocalDate.of(2025, 1, 1);
+ if (legalRetirement.isBefore(delayStart)) {
+ return legalRetirement;
+ }
+
+ // 法定退休时间晚于等于2025-01,计算延迟
+ long monthsBetween = ChronoUnit.MONTHS.between(delayStart, legalRetirement);
+ long delayMonths = (monthsBetween / delayDivisor) + 1;
+
+ return legalRetirement.plusMonths(delayMonths);
+ }
+
+ /**
+ * 根据时间范围类型计算开始和结束日期
+ *
+ * @param timeRange 0-当天 1-本周 2-本月 3-今年
+ * @return 包含开始日期和结束日期的数组 [startDate, endDate)
+ */
+ private LocalDate[] calculateDateRange(Integer timeRange) {
+ if (timeRange == null) {
+ timeRange = 2;
+ }
+
+ LocalDate now = LocalDate.now();
+ LocalDate startDate;
+ LocalDate endDate;
+
+ switch (timeRange) {
+ case 0: // 当天
+ startDate = now;
+ endDate = now.plusDays(1);
+ break;
+ case 1: // 本周(周一为开始)
+ startDate = now.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
+ endDate = startDate.plusWeeks(1);
+ break;
+ case 2: // 本月
+ startDate = now.withDayOfMonth(1);
+ endDate = startDate.plusMonths(1);
+ break;
+ case 3: // 今年
+ startDate = now.withDayOfYear(1);
+ endDate = startDate.plusYears(1);
+ break;
+ default:
+ startDate = now.withDayOfMonth(1);
+ endDate = startDate.plusMonths(1);
+ }
+
+ return new LocalDate[]{startDate, endDate};
+ }
+
+ private QueryWrapper<EmpBaseInfo> createProbationAlertQueryWrapper(EmpBaseInfo empBaseInfo) {
+ QueryWrapper<EmpBaseInfo> queryWrapper = new QueryWrapper<>();
+ queryWrapper.eq("a.DelFlag", 0)
+ .eq("a.empStatus", "0");
+
+ // 计算时间范围
+ LocalDate[] dateRange = calculateDateRange(empBaseInfo.getTimeRange());
+
+ // 转正日期范围条件
+ queryWrapper.ge("a.probationDate", dateRange[0])
+ .lt("a.probationDate", dateRange[1]);
+
+ // 转正状态条件:查询状态为 0 或 3 的员工
+ queryWrapper.in("a.probationStatus", "0", "3");
+
+ return queryWrapper;
+ }
}
--
Gitblit v1.8.0