| | |
| | | package me.zhengjie.modules.treatment.service.impl; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Optional; |
| | | import java.sql.Timestamp; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public UserInsuranceDto queryTargetYearMonth(UserInsuranceQueryCriteria criteria) { |
| | | // 国际时间转中国时间 |
| | | String targetYearMonth = criteria.getTargetYearMonth(); |
| | | // 获取某年某月最后一天 |
| | | String yearMonth = targetYearMonth.substring(0,7); |
| | | // 根据用户ID、指定年月查询 |
| | | // Optional<UserInsurance> userInsuranceOpt = userInsuranceRepository.findByUserIdAndYearMonth(criteria.getUserId(), yearMonth); |
| | | UserInsurance userInsuranceOpt = userInsuranceRepository.findbyUserIdAndDate(criteria.getUserId(), yearMonth); |
| | | public UserInsuranceDto queryTargetYearMonth(UserInsuranceQueryCriteria criteria) throws ParseException { |
| | | |
| | | // 获取前台传递的时间 |
| | | String yearMonth = criteria.getTargetYearMonth().substring(0,7); |
| | | // 查询用户 |
| | | 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); |
| | | UserInsurance userInsuranceOpt = null; |
| | | // 如果传递的时间在转正时间之前 |
| | | if(date1.before(date2)) { |
| | | // 查询没转正的日期数据 |
| | | userInsuranceOpt = userInsuranceRepository.findbyUserIdAndNotEqualTo(criteria.getUserId(), confirmationTime); |
| | | } else { |
| | | // 查询第二条转正后的数据 |
| | | userInsuranceOpt = userInsuranceRepository.findbyUserIdAndDate(criteria.getUserId(), confirmationTime); |
| | | } |
| | | // 判断查询结果 |
| | | // if (userInsuranceOpt.isPresent()) { |
| | | if (userInsuranceOpt != null) { |
| | | // UserInsurance userInsurance = userInsuranceOpt.get(); |
| | | // 返回 |
| | | return userInsuranceMapper.toDto(userInsuranceOpt); |
| | | } else { |
| | | // throw new BadRequestException("没有获取到当前员工的级别信息!"); |
| | | throw new RuntimeException("没有获取到当前员工的级别信息!"); |
| | | } |
| | | } |