From b5ca4fa6acd8c7ea8ed1400b133eb2eb6b5cb8ba Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期三, 14 十月 2026 15:22:16 +0800
Subject: [PATCH] feat(hrm): 社保公积金方案支持按部门绑定,修比例输入精度
---
yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/salary/HrmSalaryCalculationServiceImpl.java | 64 ++++++++++++++++++++++++-------
1 files changed, 49 insertions(+), 15 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 6cf8b19..c2b563e 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
@@ -44,6 +44,7 @@
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -85,6 +86,8 @@
private HrmEmployeeSocialSecurityMapper employeeSocialSecurityMapper;
@Resource
private HrmSocialSecuritySchemeMapper socialSecuritySchemeMapper;
+ @Resource
+ private HrmSocialSecuritySchemeService socialSecuritySchemeService;
@Resource
private HrmNoRedisDAO noRedisDAO;
@Resource
@@ -140,6 +143,8 @@
.toList();
// 2. 閬嶅巻鍛樺伐杩涜钖叕鏍哥畻
+ // 閮ㄩ棬 -> 鏂规 鐨勮В鏋愮粨鏋滃湪鏈鏍哥畻鍐呯紦瀛橈紝閬垮厤閫愬憳宸ラ噸澶嶆煡搴�
+ Map<Long, HrmSocialSecuritySchemeDO> deptSchemeCache = new HashMap<>();
for (HrmEmployeeDO employee : employees) {
// employeeId 鏄憳宸D锛岀敤浜庡叧鑱旇柂閰。妗堛�佺ぞ淇濇。妗堛�佹牳绠楄褰�
Long employeeId = employee.getId();
@@ -165,11 +170,8 @@
// 2.3 鑾峰彇鍛樺伐绀句繚鍏Н閲戞。妗堬紙鎸夊憳宸D鏌ヨ锛屽彇鏈�鏂扮敓鏁堢殑锛�
HrmEmployeeSocialSecurityDO socialSecurity = employeeSocialSecurityMapper.selectLatestByUserId(employeeId);
- // 2.4 濡傛灉鏈夌ぞ淇濇。妗堬紝鑾峰彇缁戝畾鐨勬柟妗�
- HrmSocialSecuritySchemeDO scheme = null;
- if (socialSecurity != null && socialSecurity.getSocialSecuritySchemeId() != null) {
- scheme = socialSecuritySchemeMapper.selectById(socialSecurity.getSocialSecuritySchemeId());
- }
+ // 2.4 鑾峰彇鏂规锛氬憳宸ユ。妗堟寚瀹� > 鎵�鍦ㄩ儴闂ㄧ粦瀹� > 鍏ㄥ眬榛樿
+ HrmSocialSecuritySchemeDO scheme = resolveScheme(socialSecurity, employee, effectiveDate, deptSchemeCache);
// 2.5 鏋勫缓鏍哥畻璁板綍锛堝寘鍚墸闄よ绠楋紝閫氳繃鏂规鑾峰彇姣斾緥锛�
HrmSalaryCalculationDO calculation = buildSalaryCalculation(period, employeeId, employee, employeeSalary, socialSecurity, scheme, effectiveDate);
@@ -245,13 +247,22 @@
BigDecimal totalIncome = baseSalary.add(performanceSalary).add(mealAllowance)
.add(transportAllowance).add(otherAllowance).add(overtimePay);
- // 鑾峰彇绀句繚鍩烘暟锛氬憳宸ョぞ淇濇。妗� > 鍛樺伐鍩烘湰宸ヨ祫
+ // 鑾峰彇绀句繚鍩烘暟锛氬憳宸ョぞ淇濇。妗� > 鏂规榛樿缂磋垂鍩烘暟 > 鍛樺伐鍩烘湰宸ヨ祫
BigDecimal socialSecurityBase = (socialSecurity != null && socialSecurity.getSocialSecurityBase() != null)
- ? socialSecurity.getSocialSecurityBase() : baseSalary;
+ ? socialSecurity.getSocialSecurityBase()
+ : (scheme != null && scheme.getDefaultSocialSecurityBase() != null
+ ? scheme.getDefaultSocialSecurityBase() : baseSalary);
- // 鑾峰彇鍏Н閲戝熀鏁帮細鍛樺伐绀句繚妗f > 鍛樺伐鍩烘湰宸ヨ祫
- BigDecimal housingFundBase = (socialSecurity != null && socialSecurity.getHousingFundBase() != null)
- ? socialSecurity.getHousingFundBase() : baseSalary;
+ // 鑾峰彇鍏Н閲戝熀鏁帮細鍛樺伐绀句繚妗f > 鏂规榛樿鍏Н閲戝熀鏁帮紙澶т簬 0 鏃讹級> 绀句繚鍩烘暟
+ BigDecimal housingFundBase;
+ if (socialSecurity != null && socialSecurity.getHousingFundBase() != null) {
+ housingFundBase = socialSecurity.getHousingFundBase();
+ } else if (scheme != null && scheme.getDefaultHousingFundBase() != null
+ && scheme.getDefaultHousingFundBase().compareTo(BigDecimal.ZERO) > 0) {
+ housingFundBase = scheme.getDefaultHousingFundBase();
+ } else {
+ housingFundBase = socialSecurityBase;
+ }
// 浠庢柟妗堜腑鑾峰彇缂寸撼姣斾緥锛堜紭鍏堜娇鐢ㄦ柟妗堜腑鐨勬瘮渚嬶紝鍚﹀垯浣跨敤榛樿姣斾緥锛�
BigDecimal pensionPersonalRatio = (scheme != null && scheme.getPensionPersonalRatio() != null)
@@ -316,6 +327,30 @@
.totalWorkHours(totalWorkHours)
.status(0) // 寰呯‘璁�
.build();
+ }
+
+ /**
+ * 瑙f瀽鍛樺伐鏍哥畻鐢ㄧ殑绀句繚鍏Н閲戞柟妗�
+ *
+ * 浼樺厛绾э細鍛樺伐绀句繚妗f鎸囧畾鐨勬柟妗堬紙涓埆瑕嗙洊锛�> 鍛樺伐鎵�鍦ㄩ儴闂ㄧ粦瀹氱殑鏂规 > 鍏ㄥ眬榛樿鏂规銆�
+ * 閮藉彇涓嶅埌鏃惰繑鍥� null锛岀敱 {@link #buildSalaryCalculation} 浣跨敤榛樿姣斾緥甯搁噺銆�
+ *
+ * @param deptSchemeCache 鏈鏍哥畻鍐呫�岄儴闂� -> 鏂规銆嶇殑缂撳瓨锛堝厑璁� null 鍊硷紝鐢ㄤ簬缂撳瓨"璇ラ儴闂ㄦ棤鏂规"锛�
+ */
+ private HrmSocialSecuritySchemeDO resolveScheme(HrmEmployeeSocialSecurityDO socialSecurity, HrmEmployeeDO employee,
+ LocalDate periodDate,
+ Map<Long, HrmSocialSecuritySchemeDO> deptSchemeCache) {
+ if (socialSecurity != null && socialSecurity.getSocialSecuritySchemeId() != null) {
+ HrmSocialSecuritySchemeDO scheme = socialSecuritySchemeMapper.selectById(socialSecurity.getSocialSecuritySchemeId());
+ if (scheme != null) {
+ return scheme;
+ }
+ }
+ Long deptId = employee.getDeptId();
+ if (!deptSchemeCache.containsKey(deptId)) {
+ deptSchemeCache.put(deptId, socialSecuritySchemeService.resolveSchemeByDeptId(deptId, periodDate));
+ }
+ return deptSchemeCache.get(deptId);
}
/**
@@ -531,6 +566,8 @@
// 2. 閬嶅巻鍛樺伐瀹炴椂璁$畻钖叕
List<HrmSalaryCalculationDO> resultList = new java.util.ArrayList<>();
+ // 閮ㄩ棬 -> 鏂规 鐨勮В鏋愮粨鏋滃湪鏈棰勮鍐呯紦瀛橈紝閬垮厤閫愬憳宸ラ噸澶嶆煡搴�
+ Map<Long, HrmSocialSecuritySchemeDO> deptSchemeCache = new HashMap<>();
for (HrmEmployeeDO employee : employees) {
Long employeeId = employee.getId();
@@ -543,11 +580,8 @@
// 2.2 鑾峰彇鍛樺伐绀句繚鍏Н閲戞。妗堬紙鎸夊憳宸D鏌ヨ锛屽彇鏈�鏂扮敓鏁堢殑锛�
HrmEmployeeSocialSecurityDO socialSecurity = employeeSocialSecurityMapper.selectLatestByUserId(employeeId);
- // 2.3 濡傛灉鏈夌ぞ淇濇。妗堬紝鑾峰彇缁戝畾鐨勬柟妗�
- HrmSocialSecuritySchemeDO scheme = null;
- if (socialSecurity != null && socialSecurity.getSocialSecuritySchemeId() != null) {
- scheme = socialSecuritySchemeMapper.selectById(socialSecurity.getSocialSecuritySchemeId());
- }
+ // 2.3 鑾峰彇鏂规锛氬憳宸ユ。妗堟寚瀹� > 鎵�鍦ㄩ儴闂ㄧ粦瀹� > 鍏ㄥ眬榛樿
+ HrmSocialSecuritySchemeDO scheme = resolveScheme(socialSecurity, employee, effectiveDate, deptSchemeCache);
// 2.4 鏋勫缓鏍哥畻璁板綍锛堝疄鏃惰绠楋紝涓嶅瓨鍌級
HrmSalaryCalculationDO calculation = buildSalaryCalculation(period, employeeId, employee, employeeSalary, socialSecurity, scheme, effectiveDate);
--
Gitblit v1.9.3