| | |
| | | private TTaskCleanService taskCleanService; |
| | | @Autowired |
| | | private TTemplateCountService templateCountService; |
| | | @Autowired |
| | | private TEarlyWarningService earlyWarningService; |
| | | @Autowired |
| | | private TLeaveService leaveService; |
| | | |
| | | |
| | | // 每一个小时执行一次 |
| | |
| | | createInspection(template); |
| | | }); |
| | | |
| | | // 查询前一天为执行的所有任务,改成已超时状态 |
| | | List<TTask> taskCleanList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class) |
| | | .like(TTask::getImplementTime, LocalDate.now().minusDays(1)) |
| | | .eq(TTask::getStatus, 1)); |
| | | if (!CollectionUtils.isEmpty(taskCleanList)) { |
| | | taskCleanList.forEach(task -> { |
| | | task.setStatus(2); |
| | | }); |
| | | taskCleanService.updateBatchById(taskCleanList); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Scheduled(cron = "0 0 20 * * ?") |
| | | public void dayOfEarlyWarning() { |
| | | try { |
| | | // 查询前一天为执行的所有任务,改成已超时状态 |
| | | List<TTask> taskCleanList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class) |
| | | .like(TTask::getImplementTime, LocalDate.now()) |
| | | .eq(TTask::getStatus, 1)); |
| | | if (!CollectionUtils.isEmpty(taskCleanList)) { |
| | | List<TEarlyWarning> earlyWarningList = new ArrayList<>(); |
| | | taskCleanList.forEach(task -> { |
| | | task.setStatus(2); |
| | | TEarlyWarning earlyWarning = new TEarlyWarning(); |
| | | earlyWarning.setWarningType(1); |
| | | earlyWarning.setTaskId(task.getId()); |
| | | earlyWarningList.add(earlyWarning); |
| | | }); |
| | | earlyWarningService.saveBatch(earlyWarningList); |
| | | taskCleanService.updateBatchById(taskCleanList); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 生成点位预警 |
| | | */ |
| | | // 每分钟执行一次 |
| | | public void earning() { |
| | | |
| | | } |
| | | |
| | | public void createInspection(TTemplate template) { |
| | |
| | | |
| | | int taskCount = 0; |
| | | for (SysUser sysUser : sysUsers) { |
| | | |
| | | if("1".equals(sysUser.getStatus())){ |
| | | continue; |
| | | } |
| | | |
| | | List<TProjectDept> projectDeptLists = new ArrayList<>(); |
| | | if(sysUser.getDeptType() == 1){ |
| | | TProjectDept projectDept = projectDeptService.getById(sysUser.getDeptId()); |
| | | if("0".equals(projectDept.getParentId())){ |
| | | projectDeptLists = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) |
| | | .eq(TProjectDept::getParentId, projectDept.getId())); |
| | | }else { |
| | | projectDeptLists.add(projectDept); |
| | | if(projectDept.getStatus() == 1){ |
| | | if("0".equals(projectDept.getParentId())){ |
| | | projectDeptLists = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) |
| | | .eq(TProjectDept::getParentId, projectDept.getId()) |
| | | .eq(TProjectDept::getStatus, 1)); |
| | | }else { |
| | | projectDeptLists.add(projectDept); |
| | | } |
| | | } |
| | | }else { |
| | | projectDeptLists = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) |
| | | .ne(TProjectDept::getParentId,0)); |
| | | .ne(TProjectDept::getParentId,0) |
| | | .eq(TProjectDept::getStatus, 1)); |
| | | } |
| | | if(CollectionUtils.isEmpty(projectDeptLists)){ |
| | | continue; |
| | | } |
| | | List<String> proDeptIds = projectDeptLists.stream().map(TProjectDept::getId).collect(Collectors.toList()); |
| | | |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | tLocationList = tLocationList.stream().distinct().collect(Collectors.toList()); |
| | | // 抽取重复点位 |
| | | Integer currentValue = detail.getCurrentValue(); |
| | | if(currentValue != cycle){ |
| | | // 周期天数加一 |
| | | detail.setCurrentValue(currentValue + 1); |
| | | // 获取重复点位 |
| | | Set<TLocation> repeatLocation = redisCache.getCacheSet(detail.getId() + REPEAT_LOCATION); |
| | | Set<TLocation> repeatLocation = redisCache.getCacheSet(detail.getId() + ":" + sysUser.getUserId() + REPEAT_LOCATION); |
| | | if(!CollectionUtils.isEmpty(repeatLocation)){ |
| | | List<TLocation> locations = randomSelection(new ArrayList<>(tLocationList), num3); |
| | | tLocationList.addAll(locations); |
| | | } |
| | | Set<TLocation> locationSet = new HashSet<>(tLocationList); |
| | | redisCache.setCacheSet(detail.getId() + REPEAT_LOCATION, locationSet); |
| | | redisCache.setCacheSet(detail.getId() + ":" + sysUser.getUserId() + REPEAT_LOCATION, locationSet); |
| | | |
| | | }else { |
| | | // 设置当前周期为0 |
| | | detail.setCurrentValue(0); |
| | | // 将重复点位置空 |
| | | redisCache.deleteObject(detail.getId() + REPEAT_LOCATION); |
| | | redisCache.deleteObject(detail.getId() + ":" + sysUser.getUserId() + REPEAT_LOCATION); |
| | | // 将项目部权重置空 |
| | | redisCache.deleteObject(detail.getId() + PROJECT_DEPT_WEIGHT); |
| | | // 将保洁员权重置空 |
| | | redisCache.deleteObject(detail.getId() + CLEANER_WEIGHT); |
| | | } |
| | | |
| | | |
| | | // 查询请假记录 |
| | | TLeave leave = leaveService.getOne(Wrappers.lambdaQuery(TLeave.class) |
| | | .eq(TLeave::getLeavePerson, sysUser.getUserId()) |
| | | .eq(TLeave::getAuditStatus, 2) |
| | | .orderByDesc(TLeave::getCreateTime) |
| | | .last("LIMIT 1")); |
| | | |
| | | // 创建任务 |
| | | List<TTask> tasks = new ArrayList<>(); |
| | |
| | | task.setUserId(sysUser.getUserId()); |
| | | task.setStatus(1); |
| | | task.setLocationId(tLocation.getId()); |
| | | task.setImplementTime(LocalDateTime.now().plusDays(1)); |
| | | |
| | | // 判断今天是否在请假时间内 |
| | | if(Objects.nonNull(leave) && ((leave.getStartTime().toLocalDate().isBefore(LocalDate.now().plusDays(1)) && leave.getEndTime().toLocalDate().isAfter(LocalDate.now().plusDays(1))) |
| | | || (leave.getStartTime().toLocalDate().isEqual(LocalDate.now().plusDays(1)) || leave.getEndTime().toLocalDate().isEqual(LocalDate.now().plusDays(1))))){ |
| | | task.setImplementTime(leave.getEndTime().plusDays(1)); |
| | | }else { |
| | | task.setImplementTime(LocalDateTime.now().plusDays(1)); |
| | | } |
| | | task.setTaskType(1); |
| | | task.setTemplateId(detail.getTemplateId()); |
| | | String nameAndCode = CodeGenerateUtils.generateVolumeSn(); |
| | |
| | | tasks.add(task); |
| | | } |
| | | |
| | | // 添加应生成任务数量 |
| | | TTemplateCount templateCount = new TTemplateCount(); |
| | | templateCount.setTemplateId(detail.getTemplateId()); |
| | | templateCount.setTaskCount(tLocationList.size()* cycle); |
| | | templateCount.setUserId(sysUser.getUserId()); |
| | | templateCountService.save(templateCount); |
| | | |
| | | // 添加应生成任务数量 |
| | | TTemplateCount templateCount = new TTemplateCount(); |
| | | templateCount.setTemplateId(detail.getTemplateId()); |
| | | // 查询所有的保洁员下面的点位 |
| | | List<String> cleanIds = cleaners.stream().map(TCleaner::getId).collect(Collectors.toList()); |
| | | List<TLocation> tLocations = locationService.list(Wrappers.lambdaQuery(TLocation.class) |
| | | .in(TLocation::getLocationCleaner, cleanIds)); |
| | | templateCount.setTaskCount(tLocations.size()); |
| | | templateCount.setUserId(sysUser.getUserId()); |
| | | templateCountService.save(templateCount); |
| | | taskCleanService.saveBatch(tasks); |
| | | taskCount = taskCount + tasks.size(); |
| | | } |