From e2a6bb12ebb7ee07fbd5a428603995dbaccd1ce9 Mon Sep 17 00:00:00 2001
From: tuqin <tuqin@tuqin.cn>
Date: 星期一, 02 十一月 2026 14:43:06 +0800
Subject: [PATCH] fix(hrm): 核算批量删除增加工资发放引用保护
---
yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/salary/HrmSalaryCalculationServiceImpl.java | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 50 insertions(+), 9 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 5ed819e..858e2b1 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
@@ -277,19 +277,17 @@
BigDecimal socialSecurityBase = (socialSecurity != null && socialSecurity.getSocialSecurityBase() != null)
? socialSecurity.getSocialSecurityBase() : baseSalary;
- // 鑾峰彇鍏Н閲戝熀鏁帮細鍛樺伐绀句繚妗f > 鍛樺伐鍩烘湰宸ヨ祫
- BigDecimal housingFundBase = (socialSecurity != null && socialSecurity.getHousingFundBase() != null)
- ? socialSecurity.getHousingFundBase() : baseSalary;
-
- // 浠庢柟妗堜腑鑾峰彇缂寸撼姣斾緥锛堜紭鍏堜娇鐢ㄦ柟妗堜腑鐨勬瘮渚嬶紝鍚﹀垯浣跨敤榛樿姣斾緥锛�
+ // 浠庢柟妗堜腑鑾峰彇绀句繚缂寸撼姣斾緥锛堟柟妗堟湭閰嶇疆鏃跺洖閫�榛樿姣斾緥锛�
BigDecimal pensionPersonalRatio = (scheme != null && scheme.getPensionPersonalRatio() != null)
? scheme.getPensionPersonalRatio() : DEFAULT_PENSION_PERSONAL_RATIO;
BigDecimal medicalPersonalRatio = (scheme != null && scheme.getMedicalPersonalRatio() != null)
? scheme.getMedicalPersonalRatio() : DEFAULT_MEDICAL_PERSONAL_RATIO;
BigDecimal unemploymentPersonalRatio = (scheme != null && scheme.getUnemploymentPersonalRatio() != null)
? scheme.getUnemploymentPersonalRatio() : DEFAULT_UNEMPLOYMENT_PERSONAL_RATIO;
- BigDecimal housingFundPersonalRatio = (scheme != null && scheme.getHousingFundPersonalRatio() != null)
- ? scheme.getHousingFundPersonalRatio() : DEFAULT_HOUSING_FUND_PERSONAL_RATIO;
+
+ // 鍏Н閲戜釜浜烘瘮渚嬶細鍙彇鏂规閰嶇疆鍊硷紝涓嶅啀鍥為��榛樿姣斾緥銆�
+ // 鍚﹀垯銆屽叕鍙告病閰嶅叕绉噾鏂规銆嶆椂浼氳鎸夐粯璁� 12% 鎵f锛堣繖灏辨槸瀹㈡埛鍙嶉鐨勯棶棰橈級銆�
+ BigDecimal housingFundPersonalRatio = scheme != null ? scheme.getHousingFundPersonalRatio() : null;
// 绀句繚鎵i櫎 = 鍩烘暟 脳 (鍏昏�佷釜浜烘瘮渚� + 鍖荤枟涓汉姣斾緥 + 澶变笟涓汉姣斾緥)
BigDecimal socialSecurityDeduction = socialSecurityBase
@@ -298,8 +296,15 @@
.add(socialSecurityBase.multiply(unemploymentPersonalRatio))
.setScale(2, RoundingMode.HALF_UP);
- // 鍏Н閲戞墸闄� = 鍩烘暟 脳 鍏Н閲戜釜浜烘瘮渚�
- BigDecimal housingFundDeduction = housingFundBase.multiply(housingFundPersonalRatio).setScale(2, RoundingMode.HALF_UP);
+ // 鍏Н閲戞墸闄わ細蹇呴』鍚屾椂婊¤冻銆屾柟妗堥厤缃簡鍏Н閲戞瘮渚� > 0銆嶄笖銆屽憳宸ユ。妗堥厤缃簡鍏Н閲戝熀鏁� > 0銆嶆墠鎵f锛�
+ // 浠讳竴涓嶆弧瓒抽兘瑙嗕负鍏徃鏈即绾冲叕绉噾锛屾墸娆句负 0銆�
+ BigDecimal housingFundDeduction = BigDecimal.ZERO;
+ BigDecimal housingFundBase = socialSecurity != null ? socialSecurity.getHousingFundBase() : null;
+ if (housingFundPersonalRatio != null && housingFundPersonalRatio.signum() > 0
+ && housingFundBase != null && housingFundBase.signum() > 0) {
+ housingFundDeduction = housingFundBase.multiply(housingFundPersonalRatio)
+ .setScale(2, RoundingMode.HALF_UP);
+ }
// 璁$畻璇峰亣鎵f
BigDecimal leaveDeduction = calculateLeaveDeduction(employee, period, baseSalary);
@@ -873,4 +878,40 @@
salaryCalculationMapper.deleteById(id);
}
+ /**
+ * 鎵归噺鍒犻櫎鏍哥畻璁板綍锛堝叏閫夊悗涓�閿垹闄わ級
+ *
+ * 璇存槑锛�
+ * 1. 鎸変笟鍔¤姹傦紝鎵归噺鍒犻櫎涓嶉檺鍒舵牳绠楀崟鐘舵�侊紝鍕鹃�夊嵆鍒狅紱
+ * 2. 涓嶅瓨鍦ㄧ殑 ID 鐩存帴璺宠繃锛屼笉鎶ラ敊锛堥伩鍏嶅墠绔嬀閫夊垪琛ㄤ笌搴撲笉涓�鑷存椂鏁翠綋澶辫触锛夛紱
+ * 3. 宸茶銆屽伐璧勫彂鏀炬槑缁嗐�嶅紩鐢ㄧ殑璁板綍浼氳烦杩囦笉鍒狅紝閬垮厤鍙戞斁鏄庣粏鍙樻垚瀛ゅ効鏁版嵁銆�
+ *
+ * @return 瀹為檯鍒犻櫎鐨勬潯鏁帮紙鍙兘灏忎簬浼犲叆鏉℃暟锛�
+ */
+ @Override
+ public Integer deleteSalaryCalculationList(List<Long> ids) {
+ if (CollUtil.isEmpty(ids)) {
+ return 0;
+ }
+ List<Long> existIds = salaryCalculationMapper.selectBatchIds(ids).stream()
+ .map(HrmSalaryCalculationDO::getId)
+ .collect(Collectors.toList());
+ if (CollUtil.isEmpty(existIds)) {
+ return 0;
+ }
+ // 寮曠敤淇濇姢锛氬凡杩涘叆宸ヨ祫鍙戞斁娴佺▼鐨勬牳绠楀崟涓嶅厑璁稿垹闄�
+ Set<Long> referencedIds = salaryPaymentDetailMapper.selectListByCalculationIds(existIds).stream()
+ .map(HrmSalaryPaymentDetailDO::getCalculationId)
+ .filter(Objects::nonNull)
+ .collect(Collectors.toSet());
+ List<Long> deletableIds = existIds.stream()
+ .filter(id -> !referencedIds.contains(id))
+ .collect(Collectors.toList());
+ if (CollUtil.isEmpty(deletableIds)) {
+ return 0;
+ }
+ salaryCalculationMapper.deleteByIds(deletableIds);
+ return deletableIds.size();
+ }
+
}
--
Gitblit v1.9.3