feat: There is no way the schedule

This commit is contained in:
super_liu
2021-09-30 15:25:44 +08:00
parent f96f8f4faa
commit 9ed1637677
5 changed files with 121 additions and 11 deletions
+5
View File
@@ -33,6 +33,11 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId> <artifactId>spring-boot-starter-mail</artifactId>
</dependency> </dependency>
<!-- scheduled所属资源为spring-context-support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<!-- Eureka --> <!-- Eureka -->
<dependency> <dependency>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
@@ -12,9 +12,8 @@ import com.ydw.bat.wkflow.util.Utils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.text.SimpleDateFormat;
import java.util.Map; import java.util.*;
import java.util.TreeMap;
/** /**
* <p> * <p>
@@ -43,12 +42,11 @@ public class OaTaskExecServiceImpl extends ServiceImpl<OaTaskExecMapper, OaTaskE
if(!taskExecs.isEmpty()){ if(!taskExecs.isEmpty()){
OaTaskExec oaTaskExec = taskExecs.get(0); OaTaskExec oaTaskExec = taskExecs.get(0);
BusProcessNew object = (BusProcessNew) net.sf.json.JSONObject.toBean(net.sf.json.JSONObject.fromObject(oaTaskExec.getMesg()), BusProcessNew.class); BusProcessNew object = (BusProcessNew) net.sf.json.JSONObject.toBean(net.sf.json.JSONObject.fromObject(oaTaskExec.getMesg()), BusProcessNew.class);
int days = Utils.subDayNum(oaTaskExec.getEndTime()); int days = Utils.subDayNum(oaTaskExec.getEndTime());
if(days > 3){ if(days > 3){
// 3天外处理 更改执行状态 1 进入定时任务 不发送OA待办 // 3天外处理 更改执行状态 1 进入定时任务 不发送OA待办
// ????? 待
updateOaTaskExec(taskExecs,1,2); updateOaTaskExec(taskExecs,1,2);
getSuccess(map, "0", "操作成功");
}else { }else {
if(days < 0){ if(days < 0){
// 超时处理 // 超时处理
@@ -56,12 +54,14 @@ public class OaTaskExecServiceImpl extends ServiceImpl<OaTaskExecMapper, OaTaskE
// 直接发送OA待办 重置任务状态 0 // 直接发送OA待办 重置任务状态 0
object.setTaskStatus(0); object.setTaskStatus(0);
oaService.sendTodoMq(object); oaService.sendTodoMq(object);
getSuccess(map, "0", "操作成功");
}else { }else {
// 3天内处理 // 3天内处理
updateOaTaskExec(taskExecs,0,1); updateOaTaskExec(taskExecs,0,1);
// 直接发送OA待办 重置任务状态 0 // 直接发送OA待办 重置任务状态 0
object.setTaskStatus(0); object.setTaskStatus(0);
oaService.sendTodoMq(object); oaService.sendTodoMq(object);
getSuccess(map, "0", "操作成功");
} }
} }
@@ -69,12 +69,22 @@ public class OaTaskExecServiceImpl extends ServiceImpl<OaTaskExecMapper, OaTaskE
return map; return map;
} }
private void getSuccess(Map<String, Object> map, String sign, String message) {
map.put("sign",sign);
map.put("message",message);
}
private void updateOaTaskExec(List<OaTaskExec> taskExecs, int execStatus, int execType){ private void updateOaTaskExec(List<OaTaskExec> taskExecs, int execStatus, int execType){
taskExecs.forEach(taskExec -> { List<OaTaskExec> updateList = new ArrayList<>();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
updateList.addAll(taskExecs);
updateList.forEach(taskExec -> {
// 任务修改为 启动状态 // 任务修改为 启动状态
taskExec.setExecStatus(execStatus); taskExec.setExecStatus(execStatus);
taskExec.setExecType(execType); taskExec.setExecType(execType);
taskExec.setUpdateTime(sdf.format(new Date()));
}); });
oaTaskExecService.updateBatchById(taskExecs); oaTaskExecService.updateBatchById(updateList);
} }
} }
@@ -64,7 +64,7 @@ public class SendMQService {
try{ try{
Thread.sleep(5000); Thread.sleep(5000);
if(object.getTaskStatus() == 2 && object.getEndTime() != null && StringUtils.isNotBlank(object.getEndTime())){ 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()); int days = Utils.subDayNum(object.getEndTime());
// 3 天 外 // 3 天 外
if(days > 3){ if(days > 3){
@@ -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<OaTaskExec> 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<HistoricTaskInstance> 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);
}
}
+10 -3
View File
@@ -47,6 +47,9 @@ spring:
username: guest username: guest
password: guest password: guest
listener: listener:
direct:
# 默认加载 发版 需改为 true
auto-startup: false
simple: simple:
concurrency: 5 concurrency: 5
max-concurrency: 10 max-concurrency: 10
@@ -59,10 +62,12 @@ spring:
enabled: true enabled: true
#最大重试9次 #最大重试9次
max-attempts: 6 max-attempts: 6
# 消费者默认加载 发版 需改为 true
auto-startup: false
# ============================================================================= # =============================================================================
# 邮箱配置-1 # 邮箱配置-1
# ============================================================================= # =============================================================================
mail: mail:
host: smtp.163.com host: smtp.163.com
protocol: smtp protocol: smtp
@@ -100,3 +105,5 @@ oa:
# 配置前端服务全路径地址 如下 /#/ # 配置前端服务全路径地址 如下 /#/
webUrl: http://62.234.136.153:8038/#/ webUrl: http://62.234.136.153:8038/#/
isNotScheduled: true