yusm 10 月之前
父節點
當前提交
c427cab83c

+ 96 - 17
fhKeeper/formulahousekeeper/management-crm/src/main/java/com/management/platform/controller/TaskController.java

@@ -14,8 +14,10 @@ import com.management.platform.entity.dto.TaskDto;
 import com.management.platform.entity.vo.SysRichFunction;
 import com.management.platform.mapper.*;
 import com.management.platform.service.*;
+import com.management.platform.util.DateTimeUtil;
 import com.management.platform.util.HttpRespMsg;
 import com.management.platform.util.MessageUtils;
+import com.management.platform.util.WorkDayCalculateUtils;
 import com.taobao.api.internal.mapping.ApiField;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.poi.ss.formula.functions.T;
@@ -36,6 +38,7 @@ import java.time.Duration;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -161,30 +164,106 @@ public class TaskController {
                 if (task.getRepeatType()!=null&&task.getRepeatType()==0){
                     //获取任务重复结束 重复永不结束   1:勾选
                     if (task.getRepeatEndNever()!=null&&task.getRepeatEndNever()==1){
-                        if (!executorIdList.isEmpty()){
-                            ArrayList<Information> informationArrayList = new ArrayList<>();
-                            for (String userId : executorIdList) {
-                                Information information = new Information();
-                                information.setUserId(userId).setMsg("任务提醒")
-                                        .setTime(LocalDateTime.now()).setChecked(0);
-                                informationArrayList.add(information);
+                        saveInformationList(executorIdList);
+                    }else if (task.getRepeatEndCount()!=null&&task.getRepeatEndCount()>0){
+                        TaskInformation taskInformation = selectTaskInformation(task);
+                        int between = task.getRepeatEndCount();
+                        saveInformationListWithCount(task, taskInformation, between, executorIdList);
+                    }else if (task.getRepeatEndDate()!=null){
+                        TaskInformation taskInformation = selectTaskInformation(task);
+                        if (LocalDateTime.now().isAfter(task.getRepeatEndDate())){
+                            continue;
+                        }
+                        int between = (int) ChronoUnit.DAYS.between(LocalDateTime.now(), task.getRepeatEndDate());
+                        saveInformationListWithCount(task, taskInformation, between, executorIdList);
+                    }
+                }
+                //每周
+                else if (task.getRepeatType() != null && task.getRepeatType() == 1) {
+                    //获取任务重复结束 重复永不结束   1:勾选
+                    //每周一才执行
+                    if (LocalDateTime.now().getDayOfWeek().getValue()==1){
+                        if (task.getRepeatEndNever()!=null&&task.getRepeatEndNever()==1){
+                            saveInformationList(executorIdList);
+                        }else if (task.getRepeatEndCount()!=null&&task.getRepeatEndCount()>0){
+                            TaskInformation taskInformation = selectTaskInformation(task);
+                            int between = task.getRepeatEndCount();
+                            saveInformationListWithCount(task, taskInformation, between, executorIdList);
+                        }else if (task.getRepeatEndDate()!=null){
+                            TaskInformation taskInformation = selectTaskInformation(task);
+                            if (LocalDateTime.now().isAfter(task.getRepeatEndDate())){
+                                continue;
                             }
-                            informationService.saveBatch(informationArrayList);
+                            int between = (int) ChronoUnit.DAYS.between(LocalDateTime.now(), task.getRepeatEndDate());
+                            between=between/7;
+                            saveInformationListWithCount(task, taskInformation, between, executorIdList);
                         }
-                    }else if (task.getRepeatEndCount()!=null&&task.getRepeatEndCount()>0){
-                        LambdaQueryWrapper<TaskInformation> lqw = new LambdaQueryWrapper<>();
-                        lqw.eq(TaskInformation::getTaskId,task.getId()).eq(TaskInformation::getCompanyId,task.getCompanyId());
-                        TaskInformation taskInformation = taskInformationService.getOne(lqw);
-
-                        if (taskInformation==null){
-
+                    }else {
+                        continue;
+                    }
+                }
+                //每月
+                else if (task.getRepeatType() != null && task.getRepeatType() == 2) {
+                    //获取任务重复结束 重复永不结束   1:勾选
+                    //每月一号才执行
+                    if (LocalDateTime.now().getDayOfMonth()==1){
+                        if (task.getRepeatEndNever()!=null&&task.getRepeatEndNever()==1){
+                            saveInformationList(executorIdList);
+                        }else if (task.getRepeatEndCount()!=null&&task.getRepeatEndCount()>0){
+                            TaskInformation taskInformation = selectTaskInformation(task);
+                            int between = task.getRepeatEndCount();
+                            saveInformationListWithCount(task, taskInformation, between, executorIdList);
+                        }else if (task.getRepeatEndDate()!=null){
+                            TaskInformation taskInformation = selectTaskInformation(task);
+                            if (LocalDateTime.now().isAfter(task.getRepeatEndDate())){
+                                continue;
+                            }
+                            int between = (int) ChronoUnit.DAYS.between(LocalDateTime.now(), task.getRepeatEndDate());
+                            between=between/30;
+                            saveInformationListWithCount(task, taskInformation, between, executorIdList);
                         }
-
+                    }else {
+                        continue;
                     }
+                }
+            }
+        }
+    }
+
+    private TaskInformation selectTaskInformation(Task task) {
+        LambdaQueryWrapper<TaskInformation> lqw = new LambdaQueryWrapper<>();
+        lqw.eq(TaskInformation::getTaskId, task.getId()).eq(TaskInformation::getCompanyId, task.getCompanyId());
+        return taskInformationService.getOne(lqw);
+    }
 
+    private void saveInformationListWithCount(Task task, TaskInformation taskInformation, int between, List<String> executorIdList) {
+        if (taskInformation ==null){
+            TaskInformation taskInformationNew = new TaskInformation();
+            taskInformationNew.setTaskId(task.getId())
+                    .setCompanyId(task.getCompanyId()).setCount(between -1);
+            taskInformationService.save(taskInformationNew);
+            saveInformationList(executorIdList);
+        }else {
+            Integer count = taskInformation.getCount();
+            if (count>0){
+                count -= 1;
+                UpdateWrapper<TaskInformation> updateWrapper = new UpdateWrapper<TaskInformation>().set("count", count).eq("id", taskInformation.getId());
+                taskInformationService.update(updateWrapper);
+                saveInformationList(executorIdList);
+            }
+        }
+    }
 
-                }
+    private void saveInformationList(List<String> executorIdList) {
+        if (!executorIdList.isEmpty()){
+            ArrayList<Information> informationArrayList = new ArrayList<>();
+            for (String userId : executorIdList) {
+                Information information = new Information();
+                information.setUserId(userId).setMsg("任务提醒")
+                        .setTime(LocalDateTime.now()).setChecked(0);
+                informationArrayList.add(information);
             }
+            informationService.saveBatch(informationArrayList);
         }
     }