From 02bb94e413f6950b9786c5ee86c0937bc20f8ae8 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期六, 12 七月 2025 14:42:20 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/task/TaskUtil.java |  502 ++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 313 insertions(+), 189 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 adf3fd3..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,9 +19,12 @@
 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;
 import java.time.LocalDateTime;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -59,11 +64,17 @@
     private TTaskCleanService taskCleanService;
     @Autowired
     private TTemplateCountService templateCountService;
+    @Autowired
+    private TEarlyWarningService earlyWarningService;
+    @Autowired
+    private TLeaveService leaveService;
+    @Resource
+    private TNoticeService noticeService;
 
 
     // 每一个小时执行一次
 //    @Scheduled(cron = "0 0 0 * * ?")
-    @Scheduled(fixedRate = 1500000000)
+//    @Scheduled(fixedRate = 1500000000)
     public void dayOfCreateInspection() {
         try {
 
@@ -80,6 +91,88 @@
         } catch (Exception e) {
             e.printStackTrace();
         }
+    }
+    @Resource
+    private TNoticeSetService noticeSetService;
+    @Resource
+    private MsgUtils msgUtils;
+    @Resource
+    private TDictDataService dictDataService;
+    @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));
+            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) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 生成点位预警
+     */
+    // 每分钟执行一次
+    public void earning() {
+
     }
 
     public void createInspection(TTemplate template) {
@@ -124,205 +217,236 @@
                 continue;
             }
 
+            int taskCount = 0;
+            for (SysUser sysUser : sysUsers) {
 
+                if("1".equals(sysUser.getStatus())){
+                    continue;
+                }
 
-            SysUser sysUser = sysUsers.get(0);
-            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()));
+                List<TProjectDept> projectDeptLists = new ArrayList<>();
+                if(sysUser.getDeptType() == 1){
+                    TProjectDept projectDept = projectDeptService.getById(sysUser.getDeptId());
+                    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.add(projectDept);
+                    projectDeptLists = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
+                            .ne(TProjectDept::getParentId,0)
+                            .eq(TProjectDept::getStatus, 1));
                 }
-            }else {
-                projectDeptLists = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
-                        .ne(TProjectDept::getParentId,0));
-            }
-            List<String> proDeptIds = projectDeptLists.stream().map(TProjectDept::getId).collect(Collectors.toList());
+                if(CollectionUtils.isEmpty(projectDeptLists)){
+                    continue;
+                }
+                List<String> proDeptIds = projectDeptLists.stream().map(TProjectDept::getId).collect(Collectors.toList());
 
