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

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/task/TaskUtil.java |   66 ++++++++++++++++++++++++++++++++
 1 files changed, 65 insertions(+), 1 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 ed09dd1..34324ab 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
@@ -10,6 +10,8 @@
 import com.ruoyi.system.mapper.TCleanerMapper;
 import com.ruoyi.system.model.*;
 import com.ruoyi.system.service.*;
+import com.ruoyi.web.controller.tool.EmailUtils;
+import com.ruoyi.web.controller.tool.MsgUtils;
 import javafx.concurrent.Task;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.poi.ss.formula.functions.T;
@@ -17,7 +19,9 @@
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
+import org.springframework.util.StringUtils;
 
+import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
@@ -64,6 +68,8 @@
     private TEarlyWarningService earlyWarningService;
     @Autowired
     private TLeaveService leaveService;
+    @Resource
+    private TNoticeService noticeService;
 
 
     // 每一个小时执行一次
@@ -86,7 +92,12 @@
             e.printStackTrace();
         }
     }
-
+    @Resource
+    private TNoticeSetService noticeSetService;
+    @Resource
+    private MsgUtils msgUtils;
+    @Resource
+    private TDictDataService dictDataService;
     @Scheduled(cron = "0 0 20 * * ?")
     public void dayOfEarlyWarning() {
         try {
@@ -94,16 +105,61 @@
             List<TTask> taskCleanList = taskCleanService.list(Wrappers.lambdaQuery(TTask.class)
                     .like(TTask::getImplementTime, LocalDate.now())
                     .eq(TTask::getStatus, 1));
+            List<String> userIds = taskCleanList.stream().map(TTask::getPatrolInspector).distinct().collect(Collectors.toList());
+            List<SysUser> sysUsers = sysUserService.selectAllList();
+            TNoticeSet noticeSet = noticeSetService.lambdaQuery().eq(TNoticeSet::getType, 2).last("limit 1")
+                    .one();
+            // 邮箱
+            TDictData email = dictDataService.lambdaQuery().eq(TDictData::getDataType,4).one();
+            // 授权码
+            TDictData code = dictDataService.lambdaQuery().eq(TDictData::getDataType,5).one();
             if (!CollectionUtils.isEmpty(taskCleanList)) {
                 List<TEarlyWarning> earlyWarningList = new ArrayList<>();
+                List<TNotice> noticeList = new ArrayList<>();
+                List<TNotice> addNotice = new ArrayList<>();
                 taskCleanList.forEach(task -> {
                     task.setStatus(2);
                     TEarlyWarning earlyWarning = new TEarlyWarning();
                     earlyWarning.setWarningType(1);
                     earlyWarning.setTaskId(task.getId());
                     earlyWarningList.add(earlyWarning);
+                    TNotice tNotice = new TNotice();
+                    tNotice.setUserId(task.getPatrolInspector());
+                    tNotice.setStatus(1);
+                    tNotice.setDataId(task.getId());
+                    tNotice.setNoticeType(3);
+                    tNotice.setNoticeSetType(noticeSet.getNoticeType());
+                    noticeList.add(tNotice);
                 });
                 earlyWarningService.saveBatch(earlyWarningList);
+
+                for (String userId : userIds) {
+                    SysUser sysUser = sysUsers.stream().filter(e -> e.getUserId().equals(Long.valueOf(userId))).findFirst().orElse(null);
+                    long count = taskCleanList.stream().filter(e -> e.getPatrolInspector().equals(userId)).count();
+                    TNotice tNotice = new TNotice();
+                    tNotice.setUserId(userId);
+                    tNotice.setStatus(1);
+                    tNotice.setNoticeType(3);
+                    tNotice.setNoticeContent("今日剩余"+count+"个任务未完成,请尽快处理");
+                    tNotice.setNoticeSetType(noticeSet.getNoticeType());
+                    addNotice.add(tNotice);
+
+                    if (sysUser!=null){
+                        switch (noticeSet.getNoticeType()) {
+                            case 1:
+                                msgUtils.sendMsg2(sysUser.getPhonenumber(),count+"");
+                                break;
+                            case 2:
+                                if (StringUtils.hasLength(email.getDataContent())&&StringUtils.hasLength(code.getDataContent())){
+                                    EmailUtils.sendEmail(sysUser.getEmail(),email.getDataContent(),code.getDataContent(),"今日剩余"+count+"个任务未完成,请尽快处理");
+                                }
+                                break;
+                            case 3:
+                                break;
+                        }
+                    }
+                }
+                noticeService.saveBatch(addNotice);
                 taskCleanService.updateBatchById(taskCleanList);
             }
         } catch (Exception e) {
@@ -111,6 +167,14 @@
         }
     }
 
+    /**
+     * 生成点位预警
+     */
+    // 每分钟执行一次
+    public void earning() {
+
+    }
+
     public void createInspection(TTemplate template) {
         // 查询所有的模板详情
         List<TTemplateDetail> list = templateDetailService.list(Wrappers.lambdaQuery(TTemplateDetail.class)

--
Gitblit v1.7.1