| | |
| | | package com.yuanchu.mom.service.impl; |
| | | |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.yuanchu.mom.dto.PerformanceShiftAddDto; |
| | | import com.yuanchu.mom.dto.PerformanceShiftMapDto; |
| | | import com.yuanchu.mom.mapper.PerformanceShiftMapper; |
| | | import com.yuanchu.mom.pojo.Enums; |
| | | import com.yuanchu.mom.pojo.PerformanceShift; |
| | |
| | | public void performanceShiftAdd(PerformanceShiftAddDto performanceShiftAddDto) { |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | String formattedDateTime = performanceShiftAddDto.getStartWeek().format(formatter); |
| | | boolean exists = baseMapper.exists(Wrappers.<PerformanceShift>lambdaQuery() |
| | | .eq(PerformanceShift::getWorkTime, formattedDateTime)); |
| | | String[] splitUserId = performanceShiftAddDto.getUserId().split(","); |
| | | // 妿ä¸å卿·»å æ°æ® |
| | | 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 -> { |
| | | for (String s : splitUserId) { |
| | | PerformanceShift performanceShift = new PerformanceShift(); |
| | | performanceShift.setUserId(Integer.valueOf(s)); |
| | | performanceShift.setWorkTime(i); |
| | | performanceShift.setShift(""); |
| | | list.add(performanceShift); |
| | | } |
| | | if (list.size() >= 1000) { |
| | | 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 -> { |
| | | for (String s : splitUserId) { |
| | | PerformanceShift performanceShift = new PerformanceShift(); |
| | | performanceShift.setUserId(Integer.valueOf(s)); |
| | | performanceShift.setWorkTime(i); |
| | | performanceShift.setShift(""); |
| | | list.add(performanceShift); |
| | | } |
| | | if (list.size() >= 1000) { |
| | | baseMapper.insertBatchSomeColumn(list); |
| | | list.clear(); |
| | | } |
| | | }); |
| | | if (!list.isEmpty()) { |
| | | baseMapper.insertBatchSomeColumn(list); |
| | | list.clear(); |
| | | } |
| | | }); |
| | | if (!list.isEmpty()) { |
| | | baseMapper.insertBatchSomeColumn(list); |
| | | } |
| | | } |
| | | // 忬¡æ´æ° |
| | |
| | | } |
| | | |
| | | @Override |
| | | public IPage<Map<String, Object>> performanceShiftPage(Page<Object> page, String time, String userName, String laboratory) { |
| | | IPage<Map<String, Object>> mapIPage = baseMapper.performanceShiftPage(page, time, userName, laboratory); |
| | | public IPage<PerformanceShiftMapDto> performanceShiftPage(Page<Object> page, String time, String userName, String laboratory) { |
| | | IPage<PerformanceShiftMapDto> mapIPage = baseMapper.performanceShiftPage(page, time, userName, laboratory); |
| | | List<Enums> shiftType = enumService.selectEnumByCategory("çæ¬¡ç±»å"); |
| | | for (Map<String, Object> i : mapIPage.getRecords()) { |
| | | String[] shiftTimes = i.get("shiftTime").toString().split(";"); |
| | | List<Map<String, Object>> mapYearIPage = baseMapper.performanceShiftYearPage(time, userName, laboratory); |
| | | mapIPage.getRecords().forEach(i -> { |
| | | String[] shiftTimes = i.getShiftTime().split(";"); |
| | | int totalAttendance = 0; |
| | | List<Object> map = new ArrayList<>(); |
| | | // å岿¥æ |
| | |
| | | Map<Object, Object> hashMap = new HashMap<>(); |
| | | String[] shiftTimeAndShift = shiftTime.split("ï¼"); |
| | | for (Enums enums : shiftType) { |
| | | if (!i.containsKey(enums.getLabel())) { |
| | | i.put(enums.getLabel(), 0); |
| | | if (!i.getMonthlyAttendance().containsKey(enums.getLabel())) { |
| | | i.getMonthlyAttendance().put(enums.getLabel(), 0); |
| | | } |
| | | if (enums.getValue().equals(shiftTimeAndShift[1])) { |
| | | Integer num = (Integer) i.get(enums.getLabel()); |
| | | i.put(enums.getLabel(), num += 1); |
| | | Integer num = (Integer) i.getMonthlyAttendance().get(enums.getLabel()); |
| | | i.getMonthlyAttendance().put(enums.getLabel(), num += 1); |
| | | } |
| | | } |
| | | if (shiftTimeAndShift[1].equals("1") || shiftTimeAndShift[1].equals("2") || shiftTimeAndShift[1].equals("0")) { |
| | | i.put("totalAttendance", totalAttendance += 1); |
| | | i.getMonthlyAttendance().put("totalAttendance", totalAttendance += 1); |
| | | } |
| | | hashMap.put("id", shiftTimeAndShift[2]); |
| | | hashMap.put("shift", shiftTimeAndShift[1]); |
| | | hashMap.put("weekly", DateUtil.weekOfYear(DateUtil.parse(shiftTimeAndShift[0]))); |
| | | DateTime parse = DateUtil.parse(shiftTimeAndShift[0]); |
| | | hashMap.put("weekly", DateUtil.weekOfYear(DateUtil.offsetDay(parse, 1))); |
| | | hashMap.put("time", shiftTimeAndShift[0]); |
| | | hashMap.put("headerTime", getWeek(shiftTimeAndShift[0])); |
| | | map.add(hashMap); |
| | | } |
| | | i.put("list", map); |
| | | i.remove("shiftTime"); |
| | | } |
| | | int totalYearAttendance = 0; |
| | | Map<String, Object> hashMap = new HashMap<>(); |
| | | for (Map<String, Object> record : mapYearIPage) { |
| | | if (record.get("user_id").toString().equals(i.getUserId())) { |
| | | for (Enums enums : shiftType) { |
| | | if (!hashMap.containsKey(enums.getLabel())) { |
| | | hashMap.put(enums.getLabel(), 0); |
| | | } |
| | | if (enums.getValue().equals(record.get("shift"))) { |
| | | Integer num = (Integer) hashMap.get(enums.getLabel()); |
| | | hashMap.put(enums.getLabel(), num += 1); |
| | | } |
| | | } |
| | | if (record.get("shift").equals("1") || record.get("shift").equals("2") || record.get("shift").equals("0")) { |
| | | hashMap.put("totalAttendance", totalYearAttendance += 1); |
| | | } |
| | | } |
| | | } |
| | | i.setSidebarAnnualAttendance(hashMap); |
| | | i.setList(map); |
| | | i.setShiftTime(null); |
| | | }); |
| | | return mapIPage; |
| | | } |
| | | |
| | |
| | | PerformanceShift performanceShift = new PerformanceShift(); |
| | | performanceShift.setId(id); |
| | | performanceShift.setShift(shift); |
| | | baseMapper.updateById(performanceShift); |
| | | baseMapper.update(new PerformanceShift(), Wrappers.<PerformanceShift>lambdaUpdate() |
| | | .eq(PerformanceShift::getId, id) |
| | | .set(PerformanceShift::getShift, shift)); |
| | | } |
| | | |
| | | // è·å两个localDateTimeçæ¯ä¸å¤© |