From b8607f49fb2ec4a4113aeb01455e90ae83781bcc Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期三, 27 五月 2026 17:11:24 +0800
Subject: [PATCH] 增加餐补夜补,计算薪资

---
 src/main/java/com/ruoyi/staff/service/impl/SchemeApplicableStaffServiceImpl.java |  207 +++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 157 insertions(+), 50 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 e8d3982..e59ca71 100644
--- a/src/main/java/com/ruoyi/staff/service/impl/SchemeApplicableStaffServiceImpl.java
+++ b/src/main/java/com/ruoyi/staff/service/impl/SchemeApplicableStaffServiceImpl.java
@@ -2,32 +2,29 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.framework.web.domain.AjaxResult;
+import com.ruoyi.production.bean.dto.UserAccountDto;
+import com.ruoyi.production.bean.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.mapper.*;
+import com.ruoyi.staff.pojo.*;
 import com.ruoyi.staff.service.SchemeApplicableStaffService;
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import org.springframework.beans.factory.annotation.Autowired;
+import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
-import javax.annotation.Resource;
 import java.math.BigDecimal;
-import java.util.*;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
 import java.util.stream.Collectors;
 
 /**
@@ -39,25 +36,18 @@
  * @since 2026-03-05 11:50:17
  */
 @Service
+@RequiredArgsConstructor
 public class SchemeApplicableStaffServiceImpl extends ServiceImpl<SchemeApplicableStaffMapper, SchemeApplicableStaff> implements SchemeApplicableStaffService {
 
-    @Autowired
-    private SchemeApplicableStaffMapper schemeApplicableStaffMapper;
-
-    @Autowired
-    private SchemeInsuranceDetailMapper schemeInsuranceDetailMapper;
-
-    @Autowired
-    private SysUserDeptMapper sysUserDeptMapper;
-
-    @Autowired
-    private SysUserMapper sysUserMapper;
-
-    @Autowired
-    private SysDeptMapper sysDeptMapper;
-
-    @Autowired
-    private StaffOnJobMapper staffOnJobMapper;
+    private final SchemeApplicableStaffMapper schemeApplicableStaffMapper;
+    private final SchemeInsuranceDetailMapper schemeInsuranceDetailMapper;
+    private final SysUserMapper sysUserMapper;
+    private final SysDeptMapper sysDeptMapper;
+    private final StaffOnJobMapper staffOnJobMapper;
+    private final PersonalShiftMapper personalShiftMapper;
+    private final PersonalAttendanceLocationConfigMapper personalAttendanceLocationConfigMapper;
+    private final SalesLedgerProductionAccountingService salesLedgerProductionAccountingService;
+    private final SubsidyConfigurationMapper subsidyConfigurationMapper;
 
 
     @Override
@@ -68,6 +58,7 @@
                 schemeApplicableStaffLambdaQueryWrapper.like(SchemeApplicableStaff::getTitle, schemeApplicableStaff.getTitle());
             }
         }
