From 53edb16da9103f717a3beb28de8de1ebcb00157b Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期四, 12 三月 2026 15:40:01 +0800
Subject: [PATCH] fix(staff): 修复员工状态更新时未同步删除标志的问题
---
src/main/java/com/ruoyi/staff/service/impl/SchemeApplicableStaffServiceImpl.java | 180 +++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 167 insertions(+), 13 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 f06704d..7d59c26 100644
--- a/src/main/java/com/ruoyi/staff/service/impl/SchemeApplicableStaffServiceImpl.java
+++ b/src/main/java/com/ruoyi/staff/service/impl/SchemeApplicableStaffServiceImpl.java
@@ -4,25 +4,33 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.domain.AjaxResult;
+import com.ruoyi.production.dto.UserAccountDto;
+import com.ruoyi.production.dto.UserProductionAccountingDto;
+import com.ruoyi.production.service.SalesLedgerProductionAccountingService;
import com.ruoyi.project.system.domain.SysDept;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.domain.SysUserDept;
import com.ruoyi.project.system.mapper.SysDeptMapper;
import com.ruoyi.project.system.mapper.SysUserDeptMapper;
import com.ruoyi.project.system.mapper.SysUserMapper;
+import com.ruoyi.staff.controller.TaxCalculator;
+import com.ruoyi.staff.dto.StaffOnJobDto;
import com.ruoyi.staff.mapper.SchemeInsuranceDetailMapper;
+import com.ruoyi.staff.mapper.StaffOnJobMapper;
import com.ruoyi.staff.pojo.SchemeApplicableStaff;
import com.ruoyi.staff.mapper.SchemeApplicableStaffMapper;
import com.ruoyi.staff.pojo.SchemeInsuranceDetail;
+import com.ruoyi.staff.pojo.StaffOnJob;
+import com.ruoyi.staff.service.IStaffOnJobService;
import com.ruoyi.staff.service.SchemeApplicableStaffService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Objects;
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.*;
import java.util.stream.Collectors;
/**
@@ -50,6 +58,12 @@
@Autowired
private SysDeptMapper sysDeptMapper;
+
+ @Autowired
+ private StaffOnJobMapper staffOnJobMapper;
+
+ @Autowired
+ private SalesLedgerProductionAccountingService salesLedgerProductionAccountingService;
@Override
@@ -88,22 +102,19 @@
public void setSchemeApplicableStaffUserInfo(SchemeApplicableStaff schemeApplicableStaff) {
// 閫氳繃閮ㄩ棬鑾峰彇浜哄憳id
- List<SysUserDept> sysUserDepts = sysUserDeptMapper.selectList(new LambdaQueryWrapper<SysUserDept>()
- .in(SysUserDept::getDeptId, schemeApplicableStaff.getDeptIds()));
- if(CollectionUtils.isEmpty(sysUserDepts)){
+ String[] split = schemeApplicableStaff.getDeptIds().split(",");
+ List<StaffOnJob> staffOnJobs = staffOnJobMapper.selectList(new LambdaQueryWrapper<StaffOnJob>()
+ .in(StaffOnJob::getSysDeptId, Arrays.stream(split).map(Long::valueOf).collect(Collectors.toList())));
+ if(CollectionUtils.isEmpty(staffOnJobs)){
throw new IllegalArgumentException("閮ㄩ棬涓嬫棤鍛樺伐");
}
- List<SysUser> sysUsers = sysUserMapper.selectUserByIds(sysUserDepts.stream().map(SysUserDept::getUserId).collect(Collectors.toList()));
- if(CollectionUtils.isEmpty(sysUsers)){
- throw new IllegalArgumentException("閮ㄩ棬涓嬫棤鍛樺伐");
- }
- schemeApplicableStaff.setStaffIds(sysUsers
+ schemeApplicableStaff.setStaffIds(staffOnJobs
.stream()
- .map(SysUser::getUserId)
+ .map(StaffOnJob::getId)
.filter(Objects::nonNull) // 杩囨护鎺� null 鍊�
.map(String::valueOf)
.collect(Collectors.joining( ",")));
- schemeApplicableStaff.setStaffNames(sysUsers.stream().map(SysUser::getNickName).collect(Collectors.joining(",")));
+ schemeApplicableStaff.setStaffNames(staffOnJobs.stream().map(StaffOnJob::getStaffName).collect(Collectors.joining(",")));
}
@Override
@@ -150,4 +161,147 @@
.in(SchemeInsuranceDetail::getSchemeId, ids));
return AjaxResult.success(delete);
}
+
+ /**
+ * 閫氳繃鍛樺伐id璁$畻绀句繚鏂规
+ * @param id
+ */
+ public void calculateByEmployeeId(Integer id,Map<String, Object> map,String date) {
+ // 1. 鍏ュ弬鏍¢獙
+ if (id == null) {
+ return; // 鎴栬繑鍥炵┖鍒楄〃锛屾牴鎹笟鍔¢渶姹傝皟鏁�
+ }
+ Long staffId = id.longValue();
+ // 绀句繚閲戦
+ BigDecimal socialPersonal = new BigDecimal("0.00");
+ // 鍏Н閲戦噾棰�
+ BigDecimal fundPersonal = new BigDecimal("0.00");
+ // 鍩烘湰宸ヨ祫
+ BigDecimal basicSalary = new BigDecimal("0.00");
+ map.put("fundPersonal", fundPersonal); // 鍏Н閲�
+ map.put("socialPersonal", socialPersonal); // 绀句繚閲戦
+ map.put("basicSalary", basicSalary); // 鍩烘湰宸ヨ祫
+ // 涓◣閲戦
+ BigDecimal salaryTax = new BigDecimal("0.00");
+ map.put("salaryTax", salaryTax);
+ // 璁′欢宸ヨ祫
+ BigDecimal pieceSalary = new BigDecimal("0.00");
+ map.put("pieceSalary", pieceSalary);
+ // 璁℃椂宸ヨ祫
+ BigDecimal hourlySalary = new BigDecimal("0.00");
+ map.put("hourlySalary", hourlySalary);
+ // 鍏朵粬鏀跺叆
+ BigDecimal otherIncome = new BigDecimal("0.00");
+ map.put("otherIncome", otherIncome);
+ // 鍏朵粬鏀嚭
+ BigDecimal otherDeduct = new BigDecimal("0.00");
+ map.put("otherDeduct", otherDeduct);
+ // 搴斿彂宸ヨ祫
+ BigDecimal grossSalary = new BigDecimal("0.00");
+ map.put("grossSalary", grossSalary);
+ // 搴旀墸宸ヨ祫
+ BigDecimal deductSalary = new BigDecimal("0.00");
+ map.put("deductSalary", deductSalary);
+ // 瀹炲彂宸ヨ祫
+ BigDecimal netSalary = new BigDecimal("0.00");
+ map.put("netSalary", netSalary);
+ // 璋冪敤鍩烘湰宸ヨ祫
+ StaffOnJob staffOnJobDto = staffOnJobMapper.selectById(staffId);
+ if(staffOnJobDto == null){
+ return;
+ }
+ basicSalary = staffOnJobDto.getBasicSalary();
+ map.put("basicSalary", basicSalary);
+ // 搴斿彂宸ヨ祫
+ map.put("grossSalary", basicSalary);
+ // 涓◣閲戦锛堟棤绀句繚鐗堬級
+ BigDecimal bigDecimal = TaxCalculator.calculateMonthlyTax(basicSalary, socialPersonal, fundPersonal);
+ map.put("salaryTax", bigDecimal);
+ // 璁℃椂宸ヨ祫 璁′欢宸ヨ祫
+ UserProductionAccountingDto userProductionAccountingDto = new UserProductionAccountingDto();
+ userProductionAccountingDto.setUserId(getUidByStaffId(staffId));
+ userProductionAccountingDto.setDate(date);
+ UserAccountDto byUserId = salesLedgerProductionAccountingService.getByUserId(userProductionAccountingDto);
+ if(byUserId != null){
+ map.put("pieceSalary", byUserId.getAccountBalance());
+ map.put("hourlySalary", byUserId.getAccount());
+ // 搴斿彂 瀹炲彂澧炲姞
+ grossSalary = grossSalary.add(byUserId.getAccountBalance()).add(byUserId.getAccount());
+ map.put("grossSalary", grossSalary);
+ netSalary = netSalary.add(byUserId.getAccountBalance()).add(byUserId.getAccount());
+ map.put("netSalary", netSalary);
+ }
+ // 2. 鏌ヨ璇ヤ汉鍛樺搴旂殑绀句繚鏂规
+ List<SchemeApplicableStaff> schemeList = schemeApplicableStaffMapper.selectSchemeByStaffId(staffId);
+ if (CollectionUtils.isEmpty(schemeList)) {
+ return; // 鏃犲尮閰嶆柟妗堬紝杩斿洖绌哄垪琛�
+ }
+ // 3. 涓烘瘡涓柟妗堝叧鑱旀槑缁嗗垪琛�
+ for (SchemeApplicableStaff scheme : schemeList) {
+ List<SchemeInsuranceDetail> detailList = schemeApplicableStaffMapper.selectDetailBySchemeId(scheme.getId());
+ // 鏍规嵁鏄庣粏鍒楄〃璁$畻绀句繚缂磋垂閲戦
+ if(CollectionUtils.isEmpty(detailList)){
+ continue;
+ }
+ for (SchemeInsuranceDetail detail : detailList) {
+ if("鍏Н閲�".equals(detail.getInsuranceType())){
+ fundPersonal = fundPersonal.add(calculateByEmployeeIdType(detail.getInsuranceType(),fundPersonal, staffOnJobDto, detail));
+ }else{
+ socialPersonal = socialPersonal.add(calculateByEmployeeIdType(detail.getInsuranceType(),socialPersonal, staffOnJobDto, detail));
+ }
+ }
+ }
+ map.put("socialPersonal", socialPersonal);
+ map.put("fundPersonal", fundPersonal);
+ // 涓◣閲戦锛堢ぞ淇濈増锛�
+ bigDecimal = TaxCalculator.calculateMonthlyTax(basicSalary, socialPersonal, fundPersonal);
+ map.put("salaryTax", bigDecimal);
+ // 搴旀墸宸ヨ祫
+ map.put("deductSalary", bigDecimal.add(fundPersonal).add(socialPersonal));
+ // 瀹炲彂宸ヨ祫
+ map.put("netSalary", basicSalary.subtract(bigDecimal).subtract(fundPersonal).subtract(socialPersonal));
+
+ }
+
+ /**
+ * 閫氳繃鍛樺伐Id鑾峰彇鐢ㄦ埛id
+ * @param staffId
+ * @return
+ */
+ public Long getUidByStaffId(Long staffId){
+ StaffOnJob staffOnJob = staffOnJobMapper.selectById(staffId);
+ if(staffOnJob == null){
+ return -1L; // 杩斿洖涓嶅瓨鍦↖d
+ }
+ SysUser sysUser = sysUserMapper.selectOne(new LambdaQueryWrapper<SysUser>()
+ .eq(SysUser::getUserName, staffOnJob.getStaffNo())
+ .eq(SysUser::getDelFlag, "0")
+ .last("limit 1"));
+ if(sysUser == null){
+ return -1L; // 杩斿洖涓嶅瓨鍦↖d
+ }
+ return sysUser.getUserId();
+ }
+
+ /**
+ * 璁$畻
+ * @param type
+ * @param bigDecimal
+ * @param staffOnJobDto
+ * @param detail
+ * @return
+ */
+ public BigDecimal calculateByEmployeeIdType(String type,BigDecimal bigDecimal, StaffOnJob staffOnJobDto,SchemeInsuranceDetail detail) {
+ // 鍒ゆ柇鏄惁璋冪敤鍩烘湰宸ヨ祫
+ if (detail.getUseBasicSalary() == 1) {
+ BigDecimal divide = detail.getPaymentBase().multiply(detail.getPersonalRatio()).divide(new BigDecimal("100"), 2);
+ bigDecimal = bigDecimal.add(divide);
+ }else{
+ // 璋冪敤鍩烘湰宸ヨ祫
+ BigDecimal multiply = staffOnJobDto.getBasicSalary().multiply(detail.getPersonalRatio().divide(new BigDecimal("100"), 2));
+ bigDecimal = bigDecimal.add(multiply);
+ }
+ bigDecimal = bigDecimal.add(detail.getPersonalFixed());
+ return bigDecimal;
+ }
}
--
Gitblit v1.9.3