From 47806d9e390ee00e1d29ad1da8c1aa908882a758 Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期二, 11 八月 2026 14:43:59 +0800
Subject: [PATCH] 用河南鹤壁代码覆盖山西长治

---
 src/main/java/com/ruoyi/staff/service/impl/SchemeApplicableStaffServiceImpl.java |  209 +++++++++++++++++++--------------------------------
 1 files changed, 79 insertions(+), 130 deletions(-)

diff --git a/src/main/java/com/ruoyi/staff/service/impl/SchemeApplicableStaffServiceImpl.java b/src/main/java/com/ruoyi/staff/service/impl/SchemeApplicableStaffServiceImpl.java
index 60607ba..bd61ca3 100644
--- a/src/main/java/com/ruoyi/staff/service/impl/SchemeApplicableStaffServiceImpl.java
+++ b/src/main/java/com/ruoyi/staff/service/impl/SchemeApplicableStaffServiceImpl.java
@@ -25,7 +25,6 @@
 import org.springframework.util.CollectionUtils;
 
 import java.math.BigDecimal;
-import java.math.RoundingMode;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
@@ -60,7 +59,6 @@
                 schemeApplicableStaffLambdaQueryWrapper.like(SchemeApplicableStaff::getTitle, schemeApplicableStaff.getTitle());
             }
         }