+        schemeApplicableStaffLambdaQueryWrapper.orderByDesc(SchemeApplicableStaff::getId);
         Page<SchemeApplicableStaff> page1 = schemeApplicableStaffMapper.selectPage(page, schemeApplicableStaffLambdaQueryWrapper);
         List<Long> collect = page1.getRecords().stream().map(SchemeApplicableStaff::getId).collect(Collectors.toList());
         if(CollectionUtils.isEmpty(collect)){
@@ -160,20 +151,20 @@
      * 閫氳繃鍛樺伐id璁$畻绀句繚鏂规
      * @param id
      */
-    public void calculateByEmployeeId(Integer id,Map<String, Object> map) {
+    public void calculateByEmployeeId(Integer id,Map<String, Object> map,String date) {
         // 1. 鍏ュ弬鏍¢獙
         if (id == null) {
             return; // 鎴栬繑鍥炵┖鍒楄〃锛屾牴鎹笟鍔¢渶姹傝皟鏁�
         }
         Long staffId = id.longValue();
         // 绀句繚閲戦
-        BigDecimal schemeAmount = new BigDecimal("0.00");
+        BigDecimal socialPersonal = new BigDecimal("0.00");
         // 鍏Н閲戦噾棰�
-        BigDecimal gjj = new BigDecimal("0.00");
+        BigDecimal fundPersonal = new BigDecimal("0.00");
         // 鍩烘湰宸ヨ祫
         BigDecimal basicSalary = new BigDecimal("0.00");
-        map.put("gjj", gjj); // 鍏Н閲�
-        map.put("schemeAmount", schemeAmount); // 绀句繚閲戦
+        map.put("fundPersonal", fundPersonal); // 鍏Н閲�
+        map.put("socialPersonal", socialPersonal); // 绀句繚閲戦
         map.put("basicSalary", basicSalary); // 鍩烘湰宸ヨ祫
         // 涓◣閲戦
         BigDecimal salaryTax = new BigDecimal("0.00");
@@ -199,18 +190,110 @@
         // 瀹炲彂宸ヨ祫
         BigDecimal netSalary = new BigDecimal("0.00");
         map.put("netSalary", netSalary);
-        // 璋冪敤鍩烘湰宸ヨ祫
+        // 鏍规嵁鎺掔彮鏁版嵁璁$畻鐧界彮澶╂暟鍜屽鐝ぉ鏁�
+        BigDecimal dayDays = new BigDecimal("0.00");
+        BigDecimal nightDays = new BigDecimal("0.00");
+
+        // 鏌ヨ褰撴湀鎺掔彮璁板綍
+        List<PersonalShift> shiftList = personalShiftMapper.selectList(new LambdaQueryWrapper<PersonalShift>()
+                .eq(PersonalShift::getStaffOnJobId, staffId)
+                .like(PersonalShift::getWorkTime, date));
+
+        if(!CollectionUtils.isEmpty(shiftList)){
+            // 鏀堕泦鎵�鏈夌彮娆¢厤缃甀D
+            List<Integer> configIds = shiftList.stream()
+                    .map(PersonalShift::getPersonalAttendanceLocationConfigId)
+                    .filter(Objects::nonNull)
+                    .collect(Collectors.toList());
+
+            if(!CollectionUtils.isEmpty(configIds)){
+                // 鏌ヨ鐝閰嶇疆淇℃伅
+                List<PersonalAttendanceLocationConfig> configList = personalAttendanceLocationConfigMapper.selectList(
+                        new LambdaQueryWrapper<PersonalAttendanceLocationConfig>()
+                                .in(PersonalAttendanceLocationConfig::getId, configIds));
+
+                // 鏋勫缓鐝閰嶇疆鏄犲皠
+                Map<Integer, String> configMap = configList.stream()
+                        .collect(Collectors.toMap(
+                                PersonalAttendanceLocationConfig::getId,
+                                PersonalAttendanceLocationConfig::getShift,
+                                (a, b) -> a));
+
+                // 缁熻鐧界彮鍜屽鐝ぉ鏁�
+                for (PersonalShift shift : shiftList) {
+                    Integer configId = shift.getPersonalAttendanceLocationConfigId();
+                    String shiftName = configMap.get(configId);
+                    if(shiftName != null){
+                        // 鏍规嵁鐝鍚嶇О鍒ゆ柇锛氬寘鍚�"鐧�"鎴�"鏃�"涓虹櫧鐝紝鍖呭惈"澶�"涓哄鐝�
+                        if(shiftName.contains("鐧�") || shiftName.contains("鏃�")){
+                            dayDays = dayDays.add(BigDecimal.ONE);
+                        } else if(shiftName.contains("澶�")){
+                            nightDays = nightDays.add(BigDecimal.ONE);
+                        }
+                    }
+                }
+            }
+        }
+        map.put("dayDays", dayDays); // 鐧界彮澶╂暟
+        map.put("nightDays", nightDays); // 澶滅彮澶╂暟
+
+        // 鏌ヨ椁愯ˉ鍜屽鐝ˉ璐�
+        // 璁$畻椁愯ˉ锛堝洖鏃忕壒鏈夛級鍜屽鐝ˉ鍔�
+        BigDecimal mealAmount = new BigDecimal("0.00"); // 椁愯ˉ
+        BigDecimal nightAmount = new BigDecimal("0.00"); // 澶滅彮琛ュ姪
+
+        // 鑾峰彇椁愯ˉ鍜屽鐝ˉ璐存爣鍑嗭紙浠庤ˉ璐撮厤缃腑鑾峰彇锛�
+        SubsidyConfiguration subsidyConfig = subsidyConfigurationMapper.selectOne(null);
+        BigDecimal mealStandard = new BigDecimal("0.00"); // 椁愯ˉ鏍囧噯
+        BigDecimal nightStandard = new BigDecimal("0.00"); // 澶滅彮琛ヨ创鏍囧噯
+        if(subsidyConfig != null){
+            mealStandard = subsidyConfig.getMealAmount() != null ? subsidyConfig.getMealAmount() : new BigDecimal("0.00");
+            nightStandard = subsidyConfig.getNightAmount() != null ? subsidyConfig.getNightAmount() : new BigDecimal("0.00");
+        }
+
+        // 椁愯ˉ锛氭皯鏃忎负鍥炴棌鐗规湁锛岃绠楁柟寮忎负(鐧界彮澶╂暟+澶滅彮澶╂暟)*椁愯ˉ鏍囧噯
         StaffOnJob staffOnJobDto = staffOnJobMapper.selectById(staffId);
         if(staffOnJobDto == null){
             return;
         }
+
+        String nation = staffOnJobDto.getNation();
+        if("鍥炴棌".equals(nation)){
+            mealAmount = dayDays.add(nightDays).multiply(mealStandard);
+        }
+
+        // 澶滅彮琛ュ姪锛氬鐝ぉ鏁�*澶滅彮琛ヨ创鏍囧噯
+        nightAmount = nightDays.multiply(nightStandard);
+
+        map.put("mealAmount", mealAmount); // 椁愯ˉ
+        map.put("nightAmount", nightAmount); // 澶滅彮琛ュ姪
+
+        // 璋冪敤鍩烘湰宸ヨ祫
         basicSalary = staffOnJobDto.getBasicSalary();
         map.put("basicSalary", basicSalary);
-        // 搴斿彂宸ヨ祫
-        map.put("grossSalary", basicSalary);
+        // 搴斿彂宸ヨ祫锛堝熀鏈伐璧�+椁愯ˉ+澶滅彮琛ュ姪+鍏朵粬鏀跺叆锛�
+        grossSalary = basicSalary.add(mealAmount).add(nightAmount).add(otherIncome);
+        map.put("grossSalary", grossSalary);
+        // 瀹炲彂宸ヨ祫鍒濆鍊�
+        netSalary = grossSalary;
+        map.put("netSalary", netSalary);
         // 涓◣閲戦锛堟棤绀句繚鐗堬級
-        BigDecimal bigDecimal = TaxCalculator.calculateMonthlyTax(basicSalary, schemeAmount, gjj);
+        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)) {
@@ -224,23 +307,47 @@
                 continue;
             }
             for (SchemeInsuranceDetail detail : detailList) {
-                if("浣忔埧鍏Н閲�".equals(detail.getInsuranceType())){
-                    gjj = gjj.add(calculateByEmployeeIdType(detail.getInsuranceType(),gjj, staffOnJobDto, detail));
+                if("鍏Н閲�".equals(detail.getInsuranceType())){
+                    fundPersonal = fundPersonal.add(calculateByEmployeeIdType(detail.getInsuranceType(),fundPersonal, staffOnJobDto, detail));
                 }else{
-                    schemeAmount = schemeAmount.add(calculateByEmployeeIdType(detail.getInsuranceType(),schemeAmount, staffOnJobDto, detail));
+                    socialPersonal = socialPersonal.add(calculateByEmployeeIdType(detail.getInsuranceType(),socialPersonal, staffOnJobDto, detail));
                 }
             }
         }
-        map.put("schemeAmount", schemeAmount);
-        map.put("gjj", gjj);
+        map.put("socialPersonal", socialPersonal);
+        map.put("fundPersonal", fundPersonal);
         // 涓◣閲戦锛堢ぞ淇濈増锛�
-        bigDecimal = TaxCalculator.calculateMonthlyTax(basicSalary, schemeAmount, gjj);
+        bigDecimal = TaxCalculator.calculateMonthlyTax(basicSalary, socialPersonal, fundPersonal);
         map.put("salaryTax", bigDecimal);
-        // 搴旀墸宸ヨ祫
-        map.put("deductSalary", bigDecimal.add(gjj).add(schemeAmount));
-        // 瀹炲彂宸ヨ祫
-        map.put("netSalary", basicSalary.subtract(bigDecimal).subtract(gjj).subtract(schemeAmount));
 
+        // 搴旀墸宸ヨ祫 = 涓◣ + 鍏Н閲戜釜浜� + 绀句繚涓汉 + 鍏朵粬鏀嚭
+        deductSalary = bigDecimal.add(fundPersonal).add(socialPersonal).add(otherDeduct);
+        map.put("deductSalary", deductSalary);
+
+        // 瀹炲彂宸ヨ祫 = 搴斿彂宸ヨ祫 - 搴旀墸宸ヨ祫
+        netSalary = grossSalary.subtract(deductSalary);
+        map.put("netSalary", netSalary);
+
+    }
+
+    /**
+     * 閫氳繃鍛樺伐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();
     }
 
     /**

--
Gitblit v1.9.3