Jelajahi Sumber

流程图状态优化

ZhuDeKang 4 bulan lalu
induk
melakukan
e295649f2c

+ 40 - 0
ruoyi-api-patform/src/main/java/com/ruoyi/interfaces/service/impl/MdAppFlowServiceImpl.java

@@ -4,6 +4,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.TimeoutException;
 
 import com.agentsflex.core.chain.Chain;
 import com.agentsflex.core.chain.ChainEvent;
@@ -11,6 +12,7 @@ import com.agentsflex.core.chain.ChainNode;
 import com.agentsflex.core.chain.event.NodeEndEvent;
 import com.agentsflex.core.chain.event.NodeStartEvent;
 import com.agentsflex.core.chain.listener.ChainEventListener;
+import com.agentsflex.core.chain.listener.NodeErrorListener;
 import com.ruoyi.common.utils.DateUtils;
 import com.ruoyi.common.utils.JsonUtils;
 import com.ruoyi.common.utils.StringUtils;
@@ -19,6 +21,7 @@ import com.ruoyi.interfaces.domain.vo.MdAppFlowVo;
 import com.ruoyi.interfaces.tinyflow.TinyflowUtil;
 import com.ruoyi.interfaces.tinyflow.parser.PrintNodeParser;
 import dev.tinyflow.core.Tinyflow;
+import dev.tinyflow.core.node.HttpNode;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.ruoyi.interfaces.mapper.MdAppFlowMapper;
@@ -122,6 +125,7 @@ public class MdAppFlowServiceImpl implements IMdAppFlowService {
         chain.addEventListener(new ChainEventListener() {
             @Override
             public void onEvent(ChainEvent event, Chain chain) {
+
                 if (event instanceof NodeStartEvent) {
                     if (StringUtils.isNotNull(session)) {
                         NodeStartEvent nodeEndEvent = (NodeStartEvent) event;
@@ -149,6 +153,42 @@ public class MdAppFlowServiceImpl implements IMdAppFlowService {
             }
         });
 
+        chain.addNodeErrorListener(new NodeErrorListener(){
+            @Override
+            public void onError(Throwable error, ChainNode node, Map<String, Object> nodeResult, Chain chain) {
+
+
+                if (StringUtils.isNotNull(session)) {
+                    HashMap<String, Object> nodeMap = new HashMap<>();
+                    nodeMap.put("id", node.getId());
+                    nodeMap.put("name", node.getName());
+                    nodeMap.put("nodeState", "ERROR");
+                    nodeMap.put("timestamp", System.currentTimeMillis());
+                    // 根据错误类型分类处理
+                    if (error instanceof TimeoutException) {
+                        nodeMap.put("errorType", "TIMEOUT");
+                        nodeMap.put("errorMessage", "节点执行超时");
+                        nodeMap.put("suggestion", "请检查网络连接或增加超时时间");
+                    } else if (error instanceof IllegalArgumentException) {
+                        nodeMap.put("errorType", "INVALID_PARAMETER");
+                        nodeMap.put("errorMessage", "参数错误: " + error.getMessage());
+                        nodeMap.put("suggestion", "请检查输入参数格式");
+                    } else if (error instanceof NullPointerException) {
+                        nodeMap.put("errorType", "NULL_POINTER");
+                        nodeMap.put("errorMessage", "空指针异常");
+                        nodeMap.put("suggestion", "请检查数据完整性");
+                    } else {
+                        nodeMap.put("errorType", "UNKNOWN_ERROR");
+                        nodeMap.put("errorMessage", error.getMessage());
+                    }
+
+
+
+                    WebSocketUsers.sendMessageToUserByText(session, JsonUtils.objectToJson(nodeMap));
+                }
+            }
+        });
+
         return chain.executeForResult(appFlow.getParams());
     }
 }

+ 1 - 1
ruoyi-api-patform/src/main/java/com/ruoyi/interfaces/tinyflow/node/ServiceNode.java

@@ -30,8 +30,8 @@ public class ServiceNode extends BaseNode {
 
     @Override
     protected Map<String, Object> execute(Chain chain) {
-        Map<String, Object> map = new HashMap<>();
 
+        Map<String, Object> map = new HashMap<>();
         String url = RuoYiConfig.getGatewayUrl() + ptService.getProxyPath() + ptService.getUrl();
         System.out.println("url:" + url);
         Map<String, Object> parameterValues = chain.getParameterValues(this); //获取参数