| | |
| | | */ |
| | | 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; |
| | | import me.zhengjie.modules.system.repository.SysConfigHolidayRepository; |
| | | import me.zhengjie.modules.system.repository.UserRepository; |
| | | import me.zhengjie.modules.system.service.dto.SysConfigHolidayQueryCriteria; |
| | | import me.zhengjie.utils.*; |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.sql.Timestamp; |
| | | import java.util.ArrayList; |
| | | import java.util.Calendar; |
| | | import java.util.Collections; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.zhengjie.exception.BadRequestException; |
| | | import me.zhengjie.modules.attendance.service.AttendanceService; |
| | | import me.zhengjie.modules.attendance.service.dto.AttendanceQueryCriteria; |
| | | import me.zhengjie.modules.constant.Constant; |
| | | import me.zhengjie.modules.project.service.ProjectPerformanceDetailService; |
| | | import me.zhengjie.modules.project.service.dto.ProjectPerformanceDetailQueryCriteria; |
| | | import me.zhengjie.modules.salary.domain.Salary; |
| | | import me.zhengjie.modules.salary.repository.SalaryRepository; |
| | | import me.zhengjie.modules.salary.service.SalaryService; |
| | | import me.zhengjie.modules.salary.service.dto.SalaryDto; |
| | | import me.zhengjie.modules.salary.service.dto.SalaryQueryCriteria; |
| | | import me.zhengjie.modules.salary.service.mapstruct.SalaryMapper; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.io.IOException; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.function.Function; |
| | | import me.zhengjie.modules.system.domain.SysConfigHoliday; |
| | | import me.zhengjie.modules.system.domain.User; |
| | | import me.zhengjie.modules.system.repository.DictDetailRepository; |
| | | import me.zhengjie.modules.system.repository.SysConfigHolidayRepository; |
| | | import me.zhengjie.modules.system.repository.UserRepository; |
| | | import me.zhengjie.modules.system.service.RoleService; |
| | | import me.zhengjie.modules.system.service.SysConfigIndividualIncomeTaxService; |
| | | import me.zhengjie.modules.system.service.SysUserLevelInsuranceService; |
| | | 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; |
| | | import me.zhengjie.utils.FileUtil; |
| | | import me.zhengjie.utils.PageUtil; |
| | | import me.zhengjie.utils.QueryHelp; |
| | | import me.zhengjie.utils.SecurityUtils; |
| | | import me.zhengjie.utils.ValidationUtil; |
| | | |
| | | /** |
| | | * @website https://eladmin.vip |
| | |
| | | private final SalaryMapper salaryMapper; |
| | | private final UserRepository userRepository; |
| | | private final SysConfigHolidayRepository sysConfigHolidayRepository; |
| | | private final RoleService roleService; |
| | | private final DictDetailRepository dictDetailRepository; |
| | | // ==================== 以下为定时生成工资记录主要依赖 ==================== |
| | | private final UserService userService; |
| | | private final SysUserLevelWageService sysUserLevelWageService; |
| | | private final SysUserLevelInsuranceService sysUserLevelInsuranceService; |
| | | private final SysUserLevelOtherService sysUserLevelOtherService; |
| | | private final AttendanceService attendanceService; |
| | | private final TaskDaliyService taskDaliyService; |
| | | private final SysConfigIndividualIncomeTaxService sysConfigIndividualIncomeTaxService; |
| | | private final ProjectPerformanceDetailService projectPerformanceDetailService; |
| | | // ==================== 以上为定时生成工资记录主要依赖 ==================== |
| | | |
| | | @Override |
| | | public Map<String,Object> queryAll(SalaryQueryCriteria criteria, Pageable pageable){ |
| | | // 判断工资查询类工资年月是否为空 |
| | | if (criteria.getSalaryYearMonth() != null && !"".equals(criteria.getSalaryYearMonth())) { |
| | | // 工资年月:国际时间转中国时间 |
| | | criteria.setSalaryYearMonth(DateUtil.internationalTimeToChinaTime(criteria.getSalaryYearMonth())); |
| | | } |
| | | // 获取登录用户角色等级 |
| | | List<Integer> levels = roleService.findByUsersId(SecurityUtils.getCurrentUserId()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList()); |
| | | // 登录用户最大角色等级 |
| | | int min = Collections.min(levels); |
| | | // 判断角色等级 |
| | | if (min == Constant.ROLE_LEVEL_MANAGER || min == Constant.ROLE_LEVEL_LEADER || min == Constant.ROLE_LEVEL_ORDINARY) { |
| | | // 工资查询类 |
| | | criteria.setUserId(SecurityUtils.getCurrentUserId()); |
| | | criteria.setPublicityStatus(Constant.PUBLICITY_STATUS_YES); |
| | | } |
| | | Page<Salary> page = salaryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); |
| | | // 将实体类转换为DTO(重写) |
| | | Function<Salary, SalaryDto> func = new Function<Salary, SalaryDto>(){ |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public SalaryDto create(Salary resources) { |
| | | // 新增验证 |
| | | checkCreate(resources); |
| | | return salaryMapper.toDto(salaryRepository.save(resources)); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void update(Salary resources) { |
| | | 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("找到相同用户相同年月的工资记录!"); |
| | | } |
| | | return salaryMapper.toDto(salaryRepository.save(resources)); |
| | | } |
| | | |
| | | // 修改验证 |
| | | private void checkUpdate(Salary resources) { |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void update(Salary resources) { |
| | | // 根据用户ID和工资年月查询 |
| | | List<Salary> salaryList = salaryRepository.findByUserIdAndSalaryYearMonth(resources.getUserId(), resources.getSalaryYearMonth()); |
| | | // 判断列表长度 |
| | |
| | | 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("找到相同用户相同年月的工资记录!"); |
| | | } |
| | | } |
| | | Salary salary = salaryRepository.findById(resources.getId()).orElseGet(Salary::new); |
| | | // 判断承认状态 |
| | | if (Constant.APPROVE_STATUS_ACKNOWLEDGED.equals(salary.getApproveStatus())) { |
| | | throw new BadRequestException("已承认的工资记录无法进行修改!"); |
| | | } |
| | | ValidationUtil.isNull( salary.getId(),"Salary","id",resources.getId()); |
| | | salary.copy(resources); |
| | | salaryRepository.save(salary); |
| | | } |
| | | |
| | | @Override |
| | |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | for (SalaryDto salary : all) { |
| | | String userNickName = salary.getUserId() != null ? userRepository.findById(salary.getUserId()).orElseGet(User::new).getNickName() : ""; |
| | | String publicityStatus = salary.getPublicityStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.PUBLICITY_STATUS, salary.getPublicityStatus()).getLabel() : ""; |
| | | String approveStatus = salary.getApproveStatus() != null ? dictDetailRepository.findByDictNameAndValue(Constant.APPROVE_STATUS, salary.getApproveStatus()).getLabel() : ""; |
| | | Map<String,Object> map = new LinkedHashMap<>(); |
| | | map.put("员工姓名", userNickName); |
| | | map.put("工资年月", salary.getSalaryYearMonth()); |
| | |
| | | map.put("个人所得税", salary.getIndividualIncomeTax()); |
| | | map.put("税后金额", salary.getAfterTaxAmount()); |
| | | map.put("备注", salary.getRemarks()); |
| | | map.put("公示状态", publicityStatus); |
| | | map.put("承认状态", approveStatus); |
| | | map.put("创建者", salary.getCreateBy()); |
| | | map.put("创建时间", salary.getCreateTime()); |
| | | map.put("更新者", salary.getUpdateBy()); |
| | |
| | | // 保存 |
| | | salaryRepository.save(resources); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void publicity(Long[] ids) { |
| | | // 循环ID列表 |
| | | for (Long id : ids) { |
| | | // 查询工资 |
| | | Salary salary = salaryRepository.findById(id).orElseGet(Salary::new); |
| | | ValidationUtil.isNull( salary.getId(),"Salary","id",id); |
| | | // 公示状态 |
| | | salary.setPublicityStatus(Constant.PUBLICITY_STATUS_YES); |
| | | // 保存 |
| | | salaryRepository.save(salary); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void approve(Long[] ids) { |
| | | // 循环ID列表 |
| | | for (Long id : ids) { |
| | | // 查询工资 |
| | | Salary salary = salaryRepository.findById(id).orElseGet(Salary::new); |
| | | ValidationUtil.isNull( salary.getId(),"Salary","id",id); |
| | | // 承认状态 |
| | | salary.setApproveStatus(Constant.APPROVE_STATUS_ACKNOWLEDGED); |
| | | // 保存 |
| | | salaryRepository.save(salary); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void generate(SalaryQueryCriteria criteria) { |
| | | // 用户工资结算 |
| | | userSalarySettlement(criteria.getUserId(), DateUtil.internationalTimeToChinaTime(criteria.getTargetYearMonth())); |
| | | } |
| | | |
| | | // ==================== 以下为定时生成工资记录主要逻辑 ==================== |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void userSalarySettlement(Long userId, String targetYearMonth) { |
| | | // 判断用户ID是否为空 |
| | | if (userId != null) { |
| | | // 单个用户工资结算 |
| | | 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.setPublicityStatus(Constant.PUBLICITY_STATUS_NOT); |
| | | salary.setApproveStatus(Constant.APPROVE_STATUS_UNRECOGNIZED); |
| | | // 获取用户级别工资 |
| | | 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 { |
| | | // 保存 |
| | | create(salary); |
| | | } catch (Exception e) { |
| | | // 删除 |
| | | 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 = queryWorkDays(salaryQueryCriteria); |
| | | // 全勤小时数 |
| | | salary.setFullDays(Double.valueOf(workDays * 8)); |
| | | // 应完成绩效工时 |
| | | salary.setNeedCompletedAchievementsHours(Double.valueOf(workDays * 8)); |
| | | // 定时器 |
| | | while (true) { |
| | | // 判断个人业绩比例是否为空 |
| | | if (salary.getPersonalPerformanceProportion() != null) { |
| | | // 应完成业绩工时 |
| | | 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 && 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 absenceDays = new BigDecimal(salary.getAbsenceDays()); |
| | | // 实际基础工资 |
| | | salary.setActualBasicWage(salary.getBasicWage().subtract(hourWage.multiply(absenceDays))); |
| | | // 清空定时器 |
| | | break; |
| | | } |
| | | } |
| | | // 返回 |
| | | return salary; |
| | | } |
| | | |
| | | // 获取达标工时 |
| | | private Salary getComplianceWork(Long userId, String targetYearMonth, Salary salary) { |
| | | // 任务日报查询类 |
| | | ProjectPerformanceDetailQueryCriteria taskDaliyQueryCriteria = new ProjectPerformanceDetailQueryCriteria(); |
| | | taskDaliyQueryCriteria.setUserId(userId); |
| | | taskDaliyQueryCriteria.setYearMonth(Timestamp.valueOf(targetYearMonth + " 00:00:00")); |
| | | // 查询某月已达标工时 |
| | | Double complianceWork = projectPerformanceDetailService.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, 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()))); |
| | | // 清空绩效定时器 |
| | | break; |
| | | } |
| | | } |
| | | // 业绩定时器 |
| | | while (true) { |
| | | // 判断预计业绩工资、应完成业绩工时是否为空 |
| | | if (salary.getPerformanceWage() != null && salary.getNeedCompletedPerformanceHours() != null) { |
| | | // 实际业绩工资 |
| | | salary.setActualPerformanceWage(completedWork >= salary.getNeedCompletedPerformanceHours() ? salary.getPerformanceWage() : new BigDecimal(0)); |
| | | // 清空业绩定时器 |
| | | break; |
| | | } |
| | | } |
| | | // 团队定时器 |
| | | while (true) { |
| | | // 判断预计团队工资、实达标团队工时是否为空 |
| | | if (salary.getTeamWage() != null && salary.getActualComplianceTeamHours() != null) { |
| | | // 实际团队工资 |
| | | salary.setActualTeamWage(salary.getActualComplianceTeamHours() != 0 ? salary.getTeamWage().multiply(new BigDecimal(salary.getActualComplianceTeamHours() / completedWork)) : new BigDecimal(0)); |
| | | // 清空团队定时器 |
| | | break; |
| | | } |
| | | } |
| | | // 统计定时器 |
| | | while (true) { |
| | | // 判断 实际基础工资、实际绩效工资、实际业绩工资、实际团队工资、公积金个人缴纳金额、养老险个人缴纳金额、 |
| | | // 医疗险个人缴纳金额、失业险个人缴纳金额、生育险个人缴纳金额、工伤险个人缴纳金额 是否为空 |
| | | if ( |
| | | salary.getActualBasicWage() != null && |
| | | salary.getActualAchievementsWage() != null && |
| | | salary.getActualPerformanceWage() != null && |
| | | salary.getActualTeamWage() != null && |
| | | salary.getAccumulationPersonalAmount() != null && |
| | | salary.getPensionPersonalAmount() != null && |
| | | salary.getMedicalPersonalAmount() != null && |
| | | salary.getUnemploymentPersonalAmount() != null && |
| | | salary.getMaternityPersonalAmount() != null && |
| | | salary.getIndustrialInjuryPersonalAmount() != null |
| | | ) { |
| | | // 税前金额 |
| | | 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 && |
| | | 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 || |
| | | 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; |
| | | } |
| | | // ==================== 以上为定时生成工资记录主要逻辑 ==================== |
| | | } |