| | |
| | | @Override |
| | | public void performanceShiftAdd(PerformanceShiftAddDto performanceShiftAddDto) { |
| | | List<PerformanceShift> list = new ArrayList<>(); |
| | | LocalDateTime startWeek = performanceShiftAddDto.getStartWeek(); |
| | | LocalDateTime endWeek = performanceShiftAddDto.getEndWeek(); |
| | | |
| | | |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | String formattedDateTime = performanceShiftAddDto.getStartWeek().format(formatter); |
| | | String[] splitUserId = performanceShiftAddDto.getUserId().split(","); |
| | | for (String userId : splitUserId) { |
| | | boolean exists = baseMapper.exists(Wrappers.<PerformanceShift>lambdaQuery() |
| | | .eq(PerformanceShift::getWorkTime, formattedDateTime) |
| | | .eq(PerformanceShift::getUserId, userId)); |
| | | // 如果不存在添加数据 |
| | | if (!exists) { |
| | | LocalDate firstDayOfMonth = performanceShiftAddDto.getEndWeek().toLocalDate().withDayOfMonth(1); |
| | | LocalDate lastDayOfMonth = performanceShiftAddDto.getEndWeek().toLocalDate().with(TemporalAdjusters.lastDayOfMonth()); |
| | | List<LocalDateTime> localDateTimesBetween = getLocalDateTimesBetween(firstDayOfMonth.atStartOfDay(), lastDayOfMonth.atStartOfDay()); |
| | | localDateTimesBetween.forEach(i -> { |
| | | PerformanceShift performanceShift = new PerformanceShift(); |
| | | performanceShift.setUserId(Integer.valueOf(userId)); |
| | | performanceShift.setWorkTime(i); |
| | | performanceShift.setShift(""); |
| | | list.add(performanceShift); |
| | | if (list.size() >= 1000) { |
| | | baseMapper.insertBatchSomeColumn(list); |
| | | list.clear(); |
| | | } |
| | | }); |
| | | //判断是否跨月 |
| | | boolean isMonth = startWeek.getMonthValue() != endWeek.getMonthValue(); |
| | | if (isMonth){ |
| | | //如果跨月,则两个月都判断一下看数据库是哪个月份的数据没有 |
| | | boolean exists1 = baseMapper.exists(Wrappers.<PerformanceShift>lambdaQuery() |
| | | .eq(PerformanceShift::getWorkTime, startWeek) |
| | | .eq(PerformanceShift::getUserId, userId)); |
| | | boolean exists2 = baseMapper.exists(Wrappers.<PerformanceShift>lambdaQuery() |
| | | .eq(PerformanceShift::getWorkTime, endWeek) |
| | | .eq(PerformanceShift::getUserId, userId)); |
| | | if (!exists1 && !exists2){ |
| | | //两个月都不存在数据 |
| | | list = saveMonth(performanceShiftAddDto.getStartWeek(), userId, list); |
| | | list = saveMonth(performanceShiftAddDto.getEndWeek(), userId, list); |
| | | }else if (!exists1 && exists2){ |
| | | //开始的月份不存在数据 |
| | | list = saveMonth(performanceShiftAddDto.getStartWeek(), userId, list); |
| | | }else if (exists1 && !exists2){ |
| | | //结束的月份不存在数据 |
| | | list = saveMonth(performanceShiftAddDto.getEndWeek(), userId, list); |
| | | } |
| | | }else { |
| | | //不跨月 |
| | | boolean exists = baseMapper.exists(Wrappers.<PerformanceShift>lambdaQuery() |
| | | .in(PerformanceShift::getWorkTime, formattedDateTime) |
| | | .eq(PerformanceShift::getUserId, userId)); |
| | | // 如果不存在添加数据 |
| | | if (!exists) { |
| | | list = saveMonth(performanceShiftAddDto.getEndWeek(), userId, list); |
| | | } |
| | | } |
| | | } |
| | | if (!list.isEmpty()) { |
| | |
| | | } |
| | | } |
| | | |
| | | private List<PerformanceShift> saveMonth (LocalDateTime week,String userId,List<PerformanceShift> list){ |
| | | LocalDate firstDayOfMonth = week.toLocalDate().withDayOfMonth(1); |
| | | LocalDate lastDayOfMonth = week.toLocalDate().with(TemporalAdjusters.lastDayOfMonth()); |
| | | List<LocalDateTime> localDateTimesBetween = getLocalDateTimesBetween(firstDayOfMonth.atStartOfDay(), lastDayOfMonth.atStartOfDay()); |
| | | localDateTimesBetween.forEach(i -> { |
| | | PerformanceShift performanceShift = new PerformanceShift(); |
| | | performanceShift.setUserId(Integer.valueOf(userId)); |
| | | performanceShift.setWorkTime(i); |
| | | performanceShift.setShift(""); |
| | | list.add(performanceShift); |
| | | if (list.size() >= 1000) { |
| | | baseMapper.insertBatchSomeColumn(list); |
| | | list.clear(); |
| | | } |
| | | }); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> performanceShiftPage(Page<Object> page, String time, String userName, String laboratory) { |
| | | //查询当前登录人员的架构 |