| | |
| | | */ |
| | | package me.zhengjie.modules.salary.service.impl; |
| | | |
| | | import cn.hutool.core.io.resource.MultiFileResource; |
| | | import io.swagger.models.auth.In; |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.zhengjie.exception.BadRequestException; |
| | |
| | | import org.springframework.data.domain.Page; |
| | | import org.springframework.data.domain.Pageable; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Propagation; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | |
| | | if (newSalaryList.size() > 0) { |
| | | throw new BadRequestException("找到相同用户相同年月的工资记录!"); |
| | | } |
| | | // NewSalary savedSalary = newSalaryRepository.save(resources); |
| | | // if (savedSalary.getId() != null) { |
| | | // // 保存成功 |
| | | // } else { |
| | | // // 保存失败 |
| | | // Prin |
| | | // } |
| | | return newSalaryMapper.toDto(newSalaryRepository.save(resources)); |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | // @Transactional(rollbackFor = Exception.class) |
| | | public void generate(NewSalaryQueryCriteria criteria) { |
| | | // 用户工资结算 |
| | | userSalarySettlement(criteria.getUserId(), DateUtil.internationalTimeToChinaTime(criteria.getTargetYearMonth())); |
| | | List<String> errors = new ArrayList<>(); |
| | | for (Long id : criteria.getSelectedValue1()) { |
| | | try { |
| | | // 用户工资结算 |
| | | userSalarySettlement(id, DateUtil.internationalTimeToChinaTime(criteria.getTargetYearMonth()), errors); |
| | | } catch (Exception e) { |
| | | // 记录错误信息 |
| | | errors.add("ID " + id + ": " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | // 在循环结束后处理错误 |
| | | if (!errors.isEmpty()) { |
| | | // 将所有的错误信息收集到一个字符串中 |
| | | String errorMessage = String.join("; ", errors); |
| | | // 抛出一个新的异常 |
| | | throw new RuntimeException(errorMessage); |
| | | } |
| | | } |
| | | |
| | | // ==================== 以下为定时生成工资记录主要逻辑 ==================== |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void userSalarySettlement(Long userId, String targetYearMonth) { |
| | | @Transactional(rollbackFor = Exception.class) // propagation = Propagation.REQUIRES_NEW, |
| | | public void userSalarySettlement(Long userId, String targetYearMonth, List<String> errors) { |
| | | // 判断用户ID是否为空 |
| | | if (userId != null) { |
| | | // 单个用户工资结算 |
| | | singleUserSalarySettlement(userId, targetYearMonth); |
| | | singleUserSalarySettlement(userId, targetYearMonth, errors); |
| | | } else { |
| | | // 用户检索类 |
| | | UserQueryCriteria userQueryCriteria = new UserQueryCriteria(); |
| | |
| | | for (int i = 0; i < userDtoList.size(); i++) { |
| | | try { |
| | | // 单个用户工资结算 |
| | | singleUserSalarySettlement(userDtoList.get(i).getId(), targetYearMonth); |
| | | singleUserSalarySettlement(userDtoList.get(i).getId(), targetYearMonth, errors); |
| | | } catch (Exception e) { |
| | | // 跳过本次循环 |
| | | continue; |
| | |
| | | |
| | | |
| | | // 单个用户工资结算 |
| | | private void singleUserSalarySettlement(Long userId, String targetYearMonth) { |
| | | private void singleUserSalarySettlement(Long userId, String targetYearMonth, List<String> errors) { |
| | | // 日历类 |
| | | Calendar cal = Calendar.getInstance(); |
| | | // 设置年份 |
| | |
| | | newSalary.setSalaryYearMonth(new Timestamp(cal.getTime().getTime())); |
| | | newSalary.setPublicityStatus(Constant.PUBLICITY_STATUS_NOT); |
| | | newSalary.setApproveStatus(Constant.APPROVE_STATUS_UNRECOGNIZED); |
| | | // 获取用户级别工资 |
| | | newSalary = getUserLevelWage(userId, targetYearMonth, newSalary); |
| | | // 获取用户级别保险 |
| | | newSalary = getUserLevelInsurance(userId, targetYearMonth, newSalary); |
| | | // 获取用户级别其他 |
| | | newSalary = getUserLevelOther(userId, targetYearMonth, newSalary); |
| | | // 获取工作天数 |
| | | newSalary = getWorkDays(targetYearMonth, newSalary); |
| | | // 获取出勤小时数 |
| | | newSalary = getAttendanceHours(userId, targetYearMonth, newSalary); |
| | | // 获取达标工时 |
| | | newSalary = getComplianceWork(userId, targetYearMonth, newSalary); |
| | | // 获取已完成工时 |
| | | newSalary = getCompletedWork(userId, targetYearMonth, newSalary); |
| | | try { |
| | | // 获取用户级别工资 |
| | | newSalary = getUserLevelWage(userId, targetYearMonth, newSalary, errors); |
| | | // 获取用户级别保险 |
| | | newSalary = getUserLevelInsurance(userId, targetYearMonth, newSalary); |
| | | // 获取用户级别其他 |
| | | newSalary = getUserLevelOther(userId, targetYearMonth, newSalary); |
| | | // 获取工作天数 |
| | | newSalary = getWorkDays(targetYearMonth, newSalary); |
| | | // 获取出勤小时数 |
| | | newSalary = getAttendanceHours(userId, targetYearMonth, newSalary); |
| | | // 获取达标工时 |
| | | newSalary = getComplianceWork(userId, targetYearMonth, newSalary); |
| | | // 获取已完成工时 |
| | | newSalary = getCompletedWork(userId, targetYearMonth, newSalary); |
| | | } catch (BadRequestException e) { |
| | | errors.add(e.getMessage()); |
| | | return; |
| | | } |
| | | try { |
| | | // 保存 |
| | | create(newSalary); |
| | |
| | | } |
| | | |
| | | // 获取用户级别工资 |
| | | private NewSalary getUserLevelWage(Long userId, String targetYearMonth, NewSalary newSalary) { |
| | | private NewSalary getUserLevelWage(Long userId, String targetYearMonth, NewSalary newSalary, List<String> errors) { |
| | | // 用户级别工资检索类 |
| | | UserLevelWageQueryCriteria userLevelWageQueryCriteria = new UserLevelWageQueryCriteria(); |
| | | userLevelWageQueryCriteria.setUserId(userId); |
| | | userLevelWageQueryCriteria.setTargetYearMonth(targetYearMonth); |
| | | // 查询指定年月用户级别工资 |
| | | UserLevelWageDto userLevelWageDto = userLevelWageService.queryTargetYearMonth(userLevelWageQueryCriteria); |
| | | // 级别基本工资 |
| | | BigDecimal basicWage = userLevelWageDto.getBasicWage(); |
| | | // 级别等级工资 |
| | | BigDecimal rankWage = userLevelWageDto.getRankWage(); |
| | | // 设置工资条的基本工资 |
| | | newSalary.setBasicWage(basicWage.add(rankWage)); |
| | | // 绩效工资 |
| | | BigDecimal performanceWage = userLevelWageDto.getPerformanceWage(); |
| | | // 设置工资条的基本工资 |
| | | newSalary.setAchievementsWage(performanceWage); |
| | | // 设置工资条的业绩工资 |
| | | newSalary.setPerformanceWage(BigDecimal.ZERO); |
| | | // 设置工资条的基本工资 |
| | | newSalary.setTeamWage(BigDecimal.ZERO); |
| | | try { |
| | | // 查询指定年月用户级别工资 |
| | | UserLevelWageDto userLevelWageDto = userLevelWageService.queryTargetYearMonth(userLevelWageQueryCriteria); |
| | | // 级别基本工资 |
| | | BigDecimal basicWage = userLevelWageDto.getBasicWage(); |
| | | // 级别等级工资 |
| | | BigDecimal rankWage = userLevelWageDto.getRankWage(); |
| | | // 设置工资条的基本工资 |
| | | newSalary.setBasicWage(basicWage.add(rankWage)); |
| | | // 绩效工资 |
| | | BigDecimal performanceWage = userLevelWageDto.getPerformanceWage(); |
| | | // 设置工资条的基本工资 |
| | | newSalary.setAchievementsWage(performanceWage); |
| | | // 设置工资条的业绩工资 |
| | | newSalary.setPerformanceWage(BigDecimal.ZERO); |
| | | // 设置工资条的基本工资 |
| | | newSalary.setTeamWage(BigDecimal.ZERO); |
| | | } catch (RuntimeException e) { |
| | | errors.add(e.getMessage()); |
| | | return null; |
| | | } |
| | | // 返回 |
| | | return newSalary; |
| | | } |