|
@@ -14,8 +14,10 @@ import com.management.platform.entity.dto.TaskDto;
|
|
import com.management.platform.entity.vo.SysRichFunction;
|
|
import com.management.platform.entity.vo.SysRichFunction;
|
|
import com.management.platform.mapper.*;
|
|
import com.management.platform.mapper.*;
|
|
import com.management.platform.service.*;
|
|
import com.management.platform.service.*;
|
|
|
|
+import com.management.platform.util.DateTimeUtil;
|
|
import com.management.platform.util.HttpRespMsg;
|
|
import com.management.platform.util.HttpRespMsg;
|
|
import com.management.platform.util.MessageUtils;
|
|
import com.management.platform.util.MessageUtils;
|
|
|
|
+import com.management.platform.util.WorkDayCalculateUtils;
|
|
import com.taobao.api.internal.mapping.ApiField;
|
|
import com.taobao.api.internal.mapping.ApiField;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.poi.ss.formula.functions.T;
|
|
import org.apache.poi.ss.formula.functions.T;
|
|
@@ -36,6 +38,7 @@ import java.time.Duration;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
+import java.time.temporal.ChronoUnit;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -55,6 +58,10 @@ public class TaskController {
|
|
private HttpServletRequest request;
|
|
private HttpServletRequest request;
|
|
@Resource
|
|
@Resource
|
|
private TaskService taskService;
|
|
private TaskService taskService;
|
|
|
|
+ @Resource
|
|
|
|
+ private InformationService informationService;
|
|
|
|
+ @Resource
|
|
|
|
+ private TaskInformationService taskInformationService;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -134,5 +141,131 @@ public class TaskController {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 消息提醒
|
|
|
|
+ */
|
|
|
|
+// @Scheduled(cron = "0 8 * * * ?")
|
|
|
|
+ public void InfoMationAlerts(){
|
|
|
|
+ log.info("定时执行了===========>");
|
|
|
|
+ QueryWrapper<Task> taskQueryWrapper = new QueryWrapper<>();
|
|
|
|
+ //应该不用考虑任务的状态
|
|
|
|
+ taskQueryWrapper.eq("is_delete",0).eq("is_repeat",1);
|
|
|
|
+ List<Task> list = taskService.list(taskQueryWrapper);
|
|
|
|
+ if (!list.isEmpty()){
|
|
|
|
+ for (Task task : list) {
|
|
|
|
+ List<String> executorIdList=new ArrayList<>();
|
|
|
|
+ String executorId = task.getExecutorId();
|
|
|
|
+ if (!StringUtils.isEmpty(executorId)){
|
|
|
|
+ String[] split = executorId.split(",");
|
|
|
|
+ executorIdList = Arrays.asList(split);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// 重复类型 :每天:0、每周:1、每月:2、自定义周期:3、自定义日期:4
|
|
|
|
+ if (task.getRepeatType()!=null&&task.getRepeatType()==0){
|
|
|
|
+ //获取任务重复结束 重复永不结束 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());
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+ int between = (int) ChronoUnit.DAYS.between(LocalDateTime.now(), task.getRepeatEndDate());
|
|
|
|
+ between=between/7;
|
|
|
|
+ saveInformationListWithCount(task, taskInformation, between, executorIdList);
|
|
|
|
+ }
|
|
|
|
+ }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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|