From 083c414ff683ab12e65069c6c0ba6871ed1ed09f Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期六, 12 七月 2025 10:19:09 +0800
Subject: [PATCH] 保洁巡检本周代码

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/task/TaskUtil.java |   51 ++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 44 insertions(+), 7 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/task/TaskUtil.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/task/TaskUtil.java
index 6457e24..de1f249 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/task/TaskUtil.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/task/TaskUtil.java
@@ -60,6 +60,8 @@
     private TTaskCleanService taskCleanService;
     @Autowired
     private TTemplateCountService templateCountService;
+    @Autowired
+    private TEarlyWarningService earlyWarningService;
 
 
     // 每一个小时执行一次
@@ -92,6 +94,38 @@
         } 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().minusDays(1))
+                    .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) {
@@ -275,26 +309,26 @@
                         }
                     }
                 }
-
+                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);
                     // 将保洁员权重置空
@@ -327,11 +361,14 @@
 
                 // 添加应生成任务数量
                 TTemplateCount templateCount = new TTemplateCount();
-                templateCount.setTemplateId(detail.getId());
-                templateCount.setTaskCount(tLocationList.size()* cycle);
+                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();
             }

--
Gitblit v1.7.1