吴树波 3 недель назад
Родитель
Сommit
a10c1624c9

+ 19 - 34
fs-service/src/main/java/com/fs/company/service/impl/CompanyWorkflowEngineImpl.java

@@ -102,8 +102,6 @@ public class CompanyWorkflowEngineImpl implements CompanyWorkflowEngine {
                     currentExecutionMapper.selectByWorkflowInstanceId(workflowInstanceId);
 
             if (currentExec == null) {
-//                return ExecutionResult.failure()
-//                        .errorMessage("工作流实例不存在: " + workflowInstanceId).build();
                 throw new CustomException("工作流实例不存在: " + workflowInstanceId);
             }
 
@@ -124,40 +122,27 @@ public class CompanyWorkflowEngineImpl implements CompanyWorkflowEngine {
             context.setCurrentNodeKey(nodeKey);
             ExecutionResult result = node.execute(context);
 
-//            if (node.isAsync()) {
-//                // 阻塞节点:执行节点后暂停流程,等待外部事件唤醒
-//
-//                // 返回特殊结果表示流程被阻塞
-//                return ExecutionResult.paused()
-//                        .nextNodeKey(result.getNextNodeKey())
-//                        .outputData(result.getOutputData()).build();
-//            } else {
-//                // 执行节点
-//                ExecutionResult result = node.execute(context);
-//
-//                // 如果执行成功,返回下一个节点ID
-//                if (result.isSuccess()) {
-//                    // 检查是否是结束节点
-//                    if (StringUtils.isBlank(result.getNextNodeKey())) {
-//                        // 结束工作流
-//                        completeWorkflow(workflowInstanceId);
-//                    } else {
-//                        // 更新当前节点为下一个节点
-//                        updateCurrentNode(workflowInstanceId, result.getNextNodeKey());
-//                    }
-//                } else {
-//                    // 执行失败时更新状态
-//                    updateWorkflowStatus(workflowInstanceId, ExecutionStatusEnum.FAILURE);
-//                }
-
-//                return result;
-//            }
+            // 处理执行结果
+            if (result.isSuccess()) {
+                // 检查是否是结束节点或无下一节点
+                if (StringUtils.isBlank(result.getNextNodeKey())) {
+                    // 结束工作流
+                    completeWorkflow(workflowInstanceId);
+                    log.info("工作流执行完成 - workflowInstanceId: {}", workflowInstanceId);
+                } else {
+                    // 继续执行下一个节点
+                    executeNode(workflowInstanceId, result.getNextNodeKey());
+                }
+            } else {
+                // 执行失败时更新状态
+                updateWorkflowStatus(workflowInstanceId, ExecutionStatusEnum.FAILURE);
+                log.error("节点执行失败 - workflowInstanceId: {}, nodeKey: {}, error: {}",
+                        workflowInstanceId, nodeKey, result.getErrorMessage());
+            }
         } catch (Exception e) {
-            log.error("节点执行失败: {} -> {}", workflowInstanceId, nodeKey, e);
+            log.error("节点执行异常: {} -> {}", workflowInstanceId, nodeKey, e);
             updateWorkflowStatus(workflowInstanceId, ExecutionStatusEnum.FAILURE);
-            throw new CustomException("节点执行失败");
-//            return ExecutionResult.failure()
-//                    .errorMessage("Node execution failed: " + e.getMessage()).build();
+            throw new CustomException("节点执行失败: " + e.getMessage());
         }
     }
 

+ 0 - 20
fs-service/src/main/java/com/fs/company/service/impl/call/node/StartNode.java

@@ -45,24 +45,4 @@ public class StartNode extends AbstractWorkflowNode {
     public Boolean isAsync() {
         return false;
     }
-
-    @Override
-    protected void postExecute(ExecutionContext context, ExecutionResult result){
-        super.postExecute(context, result);
-        CompanyAiWorkflowExec exec = companyAiWorkflowExecMapper.selectByWorkflowInstanceId(context.getWorkflowInstanceId());
-        List<CompanyWorkflowEdge> edges = companyWorkflowEdgeMapper.selectListByWorkflowIdAndNodeKey(exec.getWorkflowId(), nodeKey);
-        this.runNextNode(context,edges.get(0));
-    }
-
-    /**
-     * 运行下一个节点
-     * @param context
-     * @param edge
-     */
-    private void runNextNode(ExecutionContext context, CompanyWorkflowEdge edge){
-        ExecutionContext nextContext = context.clone();
-        nextContext.setCurrentNodeKey(edge.getTargetNodeKey());
-        super.execPointNextNode(nextContext);
-        super.execute(nextContext);
-    }
 }