|
@@ -49,6 +49,7 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public ExecutionResult execute(ExecutionContext context) {
|
|
public ExecutionResult execute(ExecutionContext context) {
|
|
|
|
|
+ log.info("开始执行节点:" + nodeName + " - " + nodeKey);
|
|
|
// 记录执行开始时间
|
|
// 记录执行开始时间
|
|
|
long startTime = System.currentTimeMillis();
|
|
long startTime = System.currentTimeMillis();
|
|
|
ExecutionResult result = null;
|
|
ExecutionResult result = null;
|
|
@@ -76,8 +77,9 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
|
|
|
try {
|
|
try {
|
|
|
CompanyAiWorkflowExec companyAiWorkflowExec = companyAiWorkflowExecMapper.selectByWorkflowInstanceId(context.getWorkflowInstanceId());
|
|
CompanyAiWorkflowExec companyAiWorkflowExec = companyAiWorkflowExecMapper.selectByWorkflowInstanceId(context.getWorkflowInstanceId());
|
|
|
log.info("收到继续执行请求 - workflowInstanceId: {}, nodeKey: {}, 当前状态: {}",
|
|
log.info("收到继续执行请求 - workflowInstanceId: {}, nodeKey: {}, 当前状态: {}",
|
|
|
- context.getWorkflowInstanceId(), context.getCurrentNodeKey(), companyAiWorkflowExec.getStatus());
|
|
|
|
|
-
|
|
|
|
|
|
|
+ context.getWorkflowInstanceId(), nodeKey, companyAiWorkflowExec.getStatus());
|
|
|
|
|
+ CompanyWorkflowNode node = companyWorkflowNodeMapper.selectNodeByNodeKey(nodeKey);
|
|
|
|
|
+ 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())
|
|
|
&& !Integer.valueOf(ExecutionStatusEnum.WAITING.getValue()).equals(companyAiWorkflowExec.getStatus())) {
|
|
&& !Integer.valueOf(ExecutionStatusEnum.WAITING.getValue()).equals(companyAiWorkflowExec.getStatus())) {
|
|
@@ -93,10 +95,10 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
|
|
|
//更新流程日志信息
|
|
//更新流程日志信息
|
|
|
CompanyAiWorkflowExecLog companyAiWorkflowExecLog = new CompanyAiWorkflowExecLog();
|
|
CompanyAiWorkflowExecLog companyAiWorkflowExecLog = new CompanyAiWorkflowExecLog();
|
|
|
companyAiWorkflowExecLog.setWorkflowInstanceId(context.getWorkflowInstanceId());
|
|
companyAiWorkflowExecLog.setWorkflowInstanceId(context.getWorkflowInstanceId());
|
|
|
- companyAiWorkflowExecLog.setNodeKey(context.getCurrentNodeKey());
|
|
|
|
|
|
|
+ companyAiWorkflowExecLog.setNodeKey(nodeKey);
|
|
|
companyAiWorkflowExecLog.setStatus(ExecutionStatusEnum.PAUSED.getValue());
|
|
companyAiWorkflowExecLog.setStatus(ExecutionStatusEnum.PAUSED.getValue());
|
|
|
List<CompanyAiWorkflowExecLog> companyAiWorkflowExecLogs = companyAiWorkflowExecLogMapper.selectCompanyAiWorkflowExecLogList(companyAiWorkflowExecLog);
|
|
List<CompanyAiWorkflowExecLog> companyAiWorkflowExecLogs = companyAiWorkflowExecLogMapper.selectCompanyAiWorkflowExecLogList(companyAiWorkflowExecLog);
|
|
|
- if(null != companyAiWorkflowExecLogs){
|
|
|
|
|
|
|
+ if (null != companyAiWorkflowExecLogs && !companyAiWorkflowExecLogs.isEmpty()) {
|
|
|
CompanyAiWorkflowExecLog fExecLog = companyAiWorkflowExecLogs.get(0);
|
|
CompanyAiWorkflowExecLog fExecLog = companyAiWorkflowExecLogs.get(0);
|
|
|
fExecLog.setStatus(ExecutionStatusEnum.SUCCESS.getValue());
|
|
fExecLog.setStatus(ExecutionStatusEnum.SUCCESS.getValue());
|
|
|
fExecLog.setEndTime(new Date());
|
|
fExecLog.setEndTime(new Date());
|
|
@@ -116,8 +118,22 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
|
|
|
*/
|
|
*/
|
|
|
protected void preExecute(ExecutionContext context) {
|
|
protected void preExecute(ExecutionContext context) {
|
|
|
context.setVariable("node_start_time_" + nodeKey, System.currentTimeMillis());
|
|
context.setVariable("node_start_time_" + nodeKey, System.currentTimeMillis());
|
|
|
- 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);
|
|
|
|
|
+ CompanyWorkflowNode node = companyWorkflowNodeMapper.selectNodeByNodeKey(nodeKey);
|
|
|
|
|
+ context.setVariable("currentNode", node);
|
|
|
|
|
+ CompanyAiWorkflowExec companyAiWorkflowExec = companyAiWorkflowExecMapper.selectByWorkflowInstanceId(context.getWorkflowInstanceId());
|
|
|
|
|
+ if (!companyAiWorkflowExec.getCurrentNodeKey().equals(nodeKey)) {
|
|
|
|
|
+ CompanyWorkflowNode cNode = companyWorkflowNodeMapper.selectNodeByNodeKey(nodeKey);
|
|
|
|
|
+ CompanyAiWorkflowExec update = new CompanyAiWorkflowExec();
|
|
|
|
|
+ update.setCurrentNodeKey(nodeKey);
|
|
|
|
|
+ update.setCurrentNodeName(nodeName);
|
|
|
|
|
+ update.setCurrentNodeType(NodeTypeEnum.fromCode(cNode.getNodeType()).getValue());
|
|
|
|
|
+ update.setLastUpdateTime(LocalDateTime.now());
|
|
|
|
|
+ companyAiWorkflowExecMapper.updateCompanyAiWorkflowExec(update);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -129,10 +145,10 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
|
|
|
log.info("Completed execution of node: {} ({})", nodeKey, nodeName);
|
|
log.info("Completed execution of node: {} ({})", nodeKey, nodeName);
|
|
|
//todo 写入执行日志等后置操作
|
|
//todo 写入执行日志等后置操作
|
|
|
int logStatus;
|
|
int logStatus;
|
|
|
- if (ExecutionStatusEnum.SUCCESS.equals(result.getStatus()) ) {
|
|
|
|
|
|
|
+ if (ExecutionStatusEnum.SUCCESS.equals(result.getStatus())) {
|
|
|
logStatus = ExecutionStatusEnum.SUCCESS.getValue();
|
|
logStatus = ExecutionStatusEnum.SUCCESS.getValue();
|
|
|
updateWorkflowStatus(context.getWorkflowInstanceId(), ExecutionStatusEnum.SUCCESS);
|
|
updateWorkflowStatus(context.getWorkflowInstanceId(), ExecutionStatusEnum.SUCCESS);
|
|
|
- } else if(ExecutionStatusEnum.FAILURE.equals(result.getStatus())) {
|
|
|
|
|
|
|
+ } else if (ExecutionStatusEnum.FAILURE.equals(result.getStatus())) {
|
|
|
logStatus = ExecutionStatusEnum.FAILURE.getValue();
|
|
logStatus = ExecutionStatusEnum.FAILURE.getValue();
|
|
|
updateWorkflowStatus(context.getWorkflowInstanceId(), ExecutionStatusEnum.FAILURE);
|
|
updateWorkflowStatus(context.getWorkflowInstanceId(), ExecutionStatusEnum.FAILURE);
|
|
|
} else {
|
|
} else {
|
|
@@ -281,6 +297,10 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
|
|
|
update.setStatus(status.getValue());
|
|
update.setStatus(status.getValue());
|
|
|
update.setLastUpdateTime(LocalDateTime.now());
|
|
update.setLastUpdateTime(LocalDateTime.now());
|
|
|
update.setVariables(objectMapper.writeValueAsString(context.getVariables()));
|
|
update.setVariables(objectMapper.writeValueAsString(context.getVariables()));
|
|
|
|
|
+ update.setCurrentNodeKey(nodeKey);
|
|
|
|
|
+ CompanyWorkflowNode currentNode = context.getVariable("currentNode", CompanyWorkflowNode.class);
|
|
|
|
|
+ update.setCurrentNodeType(NodeTypeEnum.fromCode(currentNode.getNodeType()).getValue());
|
|
|
|
|
+ update.setCurrentNodeName(currentNode.getNodeName());
|
|
|
companyAiWorkflowExecMapper.updateByWorkflowInstanceId(update);
|
|
companyAiWorkflowExecMapper.updateByWorkflowInstanceId(update);
|
|
|
log.info("工作流已阻塞在节点: {} -> {}", workflowInstanceId, nodeKey);
|
|
log.info("工作流已阻塞在节点: {} -> {}", workflowInstanceId, nodeKey);
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -322,8 +342,8 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
|
|
|
CompanyAiWorkflowExec update = new CompanyAiWorkflowExec();
|
|
CompanyAiWorkflowExec update = new CompanyAiWorkflowExec();
|
|
|
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)){
|
|
|
|
|
- update.setCurrentNodeName(context.getVariable("nodeName",String.class));
|
|
|
|
|
|
|
+ if (null != context.getVariables() && null != context.getVariable("nodeName", String.class)) {
|
|
|
|
|
+ update.setCurrentNodeName(context.getVariable("nodeName", String.class));
|
|
|
}
|
|
}
|
|
|
update.setStatus(ExecutionStatusEnum.RUNNING.getValue());
|
|
update.setStatus(ExecutionStatusEnum.RUNNING.getValue());
|
|
|
update.setLastUpdateTime(LocalDateTime.now());
|
|
update.setLastUpdateTime(LocalDateTime.now());
|
|
@@ -335,14 +355,15 @@ public abstract class AbstractWorkflowNode implements IWorkflowNode {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- protected void runNextNode(ExecutionContext context, CompanyWorkflowEdge edge){
|
|
|
|
|
- if(StringUtils.isBlank(edge.getTargetNodeKey())){
|
|
|
|
|
|
|
+ protected void runNextNode(ExecutionContext context, CompanyWorkflowEdge edge) {
|
|
|
|
|
+ if (StringUtils.isBlank(edge.getTargetNodeKey())) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
ExecutionContext nextContext = context.clone();
|
|
ExecutionContext nextContext = context.clone();
|
|
|
- nextContext.setCurrentNodeKey(edge.getTargetNodeKey());
|
|
|
|
|
- execPointNextNode(nextContext);
|
|
|
|
|
CompanyWorkflowNode nextNode = companyWorkflowNodeMapper.selectNodeByNodeKey(edge.getTargetNodeKey());
|
|
CompanyWorkflowNode nextNode = companyWorkflowNodeMapper.selectNodeByNodeKey(edge.getTargetNodeKey());
|
|
|
|
|
+ nextContext.setCurrentNodeKey(nextNode.getNodeKey());
|
|
|
|
|
+ nextContext.setVariable("nodeName", nextNode.getNodeName());
|
|
|
|
|
+ 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);
|
|
|
}
|
|
}
|