-            // 获取项目部在该模板详情中的权重
-            List<String> projectDeptIds = redisCache.getCacheList(detail.getId() + PROJECT_DEPT_WEIGHT);
-            // 获取项目部列表
-            List<TProjectDept> projectDeptList;
-            if(CollectionUtils.isEmpty(projectDeptIds)){
-                projectDeptList = projectDeptLists;
-            }else {
-                projectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
-                        .ne(TProjectDept::getParentId,0)
-                        .in(TProjectDept::getId, proDeptIds)
-                        .notIn(TProjectDept::getId, projectDeptIds));
-                // 所过所有的项目部都被抽取了,则重新抽取,并且清空项目部权重
-                if(CollectionUtils.isEmpty(projectDeptList)){
+                // 获取项目部在该模板详情中的权重
+                List<String> projectDeptIds = redisCache.getCacheList(detail.getId() + PROJECT_DEPT_WEIGHT);
+                // 获取项目部列表
+                List<TProjectDept> projectDeptList;
+                if(CollectionUtils.isEmpty(projectDeptIds)){
                     projectDeptList = projectDeptLists;
-                    redisCache.deleteObject(detail.getId() + PROJECT_DEPT_WEIGHT);
-                }
-            }
-            // 如果可抽取的项目部数不足,先抽取余下项目部后,再清空权重,重新抽取
-            List<TProjectDept> projectDepts = randomSelection(projectDeptList, num2);
-            if(projectDepts.size() < num2){
-                List<String> proIds = projectDepts.stream().map(TProjectDept::getId).collect(Collectors.toList());
-                List<TProjectDept> projectDeptList1 = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
-                        .notIn(TProjectDept::getId, proIds)
-                        .ne(TProjectDept::getParentId,0));
-                redisCache.deleteObject(detail.getId() + PROJECT_DEPT_WEIGHT);
-                List<TProjectDept> projectDepts1 = randomSelection(projectDeptList1, num2 - projectDepts.size());
-                List<String> proIds1 = projectDepts1.stream().map(TProjectDept::getId).collect(Collectors.toList());
-                // 将已抽取的项目部id保存到redis中
-                redisCache.setCacheList(detail.getId() + PROJECT_DEPT_WEIGHT, proIds1);
-                projectDepts.addAll(projectDepts1);
-            }else {
-                List<String> proIds = projectDepts.stream().map(TProjectDept::getId).collect(Collectors.toList());
-                // 将已抽取的项目部id保存到redis中
-                redisCache.setCacheList(detail.getId() + PROJECT_DEPT_WEIGHT, proIds);
-            }
-            List<String> proIds = projectDepts.stream().map(TProjectDept::getId).collect(Collectors.toList());
-
-            // 拿到抽取的项目部下的所有保洁员
-//            List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
-//                    .in(TProjectDept::getId, proIds));
-            // 获取片区id
-            List<String> areaIds = projectDepts.stream().map(TProjectDept::getId).collect(Collectors.toList());
-            if(CollectionUtils.isEmpty(areaIds)){
-                return;
-            }
-
-            // 计算每天需要抽取多少个保洁员
-            long count = cleanerService.count(Wrappers.lambdaQuery(TCleaner.class)
-                    .in(TCleaner::getProjectId, areaIds));
-            int cleanerSums = num1 * Integer.parseInt(count + "");
-            // 获取每天需要抽取的保洁员数,向上取整
-            if (cleanerSums < cycle){
-                cleanerSums = cycle;
-            }
-            int dayCleanerCount = cleanerSums / cycle;
-
-            if((cycle == detail.getCurrentValue()) && cleanerSums % cycle != 0){
-                dayCleanerCount++;
-            }
-
-            // 获取保洁员权重
-            List<String> cleanerIds = redisCache.getCacheList(detail.getId() + CLEANER_WEIGHT);
-            // 获取保洁员列表
-            List<TCleaner> cleaners;
-            if(CollectionUtils.isEmpty(cleanerIds)){
-                cleaners = cleanerService.list(Wrappers.lambdaQuery(TCleaner.class)
-                        .in(TCleaner::getProjectId, areaIds));
-            }else {
-                cleaners = cleanerService.list(Wrappers.lambdaQuery(TCleaner.class)
-                        .in(TCleaner::getProjectId, areaIds)
-                        .notIn(TCleaner::getId, cleanerIds));
-                if(CollectionUtils.isEmpty(cleaners)){
-                    cleaners = cleanerService.list(Wrappers.lambdaQuery(TCleaner.class)
-                            .in(TCleaner::getProjectId, areaIds));
-                    redisCache.deleteObject(detail.getId() + CLEANER_WEIGHT);
-                }
-            }
-
-            // 抽取保洁员
-            List<TCleaner> tCleaners = randomSelection(cleaners, dayCleanerCount);
-            if(CollectionUtils.isEmpty(tCleaners)){
-                log.error("没有可抽取的保洁员");
-                continue;
-            }
-            if(tCleaners.size() < dayCleanerCount){
-                List<String> cleanIds = tCleaners.stream().map(TCleaner::getId).collect(Collectors.toList());
-                List<TCleaner> cleaners1 = cleanerService.list(Wrappers.lambdaQuery(TCleaner.class)
-                        .in(TCleaner::getProjectId, areaIds)
-                        .notIn(TCleaner::getId, cleanIds));
-                redisCache.deleteObject(detail.getId() + CLEANER_WEIGHT);
-                List<TCleaner> tCleaners1 = randomSelection(cleaners1, dayCleanerCount - tCleaners.size());
-                List<String> cleanIds1 = tCleaners1.stream().map(TCleaner::getId).collect(Collectors.toList());
-                // 将已抽取的保洁员id保存到redis中
-                cleanIds1.addAll(cleanIds);
-                redisCache.setCacheList(detail.getId() + CLEANER_WEIGHT, cleanIds1);
-                tCleaners.addAll(tCleaners1);
-            }else {
-                List<String> cleanIds = tCleaners.stream().map(TCleaner::getId).collect(Collectors.toList());
-                redisCache.setCacheList(detail.getId() + CLEANER_WEIGHT, cleanIds);
-            }
-
-            // 通过保洁员id查询点位
-            List<String> cleanersIds = tCleaners.stream().map(TCleaner::getId).collect(Collectors.toList());
-            List<TLocation> locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class)
-                    .in(TLocation::getLocationCleaner, cleanersIds));
-            // 查询点位类型
-            JSONArray jsonArray = JSONObject.parseArray(num4);
-            List<TLocation> tLocationList = new ArrayList<>();
-            for (Object o : jsonArray) {
-                JSONObject jsonObject = JSONObject.parseObject(o.toString());
-                String id = jsonObject.getString("id");
-                BigDecimal value = jsonObject.getBigDecimal("value");
-                List<TLocation> locations = locationList.stream().filter(tLocation -> tLocation.getLocationType().equals(id)).collect(Collectors.toList());
-                if(!CollectionUtils.isEmpty(locations)){
-                    BigDecimal bigDecimal = new BigDecimal(locations.size()).multiply(value.divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN)).setScale(0, BigDecimal.ROUND_UP);
-                    int locationCount = bigDecimal.intValue();
-                    if(locationCount > 0){
-                        List<TLocation> tLocations = randomSelection(locations, locationCount);
-                        tLocationList.addAll(tLocations);
+                }else {
+                    projectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
+                            .ne(TProjectDept::getParentId,0)
+                            .in(TProjectDept::getId, proDeptIds)
+                            .notIn(TProjectDept::getId, projectDeptIds));
+                    // 所过所有的项目部都被抽取了,则重新抽取,并且清空项目部权重
+                    if(CollectionUtils.isEmpty(projectDeptList)){
+                        projectDeptList = projectDeptLists;
+                        redisCache.deleteObject(detail.getId() + PROJECT_DEPT_WEIGHT);
                     }
                 }
