From beeac96779eaee7c74fb7564851f9f87b2b19b67 Mon Sep 17 00:00:00 2001
From: tuqin <tuqin@local>
Date: 星期五, 06 十一月 2026 14:40:54 +0800
Subject: [PATCH] fix(hrm): 调岗列表申请人姓名兼容 user_id 双口径(历史数据存员工主键)
---
yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/service/salary/HrmSalaryCalculationServiceImpl.java | 127 ++++++++++++++++++++++++++++++++++--------
1 files changed, 102 insertions(+), 25 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 9f9e1e4..eeee784 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
@@ -32,6 +32,9 @@
import cn.iocoder.yudao.module.hrm.dal.mysql.salary.HrmSalaryStructureMapper;
import cn.iocoder.yudao.module.hrm.dal.redis.HrmNoRedisDAO;
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
+import cn.iocoder.yudao.module.system.api.notify.NotifyMessageSendApi;
+import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
+import lombok.extern.slf4j.Slf4j;
import cn.iocoder.yudao.module.hrm.enums.HrmOvertimeTypeEnum;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
@@ -44,6 +47,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;
@@ -60,6 +64,7 @@
*/
@Service
@Validated
+@Slf4j
public class HrmSalaryCalculationServiceImpl implements HrmSalaryCalculationService {
/**
@@ -89,6 +94,8 @@
private HrmNoRedisDAO noRedisDAO;
@Resource
private DeptApi deptApi;
+ @Resource
+ private NotifyMessageSendApi notifyMessageSendApi;
@Resource
private HrmDeductionService deductionService;
@Resource
@@ -162,10 +169,17 @@
// 2. 閬嶅巻鍛樺伐杩涜钖叕鏍哥畻
for (HrmEmployeeDO employee : employees) {
- // employeeId 鏄憳宸D锛岀敤浜庡叧鑱旇柂閰。妗堛�佺ぞ淇濇。妗堛�佹牳绠楄褰�
+ // employeeId 鏄憳宸ユ。妗堜富閿紙hrm_employee.id锛夛紝浠呯敤浜庡叧鑱旀帓鐝�
+ // userId 鏄郴缁熻处鍙� ID锛坰ystem_users.id锛夛紝鏍哥畻璁板綍 / 钖叕妗f / 绀句繚妗f
+ // 鍏ㄩ儴鎸夊畠鍏宠仈 鈥斺�� 鍛樺伐鐧诲綍鍚庢煡銆屾垜鐨勮柂璧勩�嶇敤鐨勪篃鏄繖涓� ID
Long employeeId = employee.getId();
- // 2.1 妫�鏌ヨ鍛樺伐褰撴湀鏄惁宸插瓨鍦ㄦ牳绠楄褰曪紙鎸夊憳宸D鏌ヨ锛�
- List<HrmSalaryCalculationDO> existCalculations = salaryCalculationMapper.selectListByUserIdAndPeriod(employeeId, period);
+ Long userId = employee.getUserId();
+ if (userId == null) {
+ log.warn("[calculateSalary] 鍛樺伐({}) 鏈叧鑱旂郴缁熻处鍙凤紝璺宠繃鏍哥畻", employee.getName());
+ continue;
+ }
+ // 2.1 妫�鏌ヨ鍛樺伐褰撴湀鏄惁宸插瓨鍦ㄦ牳绠楄褰曪紙鎸夌郴缁熻处鍙� ID 鏌ヨ锛�
+ List<HrmSalaryCalculationDO> existCalculations = salaryCalculationMapper.selectListByUserIdAndPeriod(userId, period);
if (CollUtil.isNotEmpty(existCalculations)) {
// 濡傛灉瀛樺湪澶氭潯璁板綍锛屾彁绀哄紓甯告暟鎹�
if (existCalculations.size() > 1) {
@@ -177,15 +191,15 @@
}
}
- // 2.2 鑾峰彇鍛樺伐钖叕妗f锛堟寜鍛樺伐ID鏌ヨ锛�
- HrmEmployeeSalaryDO employeeSalary = employeeSalaryMapper.selectLatestByUserId(employeeId);
+ // 2.2 鑾峰彇鍛樺伐钖叕妗f锛堟寜绯荤粺璐﹀彿 ID 鏌ヨ锛�
+ HrmEmployeeSalaryDO employeeSalary = employeeSalaryMapper.selectLatestByUserId(userId);
if (employeeSalary == null) {
// 濡傛灉娌℃湁钖叕妗f锛屼娇鐢ㄥ憳宸ヨ〃涓殑鍩烘湰宸ヨ祫鍒涘缓榛樿鏁版嵁
- employeeSalary = buildDefaultEmployeeSalary(employeeId, employee);
+ employeeSalary = buildDefaultEmployeeSalary(userId, employee);
}
- // 2.3 鑾峰彇鍛樺伐绀句繚鍏Н閲戞。妗堬紙鎸夊憳宸D鏌ヨ锛屽彇鏈�鏂扮敓鏁堢殑锛�
- HrmEmployeeSocialSecurityDO socialSecurity = employeeSocialSecurityMapper.selectLatestByUserId(employeeId);
+ // 2.3 鑾峰彇鍛樺伐绀句繚鍏Н閲戞。妗堬紙鎸夌郴缁熻处鍙� ID 鏌ヨ锛屽彇鏈�鏂扮敓鏁堢殑锛�
+ HrmEmployeeSocialSecurityDO socialSecurity = employeeSocialSecurityMapper.selectLatestByUserId(userId);
// 2.4 濡傛灉鏈夌ぞ淇濇。妗堬紝鑾峰彇缁戝畾鐨勬柟妗�
HrmSocialSecuritySchemeDO scheme = null;
if (socialSecurity != null && socialSecurity.getSocialSecuritySchemeId() != null) {
@@ -193,7 +207,7 @@
}
// 2.5 鏋勫缓鏍哥畻璁板綍锛堝寘鍚墸闄よ绠楋紝閫氳繃鏂规鑾峰彇姣斾緥锛�
- HrmSalaryCalculationDO calculation = buildSalaryCalculation(period, employeeId, employee, employeeSalary, socialSecurity, scheme, effectiveDate);
+ HrmSalaryCalculationDO calculation = buildSalaryCalculation(period, userId, employee, employeeSalary, socialSecurity, scheme, effectiveDate);
// 2.6 淇濆瓨锛氶娆$敓鎴愬崟鍙凤紱宸叉湁寰呯‘璁よ褰曞垯淇濈暀鍗曞彿骞惰鐩栭噸绠楃粨鏋�
if (CollUtil.isNotEmpty(existCalculations)) {
@@ -224,11 +238,13 @@
/**
* 鏋勫缓榛樿鐨勫憳宸ヨ柂閰。妗堛�傚熀鏈伐璧勭粺涓�鍙栧憳宸ユ。妗堬紝缁╂晥宸ヨ祫榛樿涓嶈嚜鍔ㄧ敓鎴愩��
+ *
+ * @param userId 绯荤粺璐﹀彿 ID锛坰ystem_users.id锛夛紝涓嶆槸 hrm_employee.id
*/
- private HrmEmployeeSalaryDO buildDefaultEmployeeSalary(Long employeeId, HrmEmployeeDO employee) {
+ private HrmEmployeeSalaryDO buildDefaultEmployeeSalary(Long userId, HrmEmployeeDO employee) {
BigDecimal baseSalary = employee.getBaseSalary() != null ? employee.getBaseSalary() : BigDecimal.ZERO;
return HrmEmployeeSalaryDO.builder()
- .userId(employeeId) // 浣跨敤鍛樺伐ID
+ .userId(userId)
.salaryStructureId(employee.getSalaryStructureId())
.baseSalary(baseSalary)
.performanceSalary(BigDecimal.ZERO)
@@ -242,8 +258,10 @@
/**
* 鏋勫缓钖叕鏍哥畻璁板綍锛堝寘鍚ぞ淇濄�佸叕绉噾銆佷釜绋庛�佽鍋囨墸闄よ绠楋級
* 閫氳繃鍛樺伐绀句繚妗f缁戝畾鐨勬柟妗堣幏鍙栫即绾虫瘮渚�
+ *
+ * @param userId 绯荤粺璐﹀彿 ID锛坰ystem_users.id锛夛紝鍐欏叆鏍哥畻璁板綍鐨� user_id
*/
- private HrmSalaryCalculationDO buildSalaryCalculation(String period, Long employeeId, HrmEmployeeDO employee,
+ private HrmSalaryCalculationDO buildSalaryCalculation(String period, Long userId, HrmEmployeeDO employee,
HrmEmployeeSalaryDO employeeSalary,
HrmEmployeeSocialSecurityDO socialSecurity,
HrmSocialSecuritySchemeDO scheme,
@@ -258,7 +276,8 @@
BigDecimal overtimePay = overtimeSalary.pay();
// 鎸夋帓鐝疮璁″嚭鍕ゅぉ鏁颁笌鎺掔彮鎬诲伐鏃讹紙鏃犳帓鐝椂鍑哄嫟澶╂暟鍥為��榛樿 22锛�
- ScheduleStat scheduleStat = calculateScheduleStat(employeeId, period);
+ // 娉ㄦ剰锛氭帓鐝〃鎸夊憳宸ユ。妗� ID锛坔rm_employee.id锛夊叧鑱旓紝涓庢牳绠楄褰曠殑 userId 涓嶅悓
+ ScheduleStat scheduleStat = calculateScheduleStat(employee.getId(), period);
Integer workDays = scheduleStat.scheduledDays() > 0 ? scheduleStat.scheduledDays() : 22;
BigDecimal totalWorkHours = scheduleStat.totalWorkHours();
@@ -318,7 +337,7 @@
return HrmSalaryCalculationDO.builder()
.period(period)
- .userId(employeeId) // 浣跨敤鍛樺伐ID
+ .userId(userId)
.deptId(employee.getDeptId())
.baseSalary(baseSalary)
.performanceSalary(performanceSalary)
@@ -491,6 +510,8 @@
salaryCalculationMapper.updateById(salaryCalculation);
// 璁板綍鍛ㄦ湡
period = salaryCalculation.getPeriod();
+ // 纭鍚庣粰璇ュ憳宸ュ彂閫佸伐璧勬潯閫氱煡锛堝け璐ヤ笉褰卞搷纭涓绘祦绋嬶級
+ sendPayslipNotice(salaryCalculation);
}
// 妫�鏌ヨ鍛ㄦ湡鏄惁鎵�鏈夋牳绠楄褰曢兘宸茬‘璁わ紝鑷姩鐢熸垚鍙戞斁鍙拌处
@@ -502,6 +523,39 @@
/**
* 妫�鏌ヨ鍛ㄦ湡鏄惁鎵�鏈夋牳绠楄褰曢兘宸茬‘璁わ紝濡傛灉鍏ㄩ儴纭鍒欒嚜鍔ㄧ敓鎴愬彂鏀惧彴璐�
*/
+ /**
+ * 宸ヨ祫鏉¢�氱煡鐨勭珯鍐呬俊妯℃澘缂栫爜
+ *
+ * 瀵瑰簲 system_notify_template.code = salary_payslip_notice
+ */
+ private static final String TEMPLATE_CODE_PAYSLIP = "salary_payslip_notice";
+
+ /**
+ * 缁欏憳宸ュ彂閫佸伐璧勬潯閫氱煡锛圓PP 绔欏唴淇★級
+ *
+ * 閫氱煡澶辫触鍙鏃ュ織锛屼笉褰卞搷鏍哥畻纭涓绘祦绋�
+ */
+ private void sendPayslipNotice(HrmSalaryCalculationDO calculation) {
+ if (calculation == null || calculation.getUserId() == null) {
+ return;
+ }
+ try {
+ NotifySendSingleToUserReqDTO reqDTO = new NotifySendSingleToUserReqDTO();
+ reqDTO.setUserId(calculation.getUserId());
+ reqDTO.setTemplateCode(TEMPLATE_CODE_PAYSLIP);
+ Map<String, Object> params = new HashMap<>();
+ params.put("period", calculation.getPeriod());
+ params.put("actualSalary", calculation.getActualSalary());
+ reqDTO.setTemplateParams(params);
+ notifyMessageSendApi.sendSingleMessageToAdmin(reqDTO);
+ log.info("[sendPayslipNotice] 宸ヨ祫鏉¢�氱煡宸插彂閫侊紝userId={}, period={}",
+ calculation.getUserId(), calculation.getPeriod());
+ } catch (Exception e) {
+ log.warn("[sendPayslipNotice] 宸ヨ祫鏉¢�氱煡鍙戦�佸け璐ワ紝userId={}, period={}",
+ calculation.getUserId(), calculation.getPeriod(), e);
+ }
+ }
+
private void autoGeneratePaymentIfAllConfirmed(String period) {
// 鏌ヨ璇ュ懆鏈熸墍鏈夋牳绠楄褰�
List<HrmSalaryCalculationDO> allCalculations = salaryCalculationMapper.selectListByPeriod(period);
@@ -553,17 +607,23 @@
// 2. 閬嶅巻鍛樺伐瀹炴椂璁$畻钖叕
List<HrmSalaryCalculationDO> resultList = new java.util.ArrayList<>();
for (HrmEmployeeDO employee : employees) {
- Long employeeId = employee.getId();
-
- // 2.1 鑾峰彇鍛樺伐钖叕妗f锛堟寜鍛樺伐ID鏌ヨ锛�
- HrmEmployeeSalaryDO employeeSalary = employeeSalaryMapper.selectLatestByUserId(employeeId);
- if (employeeSalary == null) {
- // 濡傛灉娌℃湁钖叕妗f锛屼娇鐢ㄥ憳宸ヨ〃涓殑鍩烘湰宸ヨ祫鍒涘缓榛樿鏁版嵁
- employeeSalary = buildDefaultEmployeeSalary(employeeId, employee);
+ // userId 鏄郴缁熻处鍙� ID锛坰ystem_users.id锛夛紝钖叕妗f / 绀句繚妗f鎸夊畠鍏宠仈锛�
+ // 鎺掔彮琛ㄥ垯鎸� hrm_employee.id 鍏宠仈锛屼袱鑰呬笉鍚�
+ Long userId = employee.getUserId();
+ if (userId == null) {
+ log.warn("[previewSalaryCalculation] 鍛樺伐({}) 鏈叧鑱旂郴缁熻处鍙凤紝璺宠繃", employee.getName());
+ continue;
}
- // 2.2 鑾峰彇鍛樺伐绀句繚鍏Н閲戞。妗堬紙鎸夊憳宸D鏌ヨ锛屽彇鏈�鏂扮敓鏁堢殑锛�
- HrmEmployeeSocialSecurityDO socialSecurity = employeeSocialSecurityMapper.selectLatestByUserId(employeeId);
+ // 2.1 鑾峰彇鍛樺伐钖叕妗f锛堟寜绯荤粺璐﹀彿 ID 鏌ヨ锛�
+ HrmEmployeeSalaryDO employeeSalary = employeeSalaryMapper.selectLatestByUserId(userId);
+ if (employeeSalary == null) {
+ // 濡傛灉娌℃湁钖叕妗f锛屼娇鐢ㄥ憳宸ヨ〃涓殑鍩烘湰宸ヨ祫鍒涘缓榛樿鏁版嵁
+ employeeSalary = buildDefaultEmployeeSalary(userId, employee);
+ }
+
+ // 2.2 鑾峰彇鍛樺伐绀句繚鍏Н閲戞。妗堬紙鎸夌郴缁熻处鍙� ID 鏌ヨ锛屽彇鏈�鏂扮敓鏁堢殑锛�
+ HrmEmployeeSocialSecurityDO socialSecurity = employeeSocialSecurityMapper.selectLatestByUserId(userId);
// 2.3 濡傛灉鏈夌ぞ淇濇。妗堬紝鑾峰彇缁戝畾鐨勬柟妗�
HrmSocialSecuritySchemeDO scheme = null;
if (socialSecurity != null && socialSecurity.getSocialSecuritySchemeId() != null) {
@@ -571,7 +631,7 @@
}
// 2.4 鏋勫缓鏍哥畻璁板綍锛堝疄鏃惰绠楋紝涓嶅瓨鍌級
- HrmSalaryCalculationDO calculation = buildSalaryCalculation(period, employeeId, employee, employeeSalary, socialSecurity, scheme, effectiveDate);
+ HrmSalaryCalculationDO calculation = buildSalaryCalculation(period, userId, employee, employeeSalary, socialSecurity, scheme, effectiveDate);
resultList.add(calculation);
}
return resultList;
@@ -582,7 +642,24 @@
public void saveSalaryCalculationList(List<HrmSalaryCalculationDO> calculationList) {
for (HrmSalaryCalculationDO calculation : calculationList) {
if (calculation.getId() == null) {
- // 鏂板璁板綍锛岀敓鎴愭牳绠楀崟鍙�
+ // 鏂板鍓嶅厛鏌ラ噸锛氬悓涓�鍛樺伐锛堢郴缁熻处鍙� ID锛�+ 鍚屼竴鍛ㄦ湡 鍙厑璁稿瓨鍦ㄤ竴鏉¤褰曘��
+ // 鍓嶇銆岄瑙堟暟鎹� 鈫� 淇濆瓨鏍哥畻銆嶈蛋鐨勫氨鏄繖閲岋紝涓嶆煡閲嶄細閲嶅鎻掑叆銆�
+ List<HrmSalaryCalculationDO> existList = salaryCalculationMapper
+ .selectListByUserIdAndPeriod(calculation.getUserId(), calculation.getPeriod());
+ if (CollUtil.isNotEmpty(existList)) {
+ HrmSalaryCalculationDO existing = existList.get(0);
+ // 宸茬‘璁�/宸插彂鏀剧殑璁板綍涓嶅厑璁歌瑕嗙洊锛岀洿鎺ヨ烦杩�
+ if (existing.getStatus() != null && existing.getStatus() != 0) {
+ continue;
+ }
+ // 寰呯‘璁ょ殑璁板綍锛氳鐩栭噸绠楃粨鏋滐紝淇濈暀鍘熷崟鍙�
+ calculation.setId(existing.getId());
+ calculation.setNo(existing.getNo());
+ calculation.setStatus(0);
+ salaryCalculationMapper.updateById(calculation);
+ continue;
+ }
+ // 纭疄鏄柊澧烇紝鐢熸垚鏍哥畻鍗曞彿
String no = noRedisDAO.generateSalaryCalculationNo();
while (salaryCalculationMapper.selectByNo(no) != null) {
no = noRedisDAO.generateSalaryCalculationNo();
--
Gitblit v1.9.3