From f5c79994970790c2d297831404dd529970ac213f Mon Sep 17 00:00:00 2001
From: tuqin <tuqin@tuqin.cn>
Date: 星期一, 19 十月 2026 10:44:05 +0800
Subject: [PATCH] feat(hrm): 薪酬核算支持修改核算记录(仅待确认可改,实发工资后端重算)

---
 yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/salary/HrmSalaryCalculationServiceImpl.java |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/salary/HrmSalaryCalculationServiceImpl.java b/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/salary/HrmSalaryCalculationServiceImpl.java
index 5f0019e..ea55ce7 100644
--- a/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/salary/HrmSalaryCalculationServiceImpl.java
+++ b/yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/salary/HrmSalaryCalculationServiceImpl.java
@@ -663,6 +663,53 @@
         }
     }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void updateSalaryCalculation(HrmSalaryCalculationDO calculation) {
+        HrmSalaryCalculationDO exist = salaryCalculationMapper.selectById(calculation.getId());
+        if (exist == null) {
+            throw exception(SALARY_CALCULATION_NOT_EXISTS);
+        }
+        // 浠呭緟纭鐘舵�佸彲淇敼锛氬凡纭闇�鍏堟挙閿�锛涘凡鍙戞斁涓嶅彲鏀�
+        if (exist.getStatus() == null || !Objects.equals(exist.getStatus(), 0)) {
+            throw exception(SALARY_CALCULATION_UPDATE_FAIL);
+        }
+        // 浠ヤ笅瀛楁涓嶅厑璁搁�氳繃淇敼鎺ュ彛鍙樻洿锛屼竴寰嬩互搴撲腑涓哄噯
+        calculation.setNo(exist.getNo());
+        calculation.setPeriod(exist.getPeriod());
+        calculation.setUserId(exist.getUserId());
+        calculation.setDeptId(exist.getDeptId());
+        calculation.setStatus(exist.getStatus());
+        calculation.setConfirmTime(exist.getConfirmTime());
+        calculation.setConfirmUserId(exist.getConfirmUserId());
+        calculation.setPaymentTime(exist.getPaymentTime());
+        // 瀹炲彂宸ヨ祫鐢卞悗绔噸绠楋紝閬垮厤鍓嶇浼犲叆鍊间笌鏄庣粏涓嶄竴鑷�
+        calculation.setActualSalary(calcActualSalary(calculation));
+        salaryCalculationMapper.updateById(calculation);
+    }
+
+    /**
+     * 璁$畻瀹炲彂宸ヨ祫 = 鏀跺叆椤瑰悎璁� - 鎵i櫎椤瑰悎璁★紝淇濈暀涓や綅灏忔暟
+     */
+    private static BigDecimal calcActualSalary(HrmSalaryCalculationDO c) {
+        BigDecimal income = nvl(c.getBaseSalary())
+                .add(nvl(c.getPerformanceSalary()))
+                .add(nvl(c.getOvertimePay()))
+                .add(nvl(c.getMealAllowance()))
+                .add(nvl(c.getTransportAllowance()))
+                .add(nvl(c.getOtherAllowance()));
+        BigDecimal deduction = nvl(c.getSocialSecurityDeduction())
+                .add(nvl(c.getHousingFundDeduction()))
+                .add(nvl(c.getTaxDeduction()))
+                .add(nvl(c.getOtherDeduction()))
+                .add(nvl(c.getLeaveDeduction()));
+        return income.subtract(deduction).setScale(2, RoundingMode.HALF_UP);
+    }
+
+    private static BigDecimal nvl(BigDecimal v) {
+        return v == null ? BigDecimal.ZERO : v;
+    }
+
     /**
      * 鍐呴儴鐢熸垚鍙戞斁鍙拌处鏂规硶锛堜緵鑷姩鐢熸垚璋冪敤锛�
      */

--
Gitblit v1.9.3