-            }
-
-            // 抽取重复点位
-            Integer currentValue = detail.getCurrentValue();
-            if(currentValue != cycle){
-                // 周期天数加一
-                detail.setCurrentValue(currentValue + 1);
-                // 获取重复点位
-                Set<TLocation> repeatLocation = redisCache.getCacheSet(detail.getId() + REPEAT_LOCATION);
-                if(!CollectionUtils.isEmpty(repeatLocation)){
-                    List<TLocation> locations = randomSelection(new ArrayList<>(tLocationList), num3);
-                    tLocationList.addAll(locations);
+                // 如果可抽取的项目部数不足,先抽取余下项目部后,再清空权重,重新抽取
+                List<TProjectDept> projectDepts = randomSelection(projectDeptList, num2);
+                if(projectDepts.size() < num2){
+                    List<String> proIds = projectDepts.stream().map(TProjectDept::getId).collect(Collectors.toList());
+                    List<TProjectDept> projectDeptList1 = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
+                            .notIn(TProjectDept::getId, proIds)
+                            .ne(TProjectDept::getParentId,0));
+                    redisCache.deleteObject(detail.getId() + PROJECT_DEPT_WEIGHT);
+                    List<TProjectDept> projectDepts1 = randomSelection(projectDeptList1, num2 - projectDepts.size());
+                    List<String> proIds1 = projectDepts1.stream().map(TProjectDept::getId).collect(Collectors.toList());
+                    // 将已抽取的项目部id保存到redis中
+                    redisCache.setCacheList(detail.getId() + PROJECT_DEPT_WEIGHT, proIds1);
+                    projectDepts.addAll(projectDepts1);
+                }else {
+                    List<String> proIds = projectDepts.stream().map(TProjectDept::getId).collect(Collectors.toList());
+                    // 将已抽取的项目部id保存到redis中
+                    redisCache.setCacheList(detail.getId() + PROJECT_DEPT_WEIGHT, proIds);
                 }
-                Set<TLocation> locationSet = new HashSet<>(tLocationList);
-                redisCache.setCacheSet(detail.getId() + REPEAT_LOCATION, locationSet);
+                List<String> proIds = projectDepts.stream().map(TProjectDept::getId).collect(Collectors.toList());
 
-            }else {
-                // 设置当前周期为0
-                detail.setCurrentValue(0);
-                // 将重复点位置空
-                redisCache.deleteObject(detail.getId() + REPEAT_LOCATION);
-                // 将项目部权重置空
-                redisCache.deleteObject(detail.getId() + PROJECT_DEPT_WEIGHT);
-                // 将保洁员权重置空
-                redisCache.deleteObject(detail.getId() + CLEANER_WEIGHT);
+                // 拿到抽取的项目部下的所有保洁员
+//            List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class)
+//                    .in(TProjectDept::getId, proIds));
+                // 获取片区id
+                List<String> areaIds = projectDepts.stream().map(TProjectDept::getId).collect(Collectors.toList());
+                if(CollectionUtils.isEmpty(areaIds)){
+                    return;
+                }
+
+                // 计算每天需要抽取多少个保洁员
+                long count = cleanerService.count(Wrappers.lambdaQuery(TCleaner.class)
+                        .in(TCleaner::getProjectId, areaIds));
+                int cleanerSums = num1 * Integer.parseInt(count + "");
+                // 获取每天需要抽取的保洁员数,向上取整
+                if (cleanerSums < cycle){
+                    cleanerSums = cycle;
+                }
+                int dayCleanerCount = cleanerSums / cycle;
+
+                if((cycle == detail.getCurrentValue()) && cleanerSums % cycle != 0){
+                    dayCleanerCount++;
+                }
+
+                // 获取保洁员权重
+                List<String> cleanerIds = redisCache.getCacheList(detail.getId() + CLEANER_WEIGHT);
+                // 获取保洁员列表
+                List<TCleaner> cleaners;
+                if(CollectionUtils.isEmpty(cleanerIds)){
+                    cleaners = cleanerService.list(Wrappers.lambdaQuery(TCleaner.class)
+                            .in(TCleaner::getProjectId, areaIds));
+                }else {
+                    cleaners = cleanerService.list(Wrappers.lambdaQuery(TCleaner.class)
+                            .in(TCleaner::getProjectId, areaIds)
+                            .notIn(TCleaner::getId, cleanerIds));
+                    if(CollectionUtils.isEmpty(cleaners)){
+                        cleaners = cleanerService.list(Wrappers.lambdaQuery(TCleaner.class)
+                                .in(TCleaner::getProjectId, areaIds));
+                        redisCache.deleteObject(detail.getId() + CLEANER_WEIGHT);
+                    }
+                }
+
+                // 抽取保洁员
+                List<TCleaner> tCleaners = randomSelection(cleaners, dayCleanerCount);
+                if(CollectionUtils.isEmpty(tCleaners)){
+                    log.error("没有可抽取的保洁员,模板id为:{}",detail.getId());
+                    continue;
+                }
+                if(tCleaners.size() < dayCleanerCount){
+                    List<String> cleanIds = tCleaners.stream().map(TCleaner::getId).collect(Collectors.toList());
+                    List<TCleaner> cleaners1 = cleanerService.list(Wrappers.lambdaQuery(TCleaner.class)
+                            .in(TCleaner::getProjectId, areaIds)
+                            .notIn(TCleaner::getId, cleanIds));
+                    redisCache.deleteObject(detail.getId() + CLEANER_WEIGHT);
+                    List<TCleaner> tCleaners1 = randomSelection(cleaners1, dayCleanerCount - tCleaners.size());
+                    List<String> cleanIds1 = tCleaners1.stream().map(TCleaner::getId).collect(Collectors.toList());
+                    // 将已抽取的保洁员id保存到redis中
+                    cleanIds1.addAll(cleanIds);
+                    redisCache.setCacheList(detail.getId() + CLEANER_WEIGHT, cleanIds1);
+                    tCleaners.addAll(tCleaners1);
+                }else {
+                    List<String> cleanIds = tCleaners.stream().map(TCleaner::getId).collect(Collectors.toList());
+                    redisCache.setCacheList(detail.getId() + CLEANER_WEIGHT, cleanIds);
+                }
+
+                // 通过保洁员id查询点位
+                List<String> cleanersIds = tCleaners.stream().map(TCleaner::getId).collect(Collectors.toList());
+                List<TLocation> locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class)
+                        .in(TLocation::getLocationCleaner, cleanersIds));
+                // 查询点位类型
+                JSONArray jsonArray = JSONObject.parseArray(num4);
+                List<TLocation> tLocationList = new ArrayList<>();
+                for (Object o : jsonArray) {
+                    JSONObject jsonObject = JSONObject.parseObject(o.toString());
+                    String id = jsonObject.getString("id");
+                    BigDecimal value = jsonObject.getBigDecimal("value");
+                    List<TLocation> locations = locationList.stream().filter(tLocation -> tLocation.getLocationType().equals(id)).collect(Collectors.toList());
+                    if(!CollectionUtils.isEmpty(locations)){
+                        BigDecimal bigDecimal = new BigDecimal(locations.size()).multiply(value.divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN)).setScale(0, BigDecimal.ROUND_UP);
+                        int locationCount = bigDecimal.intValue();
+                        if(locationCount > 0){
+                            List<TLocation> tLocations = randomSelection(locations, locationCount);
+                            tLocationList.addAll(tLocations);
+                        }
+                    }
+                }
+                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() + ":" + 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() + ":" + sysUser.getUserId() + REPEAT_LOCATION, locationSet);
+
+                }else {
+                    // 设置当前周期为0
+                    detail.setCurrentValue(0);
+                    // 将重复点位置空
+                    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<>();
+                for (TLocation tLocation : tLocationList) {
+                    TTask task = new TTask();
+                    // 获取保洁员
+                    tCleaners.stream().filter(tCleaner -> tCleaner.getId().equals(tLocation.getLocationCleaner())).findFirst().ifPresent(tCleaner -> {
+                        task.setProjectId(tCleaner.getProjectId());
+                        task.setCleanerId(tCleaner.getId());
+                    });
+                    // 获取巡检员
+                    task.setPatrolInspector(sysUser.getUserId().toString());
+                    task.setPatrolInspectorDept(sysUser.getDeptId());
+                    task.setUserId(sysUser.getUserId());
+                    task.setStatus(1);
+                    task.setLocationId(tLocation.getId());
+
+                    // 判断今天是否在请假时间内
+                    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();
+                    task.setTaskName(nameAndCode);
+                    task.setTaskCode(nameAndCode);
+                    tasks.add(task);
+                }
+
+                // 添加应生成任务数量
+                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();
             }
