| | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.sql.Timestamp; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.YearMonth; |
| | | import java.util.ArrayList; |
| | | import java.util.Calendar; |
| | | import java.util.Collections; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import me.zhengjie.modules.system.domain.SysUserLevelWage; |
| | | import me.zhengjie.modules.system.repository.SysUserLevelWageRepository; |
| | | import me.zhengjie.modules.system.service.dto.*; |
| | | import me.zhengjie.modules.treatment.domain.UserLevelWage; |
| | | import me.zhengjie.modules.treatment.repository.UserLevelWageRepository; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import me.zhengjie.modules.system.service.SysUserLevelOtherService; |
| | | import me.zhengjie.modules.system.service.SysUserLevelWageService; |
| | | import me.zhengjie.modules.system.service.UserService; |
| | | import me.zhengjie.modules.system.service.dto.RoleSmallDto; |
| | | import me.zhengjie.modules.system.service.dto.SysConfigHolidayQueryCriteria; |
| | | import me.zhengjie.modules.system.service.dto.SysConfigIndividualIncomeTaxDto; |
| | | import me.zhengjie.modules.system.service.dto.SysConfigIndividualIncomeTaxQueryCriteria; |
| | | import me.zhengjie.modules.system.service.dto.SysUserLevelInsuranceDto; |
| | | import me.zhengjie.modules.system.service.dto.SysUserLevelInsuranceQueryCriteria; |
| | | import me.zhengjie.modules.system.service.dto.SysUserLevelOtherDto; |
| | | import me.zhengjie.modules.system.service.dto.SysUserLevelOtherQueryCriteria; |
| | | import me.zhengjie.modules.system.service.dto.SysUserLevelWageDto; |
| | | import me.zhengjie.modules.system.service.dto.SysUserLevelWageQueryCriteria; |
| | | import me.zhengjie.modules.system.service.dto.UserDto; |
| | | import me.zhengjie.modules.system.service.dto.UserQueryCriteria; |
| | | import me.zhengjie.modules.task.service.TaskDaliyService; |
| | | import me.zhengjie.modules.task.service.dto.TaskDaliyQueryCriteria; |
| | | import me.zhengjie.utils.DateUtil; |
| | |
| | | private final SysConfigHolidayRepository sysConfigHolidayRepository; |
| | | private final RoleService roleService; |
| | | private final DictDetailRepository dictDetailRepository; |
| | | private final SysUserLevelWageRepository sysUserLevelWageRepository; |
| | | // ==================== 以下为定时生成工资记录主要依赖 ==================== |
| | | private final UserService userService; |
| | | private final SysUserLevelWageService sysUserLevelWageService; |
| | |
| | | // 登录用户最大角色等级 |
| | | int min = Collections.min(levels); |
| | | // 判断角色等级 |
| | | if (min == Constant.ROLE_LEVEL_MANAGER || min == Constant.ROLE_LEVEL_LEADER || min == Constant.ROLE_LEVEL_ORDINARY) { |
| | | if (Constant.BASE_LEVEL_LIST.contains(Long.valueOf(min))) { |
| | | // 工资查询类 |
| | | criteria.setUserId(SecurityUtils.getCurrentUserId()); |
| | | criteria.setPublicityStatus(Constant.PUBLICITY_STATUS_YES); |
| | |
| | | throw new BadRequestException("找到相同用户相同年月的工资记录!"); |
| | | } else if (salaryList.size() == 1) { |
| | | // 判断是否是同一条记录 |
| | | if (salaryList.get(0).getId() != resources.getId()) { |
| | | if (salaryList.get(0).getId().longValue() != resources.getId().longValue()) { |
| | | throw new BadRequestException("找到相同用户相同年月的工资记录!"); |
| | | } |
| | | } |
| | |
| | | |
| | | @Override |
| | | public Integer queryWorkDays(SalaryQueryCriteria criteria){ |
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | List<User> user = userRepository.findByUserId(criteria.getUserId()); |
| | | String stTime = sdf.format(user.get(0).getCreateTime()).substring(0,7); |
| | | if (stTime.equals(criteria.getTargetYearMonth().substring(0,7))) { |
| | | criteria.setTargetYearMonth(sdf.format(user.get(0).getCreateTime()).substring(0,10)); |
| | | } |
| | | // 国际时间转中国时间 |
| | | String targetYearMonth = DateUtil.internationalTimeToChinaTime(criteria.getTargetYearMonth()); |
| | | // 节日查询类 |
| | |
| | | UserQueryCriteria userQueryCriteria = new UserQueryCriteria(); |
| | | userQueryCriteria.setEnabled(true); |
| | | // 获取用户列表 |
| | | List<UserDto> userDtoList = userService.queryAll(userQueryCriteria); |
| | | List<UserSmallDto> userDtoList = userService.querySmallAll(userQueryCriteria); |
| | | // 循环用户列表 |
| | | for (int i = 0; i < userDtoList.size(); i ++) { |
| | | try { |
| | |
| | | // 基本工资比例 |
| | | salary.setBasicWageProportion(sysUserLevelWageDto.getBasicWageProportion()); |
| | | // 预计基本工资 |
| | | salary.setBasicWage(sysUserLevelWageDto.getLevelWage().multiply(new BigDecimal(sysUserLevelWageDto.getBasicWageProportion() / 100))); |
| | | salary.setBasicWage(sysUserLevelWageDto.getLevelWage().multiply(new BigDecimal(sysUserLevelWageDto.getBasicWageProportion())).divide(new BigDecimal(100))); |
| | | // 绩效工资比例 |
| | | salary.setAchievementsWageProportion(sysUserLevelWageDto.getAchievementsWageProportion()); |
| | | // 预计绩效工资 |
| | | salary.setAchievementsWage(sysUserLevelWageDto.getLevelWage().multiply(new BigDecimal(sysUserLevelWageDto.getAchievementsWageProportion() / 100))); |
| | | salary.setAchievementsWage(sysUserLevelWageDto.getLevelWage().multiply(new BigDecimal(sysUserLevelWageDto.getAchievementsWageProportion())).divide(new BigDecimal(100))); |
| | | // 业绩工资比例 |
| | | salary.setPerformanceWageProportion(sysUserLevelWageDto.getPerformanceWageProportion()); |
| | | // 预计业绩工资 |
| | | salary.setPerformanceWage(sysUserLevelWageDto.getLevelWage().multiply(new BigDecimal(sysUserLevelWageDto.getPerformanceWageProportion() / 100))); |
| | | salary.setPerformanceWage(sysUserLevelWageDto.getLevelWage().multiply(new BigDecimal(sysUserLevelWageDto.getPerformanceWageProportion())).divide(new BigDecimal(100))); |
| | | // 团队工资比例 |
| | | salary.setTeamWageProportion(sysUserLevelWageDto.getTeamWageProportion()); |
| | | // 预计团队工资 |
| | | salary.setTeamWage(sysUserLevelWageDto.getLevelWage().multiply(new BigDecimal(sysUserLevelWageDto.getTeamWageProportion() / 100))); |
| | | salary.setTeamWage(sysUserLevelWageDto.getLevelWage().multiply(new BigDecimal(sysUserLevelWageDto.getTeamWageProportion())).divide(new BigDecimal(100))); |
| | | // 返回 |
| | | return salary; |
| | | } |
| | |
| | | // 公积金个人缴纳比例 |
| | | salary.setAccumulationPersonalProportion(sysUserLevelInsuranceDto.getAccumulationPersonalProportion()); |
| | | // 公积金个人缴纳金额 |
| | | salary.setAccumulationPersonalAmount(sysUserLevelInsuranceDto.getAccumulationRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getAccumulationPersonalProportion() / 100))); |
| | | salary.setAccumulationPersonalAmount(sysUserLevelInsuranceDto.getAccumulationRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getAccumulationPersonalProportion())).divide(new BigDecimal(100))); |
| | | // 公积金公司缴纳比例 |
| | | salary.setAccumulationCompanyProportion(sysUserLevelInsuranceDto.getAccumulationCompanyProportion()); |
| | | // 公积金公司缴纳金额 |
| | | salary.setAccumulationCompanyAmount(sysUserLevelInsuranceDto.getAccumulationRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getAccumulationCompanyProportion() / 100))); |
| | | salary.setAccumulationCompanyAmount(sysUserLevelInsuranceDto.getAccumulationRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getAccumulationCompanyProportion())).divide(new BigDecimal(100))); |
| | | // 养老险基数 |
| | | salary.setPensionRadix(sysUserLevelInsuranceDto.getPensionRadix()); |
| | | // 养老险个人缴纳比例 |
| | | salary.setPensionPersonalProportion(sysUserLevelInsuranceDto.getPensionPersonalProportion()); |
| | | // 养老险个人缴纳金额 |
| | | salary.setPensionPersonalAmount(sysUserLevelInsuranceDto.getPensionRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getPensionPersonalProportion() / 100))); |
| | | salary.setPensionPersonalAmount(sysUserLevelInsuranceDto.getPensionRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getPensionPersonalProportion())).divide(new BigDecimal(100))); |
| | | // 养老险公司缴纳比例 |
| | | salary.setPensionCompanyProportion(sysUserLevelInsuranceDto.getPensionCompanyProportion()); |
| | | // 养老险公司缴纳金额 |
| | | salary.setPensionCompanyAmount(sysUserLevelInsuranceDto.getPensionRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getPensionCompanyProportion() / 100))); |
| | | salary.setPensionCompanyAmount(sysUserLevelInsuranceDto.getPensionRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getPensionCompanyProportion())).divide(new BigDecimal(100))); |
| | | // 医疗险基数 |
| | | salary.setMedicalRadix(sysUserLevelInsuranceDto.getMedicalRadix()); |
| | | // 医疗险个人缴纳比例 |
| | | salary.setMedicalPersonalProportion(sysUserLevelInsuranceDto.getMedicalPersonalProportion()); |
| | | // 医疗险个人缴纳金额 |
| | | salary.setMedicalPersonalAmount(sysUserLevelInsuranceDto.getMedicalRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getMedicalPersonalProportion() / 100))); |
| | | salary.setMedicalPersonalAmount(sysUserLevelInsuranceDto.getMedicalRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getMedicalPersonalProportion())).divide(new BigDecimal(100))); |
| | | // 医疗险公司缴纳比例 |
| | | salary.setMedicalCompanyProportion(sysUserLevelInsuranceDto.getMedicalCompanyProportion()); |
| | | // 医疗险公司缴纳金额 |
| | | salary.setMedicalCompanyAmount(sysUserLevelInsuranceDto.getMedicalRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getMedicalCompanyProportion() / 100))); |
| | | salary.setMedicalCompanyAmount(sysUserLevelInsuranceDto.getMedicalRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getMedicalCompanyProportion())).divide(new BigDecimal(100))); |
| | | // 失业险基数 |
| | | salary.setUnemploymentRadix(sysUserLevelInsuranceDto.getUnemploymentRadix()); |
| | | // 失业险个人缴纳比例 |
| | | salary.setUnemploymentPersonalProportion(sysUserLevelInsuranceDto.getUnemploymentPersonalProportion()); |
| | | // 失业险个人缴纳金额 |
| | | salary.setUnemploymentPersonalAmount(sysUserLevelInsuranceDto.getUnemploymentRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getUnemploymentPersonalProportion() / 100))); |
| | | salary.setUnemploymentPersonalAmount(sysUserLevelInsuranceDto.getUnemploymentRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getUnemploymentPersonalProportion())).divide(new BigDecimal(100))); |
| | | // 失业险公司缴纳比例 |
| | | salary.setUnemploymentCompanyProportion(sysUserLevelInsuranceDto.getUnemploymentCompanyProportion()); |
| | | // 失业险公司缴纳金额 |
| | | salary.setUnemploymentCompanyAmount(sysUserLevelInsuranceDto.getUnemploymentRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getUnemploymentCompanyProportion() / 100))); |
| | | salary.setUnemploymentCompanyAmount(sysUserLevelInsuranceDto.getUnemploymentRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getUnemploymentCompanyProportion())).divide(new BigDecimal(100))); |
| | | // 生育险基数 |
| | | salary.setMaternityRadix(sysUserLevelInsuranceDto.getMaternityRadix()); |
| | | // 生育险个人缴纳比例 |
| | | salary.setMaternityPersonalProportion(sysUserLevelInsuranceDto.getMaternityPersonalProportion()); |
| | | // 生育险个人缴纳金额 |
| | | salary.setMaternityPersonalAmount(sysUserLevelInsuranceDto.getMaternityRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getMaternityPersonalProportion() / 100))); |
| | | salary.setMaternityPersonalAmount(sysUserLevelInsuranceDto.getMaternityRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getMaternityPersonalProportion())).divide(new BigDecimal(100))); |
| | | // 生育险公司缴纳比例 |
| | | salary.setMaternityCompanyProportion(sysUserLevelInsuranceDto.getMaternityCompanyProportion()); |
| | | // 生育险公司缴纳金额 |
| | | salary.setMaternityCompanyAmount(sysUserLevelInsuranceDto.getMaternityRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getMaternityCompanyProportion() / 100))); |
| | | salary.setMaternityCompanyAmount(sysUserLevelInsuranceDto.getMaternityRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getMaternityCompanyProportion())).divide(new BigDecimal(100))); |
| | | // 工伤险基数 |
| | | salary.setIndustrialInjuryRadix(sysUserLevelInsuranceDto.getIndustrialInjuryRadix()); |
| | | // 工伤险个人缴纳比例 |
| | | salary.setIndustrialInjuryPersonalProportion(sysUserLevelInsuranceDto.getIndustrialInjuryPersonalProportion()); |
| | | // 工伤险个人缴纳金额 |
| | | salary.setIndustrialInjuryPersonalAmount(sysUserLevelInsuranceDto.getIndustrialInjuryRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getIndustrialInjuryPersonalProportion() / 100))); |
| | | salary.setIndustrialInjuryPersonalAmount(sysUserLevelInsuranceDto.getIndustrialInjuryRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getIndustrialInjuryPersonalProportion())).divide(new BigDecimal(100))); |
| | | // 工伤险公司缴纳比例 |
| | | salary.setIndustrialInjuryCompanyProportion(sysUserLevelInsuranceDto.getIndustrialInjuryCompanyProportion()); |
| | | // 工伤险公司缴纳金额 |
| | | salary.setIndustrialInjuryCompanyAmount(sysUserLevelInsuranceDto.getIndustrialInjuryRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getIndustrialInjuryCompanyProportion() / 100))); |
| | | salary.setIndustrialInjuryCompanyAmount(sysUserLevelInsuranceDto.getIndustrialInjuryRadix().multiply(new BigDecimal(sysUserLevelInsuranceDto.getIndustrialInjuryCompanyProportion())).divide(new BigDecimal(100))); |
| | | // 返回 |
| | | return salary; |
| | | } |
| | |
| | | private Salary getWorkDays(String targetYearMonth, Salary salary) { |
| | | // 工资查询类 |
| | | SalaryQueryCriteria salaryQueryCriteria = new SalaryQueryCriteria(); |
| | | salaryQueryCriteria.setUserId(salary.getUserId()); |
| | | salaryQueryCriteria.setTargetYearMonth(targetYearMonth); |
| | | // 查询某月工作天数 |
| | | Integer workDays = queryWorkDays(salaryQueryCriteria); |
| | |
| | | if (salary.getBasicWage() != null && salary.getFullDays() != null) { |
| | | // 缺勤小时数 |
| | | salary.setAbsenceDays(salary.getFullDays() > attendanceHours ? Double.valueOf(salary.getFullDays() - attendanceHours) : 0); |
| | | // 小时工资 |
| | | BigDecimal hourWage = salary.getBasicWage().divide(new BigDecimal(salary.getFullDays()), 2); |
| | | // // 小时工资 |
| | | // BigDecimal hourWage = salary.getBasicWage().divide(new BigDecimal(salary.getFullDays()), 2); |
| | | // 缺勤小时数 |
| | | BigDecimal absenceDays = new BigDecimal(salary.getAbsenceDays()); |
| | | // 实际基础工资 |
| | | salary.setActualBasicWage(salary.getBasicWage().subtract(hourWage.multiply(absenceDays))); |
| | | salary.setActualBasicWage(salary.getBasicWage().subtract(salary.getBasicWage().multiply(absenceDays).divide(new BigDecimal(salary.getFullDays())))); |
| | | // 清空定时器 |
| | | break; |
| | | } |
| | |
| | | taskDaliyQueryCriteria.setUserId(userId); |
| | | taskDaliyQueryCriteria.setTargetYearMonth(targetYearMonth); |
| | | // 查询某月已完成工时 |
| | | Double completedWork = taskDaliyService.queryCompletedWork(taskDaliyQueryCriteria); |
| | | Double completedWork = taskDaliyService.queryCompletedWork(taskDaliyQueryCriteria, false); |
| | | // 已完成绩效工时 |
| | | salary.setAlreadyCompletedAchievementsHours(completedWork); |
| | | // 已完成业绩工时 |
| | | salary.setAlreadyCompletedPerformanceHours(completedWork); |
| | | // 已完成团队工时 |
| | | salary.setAlreadyCompletedTeamHours(completedWork); |
| | | |
| | | Double otherWage = taskDaliyService.queryOtherWage(taskDaliyQueryCriteria); |
| | | salary.setPieceRate(BigDecimal.valueOf(otherWage)); |
| | | // 绩效定时器 |
| | | while (true) { |
| | | // 判断预计绩效工资、应完成绩效工时是否为空 |
| | | if (salary.getAchievementsWage() != null && salary.getNeedCompletedAchievementsHours() != null) { |
| | | // 实际绩效工资 |
| | | salary.setActualAchievementsWage(salary.getAchievementsWage().multiply(new BigDecimal(completedWork / salary.getNeedCompletedAchievementsHours()))); |
| | | salary.setActualAchievementsWage(salary.getAchievementsWage().multiply(new BigDecimal(completedWork)).divide(new BigDecimal(salary.getNeedCompletedAchievementsHours()))); |
| | | // 清空绩效定时器 |
| | | break; |
| | | } |
| | |
| | | // 税额 |
| | | taxAmount.add( |
| | | (sysConfigIndividualIncomeTaxDtoList.get(i).getGearAmountEnd().subtract(sysConfigIndividualIncomeTaxDtoList.get(i).getGearAmountStart())) |
| | | .multiply(new BigDecimal(sysConfigIndividualIncomeTaxDtoList.get(i).getTaxRate()).divide(new BigDecimal(100), 2)) |
| | | .multiply(new BigDecimal(sysConfigIndividualIncomeTaxDtoList.get(i).getTaxRate()).divide(new BigDecimal(100))) |
| | | ); |
| | | } else if ( |
| | | (taxableAmount.compareTo(sysConfigIndividualIncomeTaxDtoList.get(i).getGearAmountStart()) == 1 || |
| | |
| | | // 税额 |
| | | taxAmount.add( |
| | | (taxableAmount.subtract(sysConfigIndividualIncomeTaxDtoList.get(i).getGearAmountStart())) |
| | | .multiply(new BigDecimal(sysConfigIndividualIncomeTaxDtoList.get(i).getTaxRate()).divide(new BigDecimal(100), 2)) |
| | | .multiply(new BigDecimal(sysConfigIndividualIncomeTaxDtoList.get(i).getTaxRate()).divide(new BigDecimal(100))) |
| | | ); |
| | | } |
| | | // 判断循环是否结束 |
| | | if (i == sysConfigIndividualIncomeTaxDtoList.size() - 1) { |
| | | // 个人所得税 |
| | | salary.setIndividualIncomeTax(taxAmount); |
| | | // salary.setIndividualIncomeTax(taxAmount); |
| | | salary.setIndividualIncomeTax(new BigDecimal(0)); |
| | | // 税后金额 |
| | | salary.setAfterTaxAmount(taxableAmount.subtract(taxAmount).compareTo(new BigDecimal(0)) == -1 ? new BigDecimal(0) : taxableAmount.subtract(taxAmount)); |
| | | } |