feat: There is no way the schedule
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package com.ydw.bat.wkflow.config;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.ydw.bat.wkflow.business_oa.webService.service.WebServiceOAService;
|
||||
import net.sf.json.JSONObject;
|
||||
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;
|
||||
@@ -9,8 +12,10 @@ 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.TaskService;
|
||||
import org.activiti.engine.history.HistoricTaskInstance;
|
||||
import org.activiti.engine.history.HistoricTaskInstanceQuery;
|
||||
import org.activiti.engine.task.Task;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
@@ -36,34 +41,47 @@ public class ScheduledJob {
|
||||
@Value("${isNotScheduled}")
|
||||
private boolean isNotScheduled; //是否开启定时器
|
||||
|
||||
@Scheduled(cron = "0 0 0 * * ?") //每天的凌晨0点执行
|
||||
// @Scheduled(cron="*/5 * * * * ?")
|
||||
// @Scheduled(cron = "0 0 0 * * ?") //每天的凌晨0点执行
|
||||
@Scheduled(cron="*/5 * * * * ?")
|
||||
@Async
|
||||
public void SchedulingTask() {
|
||||
if(isNotScheduled){
|
||||
TaskService taskService = SpringContextUtil.getBean(TaskService.class);
|
||||
HistoryService historyService = SpringContextUtil.getBean(HistoryService.class);
|
||||
IOaTaskExecService execService = SpringContextUtil.getBean(IOaTaskExecService.class);
|
||||
CreateMQService oaService = SpringContextUtil.getBean(CreateMQService.class);
|
||||
WebServiceOAService webServiceOAService = SpringContextUtil.getBean(WebServiceOAService.class);
|
||||
SimpleDateFormat sdfQuery = new SimpleDateFormat("yyyy-MM-dd");
|
||||
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()));
|
||||
wrapper.eq("EXEC_TIME",sdfQuery.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);
|
||||
net.sf.json.JSONObject jsonObject = JSONObject.fromObject(taskExec.getMesg());
|
||||
net.sf.json.JSONObject jsonObjectFilter = JSONObject.fromObject(taskExec.getMesg());
|
||||
jsonObjectFilter = jsonObjectFilter.discard("PId");
|
||||
jsonObjectFilter.put("pid",jsonObject.getString("PId"));
|
||||
BusProcessNew object = JSON.parseObject(jsonObjectFilter.toString(),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);
|
||||
|
||||
Task task = taskService.createTaskQuery().taskId(object.getTaskId()).singleResult();
|
||||
webServiceOAService.completeOA(task);
|
||||
|
||||
// 直接发送OA待办 重置任务状态 0
|
||||
object.setTaskStatus(0);
|
||||
oaService.sendTodoMq(object);
|
||||
|
||||
Reference in New Issue
Block a user