-        schemeApplicableStaffLambdaQueryWrapper.orderByDesc(SchemeApplicableStaff::getId);
         Page<SchemeApplicableStaff> page1 = schemeApplicableStaffMapper.selectPage(page, schemeApplicableStaffLambdaQueryWrapper);
         List<Long> collect = page1.getRecords().stream().map(SchemeApplicableStaff::getId).collect(Collectors.toList());
         if(CollectionUtils.isEmpty(collect)){
@@ -154,85 +152,100 @@
      * @param id
      */
     public void calculateByEmployeeId(Integer id,Map<String, Object> map,String date) {
-        if (id == null || map == null) {
-            return;
+        // 1. 鍏ュ弬鏍¢獙
+        if (id == null) {
+            return; // 鎴栬繑鍥炵┖鍒楄〃锛屾牴鎹笟鍔¢渶姹傝皟鏁�
         }
         Long staffId = id.longValue();
+        // 绀句繚閲戦
+        BigDecimal socialPersonal = new BigDecimal("0.00");
+        // 鍏Н閲戦噾棰�
+        BigDecimal fundPersonal = new BigDecimal("0.00");
+        // 鍩烘湰宸ヨ祫
+        BigDecimal basicSalary = new BigDecimal("0.00");
+        map.put("fundPersonal", fundPersonal); // 鍏Н閲�
+        map.put("socialPersonal", socialPersonal); // 绀句繚閲戦
+        map.put("basicSalary", basicSalary); // 鍩烘湰宸ヨ祫
+        // 涓◣閲戦
+        BigDecimal salaryTax = new BigDecimal("0.00");
+        map.put("salaryTax", salaryTax);
+        // 璁′欢宸ヨ祫
+        BigDecimal pieceSalary = new BigDecimal("0.00");
+        map.put("pieceSalary", pieceSalary);
+        // 璁℃椂宸ヨ祫
+        BigDecimal hourlySalary = new BigDecimal("0.00");
+        map.put("hourlySalary", hourlySalary);
+        // 鍏朵粬鏀跺叆
+        BigDecimal otherIncome = new BigDecimal("0.00");
+        map.put("otherIncome", otherIncome);
+        // 鍏朵粬鏀嚭
+        BigDecimal otherDeduct = new BigDecimal("0.00");
+        map.put("otherDeduct", otherDeduct);
+        // 搴斿彂宸ヨ祫
+        BigDecimal grossSalary = new BigDecimal("0.00");
+        map.put("grossSalary", grossSalary);
+        // 搴旀墸宸ヨ祫
+        BigDecimal deductSalary = new BigDecimal("0.00");
+        map.put("deductSalary", deductSalary);
+        // 瀹炲彂宸ヨ祫
+        BigDecimal netSalary = new BigDecimal("0.00");
+        map.put("netSalary", netSalary);
+        // 璋冪敤鍩烘湰宸ヨ祫
         StaffOnJob staffOnJobDto = staffOnJobMapper.selectById(staffId);
         if(staffOnJobDto == null){
             return;
         }
-        BigDecimal basicSalary = hasValue(map, "basicSalary")
-                ? normalizeMoney(getBigDecimal(map, "basicSalary"))
-                : normalizeMoney(staffOnJobDto.getBasicSalary());
-        BigDecimal otherIncome = normalizeMoney(getBigDecimal(map, "otherIncome"));
-        BigDecimal otherDeduct = normalizeMoney(getBigDecimal(map, "otherDeduct"));
-        BigDecimal socialSupplementAmount = hasValue(map, "socialSupplementAmount")
-                ? normalizeMoney(getBigDecimal(map, "socialSupplementAmount"))
-                : calculateLatestDeptSocialSupplementAmount(staffOnJobDto);
-        BigDecimal pieceSalary = normalizeMoney(getBigDecimal(map, "pieceSalary"));
-        BigDecimal hourlySalary = normalizeMoney(getBigDecimal(map, "hourlySalary"));
-        BigDecimal socialPersonal = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
-        BigDecimal fundPersonal = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
-
+        basicSalary = staffOnJobDto.getBasicSalary();
+        map.put("basicSalary", basicSalary);
+        // 搴斿彂宸ヨ祫
+        map.put("grossSalary", basicSalary);
+        // 涓◣閲戦锛堟棤绀句繚鐗堬級
+        BigDecimal bigDecimal = TaxCalculator.calculateMonthlyTax(basicSalary, socialPersonal, fundPersonal);
+        map.put("salaryTax", bigDecimal);
+        // 璁℃椂宸ヨ祫 璁′欢宸ヨ祫
         UserProductionAccountingDto userProductionAccountingDto = new UserProductionAccountingDto();
         userProductionAccountingDto.setUserId(getUidByStaffId(staffId));
         userProductionAccountingDto.setDate(date);
         UserAccountDto byUserId = salesLedgerProductionAccountingService.getByUserId(userProductionAccountingDto);
         if(byUserId != null){
-            pieceSalary = normalizeMoney(byUserId.getAccountBalance());
-            hourlySalary = normalizeMoney(byUserId.getAccount());
+            map.put("pieceSalary", byUserId.getAccountBalance());
+            map.put("hourlySalary", byUserId.getAccount());
+            // 搴斿彂 瀹炲彂澧炲姞
+            grossSalary = grossSalary.add(byUserId.getAccountBalance()).add(byUserId.getAccount());
+            map.put("grossSalary", grossSalary);
+            netSalary = netSalary.add(byUserId.getAccountBalance()).add(byUserId.getAccount());
+            map.put("netSalary", netSalary);
         }
-
-        // 鏌ヨ璇ヤ汉鍛樺搴旂殑绀句繚鏂规
+        // 2. 鏌ヨ璇ヤ汉鍛樺搴旂殑绀句繚鏂规
         List<SchemeApplicableStaff> schemeList = schemeApplicableStaffMapper.selectSchemeByStaffId(staffId);
-        if (!CollectionUtils.isEmpty(schemeList)) {
-            for (SchemeApplicableStaff scheme : schemeList) {
-                List<SchemeInsuranceDetail> detailList = schemeApplicableStaffMapper.selectDetailBySchemeId(scheme.getId());
-                if(CollectionUtils.isEmpty(detailList)){
-                    continue;
-                }
-                for (SchemeInsuranceDetail detail : detailList) {
-                    if("鍏Н閲�".equals(detail.getInsuranceType())){
-                        fundPersonal = calculateByEmployeeIdType(detail.getInsuranceType(), fundPersonal, basicSalary, staffOnJobDto, detail);
-                    }else{
-                        socialPersonal = calculateByEmployeeIdType(detail.getInsuranceType(), socialPersonal, basicSalary, staffOnJobDto, detail);
-                    }
+        if (CollectionUtils.isEmpty(schemeList)) {
+            return; // 鏃犲尮閰嶆柟妗堬紝杩斿洖绌哄垪琛�
+        }
+        // 3. 涓烘瘡涓柟妗堝叧鑱旀槑缁嗗垪琛�
+        for (SchemeApplicableStaff scheme : schemeList) {
+            List<SchemeInsuranceDetail> detailList = schemeApplicableStaffMapper.selectDetailBySchemeId(scheme.getId());
+            // 鏍规嵁鏄庣粏鍒楄〃璁$畻绀句繚缂磋垂閲戦
+            if(CollectionUtils.isEmpty(detailList)){
+                continue;
+            }
+            for (SchemeInsuranceDetail detail : detailList) {
+                if("鍏Н閲�".equals(detail.getInsuranceType())){
+                    fundPersonal = fundPersonal.add(calculateByEmployeeIdType(detail.getInsuranceType(),fundPersonal, staffOnJobDto, detail));
+                }else{
+                    socialPersonal = socialPersonal.add(calculateByEmployeeIdType(detail.getInsuranceType(),socialPersonal, staffOnJobDto, detail));
                 }
             }
         }
-
-        BigDecimal grossSalary = basicSalary.add(pieceSalary).add(hourlySalary).add(otherIncome);
-        BigDecimal salaryTax = TaxCalculator.calculateMonthlyTax(
-                grossSalary,
-                socialPersonal.add(socialSupplementAmount),
-                fundPersonal
-        );
-        BigDecimal deductSalary = salaryTax
-                .add(fundPersonal)
-                .add(socialPersonal)
-                .add(socialSupplementAmount)
-                .add(otherDeduct);
-        BigDecimal netSalary = grossSalary.subtract(deductSalary);
-
-        if (!hasText(map, "staffName")) {
-            map.put("staffName", staffOnJobDto.getStaffName());
-        }
-        if (!hasText(map, "nation")) {
-            map.put("nation", staffOnJobDto.getNation());
-        }
-        map.put("basicSalary", basicSalary);
-        map.put("pieceSalary", pieceSalary);
-        map.put("hourlySalary", hourlySalary);
-        map.put("otherIncome", otherIncome);
         map.put("socialPersonal", socialPersonal);
         map.put("fundPersonal", fundPersonal);
-        map.put("otherDeduct", otherDeduct);
-        map.put("socialSupplementAmount", socialSupplementAmount);
-        map.put("grossSalary", grossSalary);
-        map.put("salaryTax", salaryTax);
-        map.put("deductSalary", deductSalary);
-        map.put("netSalary", netSalary);
+        // 涓◣閲戦锛堢ぞ淇濈増锛�
+        bigDecimal = TaxCalculator.calculateMonthlyTax(basicSalary, socialPersonal, fundPersonal);
+        map.put("salaryTax", bigDecimal);
+        // 搴旀墸宸ヨ祫
+        map.put("deductSalary", bigDecimal.add(fundPersonal).add(socialPersonal));
+        // 瀹炲彂宸ヨ祫
+        map.put("netSalary", basicSalary.subtract(bigDecimal).subtract(fundPersonal).subtract(socialPersonal));
+
     }
 
     /**
@@ -263,81 +276,17 @@
      * @param detail
      * @return
      */
-    public BigDecimal calculateByEmployeeIdType(String type,BigDecimal bigDecimal, BigDecimal basicSalary, StaffOnJob staffOnJobDto,SchemeInsuranceDetail detail) {
+    public BigDecimal calculateByEmployeeIdType(String type,BigDecimal bigDecimal, StaffOnJob staffOnJobDto,SchemeInsuranceDetail detail) {
         // 鍒ゆ柇鏄惁璋冪敤鍩烘湰宸ヨ祫
         if (detail.getUseBasicSalary() == 1) {
             BigDecimal divide = detail.getPaymentBase().multiply(detail.getPersonalRatio()).divide(new BigDecimal("100"), 2);
             bigDecimal = bigDecimal.add(divide);
         }else{
-            // 璋冪敤褰撳墠宸ヨ祫琛ㄤ腑鐨勫熀鏈伐璧�
-            BigDecimal multiply = basicSalary.multiply(detail.getPersonalRatio().divide(new BigDecimal("100"), 2));
+            // 璋冪敤鍩烘湰宸ヨ祫
+            BigDecimal multiply = staffOnJobDto.getBasicSalary().multiply(detail.getPersonalRatio().divide(new BigDecimal("100"), 2));
             bigDecimal = bigDecimal.add(multiply);
         }
         bigDecimal = bigDecimal.add(detail.getPersonalFixed());
         return bigDecimal;
-    }
-
-    private BigDecimal calculateLatestDeptSocialSupplementAmount(StaffOnJob staffOnJobDto) {
-        if (staffOnJobDto == null || staffOnJobDto.getSysDeptId() == null) {
-            return BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
-        }
-        SchemeApplicableStaff latestScheme = schemeApplicableStaffMapper.selectLatestSchemeByDeptId(staffOnJobDto.getSysDeptId());
-        if (latestScheme == null) {
-            return BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
-        }
-        List<SchemeInsuranceDetail> detailList = schemeApplicableStaffMapper.selectDetailBySchemeId(latestScheme.getId());
-        if (CollectionUtils.isEmpty(detailList)) {
-            return BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
-        }
-        BigDecimal socialSupplementAmount = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
-        for (SchemeInsuranceDetail detail : detailList) {
-            if (!"鍏Н閲�".equals(detail.getInsuranceType())) {
-                socialSupplementAmount = calculateByEmployeeIdType(
-                        detail.getInsuranceType(),
-                        socialSupplementAmount,
-                        normalizeMoney(staffOnJobDto.getBasicSalary()),
-                        staffOnJobDto,
-                        detail
-                );
-            }
-        }
-        return socialSupplementAmount.setScale(2, RoundingMode.HALF_UP);
-    }
-
-    private boolean hasValue(Map<String, Object> map, String key) {
-        return map != null && map.get(key) != null;
-    }
-
-    private boolean hasText(Map<String, Object> map, String key) {
-        if (map == null) {
-            return false;
-        }
-        Object value = map.get(key);
-        return value != null && !String.valueOf(value).trim().isEmpty();
-    }
-
-    private BigDecimal getBigDecimal(Map<String, Object> map, String key) {
-        if (map == null) {
-            return null;
-        }
-        Object value = map.get(key);
-        if (value == null) {
-            return null;
-        }
-        if (value instanceof BigDecimal) {
-            return (BigDecimal) value;
-        }
-        if (value instanceof Number) {
-            return new BigDecimal(String.valueOf(value));
-        }
-        String text = String.valueOf(value).trim();
-        if (text.isEmpty()) {
-            return null;
-        }
-        return new BigDecimal(text);
-    }
-
-    private BigDecimal normalizeMoney(BigDecimal value) {
-        return value == null ? BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP) : value.setScale(2, RoundingMode.HALF_UP);
     }
 }

--
Gitblit v1.9.3