| | |
| | | @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()) { |
| | |
| | | .eq(PerformanceShift::getWorkTime, formatterDateTime)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | 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 |
| | |
| | | |
| | | @Override |
| | | public IPage<Map<String, Object>> performanceShiftPageYear(Page<Object> page, String time, String userName, String laboratory) { |
| | | //查询当前登录人员的架构 |
| | | Integer userId = getLook.selectPowerByMethodAndUserId(null).get("userId"); |
| | | //判断全部,个人,组织的权限 |
| | | User user = userMapper.selectById(userId);//当前登录的人 |
| | | //获取当前人所属实验室id |
| | | String departLimsId = user.getDepartLimsId(); |
| | | if (com.baomidou.mybatisplus.core.toolkit.ObjectUtils.isNotEmpty(departLimsId) && !departLimsId.equals("")) { |
| | | String[] split = departLimsId.split(","); |
| | | //查询对应架构名称(通信实验室,电力实验室,检测办) |
| | | String departLims = baseMapper.seldepLimsId(Integer.parseInt(split[split.length - 1])); |
| | | if (departLims.contains("实验室")) { |
| | | laboratory = departLims; |
| | | } |
| | | } |
| | | IPage<Map<String, Object>> mapYearIPage = baseMapper.performanceShiftYear(page, time, userName, laboratory); |
| | | List<Enums> shiftType = enumService.selectEnumByCategory("班次类型"); |
| | | mapYearIPage.setRecords(annualAttendanceProcessing(mapYearIPage.getRecords(), shiftType)); |