From 9ed1637677b992449c7c1a60d1643939d68afe58 Mon Sep 17 00:00:00 2001 From: super_liu <396572590@qq.com> Date: Thu, 30 Sep 2021 15:25:44 +0800 Subject: [PATCH] feat: There is no way the schedule --- pom.xml | 5 ++ .../service/impl/OaTaskExecServiceImpl.java | 24 +++-- .../business_mq/service/SendMQService.java | 2 +- .../ydw/bat/wkflow/config/ScheduledJob.java | 88 +++++++++++++++++++ src/main/resources/application.yml | 13 ++- 5 files changed, 121 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/ydw/bat/wkflow/config/ScheduledJob.java diff --git a/pom.xml b/pom.xml index 7585a56d..57beee38 100644 --- a/pom.xml +++ b/pom.xml @@ -33,6 +33,11 @@ org.springframework.boot spring-boot-starter-mail + + + org.springframework + spring-context-support + org.springframework.cloud diff --git a/src/main/java/com/ydw/bat/wkflow/business_main/datas/service/impl/OaTaskExecServiceImpl.java b/src/main/java/com/ydw/bat/wkflow/business_main/datas/service/impl/OaTaskExecServiceImpl.java index 282bdb88..f0ffc21f 100644 --- a/src/main/java/com/ydw/bat/wkflow/business_main/datas/service/impl/OaTaskExecServiceImpl.java +++ b/src/main/java/com/ydw/bat/wkflow/business_main/datas/service/impl/OaTaskExecServiceImpl.java @@ -12,9 +12,8 @@ import com.ydw.bat.wkflow.util.Utils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; +import java.text.SimpleDateFormat; +import java.util.*; /** *

@@ -43,12 +42,11 @@ public class OaTaskExecServiceImpl extends ServiceImpl 3){ // 3天外处理 更改执行状态 1 进入定时任务 不发送OA待办 - // ????? 待 updateOaTaskExec(taskExecs,1,2); + getSuccess(map, "0", "操作成功"); }else { if(days < 0){ // 超时处理 @@ -56,12 +54,14 @@ public class OaTaskExecServiceImpl extends ServiceImpl map, String sign, String message) { + map.put("sign",sign); + map.put("message",message); + } + private void updateOaTaskExec(List taskExecs, int execStatus, int execType){ - taskExecs.forEach(taskExec -> { + List updateList = new ArrayList<>(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + + updateList.addAll(taskExecs); + updateList.forEach(taskExec -> { // 任务修改为 启动状态 taskExec.setExecStatus(execStatus); taskExec.setExecType(execType); + taskExec.setUpdateTime(sdf.format(new Date())); }); - oaTaskExecService.updateBatchById(taskExecs); + oaTaskExecService.updateBatchById(updateList); } } diff --git a/src/main/java/com/ydw/bat/wkflow/business_mq/service/SendMQService.java b/src/main/java/com/ydw/bat/wkflow/business_mq/service/SendMQService.java index 33ea749a..46eaff1b 100644 --- a/src/main/java/com/ydw/bat/wkflow/business_mq/service/SendMQService.java +++ b/src/main/java/com/ydw/bat/wkflow/business_mq/service/SendMQService.java @@ -64,7 +64,7 @@ public class SendMQService { try{ Thread.sleep(5000); if(object.getTaskStatus() == 2 && object.getEndTime() != null && StringUtils.isNotBlank(object.getEndTime())){ - SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd HH:mm:ss"); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); int days = Utils.subDayNum(object.getEndTime()); // 3 天 外 if(days > 3){ diff --git a/src/main/java/com/ydw/bat/wkflow/config/ScheduledJob.java b/src/main/java/com/ydw/bat/wkflow/config/ScheduledJob.java new file mode 100644 index 00000000..86bd1047 --- /dev/null +++ b/src/main/java/com/ydw/bat/wkflow/config/ScheduledJob.java @@ -0,0 +1,88 @@ +package com.ydw.bat.wkflow.config; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.ydw.bat.wkflow.business_main.datas.entity.BusProcessNew; +import com.ydw.bat.wkflow.business_main.datas.entity.OaTaskExec; +import com.ydw.bat.wkflow.business_main.datas.service.IOaTaskExecService; +import com.ydw.bat.wkflow.business_mq.service.CreateMQService; +import com.ydw.bat.wkflow.util.SpringContextUtil; +import com.ydw.bat.wkflow.util.Utils; +import lombok.extern.slf4j.Slf4j; +import org.activiti.engine.HistoryService; +import org.activiti.engine.history.HistoricTaskInstance; +import org.activiti.engine.history.HistoricTaskInstanceQuery; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Async; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + + +@EnableScheduling +@Component +@Slf4j +public class ScheduledJob { + + /** + * 根据配置文件设置是否开启定时器 + */ + + @Value("${isNotScheduled}") + private boolean isNotScheduled; //是否开启定时器 + + @Scheduled(cron = "0 0 0 * * ?") //每天的凌晨0点执行 +// @Scheduled(cron="*/5 * * * * ?") + @Async + public void SchedulingTask() { + if(isNotScheduled){ + HistoryService historyService = SpringContextUtil.getBean(HistoryService.class); + IOaTaskExecService execService = SpringContextUtil.getBean(IOaTaskExecService.class); + CreateMQService oaService = SpringContextUtil.getBean(CreateMQService.class); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + QueryWrapper wrapper = new QueryWrapper(); + wrapper.eq("EXEC_TYPE",2); + wrapper.eq("EXEC_STATUS",1); + wrapper.eq("EXEC_TIME",sdf.format(new Date())); + List taskExecs = execService.list(wrapper); + if(!taskExecs.isEmpty()){ + taskExecs.forEach(taskExec -> { + BusProcessNew object = (BusProcessNew) net.sf.json.JSONObject.toBean(net.sf.json.JSONObject.fromObject(taskExec.getMesg()), BusProcessNew.class); + HistoricTaskInstanceQuery historicTaskInstanceQuery = historyService.createHistoricTaskInstanceQuery() + .processInstanceId(object.getPId()).taskId(object.getTaskId()).finished(); + List list = historicTaskInstanceQuery.list(); + // 判断定时任务的流程节点是否已完成 + if(!list.isEmpty()){ + // 业务系统流程节点已完成 则不再发送 OA 待办 + updateTask(execService, sdf, taskExec); + }else { + // 业务系统流程节点未完成 再发送 OA 待办 + // 任务状态 置为 已完成 业务流程 干活流程节点 均显示 提交 + updateTask(execService, sdf, taskExec); + // 直接发送OA待办 重置任务状态 0 + object.setTaskStatus(0); + oaService.sendTodoMq(object); + } + }); + + } + + + } + } + + private void updateTask(IOaTaskExecService execService, SimpleDateFormat sdf, OaTaskExec taskExec) { + OaTaskExec exec = new OaTaskExec(); + exec.setId(taskExec.getId()); + exec.setExecStatus(2); + exec.setUpdateTime(sdf.format(new Date())); + execService.updateById(exec); + } + + +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 797e912e..da455323 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -47,6 +47,9 @@ spring: username: guest password: guest listener: + direct: + # 默认加载 发版 需改为 true + auto-startup: false simple: concurrency: 5 max-concurrency: 10 @@ -59,10 +62,12 @@ spring: enabled: true #最大重试9次 max-attempts: 6 + # 消费者默认加载 发版 需改为 true + auto-startup: false -# ============================================================================= -# 邮箱配置-1 -# ============================================================================= + # ============================================================================= + # 邮箱配置-1 + # ============================================================================= mail: host: smtp.163.com protocol: smtp @@ -100,3 +105,5 @@ oa: # 配置前端服务全路径地址 如下 /#/ webUrl: http://62.234.136.153:8038/#/ +isNotScheduled: true +