From ff09f8e85d51c5d127796bfbd097f5fad9267d4b Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期四, 30 七月 2026 15:04:42 +0800
Subject: [PATCH] 导出工资xlsx

---
 src/main/java/com/ruoyi/staff/service/impl/SchemeApplicableStaffServiceImpl.java |  102 +++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 75 insertions(+), 27 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 c32d868..4cd0b2c 100644
--- a/src/main/java/com/ruoyi/staff/service/impl/SchemeApplicableStaffServiceImpl.java
+++ b/src/main/java/com/ruoyi/staff/service/impl/SchemeApplicableStaffServiceImpl.java
@@ -158,13 +158,13 @@
      * 閫氳繃鍛樺伐id璁$畻绀句繚鏂规
      * @param id
      */
-    public void calculateByEmployeeId(Integer id,Map<String, Object> map,String date) {
+    public void calculateByEmployeeId(Integer id, Map<String, Object> map, String date) {
         if (id == null || map == null) {
             return;
         }
         Long staffId = id.longValue();
         StaffOnJob staffOnJobDto = staffOnJobMapper.selectById(staffId);
-        if(staffOnJobDto == null){
+        if (staffOnJobDto == null) {
             return;
         }
         BigDecimal basicSalary = resolveBasicSalary(map, staffOnJobDto);
@@ -174,11 +174,12 @@
         BigDecimal socialSupplementAmount = resolveSocialSupplementAmount(map, staffOnJobDto);
         BigDecimal socialPersonal = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
         BigDecimal fundPersonal = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
-        int monthWorkDays = calculateWorkDays(date);
-        BigDecimal standardHours = calculateStandardHours(monthWorkDays);
+        int monthWorkDays = resolveMonthWorkDays(map, date);
+        BigDecimal workDays = resolveWorkDays(map, monthWorkDays);
+        BigDecimal standardHours = resolveStandardHours(map, monthWorkDays);
         BigDecimal actualOutput = resolveActualOutput(map);
         BigDecimal standardQuantity = resolveStandardQuantity(map);
-        BigDecimal conversionFactor = resolveConversionFactor(map);
+        BigDecimal dailySalary = calculateDailySalary(basicSalary, workDays);
 
         Long sysUserId = getUidByStaffId(staffId);
         UserProductionAccountingDto userProductionAccountingDto = new UserProductionAccountingDto();
@@ -190,7 +191,6 @@
                 map,
                 actualOutput,
                 standardQuantity,
-                conversionFactor,
                 repairWorkHour,
                 byUserId
         );
@@ -201,21 +201,24 @@
         if (!CollectionUtils.isEmpty(schemeList)) {
             for (SchemeApplicableStaff scheme : schemeList) {
                 List<SchemeInsuranceDetail> detailList = schemeApplicableStaffMapper.selectDetailBySchemeId(scheme.getId());
-                if(CollectionUtils.isEmpty(detailList)){
+                if (CollectionUtils.isEmpty(detailList)) {
                     continue;
                 }
                 for (SchemeInsuranceDetail detail : detailList) {
-                    if("鍏Н閲�".equals(detail.getInsuranceType())){
+                    if ("鍏Н閲�".equals(detail.getInsuranceType())) {
                         fundPersonal = calculateByEmployeeIdType(detail.getInsuranceType(), fundPersonal, basicSalary, staffOnJobDto, detail);
-                    }else{
+                    } else {
                         socialPersonal = calculateByEmployeeIdType(detail.getInsuranceType(), socialPersonal, basicSalary, staffOnJobDto, detail);
                     }
                 }
             }
         }
 
-        // 宸ヨ祫 = 鍏ㄥ嫟濂栭噾 + 鍩烘湰宸ヨ祫 * 鎶樺悎鍊嶆暟
-        BigDecimal grossSalary = attendanceBonus.add(basicSalary.multiply(conversionRatio)).add(otherIncome);
+        // 宸ヨ祫 = 鍏ㄥ嫟濂栭噾 + 鍩烘湰宸ヨ祫 * 鎶樺悎鍊嶆暟 + 鍏朵粬鏀跺叆 + 娲ヨ创
+        BigDecimal grossSalary = attendanceBonus
+                .add(basicSalary.multiply(conversionRatio))
+                .add(otherIncome)
+                .add(normalizeMoney(getBigDecimal(map, "allowance")));
         BigDecimal salaryTax = TaxCalculator.calculateMonthlyTax(
                 grossSalary,
                 socialPersonal.add(socialSupplementAmount),
@@ -236,14 +239,16 @@
         }
         map.put("basicSalary", basicSalary);
         map.put("attendanceBonus", attendanceBonus);
+        map.put("workDays", workDays);
         map.put("monthWorkDays", monthWorkDays);
+        map.put("dailySalary", dailySalary);
         map.put("standardHours", standardHours);
         map.put("actualOutput", actualOutput);
         map.put("standardQuantity", standardQuantity);
-        map.put("conversionFactor", conversionFactor);
         map.put("convertedWorkHours", convertedWorkHours);
         map.put("monthTimeTotal", convertedWorkHours);
         map.put("conversionRatio", conversionRatio);
+        map.put("benefit", conversionRatio);
         map.put("pieceSalary", convertedWorkHours);
         map.put("hourlySalary", BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP));
         map.put("otherIncome", otherIncome);
@@ -301,6 +306,20 @@
     }
 
     /**
+     * 瑙f瀽鏈堟爣鍑嗗伐鏃躲��
+     * 浼樺厛浣跨敤宸ヨ祫琛ㄤ紶鍏ョ殑宸ヤ綔鏃ヨ绠楋紝鍏舵浣跨敤褰撴湀榛樿宸ヤ綔鏃ャ��
+     */
+    private BigDecimal resolveStandardHours(Map<String, Object> map, int monthWorkDays) {
+        if (hasValue(map, "standardHours")) {
+            BigDecimal standardHours = normalizeMoney(getBigDecimal(map, "standardHours"));
+            if (standardHours.compareTo(BigDecimal.ZERO) > 0) {
+                return standardHours;
+            }
+        }
+        return calculateStandardHours(monthWorkDays);
+    }
+
+    /**
      * 瑙f瀽褰撴湀瀹為檯浜ч噺銆�
      */
     private BigDecimal resolveActualOutput(Map<String, Object> map) {
@@ -316,15 +335,6 @@
         return hasValue(map, "standardQuantity")
                 ? normalizeMoney(getBigDecimal(map, "standardQuantity"))
                 : BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
-    }
-
-    /**
-     * 瑙f瀽宸ュ簭鎶樼畻绯绘暟锛屾湭閰嶇疆鏃堕粯璁� 1銆�
-     */
-    private BigDecimal resolveConversionFactor(Map<String, Object> map) {
-        return hasValue(map, "conversionFactor")
-                ? normalizeMoney(getBigDecimal(map, "conversionFactor"))
-                : BigDecimal.ONE.setScale(2, RoundingMode.HALF_UP);
     }
 
     /**
@@ -350,14 +360,13 @@
 
     /**
      * 璁$畻鏈堟椂闂村悎璁°��
-     * 璁′欢鍦烘櫙浣跨敤瀹為檯浜ч噺銆佹爣鍑嗘暟閲忓拰鎶樼畻绯绘暟鎹㈢畻锛�
+     * 璁′欢鍦烘櫙浣跨敤瀹為檯浜ч噺鍜屾爣鍑嗘暟閲忔崲绠楋紱
      * 娌℃湁璁′欢鏁版嵁鏃讹紝鍥炶惤鍒扮敓浜ф牳绠楁眹鎬诲�硷紱
      * 鏈�鍚庡啀鍙犲姞杩斿伐琛ヤ慨鐞嗗伐鏃躲��
      */
     private BigDecimal resolveConvertedWorkHours(Map<String, Object> map,
                                                  BigDecimal actualOutput,
                                                  BigDecimal standardQuantity,
-                                                 BigDecimal conversionFactor,
                                                  BigDecimal repairWorkHour,
                                                  UserAccountDto byUserId) {
         if (hasValue(map, "monthTimeTotal")) {
@@ -367,12 +376,11 @@
             }
         }
         BigDecimal convertedWorkHours = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
-        // 璁′欢鎶樼畻宸ユ椂 = 褰撴湀瀹為檯浜ч噺 / 宸ュ簭鏍囧噯鏁伴噺 * 8 * 宸ュ簭鎶樼畻绯绘暟
+        // 璁′欢鎶樼畻宸ユ椂 = 褰撴湀瀹為檯浜ч噺 / 宸ュ簭鏍囧噯鏁伴噺 * 8
         if (actualOutput.compareTo(BigDecimal.ZERO) > 0 && standardQuantity.compareTo(BigDecimal.ZERO) > 0) {
             convertedWorkHours = actualOutput
                     .divide(standardQuantity, 8, RoundingMode.HALF_UP)
                     .multiply(new BigDecimal("8"))
-                    .multiply(conversionFactor)
                     .setScale(2, RoundingMode.HALF_UP);
         } else if (byUserId != null) {
             convertedWorkHours = normalizeMoney(byUserId.getAccountBalance().add(byUserId.getAccount()));
@@ -386,9 +394,49 @@
      */
     private BigDecimal calculateConversionRatio(BigDecimal standardHours, BigDecimal convertedWorkHours) {
         return standardHours.compareTo(BigDecimal.ZERO) == 0
-                ? BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP)
+                ? BigDecimal.ZERO.setScale(4, RoundingMode.HALF_UP)
                 : convertedWorkHours.divide(standardHours, 8, RoundingMode.HALF_UP)
-                .setScale(2, RoundingMode.HALF_UP);
+                .setScale(4, RoundingMode.HALF_UP);
+    }
+
+    /**
+     * 璁$畻鏃ヨ宸ヨ祫銆�
+     * 瑙勫垯锛氬熀鏈伐璧� / 宸ヤ綔鏃ュぉ鏁般��
+     */
+    private BigDecimal calculateDailySalary(BigDecimal basicSalary, BigDecimal workDays) {
+        if (basicSalary == null || workDays == null || workDays.compareTo(BigDecimal.ZERO) <= 0) {
+            return BigDecimal.ZERO.setScale(3, RoundingMode.HALF_UP);
+        }
+        return basicSalary.divide(workDays, 3, RoundingMode.HALF_UP);
+    }
+
+    /**
+     * 瑙f瀽宸ヨ祫琛ㄥ伐浣滄棩銆�
+     * 浼樺厛浣跨敤椤甸潰浼犲叆鐨勫伐浣滄棩锛屾湭浼犳椂鎵嶆寜鑷劧鏈堝伐浣滄棩璁$畻銆�
+     */
+    private int resolveMonthWorkDays(Map<String, Object> map, String date) {
+        if (hasValue(map, "monthWorkDays")) {
+            BigDecimal monthWorkDays = normalizeMoney(getBigDecimal(map, "monthWorkDays"));
+            if (monthWorkDays.compareTo(BigDecimal.ZERO) > 0) {
+                return monthWorkDays.intValue();
+            }
+        }
+        return calculateWorkDays(date);
+    }
+
+    /**
+     * 瑙f瀽宸ヤ綔鏃ャ��
+     * 濡傛灉宸ヨ祫琛ㄩ噷宸茬粡濉啓浜嗗伐浣滄棩锛屽垯浼樺厛浣跨敤浜哄伐濉啓鍊硷紱
+     * 鍚﹀垯榛樿浣跨敤褰撴湀宸ヤ綔鏃ュぉ鏁般��
+     */
+    private BigDecimal resolveWorkDays(Map<String, Object> map, int monthWorkDays) {
+        if (hasValue(map, "workDays")) {
+            BigDecimal workDays = normalizeMoney(getBigDecimal(map, "workDays"));
+            if (workDays.compareTo(BigDecimal.ZERO) > 0) {
+                return workDays;
+            }
+        }
+        return BigDecimal.valueOf(monthWorkDays).setScale(2, RoundingMode.HALF_UP);
     }
 
     /**

--
Gitblit v1.9.3