|
@@ -21,6 +21,7 @@ import org.springframework.scheduling.annotation.Async;
|
|
|
|
|
|
|
|
import javax.xml.soap.Node;
|
|
import javax.xml.soap.Node;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
|
|
+import java.time.LocalTime;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
@@ -45,6 +46,8 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
|
|
|
public static final ObjectMapper objectMapper = new ObjectMapper();
|
|
public static final ObjectMapper objectMapper = new ObjectMapper();
|
|
|
public static final RedissonClient redissonClient = SpringUtils.getBean(RedissonClient.class);
|
|
public static final RedissonClient redissonClient = SpringUtils.getBean(RedissonClient.class);
|
|
|
protected static final String NODE_EXEC_LOCK_PREFIX = "node_exec_lock_";
|
|
protected static final String NODE_EXEC_LOCK_PREFIX = "node_exec_lock_";
|
|
|
|
|
+ protected static final String CONTINUE_TIMER_EXECUTE_KEY = "CONTINUE:TIMER:EXECUTE:%s:%s:%s:";
|
|
|
|
|
+ public static final String CONTINUE_TIMER_EXECUTE_KEY_PREFIX = "CONTINUE:TIMER:EXECUTE:%s:*";
|
|
|
|
|
|
|
|
protected String nodeKey;
|
|
protected String nodeKey;
|
|
|
protected String nodeName;
|
|
protected String nodeName;
|
|
@@ -62,6 +65,13 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
|
|
|
log.info("当前流程已到达结束节点,节点执行失败:- {},- {} -,{}" , nodeName, nodeKey, context.getWorkflowInstanceId());
|
|
log.info("当前流程已到达结束节点,节点执行失败:- {},- {} -,{}" , nodeName, nodeKey, context.getWorkflowInstanceId());
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
+ // 校验节点执行是否符合时间设置
|
|
|
|
|
+ CompanyAiWorkflowExec timeAvailable = companyAiWorkflowExecMapper.selectExecWithTimeAvailableByInstanceId(context.getWorkflowInstanceId());
|
|
|
|
|
+ if (timeAvailable == null) {
|
|
|
|
|
+ updateWorkflowStatus(context.getWorkflowInstanceId(), ExecutionStatusEnum.PENDING);
|
|
|
|
|
+ log.info("当前流程不在可执行时间范围内 已被设置为等待状态,节点执行等待:- {},- {} -,{}" , nodeName, nodeKey, context.getWorkflowInstanceId());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
log.info("开始执行节点:" + nodeName + " - " + nodeKey);
|
|
log.info("开始执行节点:" + nodeName + " - " + nodeKey);
|
|
|
// 记录执行开始时间
|
|
// 记录执行开始时间
|
|
|
long startTime = System.currentTimeMillis();
|
|
long startTime = System.currentTimeMillis();
|
|
@@ -78,6 +88,7 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
|
|
|
}
|
|
}
|
|
|
// 执行前的通用处理
|
|
// 执行前的通用处理
|
|
|
preExecute(context);
|
|
preExecute(context);
|
|
|
|
|
+
|
|
|
// 执行具体的业务逻辑
|
|
// 执行具体的业务逻辑
|
|
|
result = doExecute(context);
|
|
result = doExecute(context);
|
|
|
// 记录执行时间
|
|
// 记录执行时间
|
|
@@ -101,6 +112,22 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
|
|
|
log.info("当前流程已到达结束节点,节点继续执行失败:- {},- {} -,{}" , nodeName, nodeKey, context.getWorkflowInstanceId());
|
|
log.info("当前流程已到达结束节点,节点继续执行失败:- {},- {} -,{}" , nodeName, nodeKey, context.getWorkflowInstanceId());
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
+ // 校验节点执行是否符合时间设置
|
|
|
|
|
+ CompanyAiWorkflowExec timeAvailable = companyAiWorkflowExecMapper.selectExecWithTimeAvailableByInstanceId(context.getWorkflowInstanceId());
|
|
|
|
|
+
|
|
|
|
|
+ if (timeAvailable == null) {
|
|
|
|
|
+ CompanyAiWorkflowExec exec = companyAiWorkflowExecMapper.selectByWorkflowInstanceId(context.getWorkflowInstanceId());
|
|
|
|
|
+ Integer cidGroupNo = exec.getCidGroupNo();
|
|
|
|
|
+ LocalTime runtimeRangeStart = exec.getRuntimeRangeStart();
|
|
|
|
|
+ String continueTimerExecuteKey = getContinueTimerExecuteKey(cidGroupNo, runtimeRangeStart);
|
|
|
|
|
+ context.setVariable("continue_timer_execute_nodekey", nodeKey);
|
|
|
|
|
+ context.setVariable("continue_timer_execute_nodetype", getType());
|
|
|
|
|
+ context.setVariable("continue_timer_execute_nodename", nodeName);
|
|
|
|
|
+ redisCache.setCacheObject(continueTimerExecuteKey , context, 1, TimeUnit.DAYS);
|
|
|
|
|
+ log.info("当前流程不在可执行时间范围内 continue已被阻塞等待唤醒执行,节点执行等待:- {},- {} -,{}" , nodeName, nodeKey, context.getWorkflowInstanceId());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
RLock lock = null;
|
|
RLock lock = null;
|
|
|
try {
|
|
try {
|
|
|
String lockKey = NODE_EXEC_LOCK_PREFIX + context.getWorkflowInstanceId();
|
|
String lockKey = NODE_EXEC_LOCK_PREFIX + context.getWorkflowInstanceId();
|
|
@@ -187,16 +214,17 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
|
|
|
context.setCurrentNodeKey(nodeKey);
|
|
context.setCurrentNodeKey(nodeKey);
|
|
|
CompanyWorkflowNode node = getNodeByKey(nodeKey);
|
|
CompanyWorkflowNode node = getNodeByKey(nodeKey);
|
|
|
context.setVariable("currentNode", node);
|
|
context.setVariable("currentNode", node);
|
|
|
- CompanyAiWorkflowExec companyAiWorkflowExec = companyAiWorkflowExecMapper.selectByWorkflowInstanceId(context.getWorkflowInstanceId());
|
|
|
|
|
- if (!companyAiWorkflowExec.getCurrentNodeKey().equals(nodeKey)) {
|
|
|
|
|
- CompanyAiWorkflowExec update = new CompanyAiWorkflowExec();
|
|
|
|
|
- update.setId(companyAiWorkflowExec.getId());
|
|
|
|
|
- update.setCurrentNodeKey(nodeKey);
|
|
|
|
|
- update.setCurrentNodeName(nodeName);
|
|
|
|
|
- update.setCurrentNodeType(NodeTypeEnum.fromCode(node.getNodeType()).getValue());
|
|
|
|
|
- update.setLastUpdateTime(LocalDateTime.now());
|
|
|
|
|
- companyAiWorkflowExecMapper.updateCompanyAiWorkflowExec(update);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ updateWorkflowStatus(context.getWorkflowInstanceId(), ExecutionStatusEnum.RUNNING);
|
|
|
|
|
+// CompanyAiWorkflowExec companyAiWorkflowExec = companyAiWorkflowExecMapper.selectByWorkflowInstanceId(context.getWorkflowInstanceId());
|
|
|
|
|
+// if (!companyAiWorkflowExec.getCurrentNodeKey().equals(nodeKey)) {
|
|
|
|
|
+// CompanyAiWorkflowExec update = new CompanyAiWorkflowExec();
|
|
|
|
|
+// update.setId(companyAiWorkflowExec.getId());
|
|
|
|
|
+// update.setCurrentNodeKey(nodeKey);
|
|
|
|
|
+// update.setCurrentNodeName(nodeName);
|
|
|
|
|
+// update.setCurrentNodeType(NodeTypeEnum.fromCode(node.getNodeType()).getValue());
|
|
|
|
|
+// update.setLastUpdateTime(LocalDateTime.now());
|
|
|
|
|
+// companyAiWorkflowExecMapper.updateCompanyAiWorkflowExec(update);
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -452,4 +480,7 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
|
|
|
return !exec.getCurrentNodeKey().equals(exec.getEndNodeKey());
|
|
return !exec.getCurrentNodeKey().equals(exec.getEndNodeKey());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public static String getContinueTimerExecuteKey(Integer groupNo, LocalTime time) {
|
|
|
|
|
+ return String.format(CONTINUE_TIMER_EXECUTE_KEY, groupNo,time.getHour(), time.getMinute());
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|