From 70a0b21595941890a9d26cfde01ff17e3427214a Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期四, 23 七月 2026 09:24:41 +0800
Subject: [PATCH] 修改工资计算
---
src/main/java/com/ruoyi/staff/service/impl/SchemeApplicableStaffServiceImpl.java | 225 ++++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 200 insertions(+), 25 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 be8abe5..c32d868 100644
--- a/src/main/java/com/ruoyi/staff/service/impl/SchemeApplicableStaffServiceImpl.java
+++ b/src/main/java/com/ruoyi/staff/service/impl/SchemeApplicableStaffServiceImpl.java
@@ -7,6 +7,7 @@
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.mapper.ProductionProductMainMapper;
import com.ruoyi.production.service.SalesLedgerProductionAccountingService;
import com.ruoyi.project.system.domain.SysDept;
import com.ruoyi.project.system.domain.SysUser;
@@ -26,11 +27,14 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
+import java.time.DayOfWeek;
+import java.time.YearMonth;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
+import java.time.LocalDate;
/**
* <p>
@@ -50,6 +54,7 @@
private final SysDeptMapper sysDeptMapper;
private final StaffOnJobMapper staffOnJobMapper;
private final SalesLedgerProductionAccountingService salesLedgerProductionAccountingService;
+ private final ProductionProductMainMapper productionProductMainMapper;
@Override
@@ -162,27 +167,34 @@
if(staffOnJobDto == null){
return;
}
- BigDecimal basicSalary = hasValue(map, "basicSalary")
- ? normalizeMoney(getBigDecimal(map, "basicSalary"))
- : normalizeMoney(staffOnJobDto.getBasicSalary());
+ BigDecimal basicSalary = resolveBasicSalary(map, staffOnJobDto);
+ BigDecimal attendanceBonus = resolveAttendanceBonus(staffOnJobDto);
BigDecimal otherIncome = normalizeMoney(getBigDecimal(map, "otherIncome"));
BigDecimal otherDeduct = normalizeMoney(getBigDecimal(map, "otherDeduct"));
- BigDecimal socialSupplementAmount = hasValue(map, "socialSupplementAmount")
- ? normalizeMoney(getBigDecimal(map, "socialSupplementAmount"))
- : calculateLatestDeptSocialSupplementAmount(staffOnJobDto);
- BigDecimal pieceSalary = normalizeMoney(getBigDecimal(map, "pieceSalary"));
- BigDecimal hourlySalary = normalizeMoney(getBigDecimal(map, "hourlySalary"));
- BigDecimal socialPersonal = normalizeMoney(getBigDecimal(map, "socialPersonal"));
- BigDecimal fundPersonal = normalizeMoney(getBigDecimal(map, "fundPersonal"));
+ BigDecimal socialSupplementAmount = resolveSocialSupplementAmount(map, staffOnJobDto);
+ BigDecimal socialPersonal = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
+ BigDecimal fundPersonal = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
+ int monthWorkDays = calculateWorkDays(date);
+ BigDecimal standardHours = calculateStandardHours(monthWorkDays);
+ BigDecimal actualOutput = resolveActualOutput(map);
+ BigDecimal standardQuantity = resolveStandardQuantity(map);
+ BigDecimal conversionFactor = resolveConversionFactor(map);
+ Long sysUserId = getUidByStaffId(staffId);
UserProductionAccountingDto userProductionAccountingDto = new UserProductionAccountingDto();
- userProductionAccountingDto.setUserId(getUidByStaffId(staffId));
+ userProductionAccountingDto.setUserId(sysUserId);
userProductionAccountingDto.setDate(date);
UserAccountDto byUserId = salesLedgerProductionAccountingService.getByUserId(userProductionAccountingDto);
- if(byUserId != null){
- pieceSalary = normalizeMoney(byUserId.getAccountBalance());
- hourlySalary = normalizeMoney(byUserId.getAccount());
- }
+ BigDecimal repairWorkHour = resolveRepairWorkHour(sysUserId, date);
+ BigDecimal convertedWorkHours = resolveConvertedWorkHours(
+ map,
+ actualOutput,
+ standardQuantity,
+ conversionFactor,
+ repairWorkHour,
+ byUserId
+ );
+ BigDecimal conversionRatio = calculateConversionRatio(standardHours, convertedWorkHours);
// 鏌ヨ璇ヤ汉鍛樺搴旂殑绀句繚鏂规
List<SchemeApplicableStaff> schemeList = schemeApplicableStaffMapper.selectSchemeByStaffId(staffId);
@@ -194,15 +206,16 @@
}
for (SchemeInsuranceDetail detail : detailList) {
if("鍏Н閲�".equals(detail.getInsuranceType())){
- fundPersonal = fundPersonal.add(calculateByEmployeeIdType(detail.getInsuranceType(), fundPersonal, staffOnJobDto, detail));
+ fundPersonal = calculateByEmployeeIdType(detail.getInsuranceType(), fundPersonal, basicSalary, staffOnJobDto, detail);
}else{
- socialPersonal = socialPersonal.add(calculateByEmployeeIdType(detail.getInsuranceType(), socialPersonal, staffOnJobDto, detail));
+ socialPersonal = calculateByEmployeeIdType(detail.getInsuranceType(), socialPersonal, basicSalary, staffOnJobDto, detail);
}
}
}
}
- BigDecimal grossSalary = basicSalary.add(pieceSalary).add(hourlySalary).add(otherIncome);
+ // 宸ヨ祫 = 鍏ㄥ嫟濂栭噾 + 鍩烘湰宸ヨ祫 * 鎶樺悎鍊嶆暟
+ BigDecimal grossSalary = attendanceBonus.add(basicSalary.multiply(conversionRatio)).add(otherIncome);
BigDecimal salaryTax = TaxCalculator.calculateMonthlyTax(
grossSalary,
socialPersonal.add(socialSupplementAmount),
@@ -222,8 +235,17 @@
map.put("nation", staffOnJobDto.getNation());
}
map.put("basicSalary", basicSalary);
- map.put("pieceSalary", pieceSalary);
- map.put("hourlySalary", hourlySalary);
+ map.put("attendanceBonus", attendanceBonus);
+ map.put("monthWorkDays", monthWorkDays);
+ map.put("standardHours", standardHours);
+ map.put("actualOutput", actualOutput);
+ map.put("standardQuantity", standardQuantity);
+ map.put("conversionFactor", conversionFactor);
+ map.put("convertedWorkHours", convertedWorkHours);
+ map.put("monthTimeTotal", convertedWorkHours);
+ map.put("conversionRatio", conversionRatio);
+ map.put("pieceSalary", convertedWorkHours);
+ map.put("hourlySalary", BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP));
map.put("otherIncome", otherIncome);
map.put("socialPersonal", socialPersonal);
map.put("fundPersonal", fundPersonal);
@@ -233,6 +255,140 @@
map.put("salaryTax", salaryTax);
map.put("deductSalary", deductSalary);
map.put("netSalary", netSalary);
+ }
+
+ /**
+ * 瑙f瀽鍛樺伐鍩虹宸ヨ祫銆�
+ * 浼樺厛浣跨敤宸ヨ祫琛ㄩ噷鏈浼犲叆鐨勫�硷紝鏈紶鏃跺洖钀藉埌鍛樺伐妗f涓殑鍩虹宸ヨ祫銆�
+ */
+ private BigDecimal resolveBasicSalary(Map<String, Object> map, StaffOnJob staffOnJobDto) {
+ // 鍛樺伐鍩虹宸ヨ祫浼樺厛鍙栧伐璧勮〃浼犲叆鍊硷紝娌℃湁鍒欏洖钀藉埌鍛樺伐妗f涓殑鍩虹宸ヨ祫銆�
+ return hasValue(map, "basicSalary")
+ ? normalizeMoney(getBigDecimal(map, "basicSalary"))
+ : normalizeMoney(staffOnJobDto.getBasicSalary());
+ }
+
+ /**
+ * 鑾峰彇鍛樺伐鏈�鏂板叏鍕ゅ閲戙��
+ * 鍏ㄥ嫟濂栭噾缁熶竴浠ュ憳宸ユ。妗堥厤缃负鍑嗐��
+ */
+ private BigDecimal resolveAttendanceBonus(StaffOnJob staffOnJobDto) {
+ // 鍏ㄥ嫟濂栭噾鐩存帴鍙栧憳宸ユ。妗堥噷鐨勬渶鏂伴厤缃��
+ return staffOnJobDto.getAttendanceBonus() == null
+ ? BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP)
+ : normalizeMoney(staffOnJobDto.getAttendanceBonus());
+ }
+
+ /**
+ * 瑙f瀽绀句繚琛ョ即閲戦銆�
+ * 濡傛灉宸ヨ祫琛ㄤ紶鍏ヤ簡琛ョ即閲戦鍒欑洿鎺ヤ娇鐢紝鍚﹀垯鎸夊憳宸ユ墍灞為儴闂ㄦ渶鏂版柟妗堣绠椼��
+ */
+ private BigDecimal resolveSocialSupplementAmount(Map<String, Object> map, StaffOnJob staffOnJobDto) {
+ return hasValue(map, "socialSupplementAmount")
+ ? normalizeMoney(getBigDecimal(map, "socialSupplementAmount"))
+ : calculateLatestDeptSocialSupplementAmount(staffOnJobDto);
+ }
+
+ /**
+ * 璁$畻鏈堟爣鍑嗗伐鏃躲��
+ * 瑙勫垯锛氬伐浣滄棩澶╂暟 * 8 灏忔椂銆�
+ */
+ private BigDecimal calculateStandardHours(int monthWorkDays) {
+ // 鏈堟爣鍑嗗伐鏃� = 宸ヤ綔鏃ュぉ鏁� * 8 灏忔椂銆�
+ return BigDecimal.valueOf(monthWorkDays)
+ .multiply(new BigDecimal("8"))
+ .setScale(2, RoundingMode.HALF_UP);
+ }
+
+ /**
+ * 瑙f瀽褰撴湀瀹為檯浜ч噺銆�
+ */
+ private BigDecimal resolveActualOutput(Map<String, Object> map) {
+ return hasValue(map, "actualOutput")
+ ? normalizeMoney(getBigDecimal(map, "actualOutput"))
+ : BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
+ }
+
+ /**
+ * 瑙f瀽宸ュ簭鏍囧噯鏁伴噺銆�
+ */
+ private BigDecimal resolveStandardQuantity(Map<String, Object> map) {
+ return hasValue(map, "standardQuantity")
+ ? normalizeMoney(getBigDecimal(map, "standardQuantity"))
+ : BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
+ }
+
+ /**
+ * 瑙f瀽宸ュ簭鎶樼畻绯绘暟锛屾湭閰嶇疆鏃堕粯璁� 1銆�
+ */
+ private BigDecimal resolveConversionFactor(Map<String, Object> map) {
+ return hasValue(map, "conversionFactor")
+ ? normalizeMoney(getBigDecimal(map, "conversionFactor"))
+ : BigDecimal.ONE.setScale(2, RoundingMode.HALF_UP);
+ }
+
+ /**
+ * 姹囨�昏交寰繑宸ョ殑琛ヤ慨鐞嗗伐鏃躲��
+ * 鎸夌郴缁熺敤鎴� ID 鍜屽伐璧勬湀浠界粺璁★紝骞朵綔涓烘湀鏃堕棿鍚堣鐨勪竴閮ㄥ垎銆�
+ */
+ private BigDecimal resolveRepairWorkHour(Long sysUserId, String date) {
+ if (sysUserId == null || sysUserId <= 0 || StringUtils.isEmpty(date)) {
+ return BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
+ }
+ LocalDate monthStart = YearMonth.parse(date).atDay(1);
+ LocalDate monthEnd = YearMonth.parse(date).atEndOfMonth();
+ return productionProductMainMapper.selectList(new LambdaQueryWrapper<com.ruoyi.production.pojo.ProductionProductMain>()
+ .eq(com.ruoyi.production.pojo.ProductionProductMain::getUserId, sysUserId)
+ .eq(com.ruoyi.production.pojo.ProductionProductMain::getReportType, 1)
+ .ge(com.ruoyi.production.pojo.ProductionProductMain::getCreateTime, monthStart.atStartOfDay())
+ .le(com.ruoyi.production.pojo.ProductionProductMain::getCreateTime, monthEnd.atTime(23, 59, 59)))
+ .stream()
+ .map(item -> normalizeMoney(item.getRepairWorkHour()))
+ .reduce(BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP), BigDecimal::add)
+ .setScale(2, RoundingMode.HALF_UP);
+ }
+
+ /**
+ * 璁$畻鏈堟椂闂村悎璁°��
+ * 璁′欢鍦烘櫙浣跨敤瀹為檯浜ч噺銆佹爣鍑嗘暟閲忓拰鎶樼畻绯绘暟鎹㈢畻锛�
+ * 娌℃湁璁′欢鏁版嵁鏃讹紝鍥炶惤鍒扮敓浜ф牳绠楁眹鎬诲�硷紱
+ * 鏈�鍚庡啀鍙犲姞杩斿伐琛ヤ慨鐞嗗伐鏃躲��
+ */
+ private BigDecimal resolveConvertedWorkHours(Map<String, Object> map,
+ BigDecimal actualOutput,
+ BigDecimal standardQuantity,
+ BigDecimal conversionFactor,
+ BigDecimal repairWorkHour,
+ UserAccountDto byUserId) {
+ if (hasValue(map, "monthTimeTotal")) {
+ BigDecimal monthTimeTotal = normalizeMoney(getBigDecimal(map, "monthTimeTotal"));
+ if (monthTimeTotal.compareTo(BigDecimal.ZERO) > 0) {
+ return monthTimeTotal;
+ }
+ }
+ BigDecimal convertedWorkHours = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
+ // 璁′欢鎶樼畻宸ユ椂 = 褰撴湀瀹為檯浜ч噺 / 宸ュ簭鏍囧噯鏁伴噺 * 8 * 宸ュ簭鎶樼畻绯绘暟
+ if (actualOutput.compareTo(BigDecimal.ZERO) > 0 && standardQuantity.compareTo(BigDecimal.ZERO) > 0) {
+ convertedWorkHours = actualOutput
+ .divide(standardQuantity, 8, RoundingMode.HALF_UP)
+ .multiply(new BigDecimal("8"))
+ .multiply(conversionFactor)
+ .setScale(2, RoundingMode.HALF_UP);
+ } else if (byUserId != null) {
+ convertedWorkHours = normalizeMoney(byUserId.getAccountBalance().add(byUserId.getAccount()));
+ }
+ return convertedWorkHours.add(repairWorkHour).setScale(2, RoundingMode.HALF_UP);
+ }
+
+ /**
+ * 璁$畻鎶樺悎鍊嶆暟銆�
+ * 瑙勫垯锛氭湀鏃堕棿鍚堣 / 鏈堟爣鍑嗗伐鏃躲��
+ */
+ private BigDecimal calculateConversionRatio(BigDecimal standardHours, BigDecimal convertedWorkHours) {
+ return standardHours.compareTo(BigDecimal.ZERO) == 0
+ ? BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP)
+ : convertedWorkHours.divide(standardHours, 8, RoundingMode.HALF_UP)
+ .setScale(2, RoundingMode.HALF_UP);
}
/**
@@ -263,14 +419,14 @@
* @param detail
* @return
*/
- public BigDecimal calculateByEmployeeIdType(String type,BigDecimal bigDecimal, StaffOnJob staffOnJobDto,SchemeInsuranceDetail detail) {
+ public BigDecimal calculateByEmployeeIdType(String type,BigDecimal bigDecimal, BigDecimal basicSalary, 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 multiply = basicSalary.multiply(detail.getPersonalRatio().divide(new BigDecimal("100"), 2));
bigDecimal = bigDecimal.add(multiply);
}
bigDecimal = bigDecimal.add(detail.getPersonalFixed());
@@ -292,8 +448,12 @@
BigDecimal socialSupplementAmount = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
for (SchemeInsuranceDetail detail : detailList) {
if (!"鍏Н閲�".equals(detail.getInsuranceType())) {
- socialSupplementAmount = socialSupplementAmount.add(
- calculateByEmployeeIdType(detail.getInsuranceType(), socialSupplementAmount, staffOnJobDto, detail)
+ socialSupplementAmount = calculateByEmployeeIdType(
+ detail.getInsuranceType(),
+ socialSupplementAmount,
+ normalizeMoney(staffOnJobDto.getBasicSalary()),
+ staffOnJobDto,
+ detail
);
}
}
@@ -336,4 +496,19 @@
private BigDecimal normalizeMoney(BigDecimal value) {
return value == null ? BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP) : value.setScale(2, RoundingMode.HALF_UP);
}
+
+ private int calculateWorkDays(String date) {
+ if (StringUtils.isEmpty(date)) {
+ return 0;
+ }
+ YearMonth yearMonth = YearMonth.parse(date);
+ int workDays = 0;
+ for (int day = 1; day <= yearMonth.lengthOfMonth(); day++) {
+ DayOfWeek dayOfWeek = yearMonth.atDay(day).getDayOfWeek();
+ if (dayOfWeek != DayOfWeek.SATURDAY && dayOfWeek != DayOfWeek.SUNDAY) {
+ workDays++;
+ }
+ }
+ return workDays;
+ }
}
--
Gitblit v1.9.3