From 25982dff708ba07e83cb91c311a6e1c1ec7a32e0 Mon Sep 17 00:00:00 2001
From: 赵士淞 <zhaoss@yhzhg.cn>
Date: Tue, 10 Jan 2023 08:39:43 +0000
Subject: [PATCH] 工资管理
---
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/repository/SalaryRepository.java | 22 ++
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/service/SalaryService.java | 6
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/service/impl/SalaryServiceImpl.java | 39 +++
eladmin-web-master/src/views/salary/salary/index.vue | 162 ++++++++++++++
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/SalaryTask.java | 418 ++++++++++++++++++++++++++++++++++++++
5 files changed, 639 insertions(+), 8 deletions(-)
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/SalaryTask.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/SalaryTask.java
new file mode 100644
index 0000000..e7a4c58
--- /dev/null
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/task/SalaryTask.java
@@ -0,0 +1,418 @@
+package me.zhengjie.modules.quartz.task;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import me.zhengjie.modules.attendance.service.AttendanceService;
+import me.zhengjie.modules.attendance.service.dto.AttendanceQueryCriteria;
+import me.zhengjie.modules.salary.domain.Salary;
+import me.zhengjie.modules.salary.service.SalaryService;
+import me.zhengjie.modules.salary.service.dto.SalaryQueryCriteria;
+import me.zhengjie.modules.system.service.*;
+import me.zhengjie.modules.system.service.dto.*;
+import me.zhengjie.modules.task.service.TaskDaliyService;
+import me.zhengjie.modules.task.service.dto.TaskDaliyQueryCriteria;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Component;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * 工资管理相关任务
+ * @author 赵士淞
+ * @date 2023-01-10
+ */
+@Slf4j
+@Service
+@RequiredArgsConstructor
+public class SalaryTask {
+
+ private final UserService userService;
+ private final SysUserLevelWageService sysUserLevelWageService;
+ private final SysUserLevelInsuranceService sysUserLevelInsuranceService;
+ private final SysUserLevelOtherService sysUserLevelOtherService;
+ private final SalaryService salaryService;
+ private final AttendanceService attendanceService;
+ private final TaskDaliyService taskDaliyService;
+ private final SysConfigIndividualIncomeTaxService sysConfigIndividualIncomeTaxService;
+
+ // 工资结算
+ public void salarySettlement() {
+ // 日历类
+ Calendar cal = Calendar.getInstance();
+ // 格式化日期
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+ // 目标年月
+ String targetYearMonth = sdf.format(cal.getTime());
+ // 用户工资结算
+ userSalarySettlement(null, targetYearMonth);
+ }
+
+ // 用户工资结算
+ public void userSalarySettlement(Long userId, String targetYearMonth) {
+ // 判断用户ID是否为空
+ if (userId != null && !"".equals(userId)) {
+ // 单个用户工资结算
+ singleUserSalarySettlement(userId, targetYearMonth);
+ } else {
+ // 用户检索类
+ UserQueryCriteria userQueryCriteria = new UserQueryCriteria();
+ userQueryCriteria.setEnabled(true);
+ // 获取用户列表
+ List<UserDto> userDtoList = userService.queryAll(userQueryCriteria);
+ // 循环用户列表
+ for (int i = 0; i < userDtoList.size(); i ++) {
+ try {
+ // 单个用户工资结算
+ singleUserSalarySettlement(userDtoList.get(i).getId(), targetYearMonth);
+ } catch (Exception e) {
+ // 跳过本次循环
+ continue;
+ }
+ }
+ }
+ }
+
+ // 单个用户工资结算
+ private void singleUserSalarySettlement(Long userId, String targetYearMonth) {
+ // 日历类
+ Calendar cal = Calendar.getInstance();
+ // 设置年份
+ cal.set(Calendar.YEAR, Integer.valueOf(targetYearMonth.substring(0,4)));
+ // 设置月份
+ cal.set(Calendar.MONTH, Integer.valueOf(targetYearMonth.substring(5,7)) - 1);
+ // 设置日份
+ cal.set(Calendar.DAY_OF_MONTH, 1);
+ // 设置时数
+ cal.set(Calendar.HOUR_OF_DAY, 0);
+ // 设置分数
+ cal.set(Calendar.MINUTE, 0);
+ // 设置秒数
+ cal.set(Calendar.SECOND, 0);
+ // 设置毫秒数
+ cal.set(Calendar.MILLISECOND, 0);
+ // 工资实体类
+ Salary salary = new Salary();
+ salary.setUserId(userId);
+ salary.setSalaryYearMonth(new Timestamp(cal.getTime().getTime()));
+ // 获取用户级别工资
+ salary = getUserLevelWage(userId, targetYearMonth, salary);
+ // 获取用户级别保险
+ salary = getUserLevelInsurance(userId, targetYearMonth, salary);
+ // 获取用户级别其他
+ salary = getUserLevelOther(userId, targetYearMonth, salary);
+ // 获取工作天数
+ salary = getWorkDays(targetYearMonth, salary);
+ // 获取出勤小时数
+ salary = getAttendanceHours(userId, targetYearMonth, salary);
+ // 获取达标工时
+ salary = getComplianceWork(userId, targetYearMonth, salary);
+ // 获取已完成工时
+ salary = getCompletedWork(userId, targetYearMonth, salary);
+ try {
+ // 保存
+ salaryService.create(salary);
+ } catch (Exception e) {
+ // 删除
+ salaryService.deleteByUserIdAndSalaryYearMonthAndCreateNew(salary);
+ }
+ }
+
+ // 获取用户级别工资
+ private Salary getUserLevelWage(Long userId, String targetYearMonth, Salary salary) {
+ // 用户级别工资检索类
+ SysUserLevelWageQueryCriteria sysUserLevelWageQueryCriteria = new SysUserLevelWageQueryCriteria();
+ sysUserLevelWageQueryCriteria.setUserId(userId);
+ sysUserLevelWageQueryCriteria.setTargetYearMonth(targetYearMonth);
+ // 查询指定年月用户级别工资
+ SysUserLevelWageDto sysUserLevelWageDto = sysUserLevelWageService.queryTargetYearMonth(sysUserLevelWageQueryCriteria);
+ // 级别工资
+ salary.setLevelWage(sysUserLevelWageDto.getLevelWage());
+ // 基本工资比例
+ salary.setBasicWageProportion(sysUserLevelWageDto.getBasicWageProportion());
+ // 预计基本工资
+ salary.setBasicWage(sysUserLevelWageDto.getLevelWage().multiply(new BigDecimal(sysUserLevelWageDto.getBasicWageProportion() / 100)));
+ // 绩效工资比例
+ salary.setAchievementsWageProportion(sysUserLevelWageDto.getAchievementsWageProportion());
+ // 预计绩效工资
+ salary.setAchievementsWage(sysUserLevelWageDto.getLevelWage().multiply(new BigDecimal(sysUserLevelWageDto.getAchievementsWageProportion() / 100)));
+ // 业绩工资比例
+ salary.setPerformanceWageProportion(sysUserLevelWageDto.getPerformanceWageProportion());
+ // 预计业绩工资
+ salary.setPerformanceWage(sysUserLevelWageDto.getLevelWage().multiply(new BigDecimal(sysUserLevelWageDto.getPerformanceWageProportion() / 100)));
+ // 团队工资比例
+ salary.setTeamWageProportion(sysUserLevelWageDto.getTeamWageProportion());
+ // 预计团队工资
+ salary.setTeamWage(sysUserLevelWageDto.getLevelWage().multiply(new BigDecimal(sysUserLevelWageDto.getTeamWageProportion() / 100)));
+ // 返回
+ return salary;
+ }
+
+ // 获取用户级别保险
+ private Salary getUserLevelInsurance(Long userId, String targetYearMonth, Salary salary) {
+ // 用户级别保险查询类
+ SysUserLevelInsuranceQueryCriteria sysUserLevelInsuranceQueryCriteria = new SysUserLevelInsuranceQueryCriteria();
+ sysUserLevelInsuranceQueryCriteria.setUserId(userId);
+ sysUserLevelInsuranceQueryCriteria.setTargetYearMonth(targetYearMonth);
+ // 查询指定年月用户级别保险
+ SysUserLevelInsuranceDto sysUserLevelInsuranceDto = sysUserLevelInsuranceService.queryTargetYearMonth(sysUserLevelInsuranceQueryCriteria);
+ // 公积金基数
+ salary.setAccumulationRadix(sysUserLevelInsuranceDto.getAccumulationRadix());
+ // 公积金个人缴纳比例
+ salary.setAccumulationPersonalProportion(sysUserLevelInsuranceDto.getAccumulationPersonalProportion());
+ // 公积金个人缴纳金额
+ salary.setAccumulationPersonalAmount(sysUserLevelInsuranceDto.getAccumulationRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getAccumulationPersonalProportion() / 100)));
+ // 公积金公司缴纳比例
+ salary.setAccumulationCompanyProportion(sysUserLevelInsuranceDto.getAccumulationCompanyProportion());
+ // 公积金公司缴纳金额
+ salary.setAccumulationCompanyAmount(sysUserLevelInsuranceDto.getAccumulationRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getAccumulationCompanyProportion() / 100)));
+ // 养老险基数
+ salary.setPensionRadix(sysUserLevelInsuranceDto.getPensionRadix());
+ // 养老险个人缴纳比例
+ salary.setPensionPersonalProportion(sysUserLevelInsuranceDto.getPensionPersonalProportion());
+ // 养老险个人缴纳金额
+ salary.setPensionPersonalAmount(sysUserLevelInsuranceDto.getPensionRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getPensionPersonalProportion() / 100)));
+ // 养老险公司缴纳比例
+ salary.setPensionCompanyProportion(sysUserLevelInsuranceDto.getPensionCompanyProportion());
+ // 养老险公司缴纳金额
+ salary.setPensionCompanyAmount(sysUserLevelInsuranceDto.getPensionRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getPensionCompanyProportion() / 100)));
+ // 医疗险基数
+ salary.setMedicalRadix(sysUserLevelInsuranceDto.getMedicalRadix());
+ // 医疗险个人缴纳比例
+ salary.setMedicalPersonalProportion(sysUserLevelInsuranceDto.getMedicalPersonalProportion());
+ // 医疗险个人缴纳金额
+ salary.setMedicalPersonalAmount(sysUserLevelInsuranceDto.getMedicalRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getMedicalPersonalProportion() / 100)));
+ // 医疗险公司缴纳比例
+ salary.setMedicalCompanyProportion(sysUserLevelInsuranceDto.getMedicalCompanyProportion());
+ // 医疗险公司缴纳金额
+ salary.setMedicalCompanyAmount(sysUserLevelInsuranceDto.getMedicalRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getMedicalCompanyProportion() / 100)));
+ // 失业险基数
+ salary.setUnemploymentRadix(sysUserLevelInsuranceDto.getUnemploymentRadix());
+ // 失业险个人缴纳比例
+ salary.setUnemploymentPersonalProportion(sysUserLevelInsuranceDto.getUnemploymentPersonalProportion());
+ // 失业险个人缴纳金额
+ salary.setUnemploymentPersonalAmount(sysUserLevelInsuranceDto.getUnemploymentRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getUnemploymentPersonalProportion() / 100)));
+ // 失业险公司缴纳比例
+ salary.setUnemploymentCompanyProportion(sysUserLevelInsuranceDto.getUnemploymentCompanyProportion());
+ // 失业险公司缴纳金额
+ salary.setUnemploymentCompanyAmount(sysUserLevelInsuranceDto.getUnemploymentRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getUnemploymentCompanyProportion() / 100)));
+ // 生育险基数
+ salary.setMaternityRadix(sysUserLevelInsuranceDto.getMaternityRadix());
+ // 生育险个人缴纳比例
+ salary.setMaternityPersonalProportion(sysUserLevelInsuranceDto.getMaternityPersonalProportion());
+ // 生育险个人缴纳金额
+ salary.setMaternityPersonalAmount(sysUserLevelInsuranceDto.getMaternityRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getMaternityPersonalProportion() / 100)));
+ // 生育险公司缴纳比例
+ salary.setMaternityCompanyProportion(sysUserLevelInsuranceDto.getMaternityCompanyProportion());
+ // 生育险公司缴纳金额
+ salary.setMaternityCompanyAmount(sysUserLevelInsuranceDto.getMaternityRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getMaternityCompanyProportion() / 100)));
+ // 工伤险基数
+ salary.setIndustrialInjuryRadix(sysUserLevelInsuranceDto.getIndustrialInjuryRadix());
+ // 工伤险个人缴纳比例
+ salary.setIndustrialInjuryPersonalProportion(sysUserLevelInsuranceDto.getIndustrialInjuryPersonalProportion());
+ // 工伤险个人缴纳金额
+ salary.setIndustrialInjuryPersonalAmount(sysUserLevelInsuranceDto.getIndustrialInjuryRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getIndustrialInjuryPersonalProportion() / 100)));
+ // 工伤险公司缴纳比例
+ salary.setIndustrialInjuryCompanyProportion(sysUserLevelInsuranceDto.getIndustrialInjuryCompanyProportion());
+ // 工伤险公司缴纳金额
+ salary.setIndustrialInjuryCompanyAmount(sysUserLevelInsuranceDto.getIndustrialInjuryRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getIndustrialInjuryCompanyProportion() / 100)));
+ // 返回
+ return salary;
+ }
+
+ // 获取用户级别其他
+ private Salary getUserLevelOther(Long userId, String targetYearMonth, Salary salary) {
+ // 用户级别其他查询类
+ SysUserLevelOtherQueryCriteria sysUserLevelOtherQueryCriteria = new SysUserLevelOtherQueryCriteria();
+ sysUserLevelOtherQueryCriteria.setUserId(userId);
+ sysUserLevelOtherQueryCriteria.setTargetYearMonth(targetYearMonth);
+ // 查询指定年月用户级别其他
+ SysUserLevelOtherDto sysUserLevelOtherDto = sysUserLevelOtherService.queryTargetYearMonth(sysUserLevelOtherQueryCriteria);
+ // 个人业绩比例
+ salary.setPersonalPerformanceProportion(sysUserLevelOtherDto.getPersonalPerformanceProportion());
+ // 返回
+ return salary;
+ }
+
+ // 获取工作天数
+ private Salary getWorkDays(String targetYearMonth, Salary salary) {
+ // 工资查询类
+ SalaryQueryCriteria salaryQueryCriteria = new SalaryQueryCriteria();
+ salaryQueryCriteria.setTargetYearMonth(targetYearMonth);
+ // 查询某月工作天数
+ Integer workDays = salaryService.queryWorkDays(salaryQueryCriteria);
+ // 全勤小时数
+ salary.setFullDays(Double.valueOf(workDays * 8));
+ // 应完成绩效工时
+ salary.setNeedCompletedAchievementsHours(Double.valueOf(workDays * 8));
+ // 定时器
+ while (true) {
+ // 判断个人业绩比例是否为空
+ if (salary.getPersonalPerformanceProportion() != null && !"".equals(salary.getPersonalPerformanceProportion())) {
+ // 应完成业绩工时
+ salary.setNeedCompletedPerformanceHours(Double.valueOf(workDays * 8 * (1 + salary.getPersonalPerformanceProportion() / 100)));
+ // 清空定时器
+ break;
+ }
+ }
+ // 返回
+ return salary;
+ }
+
+ // 获取出勤小时数
+ private Salary getAttendanceHours(Long userId, String targetYearMonth, Salary salary) {
+ // 考勤查询类
+ AttendanceQueryCriteria attendanceQueryCriteria = new AttendanceQueryCriteria();
+ attendanceQueryCriteria.setUserId(userId);
+ attendanceQueryCriteria.setTargetYearMonth(targetYearMonth);
+ // 查询某月出勤小时数
+ Double attendanceHours = attendanceService.queryAttendanceHours(attendanceQueryCriteria);
+ // 定时器
+ while (true) {
+ // 判断预计基础工资、全勤小时数是否为空
+ if (salary.getBasicWage() != null && !"".equals(salary.getBasicWage()) && salary.getFullDays() != null && !"".equals(salary.getFullDays())) {
+ // 缺勤小时数
+ salary.setAbsenceDays(Double.valueOf(salary.getFullDays() - attendanceHours));
+ // 小时工资
+ BigDecimal hourWage = salary.getBasicWage().divide(new BigDecimal(salary.getFullDays()), 2);
+ // 缺勤小时数
+ BigDecimal absenceDays = new BigDecimal(salary.getFullDays() - attendanceHours);
+ // 实际基础工资
+ salary.setActualBasicWage(salary.getBasicWage().subtract(hourWage.multiply(absenceDays)));
+ // 清空定时器
+ break;
+ }
+ }
+ // 返回
+ return salary;
+ }
+
+ // 获取达标工时
+ private Salary getComplianceWork(Long userId, String targetYearMonth, Salary salary) {
+ // 任务日报查询类
+ TaskDaliyQueryCriteria taskDaliyQueryCriteria = new TaskDaliyQueryCriteria();
+ taskDaliyQueryCriteria.setUserId(userId);
+ taskDaliyQueryCriteria.setTargetYearMonth(targetYearMonth);
+ // 查询某月已达标工时
+ Double complianceWork = taskDaliyService.queryComplianceWork(taskDaliyQueryCriteria);
+ // 实达标团队工时
+ salary.setActualComplianceTeamHours(complianceWork);
+ // 返回
+ return salary;
+ }
+
+ // 获取已完成工时
+ private Salary getCompletedWork(Long userId, String targetYearMonth, Salary salary) {
+ // 任务日报查询类
+ TaskDaliyQueryCriteria taskDaliyQueryCriteria = new TaskDaliyQueryCriteria();
+ taskDaliyQueryCriteria.setUserId(userId);
+ taskDaliyQueryCriteria.setTargetYearMonth(targetYearMonth);
+ // 查询某月已完成工时
+ Double completedWork = taskDaliyService.queryCompletedWork(taskDaliyQueryCriteria);
+ // 已完成绩效工时
+ salary.setAlreadyCompletedAchievementsHours(completedWork);
+ // 已完成业绩工时
+ salary.setAlreadyCompletedPerformanceHours(completedWork);
+ // 已完成团队工时
+ salary.setAlreadyCompletedTeamHours(completedWork);
+ // 绩效定时器
+ while (true) {
+ // 判断预计绩效工资、应完成绩效工时是否为空
+ if (salary.getAchievementsWage() != null && !"".equals(salary.getAchievementsWage()) && salary.getNeedCompletedAchievementsHours() != null && !"".equals(salary.getNeedCompletedAchievementsHours())) {
+ // 实际绩效工资
+ salary.setActualAchievementsWage(salary.getAchievementsWage().multiply(new BigDecimal(completedWork / salary.getNeedCompletedAchievementsHours())));
+ // 清空绩效定时器
+ break;
+ }
+ }
+ // 业绩定时器
+ while (true) {
+ // 判断预计业绩工资、应完成业绩工时是否为空
+ if (salary.getPerformanceWage() != null && !"".equals(salary.getPerformanceWage()) && salary.getNeedCompletedPerformanceHours() != null && !"".equals(salary.getNeedCompletedPerformanceHours())) {
+ // 实际业绩工资
+ salary.setActualPerformanceWage(completedWork >= salary.getNeedCompletedPerformanceHours() ? salary.getPerformanceWage() : new BigDecimal(0));
+ // 清空业绩定时器
+ break;
+ }
+ }
+ // 团队定时器
+ while (true) {
+ // 判断预计团队工资、实达标团队工时是否为空
+ if (salary.getTeamWage() != null && !"".equals(salary.getTeamWage()) && salary.getActualComplianceTeamHours() != null && !"".equals(salary.getActualComplianceTeamHours())) {
+ // 实际团队工资
+ salary.setActualTeamWage(salary.getActualComplianceTeamHours() != 0 ? salary.getTeamWage().multiply(new BigDecimal(salary.getActualComplianceTeamHours() / completedWork)) : new BigDecimal(0));
+ // 清空团队定时器
+ break;
+ }
+ }
+ // 统计定时器
+ while (true) {
+ // 判断 实际基础工资、实际绩效工资、实际业绩工资、实际团队工资、公积金个人缴纳金额、养老险个人缴纳金额、
+ // 医疗险个人缴纳金额、失业险个人缴纳金额、生育险个人缴纳金额、工伤险个人缴纳金额 是否为空
+ if (
+ salary.getActualBasicWage() != null && !"".equals(salary.getActualBasicWage()) &&
+ salary.getActualAchievementsWage() != null && !"".equals(salary.getActualAchievementsWage()) &&
+ salary.getActualPerformanceWage() != null && !"".equals(salary.getActualPerformanceWage()) &&
+ salary.getActualTeamWage() != null && !"".equals(salary.getActualTeamWage()) &&
+ salary.getAccumulationPersonalAmount() != null && !"".equals(salary.getAccumulationPersonalAmount()) &&
+ salary.getPensionPersonalAmount() != null && !"".equals(salary.getPensionPersonalAmount()) &&
+ salary.getMedicalPersonalAmount() != null && !"".equals(salary.getMedicalPersonalAmount()) &&
+ salary.getUnemploymentPersonalAmount() != null && !"".equals(salary.getUnemploymentPersonalAmount()) &&
+ salary.getMaternityPersonalAmount() != null && !"".equals(salary.getMaternityPersonalAmount()) &&
+ salary.getIndustrialInjuryPersonalAmount() != null && !"".equals(salary.getIndustrialInjuryPersonalAmount())
+ ) {
+ // 税前金额
+ salary.setPreTaxAmount(salary.getActualBasicWage().add(salary.getActualAchievementsWage()).add(salary.getActualPerformanceWage()).add(salary.getActualTeamWage()));
+ // 查询个人所得税列表
+ List<SysConfigIndividualIncomeTaxDto> sysConfigIndividualIncomeTaxDtoList = sysConfigIndividualIncomeTaxService.queryAll(new SysConfigIndividualIncomeTaxQueryCriteria());
+ // 税额
+ BigDecimal taxAmount = new BigDecimal(0);
+ // 计税金额
+ BigDecimal taxableAmount = salary.getPreTaxAmount().subtract(salary.getAccumulationPersonalAmount()).subtract(salary.getPensionPersonalAmount())
+ .subtract(salary.getMedicalPersonalAmount()).subtract(salary.getUnemploymentPersonalAmount()).subtract(salary.getMaternityPersonalAmount())
+ .subtract(salary.getIndustrialInjuryPersonalAmount());
+ // 循环个人所得税列表
+ for (int i = 0; i < sysConfigIndividualIncomeTaxDtoList.size(); i ++) {
+ // 判断计税金额所在个人所得税范围
+ if (sysConfigIndividualIncomeTaxDtoList.get(i).getGearAmountEnd() != null && !"".equals(sysConfigIndividualIncomeTaxDtoList.get(i).getGearAmountEnd()) &&
+ taxableAmount.compareTo(sysConfigIndividualIncomeTaxDtoList.get(i).getGearAmountEnd()) == 1) {
+ // 税额
+ taxAmount.add(
+ (sysConfigIndividualIncomeTaxDtoList.get(i).getGearAmountEnd().subtract(sysConfigIndividualIncomeTaxDtoList.get(i).getGearAmountStart()))
+ .multiply(new BigDecimal(sysConfigIndividualIncomeTaxDtoList.get(i).getTaxRate()).divide(new BigDecimal(100), 2))
+ );
+ } else if (
+ (taxableAmount.compareTo(sysConfigIndividualIncomeTaxDtoList.get(i).getGearAmountStart()) == 1 ||
+ taxableAmount.compareTo(sysConfigIndividualIncomeTaxDtoList.get(i).getGearAmountStart()) == 0) &&
+ (sysConfigIndividualIncomeTaxDtoList.get(i).getGearAmountEnd() == null || "".equals(sysConfigIndividualIncomeTaxDtoList.get(i).getGearAmountEnd()) ||
+ taxableAmount.compareTo(sysConfigIndividualIncomeTaxDtoList.get(i).getGearAmountEnd()) == -1 ||
+ taxableAmount.compareTo(sysConfigIndividualIncomeTaxDtoList.get(i).getGearAmountEnd()) == 0)
+ ) {
+ // 税额
+ taxAmount.add(
+ (taxableAmount.subtract(sysConfigIndividualIncomeTaxDtoList.get(i).getGearAmountStart()))
+ .multiply(new BigDecimal(sysConfigIndividualIncomeTaxDtoList.get(i).getTaxRate()).divide(new BigDecimal(100), 2))
+ );
+ }
+ // 判断循环是否结束
+ if (i == sysConfigIndividualIncomeTaxDtoList.size() - 1) {
+ // 个人所得税
+ salary.setIndividualIncomeTax(taxAmount);
+ // 税后金额
+ salary.setAfterTaxAmount(taxableAmount.subtract(taxAmount).compareTo(new BigDecimal(0)) == -1 ? new BigDecimal(0) : taxableAmount.subtract(taxAmount));
+ }
+ }
+ // 清空统计定时器
+ break;
+ }
+ }
+
+ // 返回
+ return salary;
+ }
+}
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/repository/SalaryRepository.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/repository/SalaryRepository.java
index 2384c2c..cd77d8b 100644
--- a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/repository/SalaryRepository.java
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/repository/SalaryRepository.java
@@ -18,6 +18,11 @@
import me.zhengjie.modules.salary.domain.Salary;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+
+import java.sql.Timestamp;
+import java.util.List;
/**
* @website https://eladmin.vip
@@ -25,4 +30,21 @@
* @date 2023-01-03
**/
public interface SalaryRepository extends JpaRepository<Salary, Long>, JpaSpecificationExecutor<Salary> {
+
+ /**
+ * 根据用户ID和工资年月查询
+ * @param userId
+ * @param salaryYearMonth
+ * @return
+ */
+ List<Salary> findByUserIdAndSalaryYearMonth(Long userId, Timestamp salaryYearMonth);
+
+ /**
+ * 根据用户ID和工资年月删除
+ * @param userId
+ * @param salaryYearMonth
+ */
+ @Modifying
+ @Query(value = "DELETE FROM salary WHERE user_id = ?1 AND salary_year_month LIKE CONCAT(?2, '%')",nativeQuery = true)
+ void deleteByUserIdAndSalaryYearMonth(Long userId, String salaryYearMonth);
}
\ No newline at end of file
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/service/SalaryService.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/service/SalaryService.java
index 12f2d24..6b53411 100644
--- a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/service/SalaryService.java
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/service/SalaryService.java
@@ -87,4 +87,10 @@
* @return List<SalaryDto>
*/
Integer queryWorkDays(SalaryQueryCriteria criteria);
+
+ /**
+ * 根据用户ID和工资年月删除
+ * @param resources
+ */
+ void deleteByUserIdAndSalaryYearMonthAndCreateNew(Salary resources);
}
\ No newline at end of file
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/service/impl/SalaryServiceImpl.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/service/impl/SalaryServiceImpl.java
index fb12cc0..b656b52 100644
--- a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/service/impl/SalaryServiceImpl.java
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/salary/service/impl/SalaryServiceImpl.java
@@ -15,6 +15,7 @@
*/
package me.zhengjie.modules.salary.service.impl;
+import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.salary.domain.Salary;
import me.zhengjie.modules.system.domain.SysConfigHoliday;
import me.zhengjie.modules.system.domain.User;
@@ -93,6 +94,8 @@
@Override
@Transactional(rollbackFor = Exception.class)
public SalaryDto create(Salary resources) {
+ // 新增验证
+ checkCreate(resources);
return salaryMapper.toDto(salaryRepository.save(resources));
}
@@ -102,7 +105,34 @@
Salary salary = salaryRepository.findById(resources.getId()).orElseGet(Salary::new);
ValidationUtil.isNull( salary.getId(),"Salary","id",resources.getId());
salary.copy(resources);
+ // 修改验证
+ checkUpdate(salary);
salaryRepository.save(salary);
+ }
+
+ // 新增验证
+ private void checkCreate(Salary resources) {
+ // 根据用户ID和工资年月查询
+ List<Salary> salaryList = salaryRepository.findByUserIdAndSalaryYearMonth(resources.getUserId(), resources.getSalaryYearMonth());
+ // 判断列表长度
+ if (salaryList.size() > 0) {
+ throw new BadRequestException("找到相同用户相同年月的工资记录!");
+ }
+ }
+
+ // 修改验证
+ private void checkUpdate(Salary resources) {
+ // 根据用户ID和工资年月查询
+ List<Salary> salaryList = salaryRepository.findByUserIdAndSalaryYearMonth(resources.getUserId(), resources.getSalaryYearMonth());
+ // 判断列表长度
+ if (salaryList.size() > 1) {
+ throw new BadRequestException("找到相同用户相同年月的工资记录!");
+ } else if (salaryList.size() == 1) {
+ // 判断是否是同一条记录
+ if (salaryList.get(0).getId() != resources.getId()) {
+ throw new BadRequestException("找到相同用户相同年月的工资记录!");
+ }
+ }
}
@Override
@@ -197,4 +227,13 @@
// 查询某月工作天数
return DateUtil.getWorkDayOfMonth(sysConfigHolidayList, targetYearMonth);
}
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void deleteByUserIdAndSalaryYearMonthAndCreateNew(Salary resources) {
+ // 根据用户ID和工资年月删除
+ salaryRepository.deleteByUserIdAndSalaryYearMonth(resources.getUserId(), resources.getSalaryYearMonth().toString().substring(0,7));
+ // 保存
+ salaryRepository.save(resources);
+ }
}
\ No newline at end of file
diff --git a/eladmin-web-master/src/views/salary/salary/index.vue b/eladmin-web-master/src/views/salary/salary/index.vue
index a64746f..798de47 100644
--- a/eladmin-web-master/src/views/salary/salary/index.vue
+++ b/eladmin-web-master/src/views/salary/salary/index.vue
@@ -614,6 +614,7 @@
import crudUserLevelOther from '@/api/system/userLevelOther'
import crudAttendance from '@/api/attendance/attendance'
import crudTaskDaliy from '@/api/task/taskDaliy'
+import crudSysConfigIndividualIncomeTax from '@/api/system/configIndividualIncomeTax'
const defaultForm = { id: null, userId: null, salaryYearMonth: null, levelWage: null, basicWageProportion: null, basicWage: null, fullDays: null, absenceDays: null, actualBasicWage: null, achievementsWageProportion: null, achievementsWage: null, needCompletedAchievementsHours: null, alreadyCompletedAchievementsHours: null, actualAchievementsWage: null, performanceWageProportion: null, performanceWage: null, personalPerformanceProportion: null, needCompletedPerformanceHours: null, alreadyCompletedPerformanceHours: null, actualPerformanceWage: null, teamWageProportion: null, teamWage: null, actualComplianceTeamHours: null, alreadyCompletedTeamHours: null, actualTeamWage: null, accumulationRadix: null, accumulationPersonalProportion: null, accumulationPersonalAmount: null, accumulationCompanyProportion: null, accumulationCompanyAmount: null, pensionRadix: null, pensionPersonalProportion: null, pensionPersonalAmount: null, pensionCompanyProportion: null, pensionCompanyAmount: null, medicalRadix: null, medicalPersonalProportion: null, medicalPersonalAmount: null, medicalCompanyProportion: null, medicalCompanyAmount: null, unemploymentRadix: null, unemploymentPersonalProportion: null, unemploymentPersonalAmount: null, unemploymentCompanyProportion: null, unemploymentCompanyAmount: null, maternityRadix: null, maternityPersonalProportion: null, maternityPersonalAmount: null, maternityCompanyProportion: null, maternityCompanyAmount: null, industrialInjuryRadix: null, industrialInjuryPersonalProportion: null, industrialInjuryPersonalAmount: null, industrialInjuryCompanyProportion: null, industrialInjuryCompanyAmount: null, preTaxAmount: null, individualIncomeTax: null, afterTaxAmount: null, remarks: null, createBy: null, createTime: null, updateBy: null, updateTime: null }
export default {
@@ -959,6 +960,27 @@
this.form.teamWage = Number((res.levelWage * (res.teamWageProportion / 100)).toFixed(2))
// 随机数
this.random = Math.random()
+ }).catch(() => {
+ // 级别工资
+ this.form.levelWage = 0
+ // 基本工资比例
+ this.form.basicWageProportion = 0
+ // 预计基本工资
+ this.form.basicWage = 0
+ // 绩效工资比例
+ this.form.achievementsWageProportion = 0
+ // 预计绩效工资
+ this.form.achievementsWage = 0
+ // 业绩工资比例
+ this.form.performanceWageProportion = 0
+ // 预计业绩工资
+ this.form.performanceWage = 0
+ // 团队工资比例
+ this.form.teamWageProportion = 0
+ // 预计团队工资
+ this.form.teamWage = 0
+ // 随机数
+ this.random = Math.random()
})
},
// 获取用户级别保险
@@ -1027,6 +1049,69 @@
this.form.industrialInjuryCompanyAmount = Number((res.industrialInjuryRadix * (res.industrialInjuryCompanyProportion / 100)).toFixed(2))
// 随机数
this.random = Math.random()
+ }).catch(() => {
+ // 公积金基数
+ this.form.accumulationRadix = 0
+ // 公积金个人缴纳比例
+ this.form.accumulationPersonalProportion = 0
+ // 公积金个人缴纳金额
+ this.form.accumulationPersonalAmount = 0
+ // 公积金公司缴纳比例
+ this.form.accumulationCompanyProportion = 0
+ // 公积金公司缴纳金额
+ this.form.accumulationCompanyAmount = 0
+ // 养老险基数
+ this.form.pensionRadix = 0
+ // 养老险个人缴纳比例
+ this.form.pensionPersonalProportion = 0
+ // 养老险个人缴纳金额
+ this.form.pensionPersonalAmount = 0
+ // 养老险公司缴纳比例
+ this.form.pensionCompanyProportion = 0
+ // 养老险公司缴纳金额
+ this.form.pensionCompanyAmount = 0
+ // 医疗险基数
+ this.form.medicalRadix = 0
+ // 医疗险个人缴纳比例
+ this.form.medicalPersonalProportion = 0
+ // 医疗险个人缴纳金额
+ this.form.medicalPersonalAmount = 0
+ // 医疗险公司缴纳比例
+ this.form.medicalCompanyProportion = 0
+ // 医疗险公司缴纳金额
+ this.form.medicalCompanyAmount = 0
+ // 失业险基数
+ this.form.unemploymentRadix = 0
+ // 失业险个人缴纳比例
+ this.form.unemploymentPersonalProportion = 0
+ // 失业险个人缴纳金额
+ this.form.unemploymentPersonalAmount = 0
+ // 失业险公司缴纳比例
+ this.form.unemploymentCompanyProportion = 0
+ // 失业险公司缴纳金额
+ this.form.unemploymentCompanyAmount = 0
+ // 生育险基数
+ this.form.maternityRadix = 0
+ // 生育险个人缴纳比例
+ this.form.maternityPersonalProportion = 0
+ // 生育险个人缴纳金额
+ this.form.maternityPersonalAmount = 0
+ // 生育险公司缴纳比例
+ this.form.maternityCompanyProportion = 0
+ // 生育险公司缴纳金额
+ this.form.maternityCompanyAmount = 0
+ // 工伤险基数
+ this.form.industrialInjuryRadix = 0
+ // 工伤险个人缴纳比例
+ this.form.industrialInjuryPersonalProportion = 0
+ // 工伤险个人缴纳金额
+ this.form.industrialInjuryPersonalAmount = 0
+ // 工伤险公司缴纳比例
+ this.form.industrialInjuryCompanyProportion = 0
+ // 工伤险公司缴纳金额
+ this.form.industrialInjuryCompanyAmount = 0
+ // 随机数
+ this.random = Math.random()
})
},
// 获取用户级别其他
@@ -1035,6 +1120,9 @@
crudUserLevelOther.getTargetYearMonth({ userId: this.form.userId, targetYearMonth: this.form.salaryYearMonth }).then(res => {
// 个人业绩比例
this.form.personalPerformanceProportion = Number(res.personalPerformanceProportion.toFixed(2))
+ }).catch(() => {
+ // 个人业绩比例
+ this.form.personalPerformanceProportion = 0
})
},
// 获取工作天数
@@ -1055,6 +1143,13 @@
clearInterval(interval)
}
}, 500)
+ }).catch(() => {
+ // 全勤小时数
+ this.form.fullDays = 0
+ // 应完成绩效工时
+ this.form.needCompletedAchievementsHours = 0
+ // 应完成业绩工时
+ this.form.needCompletedPerformanceHours = 0
})
},
// 获取出勤小时数
@@ -1075,6 +1170,13 @@
clearInterval(interval)
}
}, 500)
+ }).catch(() => {
+ // 缺勤小时数
+ this.form.absenceDays = 0
+ // 实际基础工资
+ this.form.actualBasicWage = 0
+ // 随机数
+ this.random = Math.random()
})
},
// 获取达标工时
@@ -1083,6 +1185,9 @@
crudTaskDaliy.complianceWork({ userId: this.form.userId, targetYearMonth: this.form.salaryYearMonth }).then(res => {
// 实达标团队工时
this.form.actualComplianceTeamHours = Number(res.toFixed(2))
+ }).catch(() => {
+ // 实达标团队工时
+ this.form.actualComplianceTeamHours = 0
})
},
// 获取已完成工时
@@ -1148,18 +1253,59 @@
this.form.industrialInjuryPersonalAmount != null && this.form.industrialInjuryPersonalAmount !== ''
) {
// 税前金额
- // this.form.preTaxAmount = this.form.actualBasicWage + this.form.actualAchievementsWage + this.form.actualPerformanceWage + this.form.actualTeamWage - this.form.accumulationPersonalAmount - this.form.pensionPersonalAmount - this.form.medicalPersonalAmount - this.form.unemploymentPersonalAmount - this.form.maternityPersonalAmount - this.form.industrialInjuryPersonalAmount
- this.form.preTaxAmount = 100
- // 个人所得税
- this.form.individualIncomeTax = 0
- // 税后金额
- this.form.afterTaxAmount = 100
- // 随机数
- this.random = Math.random()
+ this.form.preTaxAmount = this.form.actualBasicWage + this.form.actualAchievementsWage + this.form.actualPerformanceWage + this.form.actualTeamWage
+ // 查询个人所得税列表
+ crudSysConfigIndividualIncomeTax.getAll().then(taxRes => {
+ // 税额
+ let taxAmount = 0
+ // 计税金额
+ const taxableAmount = this.form.preTaxAmount - this.form.accumulationPersonalAmount - this.form.pensionPersonalAmount - this.form.medicalPersonalAmount - this.form.unemploymentPersonalAmount - this.form.maternityPersonalAmount - this.form.industrialInjuryPersonalAmount
+ // 循环个人所得税列表
+ for (let i = 0; i < taxRes.length; i++) {
+ // 判断计税金额所在个人所得税范围
+ if (taxRes[i].gearAmountEnd != null && taxRes[i].gearAmountEnd !== '' && taxableAmount > taxRes[i].gearAmountEnd) {
+ // 税额
+ taxAmount += (taxRes[i].gearAmountEnd - taxRes[i].gearAmountStart) * (taxRes[i].taxRate / 100)
+ } else if (taxableAmount >= taxRes[i].gearAmountStart && (taxRes[i].gearAmountEnd == null || taxRes[i].gearAmountEnd === '' || taxableAmount <= taxRes[i].gearAmountEnd)) {
+ // 税额
+ taxAmount += (taxableAmount - taxRes[i].gearAmountStart) * (taxRes[i].taxRate / 100)
+ }
+ // 判断循环是否结束
+ if (i === taxRes.length - 1) {
+ // 个人所得税
+ this.form.individualIncomeTax = taxAmount
+ // 税后金额
+ this.form.afterTaxAmount = (taxableAmount - taxAmount) < 0 ? 0 : taxableAmount - taxAmount
+ // 随机数
+ this.random = Math.random()
+ }
+ }
+ })
// 清空统计定时器
clearInterval(statisticsInterval)
}
}, 500)
+ }).catch(() => {
+ // 已完成绩效工时
+ this.form.alreadyCompletedAchievementsHours = 0
+ // 已完成业绩工时
+ this.form.alreadyCompletedPerformanceHours = 0
+ // 已完成团队工时
+ this.form.alreadyCompletedTeamHours = 0
+ // 实际绩效工资
+ this.form.actualAchievementsWage = 0
+ // 实际业绩工资
+ this.form.actualPerformanceWage = 0
+ // 实际团队工资
+ this.form.actualTeamWage = 0
+ // 税前金额
+ this.form.preTaxAmount = 0
+ // 个人所得税
+ this.form.individualIncomeTax = 0
+ // 税后金额
+ this.form.afterTaxAmount = 0
+ // 随机数
+ this.random = Math.random()
})
}
}
--
Gitblit v1.9.3