| | |
| | | |
| | | import lombok.RequiredArgsConstructor; |
| | | import me.zhengjie.exception.BadRequestException; |
| | | import me.zhengjie.modules.attendance.domain.AttendanceBusinessTravel; |
| | | import me.zhengjie.modules.attendance.domain.AttendanceOvertime; |
| | | import me.zhengjie.modules.attendance.repository.AttendanceBusinessTravelRepository; |
| | | import me.zhengjie.modules.attendance.repository.AttendanceOvertimeRepository; |
| | | import me.zhengjie.modules.system.domain.SysConfigProportion; |
| | | import me.zhengjie.modules.system.domain.User; |
| | | import me.zhengjie.modules.system.repository.SysConfigProportionRepository; |
| | | import me.zhengjie.modules.system.repository.UserRepository; |
| | | import me.zhengjie.modules.treatment.domain.UserInsurance; |
| | | import me.zhengjie.modules.treatment.domain.UserLevelWage; |
| | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.sql.Timestamp; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | |
| | |
| | | |
| | | private final UserInsuranceRepository userInsuranceRepository; |
| | | private final CmnInsuranceRepository cmnInsuranceRepository; |
| | | private final AttendanceBusinessTravelRepository attendanceBusinessTravelRepository; |
| | | private final SysConfigProportionRepository sysConfigProportionRepository; |
| | | private final AttendanceOvertimeRepository attendanceOvertimeRepository; |
| | | |
| | | @Override |
| | | public Map<String, Object> queryAll(UserLevelWageQueryCriteria criteria, Pageable pageable) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public UserLevelWageDto queryTargetYearMonth(UserLevelWageQueryCriteria criteria) { |
| | | // 国际时间转中国时间 |
| | | public UserLevelWageDto queryTargetYearMonth(UserLevelWageQueryCriteria criteria) throws ParseException { |
| | | |
| | | String targetYearMonth = criteria.getTargetYearMonth(); |
| | | // 获取某年某月最后一天 |
| | | String yearMonth = targetYearMonth.substring(0,7); |
| | | // 根据用户ID、指定年月查询 |
| | | UserLevelWage userLevelWage = userLevelWageRepository.findByUserIdAndYearMonth(criteria.getUserId(), yearMonth); |
| | | |
| | | // 查询用户 |
| | | User user = userRepository.findById(criteria.getUserId()).orElseGet(User::new); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | // 获取员工的添加时间 |
| | | calendar.setTime(user.getCreateTime()); |
| | | int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH); |
| | | int daysInMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH); |
| | | if (dayOfMonth <= daysInMonth / 2) { |
| | | calendar.add(Calendar.MONTH, user.getInternshipTime() == null ? 3 : user.getInternshipTime()); |
| | | } else { |
| | | calendar.add(Calendar.MONTH, user.getInternshipTime() == null ? 4 : user.getInternshipTime() + 1); |
| | | } |
| | | calendar.set(Calendar.DAY_OF_MONTH, 1); |
| | | // 获取转正时间 |
| | | String confirmationTime = new Timestamp(calendar.getTimeInMillis()).toString().substring(0, 7); |
| | | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM"); |
| | | Date date1 = format.parse(yearMonth); |
| | | Date date2 = format.parse(confirmationTime); |
| | | |
| | | UserLevelWage userLevelWage = null; |
| | | // 如果传递进来的日期在转正日期之前 |
| | | if(date1.before(date2)) { |
| | | // 查询没转正且年月最大的数据 |
| | | userLevelWage = userLevelWageRepository.findByUserIdAndNoWorker(criteria.getUserId(), confirmationTime); |
| | | } else { |
| | | // 查询第二条转正且日期最大的数据 |
| | | userLevelWage = userLevelWageRepository.findByUserIdAndYesWorker(criteria.getUserId(), confirmationTime); |
| | | } |
| | | |
| | | // UserLevelWage userLevelWage = userLevelWageRepository.findbyUserIdAndDate(criteria.getUserId(), yearMonth); |
| | | |
| | | // 判断查询结果 |
| | | if (userLevelWage == null) { |
| | | // throw new BadRequestException("没有获取到当前员工的级别信息!"); |
| | | throw new RuntimeException("没有获取到当前员工的级别信息!"); |
| | | } |
| | | // 返回 |
| | | return userLevelWageMapper.toDto(userLevelWage); |
| | | } |
| | | |
| | | @Override |
| | | public Double queryOverTimeAllowance(UserLevelWageQueryCriteria criteria) throws ParseException { |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | LocalDateTime dateTime = LocalDateTime.parse(criteria.getTargetYearMonth(), formatter); |
| | | // 获取月初日期 |
| | | LocalDateTime firstDayOfMonth = dateTime.withDayOfMonth(1); |
| | | // 获取下月初日期 |
| | | LocalDateTime firstDayOfNextMonth = firstDayOfMonth.plusMonths(1); |
| | | |
| | | // 查询指定员工的加班补助金额工资 |
| | | Double overTimeSalary = attendanceOvertimeRepository.findByUserIdAndYearMonth(criteria.getUserId(), firstDayOfMonth, firstDayOfNextMonth); |
| | | |
| | | // 查询配置表 |
| | | SysConfigProportion sysConfigProportion = sysConfigProportionRepository.findByTitle("加班补助金额"); |
| | | |
| | | // 出差补助金 |
| | | Double travelSubsidy = (overTimeSalary == null ? 0.0 : overTimeSalary) * sysConfigProportion.getProportion(); |
| | | |
| | | return travelSubsidy; |
| | | } |
| | | |
| | | @Override |
| | | public Double queryTravelAllowance(UserLevelWageQueryCriteria criteria) throws ParseException { |
| | | |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | LocalDateTime dateTime = LocalDateTime.parse(criteria.getTargetYearMonth(), formatter); |
| | | // 获取月初日期 |
| | | LocalDateTime firstDayOfMonth = dateTime.withDayOfMonth(1); |
| | | // 获取下月初日期 |
| | | LocalDateTime firstDayOfNextMonth = firstDayOfMonth.plusMonths(1); |
| | | |
| | | System.out.println("月初日期:" + firstDayOfMonth); |
| | | System.out.println("下月初日期:" + firstDayOfNextMonth); |
| | | |
| | | // 查询出差表的记录 |
| | | Integer bussSameMonthDays = attendanceBusinessTravelRepository.findByUserIdAndYearMonth(criteria.getUserId(), firstDayOfMonth, firstDayOfNextMonth); |
| | | // 查询配置表 |
| | | SysConfigProportion sysConfigProportion = sysConfigProportionRepository.findByTitle("出差补助金额"); |
| | | |
| | | // 出差补助金 |
| | | Double travelSubsidy = (bussSameMonthDays == null ? 0 : bussSameMonthDays) * sysConfigProportion.getProportion(); |
| | | |
| | | return travelSubsidy; |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public UserLevelWageDto create(UserLevelWage resources) { |
| | | // 根据日期查询个人级别工资表 |
| | | UserLevelWage userLevelWage = userLevelWageRepository.findByUserAndDate(resources.getUserId(), resources.getYearMonth()); |
| | | if (userLevelWage != null) { |
| | | throw new BadRequestException("级别日期重复!"); |
| | | } |
| | | resources.setPerformanceCoefficient(calculatePerformanceCoefficient(resources)); |
| | | return userLevelWageMapper.toDto(userLevelWageRepository.save(resources)); |
| | | } |
| | |
| | | public void update(UserLevelWage resources) { |
| | | UserLevelWage userLevelWage = userLevelWageRepository.findById(resources.getId()).orElseGet(UserLevelWage::new); |
| | | ValidationUtil.isNull(userLevelWage.getId(), "UserLevelWage", "id", resources.getId()); |
| | | // 根据日期查询个人级别工资表 |
| | | UserLevelWage userLevelWage1 = userLevelWageRepository.findByUserAndDate(resources.getUserId(), resources.getYearMonth()); |
| | | if (userLevelWage1 != null) { |
| | | throw new BadRequestException("级别日期重复!"); |
| | | } |
| | | userLevelWage.copy(resources); |
| | | userLevelWage.setPerformanceCoefficient(calculatePerformanceCoefficient(userLevelWage)); |
| | | userLevelWageRepository.save(userLevelWage); |