| | |
| | | import com.ruoyi.common.core.domain.entity.User; |
| | | import com.ruoyi.common.utils.JackSonUtil; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.performance.dto.PerformanceShiftAddDto; |
| | | import com.ruoyi.performance.dto.PerformanceShiftMapDto; |
| | | import com.ruoyi.performance.mapper.PerformanceShiftMapper; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.temporal.TemporalAdjusters; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Autowired |
| | | UserMapper userMapper; |
| | | |
| | | private DateTimeFormatter yyyyMMdd = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | |
| | | private DateTimeFormatter yyyyMMddHHmmss = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void performanceShiftAdd(PerformanceShiftAddDto performanceShiftAddDto) { |
| | |
| | | LocalDateTime startWeek = performanceShiftAddDto.getStartWeek(); |
| | | LocalDateTime endWeek = performanceShiftAddDto.getEndWeek(); |
| | | |
| | | |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | String formattedDateTime = performanceShiftAddDto.getStartWeek().format(formatter); |
| | | String formattedDateTime = performanceShiftAddDto.getStartWeek().format(yyyyMMdd); |
| | | String[] splitUserId = performanceShiftAddDto.getUserId().split(","); |
| | | for (String userId : splitUserId) { |
| | | //判断是否跨月 |
| | |
| | | performanceShift.setShift(performanceShiftAddDto.getShift()); |
| | | performanceShift.setUserId(Integer.valueOf(s)); |
| | | performanceShift.setWorkTime(date); |
| | | String formatterDateTime = date.format(formatter); |
| | | String formatterDateTime = date.format(yyyyMMdd); |
| | | baseMapper.update(new PerformanceShift(), Wrappers.<PerformanceShift>lambdaUpdate() |
| | | .set(PerformanceShift::getShift, performanceShiftAddDto.getShift()) |
| | | .eq(PerformanceShift::getUserId, s) |
| | |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> performanceShiftPage(Page<Object> page, String time, String userName, String laboratory) { |
| | | public Map<String, Object> performanceShift( String time, String userName, String laboratory) { |
| | | //查询当前登录人员的架构 |
| | | Integer userId = SecurityUtils.getUserId().intValue(); |
| | | //判断全部,个人,组织的权限 |
| | | User user = userMapper.selectById(userId);//当前登录的人 |
| | | //获取当前人所属实验室id |
| | | String departLimsId = user.getDepartLimsId(); |
| | | if (com.baomidou.mybatisplus.core.toolkit.ObjectUtils.isNotEmpty(departLimsId) && !departLimsId.equals("")) { |
| | | if (com.baomidou.mybatisplus.core.toolkit.ObjectUtils.isNotEmpty(departLimsId) && !departLimsId.isEmpty()) { |
| | | String[] split = departLimsId.split(","); |
| | | //查询对应架构名称(通信实验室,电力实验室,检测办) |
| | | String departLims = baseMapper.seldepLimsId(Integer.parseInt(split[split.length - 1])); |
| | |
| | | laboratory = departLims; |
| | | } |
| | | } |
| | | // 获取header时间 |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); |
| | | DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | // 将字符串时间转换为 LocalDateTime 类型时间 |
| | | LocalDateTime localDateTime = LocalDateTime.parse(time, formatters); |
| | | // List<SysDictData> shiftType = dictTypeService.selectDictDataByName("班次类型"); |
| | | //班次时间范围为上个月的26号到本月的25号 |
| | | LocalDateTime localDateTime = LocalDateTime.parse(time, yyyyMMddHHmmss); |
| | | LocalDate firstDayOfMonth = localDateTime.toLocalDate().minusMonths(1L).withDayOfMonth(26); |
| | | LocalDate lastDayOfMonth = localDateTime.toLocalDate().withDayOfMonth(25); |
| | | //人员排班详情 |
| | | 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<>(); |
| | | groupByUserId.keySet().forEach(key->{ |
| | | PerformanceShiftMapDto shiftMapDto = new PerformanceShiftMapDto(); |
| | | List<PerformanceShiftMapDto> shiftMapDtos = groupByUserId.get(key); |
| | | //统计各班次天数 |
| | | countShift(shiftMapDto.getMonthlyAttendance(),shiftMapDtos); |
| | | shiftMapDto.setList(shiftMapDtos); |
| | | |
| | | IPage<PerformanceShiftMapDto> mapIPage = baseMapper.performanceShiftPage(page, firstDayOfMonth,lastDayOfMonth, userName, laboratory); |
| | | |
| | | List<SysDictData> shiftType = dictTypeService.selectDictDataByName("班次类型"); |
| | | List<Map<String, Object>> mapYearIPage = baseMapper.performanceShiftYearPage(time, userName, laboratory); |
| | | mapIPage.getRecords().forEach(i -> { |
| | | String[] shiftTimes = i.getShiftTime().split(";"); |
| | | double totalAttendance = 0; |
| | | List<Map<String, Object>> map = new ArrayList<>(); |
| | | // 分割日期 |
| | | for (String shiftTime : shiftTimes) { |
| | | Map<String, Object> hashMap = new HashMap<>(); |
| | | String[] shiftTimeAndShift = shiftTime.split(":"); |
| | | for (SysDictData enums : shiftType) { |
| | | if (!i.getMonthlyAttendance().containsKey(enums.getDictLabel())) { |
| | | i.getMonthlyAttendance().put(enums.getDictLabel(), 0); |
| | | } |
| | | if (enums.getDictValue().equals(shiftTimeAndShift[1])) { |
| | | BigDecimal bigDecimal = new BigDecimal(i.getMonthlyAttendance().get(enums.getDictLabel()).toString()); |
| | | i.getMonthlyAttendance().put(enums.getDictLabel(), bigDecimal.add(new BigDecimal("1"))); |
| | | } |
| | | // 半,另外半天算给早 |
| | | // if (shiftTimeAndShift[1].equals("5") && enums.getDictValue().equals("0")) { |
| | | // BigDecimal bigDecimal = new BigDecimal(i.getMonthlyAttendance().get(enums.getDictLabel()).toString()); |
| | | // i.getMonthlyAttendance().put(enums.getDictLabel(), bigDecimal.add(new BigDecimal("0.5"))); |
| | | // } |
| | | } |
| | | // 早,中,夜,差 |
| | | if (shiftTimeAndShift[1].equals("2") || shiftTimeAndShift[1].equals("3") || shiftTimeAndShift[1].equals("4")) { |
| | | i.getMonthlyAttendance().put("totalAttendance", totalAttendance += 1); |
| | | } |
| | | // 半 |
| | | // if (shiftTimeAndShift[1].equals("5")) { |
| | | // i.getMonthlyAttendance().put("totalAttendance", totalAttendance += 0.5); |
| | | // } |
| | | hashMap.put("id", shiftTimeAndShift[3]); |
| | | hashMap.put("shift", shiftTimeAndShift[1]); |
| | | hashMap.put("time", shiftTimeAndShift[0]); |
| | | hashMap.put("annotationText", shiftTimeAndShift[2]); |
| | | map.add(hashMap); |
| | | } |
| | | double totalYearAttendance = 0; |
| | | Map<String, Object> hashMap = new HashMap<>(); |
| | | for (Map<String, Object> record : mapYearIPage) { |
| | | if (record.get("user_id").toString().equals(i.getUserId())) { |
| | | for (SysDictData enums : shiftType) { |
| | | if (!hashMap.containsKey(enums.getDictLabel())) { |
| | | hashMap.put(enums.getDictLabel(), 0); |
| | | } |
| | | if (enums.getDictValue().equals(record.get("shift"))) { |
| | | BigDecimal num = new BigDecimal(hashMap.get(enums.getDictLabel()).toString()); |
| | | hashMap.put(enums.getDictLabel(), num.add(new BigDecimal("1"))); |
| | | } |
| | | // 半,另外半天算给早 |
| | | // if (record.get("shift").equals("5") && enums.getDictValue().equals("0")) { |
| | | // BigDecimal bigDecimal = new BigDecimal(hashMap.get(enums.getDictLabel()).toString()); |
| | | // hashMap.put(enums.getDictLabel(), bigDecimal.add(new BigDecimal("0.5"))); |
| | | // } |
| | | } |
| | | if (record.get("shift").equals("2") || record.get("shift").equals("3") || record.get("shift").equals("4")) { |
| | | hashMap.put("totalAttendance", totalYearAttendance += 1); |
| | | } |
| | | // 半 |
| | | // if (record.get("shift").equals("5")) { |
| | | // hashMap.put("totalAttendance", totalYearAttendance += 0.5); |
| | | // } |
| | | } |
| | | } |
| | | i.setSidebarAnnualAttendance(hashMap); |
| | | i.setList(map); |
| | | i.setShiftTime(null); |
| | | shiftMapDto.setUserName(shiftMapDtos.isEmpty()?"":shiftMapDtos.get(0).getUserName()); |
| | | shiftMapDto.setUserId(key); |
| | | newRecords.add(shiftMapDto); |
| | | }); |
| | | Map<String, Object> resultMap = new HashMap<>(); |
| | | resultMap.put("page", newRecords); |
| | | resultMap.put("headerList", getYearHeaderTimeList(firstDayOfMonth,lastDayOfMonth)); |
| | | return resultMap; |
| | | } |
| | | |
| | | /** |
| | | * 统计班次 |
| | | * @param targetMap 结果对象 |
| | | * @param shiftMapDtos 班次列表 |
| | | */ |
| | | private void countShift(Map<String,Object> targetMap,List<PerformanceShiftMapDto> shiftMapDtos){ |
| | | //汇总早班、中班、夜班、休息、请假、出差的天数,以及总出勤天数 |
| | | Map<String, List<PerformanceShiftMapDto>> groupByShift = shiftMapDtos.stream().collect(Collectors.groupingBy(PerformanceShift::getShift)); |
| | | AtomicInteger morningShift = new AtomicInteger(0);//早班 |
| | | AtomicInteger swingShift = new AtomicInteger(0);//中班 |
| | | AtomicInteger nightShift = new AtomicInteger(0);//晚班 |
| | | AtomicInteger holidayShift = new AtomicInteger(0);//休 |
| | | AtomicInteger leaveShift = new AtomicInteger(0);//请假 |
| | | groupByShift.keySet().forEach(shiftKey->{ |
| | | switch (shiftKey){ |
| | | case "0"://早12 |
| | | case "2"://早班8 |
| | | case "6"://早10 |
| | | morningShift.addAndGet(groupByShift.get(shiftKey).size()); |
| | | break; |
| | | case "3"://中班8 |
| | | swingShift.addAndGet(groupByShift.get(shiftKey).size()); |
| | | break; |
| | | case "1"://夜12 |
| | | case "4"://夜班8 |
| | | nightShift.addAndGet(groupByShift.get(shiftKey).size()); |
| | | break; |
| | | case "5"://休 |
| | | holidayShift.addAndGet(groupByShift.get(shiftKey).size()); |
| | | break; |
| | | case "7"://事 |
| | | case "8"://病 |
| | | case "9"://年 |
| | | case "10"://婚 |
| | | case "11"://调休 |
| | | case "12"://产 |
| | | case "13"://丧 |
| | | leaveShift.addAndGet(groupByShift.get(shiftKey).size()); |
| | | break; |
| | | } |
| | | }); |
| | | targetMap.put("morningShift",morningShift.get()); |
| | | targetMap.put("swingShift",swingShift.get()); |
| | | targetMap.put("nightShift",nightShift.get()); |
| | | targetMap.put("holidayShift",holidayShift.get()); |
| | | targetMap.put("leaveShift",leaveShift.get()); |
| | | } |
| | | |
| | | /** |
| | | * 班次分页查询:获取月度日期表头列表 |
| | | * @param firstDayOfMonth |
| | | * @param lastDayOfMonth |
| | | * @return |
| | | */ |
| | | private List<Object> getYearHeaderTimeList(LocalDate firstDayOfMonth,LocalDate lastDayOfMonth){ |
| | | List<LocalDateTime> localDateTimesBetween = getLocalDateTimesBetween(firstDayOfMonth.atStartOfDay(), lastDayOfMonth.atStartOfDay()); |
| | | List<Object> list1 = new ArrayList<>(); |
| | | List<Object> list = new ArrayList<>(); |
| | | for (LocalDateTime dateTime : localDateTimesBetween) { |
| | | Map<Object, Object> hashMap = new HashMap<>(); |
| | | DateTime parse = DateUtil.parse(dateTime.format(formatter)); |
| | | DateTime parse = DateUtil.parse(dateTime.format(yyyyMMdd)); |
| | | hashMap.put("weekly", DateUtil.weekOfYear(DateUtil.offsetDay(parse, 1))); |
| | | hashMap.put("headerTime", getWeek(dateTime.format(formatters))); |
| | | list1.add(hashMap); |
| | | hashMap.put("headerTime", getWeek(dateTime.format(yyyyMMddHHmmss))); |
| | | list.add(hashMap); |
| | | } |
| | | Map<String, Object> resultMap = new HashMap<>(); |
| | | resultMap.put("page", mapIPage); |
| | | resultMap.put("headerList", list1); |
| | | return resultMap; |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public IPage<Map<String, Object>> performanceShiftPageYear(Page<Object> page, String time, String userName, String laboratory) { |
| | | public List<Map<String, Object>> performanceShiftPageYear(String time, String userName, String laboratory) { |
| | | //查询当前登录人员的架构 |
| | | Integer userId = SecurityUtils.getUserId().intValue(); |
| | | //判断全部,个人,组织的权限 |
| | | User user = userMapper.selectById(userId);//当前登录的人 |
| | | //获取当前人所属实验室id |
| | | String departLimsId = user.getDepartLimsId(); |
| | | if (com.baomidou.mybatisplus.core.toolkit.ObjectUtils.isNotEmpty(departLimsId) && !departLimsId.equals("")) { |
| | | if (StringUtils.isNotEmpty(departLimsId) && !departLimsId.equals("")) { |
| | | String[] split = departLimsId.split(","); |
| | | //查询对应架构名称(通信实验室,电力实验室,检测办) |
| | | String departLims = baseMapper.seldepLimsId(Integer.parseInt(split[split.length - 1])); |
| | |
| | | laboratory = departLims; |
| | | } |
| | | } |
| | | IPage<Map<String, Object>> mapYearIPage = baseMapper.performanceShiftYear(page, time, userName, laboratory); |
| | | List<SysDictData> shiftType = dictTypeService.selectDictDataByName("班次类型"); |
| | | mapYearIPage.setRecords(annualAttendanceProcessing(mapYearIPage.getRecords(), shiftType)); |
| | | return mapYearIPage; |
| | | // List<SysDictData> shiftType = dictTypeService.selectDictDataByName("班次类型"); |
| | | List<PerformanceShiftMapDto> shiftYearList = baseMapper.performanceShiftYear(time, userName, laboratory); |
| | | //按人员分组,统计每个人的年度班次 |
| | | Map<Integer, List<PerformanceShiftMapDto>> groupByUserId = shiftYearList.stream().collect(Collectors.groupingBy(PerformanceShift::getUserId)); |
| | | List<Map<String,Object>> returnList = new ArrayList<>(); |
| | | groupByUserId.keySet().forEach(userIdKey->{ |
| | | //按月份分组,统计每个月的班次详情 |
| | | Map<String, Object> returnMap = new HashMap<>(); |
| | | List<PerformanceShiftMapDto> shiftMapDtos = groupByUserId.get(userIdKey); |
| | | Map<String, Object> sidebarAnnualAttendance = new HashMap<>(); |
| | | countShift(sidebarAnnualAttendance,shiftMapDtos);//年度班次统计 |
| | | List<Map<String,Object>> monthlyAttendance = new ArrayList<>(); |
| | | if(!shiftMapDtos.isEmpty()){ |
| | | returnMap.put("userName",shiftMapDtos.get(0).getUserName()); |
| | | returnMap.put("userId",shiftMapDtos.get(0).getUserId()); |
| | | Map<Integer, List<PerformanceShiftMapDto>> groupByMonthNum = shiftMapDtos.stream().collect(Collectors.groupingBy(PerformanceShiftMapDto::getMonthNum)); |
| | | //遍历12个月的班次信息 |
| | | for (int i = 1; i <= 12; i++) { |
| | | List<PerformanceShiftMapDto> monthShiftDtos = groupByMonthNum.get(i); |
| | | Map<String, Object> monthlyAttendanceMap = new HashMap<>(); |
| | | if(CollectionUtils.isEmpty(monthShiftDtos)){ |
| | | countShift(monthlyAttendanceMap,new ArrayList<>());//月度班次统计 |
| | | }else{ |
| | | countShift(monthlyAttendanceMap,monthShiftDtos);//月度班次统计 |
| | | } |
| | | monthlyAttendance.add(monthlyAttendanceMap); |
| | | } |
| | | returnMap.put("monthlyAttendance",monthlyAttendance); |
| | | returnMap.put("sidebarAnnualAttendance",sidebarAnnualAttendance); |
| | | } |
| | | returnList.add(returnMap); |
| | | }); |
| | | return returnList; |
| | | } |
| | | |
| | | // 年分页与导出共同使用 |
| | |
| | | hashMap.put("annotationText", shiftTimeAndShift[2]); |
| | | map.add(hashMap); |
| | | } |
| | | i.setList(map); |
| | | // i.setList(map); |
| | | i.setShiftTime(null); |
| | | }); |
| | | Map<Object, Object> map = new HashMap<>(); |
| | |
| | | for (int i = 0; i < list.size(); i++) { |
| | | List<Object> excelRowList = new ArrayList<>(); |
| | | excelRowList.add(i + 1); |
| | | excelRowList.add(list.get(i).getName()); |
| | | 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(1).getDictLabel())); // 中 |
| | | excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(2).getDictLabel())); // 夜 |
| | | excelRowList.add(list.get(i).getMonthlyAttendance().get(enums.get(6).getDictLabel())); // 差 |
| | | for (Map<String, Object> o : list.get(i).getList()) { |
| | | String enumLabel = ""; |
| | | for (SysDictData anEnum : enums) { |
| | | if (anEnum.getDictValue().equals(o.get("shift"))) { |
| | | enumLabel = anEnum.getDictLabel(); |
| | | } |
| | | } |
| | | excelRowList.add(ObjectUtils.isEmpty(enumLabel) ? "-" : enumLabel); |
| | | } |
| | | // for (Map<String, Object> o : list.get(i).getList()) { |
| | | // String enumLabel = ""; |
| | | // for (SysDictData anEnum : enums) { |
| | | // if (anEnum.getDictValue().equals(o.get("shift"))) { |
| | | // enumLabel = anEnum.getDictLabel(); |
| | | // } |
| | | // } |
| | | // excelRowList.add(ObjectUtils.isEmpty(enumLabel) ? "-" : enumLabel); |
| | | // } |
| | | data.add(excelRowList); |
| | | } |
| | | return data; |