From ae60ad1dd19a86dd9723b199111bc3e2fb45f126 Mon Sep 17 00:00:00 2001
From: yubo <autumnal_wind@yeah.net>
Date: 星期五, 03 四月 2026 20:58:59 +0800
Subject: [PATCH] refactor(hr): 移除保险提醒相关冗余代码并调整退休延迟计算

---
 febs-server/febs-server-hr/src/main/java/cc/mrbird/febs/server/hr/service/impl/EmpBaseInfoServiceImpl.java |  103 +++++++++++++++++++--------------------------------
 1 files changed, 39 insertions(+), 64 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 4d89057..6656212 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
@@ -666,6 +666,8 @@
             if (null != dicItem) {
                 empBaseInfo.setArchivesStatus(dicItem.getDicItemCode());
             }
+            // 身份证有效期
+            empBaseInfo.setCertificateValidity(DateUtil.parse(list.get(33).toString()));
             empBaseInfo.setEmpStatus("0");
             boolean saveResult = this.save(empBaseInfo);
             // 新入职员工需要增加一条入职记录
@@ -1076,7 +1078,7 @@
         if (count != null) {
             stringObjectMap.put("insuranceCount", count);
         }
-        //QueryRequest request
+        // QueryRequest request
         return stringObjectMap;
     }
 