-
-            // 创建任务
-            List<TTask> tasks = new ArrayList<>();
-            for (TLocation tLocation : tLocationList) {
-                TTask task = new TTask();
-                // 获取保洁员
-                tCleaners.stream().filter(tCleaner -> tCleaner.getId().equals(tLocation.getLocationCleaner())).findFirst().ifPresent(tCleaner -> {
-                    task.setProjectId(tCleaner.getProjectId());
-                    task.setCleanerId(tCleaner.getId());
-                });
-                // 获取巡检员
-                task.setPatrolInspector(sysUser.getUserId().toString());
-                task.setPatrolInspectorDept(sysUser.getDeptId());
-                task.setUserId(sysUser.getUserId());
-                task.setStatus(1);
-                task.setLocationId(tLocation.getId());
-                task.setImplementTime(LocalDateTime.now().plusDays(1));
-                task.setTaskType(1);
-                task.setTemplateId(detail.getTemplateId());
-                String nameAndCode = CodeGenerateUtils.generateVolumeSn();
-                task.setTaskName(nameAndCode);
-                task.setTaskCode(nameAndCode);
-                tasks.add(task);
-            }
-
-            // 添加应生成任务数量
-            TTemplateCount templateCount = new TTemplateCount();
-            templateCount.setTemplateId(detail.getId());
-            templateCount.setTaskCount(tLocationList.size()* cycle);
-            templateCount.setUserId(sysUser.getUserId());
-            templateCountService.save(templateCount);
-
-            taskCleanService.saveBatch(tasks);
-            template.setTaskCount(tasks.size());
+            template.setTaskCount(taskCount);
             templateService.updateById(template);
             templateDetailService.updateById(detail);
         }

--
Gitblit v1.7.1