|
@@ -0,0 +1,89 @@
|
|
|
|
|
+package com.ruoyi.interfaces.controller;
|
|
|
|
|
+
|
|
|
|
|
+import com.agentsflex.core.chain.Chain;
|
|
|
|
|
+import com.agentsflex.core.chain.ChainEvent;
|
|
|
|
|
+import com.agentsflex.core.chain.ChainSuspendException;
|
|
|
|
|
+import com.agentsflex.core.chain.event.*;
|
|
|
|
|
+import com.agentsflex.core.chain.listener.ChainEventListener;
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.ruoyi.common.utils.JsonUtils;
|
|
|
|
|
+import dev.tinyflow.core.Tinyflow;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
+
|
|
|
|
|
+public class test {
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
|
+ String json = "{\"nodes\": [{\"id\": \"node_CVKeWeJL8jn5cGr4\",\"position\": {\"x\": -83,\"y\": 67},\"data\": {\"title\": \"开始节点\",\"description\": \"开始定义输入参数\",\"expand\": true,\"parameters\": [{\"name\": \"username\",\"dataType\": \"String\",\"refType\": \"input\",\"id\": \"YtkNFKFFC5hh4zAh\",\"required\": true}, {\"name\": \"password\",\"dataType\": \"String\",\"refType\": \"input\",\"id\": \"YW0JonLnPtsDVRlp\",\"required\": true}]},\"type\": \"startNode\",\"selected\": false,\"measured\": {\"width\": 305,\"height\": 238},\"dragging\": false}, {\"id\": \"node_Lmg446ujJkBFTq7s\",\"position\": {\"x\": 333,\"y\": 68},\"data\": {\"title\": \"结束节点\",\"description\": \"结束定义输出参数\",\"expand\": true,\"outputDefs\": [{\"name\": \"用户名\",\"dataType\": \"String\",\"refType\": \"ref\",\"id\": \"0FqjBTXWXwmNHvOm\",\"ref\": \"node_CVKeWeJL8jn5cGr4.username\"}, {\"name\": \"密码\",\"dataType\": \"String\",\"refType\": \"ref\",\"id\": \"jdXNtiAiLAqP1uto\",\"ref\": \"node_CVKeWeJL8jn5cGr4.password\"}]},\"type\": \"endNode\",\"selected\": true,\"measured\": {\"width\": 368,\"height\": 238},\"dragging\": false}],\"edges\": [{\"markerEnd\": {\"type\": \"arrowclosed\",\"width\": 20,\"height\": 20},\"source\": \"node_CVKeWeJL8jn5cGr4\",\"target\": \"node_Lmg446ujJkBFTq7s\",\"id\": \"p1QfMcJuAkHG9XN7\",\"selected\": false}],\"viewport\": {\"x\": 269.9146606773976,\"y\": 109.93970251055521,\"zoom\": 0.8705505632961242}}\n";
|
|
|
|
|
+
|
|
|
|
|
+ JSONObject root = JSON.parseObject(json);
|
|
|
|
|
+ JSONArray nodes = root.getJSONArray("nodes");
|
|
|
|
|
+ JSONArray edges = root.getJSONArray("edges");
|
|
|
|
|
+
|
|
|
|
|
+ Tinyflow tinyflow = new Tinyflow(json);
|
|
|
|
|
+
|
|
|
|
|
+ Chain chain = tinyflow.toChain();
|
|
|
|
|
+ chain.addEventListener(new ChainEventListener() {
|
|
|
|
|
+ /*@Override
|
|
|
|
|
+ public void onEvent(ChainEvent event, Chain chain) {
|
|
|
|
|
+ System.out.println("event: " + event.toString());
|
|
|
|
|
+ }*/
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onEvent(ChainEvent event, Chain chain) {
|
|
|
|
|
+ System.out.println("event: " + event.toString());
|
|
|
|
|
+ System.out.println("event: " + event.toString());
|
|
|
|
|
+ if(event instanceof ChainStartEvent){
|
|
|
|
|
+ // 处理异常逻辑
|
|
|
|
|
+ System.out.println("ChainStartEvent==============");
|
|
|
|
|
+ System.out.println("ChainStartEvent==============");
|
|
|
|
|
+ }
|
|
|
|
|
+ if(event instanceof ChainStatusChangeEvent){
|
|
|
|
|
+ // 处理异常逻辑
|
|
|
|
|
+ System.out.println("ChainStatusChangeEvent==============");
|
|
|
|
|
+ System.out.println("ChainStatusChangeEvent==============");
|
|
|
|
|
+ }
|
|
|
|
|
+ if(event instanceof NodeStartEvent){
|
|
|
|
|
+ // 处理异常逻辑
|
|
|
|
|
+ System.out.println("NodeStartEvent==============");
|
|
|
|
|
+ System.out.println("NodeStartEvent==============");
|
|
|
|
|
+ }if(event instanceof NodeEndEvent){
|
|
|
|
|
+ // 处理异常逻辑
|
|
|
|
|
+ System.out.println("NodeEndEvent==============");
|
|
|
|
|
+ System.out.println("NodeEndEvent==============");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if(event instanceof ChainResumeEvent){
|
|
|
|
|
+ // 处理异常逻辑
|
|
|
|
|
+ System.out.println("ChainResumeEvent==============");
|
|
|
|
|
+ System.out.println("ChainResumeEvent==============");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(event instanceof ChainEndEvent){
|
|
|
|
|
+ // 处理异常逻辑
|
|
|
|
|
+ System.out.println("ChainEndEvent==============");
|
|
|
|
|
+ System.out.println("ChainEndEvent==============");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
|
|
+/* map.put("username","123");
|
|
|
|
|
+ map.put("password","123");*/
|
|
|
|
|
+ // 执行执行链
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> result = chain.executeForResult(map);
|
|
|
|
|
+ } catch (Exception e){
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ System.out.println();
|
|
|
|
|
+ }
|
|
|
|
|
+}
|