@@ -1485,7 +1487,7 @@
     @Override
     public void updateAnnualLeave(String userId) {
         EmpBaseInfo empBaseInfo = this.getById(userId);
-        int holiday = calculateHoliday(empBaseInfo.getEntryDate());
+        int holiday = calculateHoliday(empBaseInfo.getEntryDate(), empBaseInfo.getEmpStatus());
         empBaseInfo.setAnnualLeave(holiday);
         baseMapper.update(null, new LambdaUpdateWrapper<EmpBaseInfo>()
                 .set(EmpBaseInfo::getAnnualLeave, holiday)
@@ -1496,7 +1498,7 @@
     public void updateAnnualLeave() {
         List<EmpBaseInfo> list = this.list();
         list.parallelStream().forEach(p -> {
-            int holiday = calculateHoliday(p.getEntryDate());
+            int holiday = calculateHoliday(p.getEntryDate(), p.getEmpStatus());
             p.setAnnualLeave(holiday);
             baseMapper.update(null, new LambdaUpdateWrapper<EmpBaseInfo>()
                     .set(EmpBaseInfo::getAnnualLeave, holiday)
@@ -1508,7 +1510,7 @@
     public void updateEmpBaseKeyInfo() {
         List<EmpBaseInfo> list = this.list();
         list.parallelStream().forEach(p -> {
-            int holiday = calculateHoliday(p.getEntryDate());
+            int holiday = calculateHoliday(p.getEntryDate(), p.getEmpStatus());
             int age = calculateAge(p.getBirthdate());
 
             baseMapper.update(null, new LambdaUpdateWrapper<EmpBaseInfo>()
@@ -1525,7 +1527,7 @@
         SortUtil.handlePageSort(request, page, "insuranceType", FebsConstant.ORDER_DESC, true);
 
         // 使用优化后的方法查询社保档位提醒员工
-        List<EmpBaseInfo> alertList = findInsuranceAlertList(empBaseInfo,request);
+        List<EmpBaseInfo> alertList = findInsuranceAlertList(empBaseInfo, request);
         // 手动分页
         int total = alertList.size();
         int start = (int) ((page.getCurrent() - 1) * page.getSize());
@@ -1569,8 +1571,9 @@
 
     @Override
     public Long countInsuranceAlert(EmpBaseInfo empBaseInfo, QueryRequest request) {
-        return (long) findInsuranceAlertList(empBaseInfo,request).size();
+        return (long) findInsuranceAlertList(empBaseInfo, request).size();
     }
+
     /**
      * 查询社保档位提醒员工列表
      * 保险类型:6-(非深户) 四险二档 7-(非深户) 四险一档 10-外参 13-临时工意外险 14-甲方购买
@@ -1582,7 +1585,6 @@
     private List<EmpBaseInfo> findInsuranceAlertList(EmpBaseInfo empBaseInfo, QueryRequest request) {
         // 1. 计算时间范围
         LocalDate[] dateRange = calculateDateRange(empBaseInfo.getTimeRange());
-        LocalDate startDate = dateRange[0];
         LocalDate endDate = dateRange[1];
 
         // 2. 获取提醒年龄配置
@@ -1621,12 +1623,14 @@
                     }
 
                     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);
+                    return !alertDate.isAfter(endDate) && endDate.isBefore(maxDate);
                 })
                 .collect(Collectors.toList());
     }
@@ -1639,14 +1643,14 @@
 
         // 使用正向计算获取退休提醒列表
         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 -> {
@@ -1656,7 +1660,7 @@
                     .map(DicItem::getDicItemName)
                     .orElse("未知"));
         });
-        
+
         // 构建分页结果
         Page<EmpBaseInfo> resultPage = new Page<>(page.getCurrent(), page.getSize(), total);
         resultPage.setRecords(pageList);
@@ -1717,58 +1721,35 @@
     /**
      * 根据设置的参数计算员工的年假
      *
-     * @param date 入职日期
+     * @param date      入职日期
+     * @param empStatus 人员状态(0-正常 1-离职 2-退休)只计算在职的
      * @return 年假天数
      */
-    private int calculateHoliday(Date date) {
-        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]);
+    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;
         }
-        return holiday;
     }
 
     private int calculateAge(Date date) {
         return DateUtil.ageOfNow(date);
-    }
-
-    private QueryWrapper<EmpBaseInfo> createInsuranceAlertQueryWrapper(EmpBaseInfo empBaseInfo) {
-        String[] alertInsuranceTypes = {"6", "7", "10", "13", "14"};
-
-        QueryWrapper<EmpBaseInfo> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("a.DelFlag", "0");
-        queryWrapper.eq("a.empStatus", "0");
-        queryWrapper.in("a.insuranceType", (Object[]) alertInsuranceTypes);
-
-        int alertWomanAge = getRedisConfigWithDefault("insurance_alert_woman", 39);
-        int alertManAge = getRedisConfigWithDefault("insurance_alert_man", 48);
-
-        queryWrapper.and(wrapper ->
-                wrapper.and(inner -> inner.eq("a.sex", "1").ge("a.age", alertManAge))
-                        .or(inner -> inner.eq("a.sex", "2").ge("a.age", alertWomanAge))
-        );
-
-
-        return queryWrapper;
-    }
-
-    private void buildAgeCondition(QueryWrapper<EmpBaseInfo> wrapper, int manAge, int womanAge) {
-        wrapper.nested(inner -> inner
-                .gt("a.age", manAge).eq("a.sex", "1")
-        ).or().nested(inner -> inner
-                .gt("a.age", womanAge).eq("a.sex", "2")
-        );
     }
 
     private int getRedisConfigWithDefault(String key, int defaultValue) {
@@ -1826,13 +1807,6 @@
     }
 
     /**
-     * 统计退休提醒数量(正向计算)
-     */
-    public Long countRetirementAlert(EmpBaseInfo empBaseInfo) {
-        return (long) findRetirementAlertList(empBaseInfo).size();
-    }
-
-    /**
      * 计算员工的实际退休时间(正向计算)
      * 方案A:法定退休时间早于2025-01时,按法定年龄退休,不延迟
      */
@@ -1861,13 +1835,14 @@
 
         // 法定退休时间晚于等于2025-01,计算延迟
         long monthsBetween = ChronoUnit.MONTHS.between(delayStart, legalRetirement);
-        long delayMonths = monthsBetween / delayDivisor;
+        long delayMonths = (monthsBetween / delayDivisor) + 1;
 
         return legalRetirement.plusMonths(delayMonths);
     }
 
     /**
      * 根据时间范围类型计算开始和结束日期
+     *
      * @param timeRange 0-当天 1-本周 2-本月 3-今年
      * @return 包含开始日期和结束日期的数组 [startDate, endDate)
      */

--
Gitblit v1.8.0