| | |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.time.ZoneId; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.temporal.TemporalAdjusters; |
| | |
| | | @Slf4j |
| | | @Service |
| | | public class PerformanceShiftServiceImpl extends ServiceImpl<PerformanceShiftMapper, PerformanceShift> implements PerformanceShiftService { |
| | | |
| | | @Autowired |
| | | private ISysDictTypeService dictTypeService; |
| | | |
| | | @Autowired |
| | | private StaffAttendanceTrackingRecordService trackingRecordService; |
| | |
| | | public void performanceShiftAdd(PerformanceShiftAddDto performanceShiftAddDto) { |
| | | //1.查询所选周次时间范围内已排班的数据 |
| | | List<PerformanceShift> shiftList = baseMapper.selectList(Wrappers.<PerformanceShift>lambdaQuery() |
| | | .between(ObjectUtils.allNotNull(performanceShiftAddDto.getStartWeek(), performanceShiftAddDto.getEndWeek()), |
| | | PerformanceShift::getWorkTime, performanceShiftAddDto.getStartWeek(), performanceShiftAddDto.getEndWeek()) |
| | | .between(ObjectUtils.allNotNull(performanceShiftAddDto.getStartTime(), performanceShiftAddDto.getEndTime()), |
| | | PerformanceShift::getWorkTime, performanceShiftAddDto.getStartTime(), performanceShiftAddDto.getEndTime()) |
| | | .in(!performanceShiftAddDto.getUserIdList().isEmpty(), PerformanceShift::getUserId, performanceShiftAddDto.getUserIdList()) |
| | | ); |
| | | List<LocalDateTime> timeList = getLocalDateTimesBetween(performanceShiftAddDto.getStartWeek(), performanceShiftAddDto.getEndWeek()); |
| | | List<LocalDateTime> timeList = getLocalDateTimesBetween(performanceShiftAddDto.getStartTime(), performanceShiftAddDto.getEndTime()); |
| | | //处理选中人员 |
| | | List<PerformanceShift> newShiftList = new ArrayList<>(); |
| | | performanceShiftAddDto.getUserIdList().forEach(userId->{ |
| | |
| | | List<PerformanceShiftMapDto> mapIPage = baseMapper.performanceShift(firstDayOfMonth,lastDayOfMonth, userName, laboratory); |
| | | Map<Integer, List<PerformanceShiftMapDto>> groupByUserId = mapIPage.stream().collect(Collectors.groupingBy(PerformanceShiftMapDto::getUserId)); |
| | | List<PerformanceShiftMapDto> newRecords = new ArrayList<>(); |
| | | List<LocalDateTime> timeList = getLocalDateTimesBetween(LocalDateTime.of(firstDayOfMonth, LocalTime.MIN), LocalDateTime.of(lastDayOfMonth, LocalTime.MIN)); |
| | | groupByUserId.keySet().forEach(key->{ |
| | | PerformanceShiftMapDto shiftMapDto = new PerformanceShiftMapDto(); |
| | | List<PerformanceShiftMapDto> shiftMapDtos = groupByUserId.get(key); |
| | | List<PerformanceShiftMapDto> newShiftMapDtos = new ArrayList<>(); |
| | | timeList.forEach(t->{ |
| | | PerformanceShiftMapDto mapDto = shiftMapDtos.stream().filter(s -> t.isEqual(s.getWorkTime())).findFirst().orElse(null); |
| | | if(ObjectUtils.isNotEmpty(mapDto)){ |
| | | newShiftMapDtos.add(mapDto); |
| | | }else{ |
| | | newShiftMapDtos.add(null); |
| | | } |
| | | }); |
| | | //统计各班次天数 |
| | | Map<String, Long> countShift = countShift(shiftMapDtos); |
| | | shiftMapDto.setMonthlyAttendance(countShift); |
| | | shiftMapDto.setMonthlyAttendanceStr(formateMap(countShift)); |
| | | shiftMapDto.setList(shiftMapDtos); |
| | | shiftMapDto.setList(newShiftMapDtos); |
| | | |
| | | shiftMapDto.setUserName(shiftMapDtos.isEmpty()?"":shiftMapDtos.get(0).getUserName()); |
| | | shiftMapDto.setUserId(key); |
| | |
| | | default: |
| | | return "未知"; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 返回表头 |
| | | * <p> |
| | | * 外层List代表行内层 List代表列 相同的列数据会被主动合并 |
| | | * 构造双列表头 |
| | | * |
| | | * @return List<List < String>> |
| | | */ |
| | | private static List<List<String>> getYearHeader(String year, List<SysDictData> enums) { |
| | | List<List<String>> line = new ArrayList<>(); |
| | | line.add(Arrays.asList("考勤汇总", "序号", "序号")); |
| | | line.add(Arrays.asList("考勤汇总", "工号", "工号")); |
| | | line.add(Arrays.asList("考勤汇总", "姓名", "姓名")); |
| | | line.add(Arrays.asList("出勤详情", year, "出勤")); |
| | | // 年 header |
| | | for (SysDictData anEnum : enums) { |
| | | if (!anEnum.getDictValue().equals("5")) { |
| | | line.add(Arrays.asList("考勤汇总", year, anEnum.getDictLabel())); |
| | | } |
| | | } |
| | | // 月header |
| | | for (int i = 1; i < 13; i++) { |
| | | line.add(Arrays.asList("出勤详情", i + " 月", "出勤")); |
| | | for (SysDictData anEnum : enums) { |
| | | if (!anEnum.getDictValue().equals("5")) { |
| | | line.add(Arrays.asList("出勤详情", i + " 月", anEnum.getDictLabel())); |
| | | } |
| | | } |
| | | } |
| | | return line; |
| | | } |
| | | |
| | | private static List<List<String>> getMonthHeader(LocalDateTime localDateTimeYear, List<SysDictData> enums) { |
| | | String year = localDateTimeYear.getYear() + " 年人员班次"; |
| | | List<List<String>> line = new ArrayList<>(); |
| | | line.add(Arrays.asList(year, "序号", "序号", "序号")); |
| | | line.add(Arrays.asList(year, "姓名", "姓名", "姓名")); |
| | | line.add(Arrays.asList(year, "实验室", "实验室", "实验室")); |
| | | line.add(Arrays.asList(year, localDateTimeYear.getYear() + "", localDateTimeYear.getYear() + "", "出勤")); |
| | | line.add(Arrays.asList(year, localDateTimeYear.getYear() + "", localDateTimeYear.getYear() + "", enums.get(3).getDictLabel())); |
| | | line.add(Arrays.asList(year, "年", "年", enums.get(4).getDictLabel())); |
| | | line.add(Arrays.asList(year, localDateTimeYear.getMonthValue() + "", localDateTimeYear.getMonthValue() + "", enums.get(0).getDictLabel())); |
| | | line.add(Arrays.asList(year, "月", "月", enums.get(1).getDictLabel())); |
| | | line.add(Arrays.asList(year, "", "", enums.get(2).getDictLabel())); |
| | | line.add(Arrays.asList(year, "周次", "星期", "出差")); |
| | | LocalDate firstDayOfMonth = localDateTimeYear.toLocalDate().withDayOfMonth(1); |
| | | LocalDate lastDayOfMonth = localDateTimeYear.toLocalDate().with(TemporalAdjusters.lastDayOfMonth()); |
| | | List<LocalDateTime> timeList = getLocalDateTimesBetween(firstDayOfMonth.atStartOfDay(), lastDayOfMonth.atStartOfDay()); |
| | | timeList.forEach(i -> { |
| | | int dayOfYear = i.getDayOfMonth(); |
| | | Date from = Date.from(i.atZone(ZoneId.systemDefault()).toInstant()); |
| | | String weekDay = getWeekDay(i.getDayOfWeek().getValue()); |
| | | line.add(Arrays.asList(year, DateUtil.weekOfYear(DateUtil.offsetDay(from, 1)) + "", weekDay, dayOfYear + "")); |
| | | }); |
| | | return line; |
| | | } |
| | | |
| | | public List<List<Object>> dataRequiredForProcessingIntoExcelMonth(List<PerformanceShiftMapDto> list, List<SysDictData> enums) { |
| | | List<List<Object>> data = new ArrayList<>(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | List<Object> excelRowList = new ArrayList<>(); |
| | | excelRowList.add(i + 1); |
| | | excelRowList.add(list.get(i).getUserName()); |
| | | excelRowList.add(list.get(i).getDepartment()); |
| | | excelRowList.add(list.get(i).getMonthlyAttendance().get("totalAttendance")); |
| | | excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(3).getDictLabel())); // 休 |
| | | excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(4).getDictLabel())); // 假 |
| | | excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(0).getDictLabel())); // 早 |
| | | excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(1).getDictLabel())); // 中 |
| | | excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(2).getDictLabel())); // 夜 |
| | | excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(6).getDictLabel())); // 差 |
| | | |
| | | data.add(excelRowList); |
| | | } |
| | | return data; |
| | | } |
| | | } |