|
@@ -17,6 +17,7 @@ import com.fs.enums.NodeTypeEnum;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.redisson.api.RLock;
|
|
import org.redisson.api.RLock;
|
|
|
import org.redisson.api.RedissonClient;
|
|
import org.redisson.api.RedissonClient;
|
|
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
@@ -37,6 +38,7 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
|
|
|
public static final CompanyWorkflowEdgeMapper companyWorkflowEdgeMapper = SpringUtils.getBean(CompanyWorkflowEdgeMapper.class);
|
|
public static final CompanyWorkflowEdgeMapper companyWorkflowEdgeMapper = SpringUtils.getBean(CompanyWorkflowEdgeMapper.class);
|
|
|
public static final CompanyVoiceRoboticBusinessMapper companyVoiceRoboticBusinessMapper = SpringUtils.getBean(CompanyVoiceRoboticBusinessMapper.class);
|
|
public static final CompanyVoiceRoboticBusinessMapper companyVoiceRoboticBusinessMapper = SpringUtils.getBean(CompanyVoiceRoboticBusinessMapper.class);
|
|
|
public static final CompanyVoiceRoboticCallLogCallphoneMapper companyVoiceRoboticCallLogCallphoneMapper = SpringUtils.getBean(CompanyVoiceRoboticCallLogCallphoneMapper.class);
|
|
public static final CompanyVoiceRoboticCallLogCallphoneMapper companyVoiceRoboticCallLogCallphoneMapper = SpringUtils.getBean(CompanyVoiceRoboticCallLogCallphoneMapper.class);
|
|
|
|
|
+ public static final CompanyVoiceRoboticMapper companyVoiceRoboticMapper = SpringUtils.getBean(CompanyVoiceRoboticMapper.class);
|
|
|
public static final RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
|
|
public static final RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
|
|
|
public static final WorkflowNodeFactory workflowNodeFactory = SpringUtils.getBean(WorkflowNodeFactory.class);
|
|
public static final WorkflowNodeFactory workflowNodeFactory = SpringUtils.getBean(WorkflowNodeFactory.class);
|
|
|
public static final ObjectMapper objectMapper = new ObjectMapper();
|
|
public static final ObjectMapper objectMapper = new ObjectMapper();
|
|
@@ -105,7 +107,7 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
|
|
|
}
|
|
}
|
|
|
log.info("收到继续执行请求 - workflowInstanceId: {}, nodeKey: {}, 当前状态: {}",
|
|
log.info("收到继续执行请求 - workflowInstanceId: {}, nodeKey: {}, 当前状态: {}",
|
|
|
context.getWorkflowInstanceId(), nodeKey, companyAiWorkflowExec.getStatus());
|
|
context.getWorkflowInstanceId(), nodeKey, companyAiWorkflowExec.getStatus());
|
|
|
- CompanyWorkflowNode node = companyWorkflowNodeMapper.selectNodeByNodeKey(nodeKey);
|
|
|
|
|
|
|
+ CompanyWorkflowNode node = getNodeByKey(nodeKey);
|
|
|
context.setVariable("currentNode", node);
|
|
context.setVariable("currentNode", node);
|
|
|
// 允许 PAUSED 或 WAITING 状态继续执行
|
|
// 允许 PAUSED 或 WAITING 状态继续执行
|
|
|
if (!Integer.valueOf(ExecutionStatusEnum.PAUSED.getValue()).equals(companyAiWorkflowExec.getStatus())
|
|
if (!Integer.valueOf(ExecutionStatusEnum.PAUSED.getValue()).equals(companyAiWorkflowExec.getStatus())
|
|
@@ -151,15 +153,15 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
|
|
|
context.setVariable("lastNodeKey", nodeKey);
|
|
context.setVariable("lastNodeKey", nodeKey);
|
|
|
log.info("Starting execution of node: {} ({})", nodeKey, nodeName);
|
|
log.info("Starting execution of node: {} ({})", nodeKey, nodeName);
|
|
|
context.setCurrentNodeKey(nodeKey);
|
|
context.setCurrentNodeKey(nodeKey);
|
|
|
- CompanyWorkflowNode node = companyWorkflowNodeMapper.selectNodeByNodeKey(nodeKey);
|
|
|
|
|
|
|
+ CompanyWorkflowNode node = getNodeByKey(nodeKey);
|
|
|
context.setVariable("currentNode", node);
|
|
context.setVariable("currentNode", node);
|
|
|
CompanyAiWorkflowExec companyAiWorkflowExec = companyAiWorkflowExecMapper.selectByWorkflowInstanceId(context.getWorkflowInstanceId());
|
|
CompanyAiWorkflowExec companyAiWorkflowExec = companyAiWorkflowExecMapper.selectByWorkflowInstanceId(context.getWorkflowInstanceId());
|
|
|
if (!companyAiWorkflowExec.getCurrentNodeKey().equals(nodeKey)) {
|
|
if (!companyAiWorkflowExec.getCurrentNodeKey().equals(nodeKey)) {
|
|
|
- CompanyWorkflowNode cNode = companyWorkflowNodeMapper.selectNodeByNodeKey(nodeKey);
|
|
|
|
|
CompanyAiWorkflowExec update = new CompanyAiWorkflowExec();
|
|
CompanyAiWorkflowExec update = new CompanyAiWorkflowExec();
|
|
|
|
|
+ update.setId(companyAiWorkflowExec.getId());
|
|
|
update.setCurrentNodeKey(nodeKey);
|
|
update.setCurrentNodeKey(nodeKey);
|
|
|
update.setCurrentNodeName(nodeName);
|
|
update.setCurrentNodeName(nodeName);
|
|
|
- update.setCurrentNodeType(NodeTypeEnum.fromCode(cNode.getNodeType()).getValue());
|
|
|
|
|
|
|
+ update.setCurrentNodeType(NodeTypeEnum.fromCode(node.getNodeType()).getValue());
|
|
|
update.setLastUpdateTime(LocalDateTime.now());
|
|
update.setLastUpdateTime(LocalDateTime.now());
|
|
|
companyAiWorkflowExecMapper.updateCompanyAiWorkflowExec(update);
|
|
companyAiWorkflowExecMapper.updateCompanyAiWorkflowExec(update);
|
|
|
}
|
|
}
|
|
@@ -173,17 +175,18 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
|
|
|
long endTime = System.currentTimeMillis();
|
|
long endTime = System.currentTimeMillis();
|
|
|
context.setVariable("node_end_time_" + nodeKey, endTime);
|
|
context.setVariable("node_end_time_" + nodeKey, endTime);
|
|
|
log.info("Completed execution of node: {} ({})", nodeKey, nodeName);
|
|
log.info("Completed execution of node: {} ({})", nodeKey, nodeName);
|
|
|
- //todo 写入执行日志等后置操作
|
|
|
|
|
- int logStatus;
|
|
|
|
|
- if (ExecutionStatusEnum.SUCCESS.equals(result.getStatus())) {
|
|
|
|
|
- logStatus = ExecutionStatusEnum.SUCCESS.getValue();
|
|
|
|
|
- updateWorkflowStatus(context.getWorkflowInstanceId(), ExecutionStatusEnum.SUCCESS);
|
|
|
|
|
- } else if (ExecutionStatusEnum.FAILURE.equals(result.getStatus())) {
|
|
|
|
|
- logStatus = ExecutionStatusEnum.FAILURE.getValue();
|
|
|
|
|
- updateWorkflowStatus(context.getWorkflowInstanceId(), ExecutionStatusEnum.FAILURE);
|
|
|
|
|
- } else {
|
|
|
|
|
- logStatus = result.getStatus().getValue();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ //不在这里控制流程状态容易出问题bug,各节点自行管理状态
|
|
|
|
|
+// int logStatus;
|
|
|
|
|
+// if (ExecutionStatusEnum.SUCCESS.equals(result.getStatus())) {
|
|
|
|
|
+// logStatus = ExecutionStatusEnum.SUCCESS.getValue();
|
|
|
|
|
+// updateWorkflowStatus(context.getWorkflowInstanceId(), ExecutionStatusEnum.SUCCESS);
|
|
|
|
|
+// } else if (ExecutionStatusEnum.FAILURE.equals(result.getStatus())) {
|
|
|
|
|
+// logStatus = ExecutionStatusEnum.FAILURE.getValue();
|
|
|
|
|
+// updateWorkflowStatus(context.getWorkflowInstanceId(), ExecutionStatusEnum.FAILURE);
|
|
|
|
|
+// } else {
|
|
|
|
|
+//
|
|
|
|
|
+// }
|
|
|
|
|
+ int logStatus = result.getStatus().getValue();
|
|
|
CompanyAiWorkflowExecLog logEntry = createLogEntry(context.getWorkflowInstanceId(), nodeKey, getType(), result, context);
|
|
CompanyAiWorkflowExecLog logEntry = createLogEntry(context.getWorkflowInstanceId(), nodeKey, getType(), result, context);
|
|
|
logEntry.setStatus(logStatus);
|
|
logEntry.setStatus(logStatus);
|
|
|
logExecution(logEntry);
|
|
logExecution(logEntry);
|
|
@@ -347,6 +350,9 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
|
|
|
public void updateWorkflowStatus(String workflowInstanceId, ExecutionStatusEnum status) {
|
|
public void updateWorkflowStatus(String workflowInstanceId, ExecutionStatusEnum status) {
|
|
|
CompanyAiWorkflowExec update = new CompanyAiWorkflowExec();
|
|
CompanyAiWorkflowExec update = new CompanyAiWorkflowExec();
|
|
|
update.setWorkflowInstanceId(workflowInstanceId);
|
|
update.setWorkflowInstanceId(workflowInstanceId);
|
|
|
|
|
+ update.setCurrentNodeName(nodeName);
|
|
|
|
|
+ update.setCurrentNodeType(getType().getValue());
|
|
|
|
|
+ update.setCurrentNodeKey(nodeKey);
|
|
|
update.setStatus(status.getValue());
|
|
update.setStatus(status.getValue());
|
|
|
update.setLastUpdateTime(LocalDateTime.now());
|
|
update.setLastUpdateTime(LocalDateTime.now());
|
|
|
companyAiWorkflowExecMapper.updateByWorkflowInstanceId(update);
|
|
companyAiWorkflowExecMapper.updateByWorkflowInstanceId(update);
|
|
@@ -373,7 +379,7 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
|
|
|
update.setWorkflowInstanceId(context.getWorkflowInstanceId());
|
|
update.setWorkflowInstanceId(context.getWorkflowInstanceId());
|
|
|
update.setCurrentNodeKey(context.getCurrentNodeKey());
|
|
update.setCurrentNodeKey(context.getCurrentNodeKey());
|
|
|
if (null != context.getVariables() && null != context.getVariable("nodeName", String.class)) {
|
|
if (null != context.getVariables() && null != context.getVariable("nodeName", String.class)) {
|
|
|
- update.setCurrentNodeName(context.getVariable("nodeName", String.class));
|
|
|
|
|
|
|
+ update.setCurrentNodeName(context.getVariable("nodeName0", String.class));
|
|
|
}
|
|
}
|
|
|
update.setStatus(ExecutionStatusEnum.RUNNING.getValue());
|
|
update.setStatus(ExecutionStatusEnum.RUNNING.getValue());
|
|
|
update.setLastUpdateTime(LocalDateTime.now());
|
|
update.setLastUpdateTime(LocalDateTime.now());
|
|
@@ -386,13 +392,19 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
protected void runNextNode(ExecutionContext context, CompanyWorkflowEdge edge) {
|
|
protected void runNextNode(ExecutionContext context, CompanyWorkflowEdge edge) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Thread.sleep(2000L);
|
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
if (StringUtils.isBlank(edge.getTargetNodeKey())) {
|
|
if (StringUtils.isBlank(edge.getTargetNodeKey())) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
ExecutionContext nextContext = context.clone();
|
|
ExecutionContext nextContext = context.clone();
|
|
|
- CompanyWorkflowNode nextNode = companyWorkflowNodeMapper.selectNodeByNodeKey(edge.getTargetNodeKey());
|
|
|
|
|
|
|
+ CompanyWorkflowNode nextNode = getNodeByKey(edge.getTargetNodeKey());
|
|
|
nextContext.setCurrentNodeKey(nextNode.getNodeKey());
|
|
nextContext.setCurrentNodeKey(nextNode.getNodeKey());
|
|
|
nextContext.setVariable("nodeName", nextNode.getNodeName());
|
|
nextContext.setVariable("nodeName", nextNode.getNodeName());
|
|
|
|
|
+ log.info("开始执行下一个节点:{}", nextNode.getNodeName());
|
|
|
execPointNextNode(nextContext);
|
|
execPointNextNode(nextContext);
|
|
|
IWorkflowNode node = workflowNodeFactory.createNode(nextNode.getNodeKey(), NodeTypeEnum.fromCode(nextNode.getNodeType()), nextNode.getNodeName(), null);
|
|
IWorkflowNode node = workflowNodeFactory.createNode(nextNode.getNodeKey(), NodeTypeEnum.fromCode(nextNode.getNodeType()), nextNode.getNodeName(), null);
|
|
|
node.execute(nextContext);
|
|
node.execute(nextContext);
|