feat: There is no way the schedule
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user