Przeglądaj źródła

开始每个节点的视线

lichunlei 4 miesięcy temu
rodzic
commit
3f04abc506
3 zmienionych plików z 187 dodań i 3 usunięć
  1. 71 0
      Model/Custom/EdgeList.cs
  2. 85 3
      Util/LogicHelper.cs
  3. 31 0
      Util/LogicNodeHelper.cs

+ 71 - 0
Model/Custom/EdgeList.cs

@@ -0,0 +1,71 @@
+using LitJson;
+
+namespace Model.Custom
+{
+    public class EdgeList
+    {
+        /// <summary>
+        /// 源节点
+        /// </summary>
+        public string source { get; set; } = string.Empty;
+
+        /// <summary>
+        /// 目标节点
+        /// </summary>
+        public string target { get; set; } = string.Empty;
+
+        /// <summary>
+        /// 边数据
+        /// </summary>
+        public JsonData edgeData { get; set; } = new JsonData();
+    }
+
+    public class NodeList
+    {
+        /// <summary>
+        /// 节点ID
+        /// </summary>
+        public string nodeId { get; set; } = string.Empty;
+
+        /// <summary>
+        /// 节点类型
+        /// </summary>
+        public string nodeType { get; set; } = string.Empty;
+
+        /// <summary>
+        /// 节点数据
+        /// </summary>
+        public JsonData nodeData { get; set; } = new JsonData();
+    }
+
+    public class SortNodeList
+    {
+        /// <summary>
+        /// 节点索引
+        /// </summary>
+        public int index { get; set; } = 1;
+
+        /// <summary>
+        /// 节点ID
+        /// </summary>
+        public NodeList node { get; set; } = new NodeList();
+    }
+
+    public class ParamList
+    {
+        /// <summary>
+        /// 参数名称
+        /// </summary>
+        public string paramName { get; set; } = string.Empty;
+
+        /// <summary>
+        /// 参数类型
+        /// </summary>
+        public string paramType { get; set; } = string.Empty;
+
+        /// <summary>
+        /// 参数值
+        /// </summary>
+        public object paramValue { get; set; } = null;
+    }
+}

+ 85 - 3
Util/LogicHelper.cs

@@ -1,12 +1,18 @@
 using Infrastructure;
 using Infrastructure;
 using LitJson;
 using LitJson;
+using Model.Custom;
 using Services;
 using Services;
 
 
 namespace Util
 namespace Util
 {
 {
     public class LogicHelper
     public class LogicHelper
     {
     {
-        public static void GetLogicJsonData(int projectId)
+        /// <summary>
+        /// 获取逻辑项目的Json数据
+        /// </summary>
+        /// <param name="projectId">项目ID</param>
+        /// <param name="request">请求参数</param>
+        public static void GetLogicJsonData(int projectId, string request)
         {
         {
             var logicProjectService = App.GetService<ILogicProjectService>();
             var logicProjectService = App.GetService<ILogicProjectService>();
             var logicProject = logicProjectService.GetById(projectId);
             var logicProject = logicProjectService.GetById(projectId);
@@ -19,20 +25,96 @@ namespace Util
             {
             {
                 return;
                 return;
             }
             }
+            JsonData requestObj = JsonMapper.ToObject(request);
             JsonData jsonDataObj = JsonMapper.ToObject(jsonData);
             JsonData jsonDataObj = JsonMapper.ToObject(jsonData);
             JsonData nodes = jsonDataObj["nodes"]; // 节点数据
             JsonData nodes = jsonDataObj["nodes"]; // 节点数据
+            List<NodeList> nodeList = new List<NodeList>(); // 节点列表
             foreach(JsonData node in nodes)
             foreach(JsonData node in nodes)
             {
             {
                 JsonData id = node["id"];
                 JsonData id = node["id"];
                 JsonData type = node["type"];
                 JsonData type = node["type"];
+                NodeList nodeListObj = new NodeList();
+                nodeListObj.nodeId = id.ToString();
+                nodeListObj.nodeType = type.ToString();
+                nodeListObj.nodeData = node;
+                nodeList.Add(nodeListObj);
             }
             }
-            Dictionary<string, string> nodeDict = new Dictionary<string, string>();
+            List<EdgeList> edgeList = new List<EdgeList>(); // 边列表
             JsonData edges = jsonDataObj["edges"]; // 边数据
             JsonData edges = jsonDataObj["edges"]; // 边数据
             foreach(JsonData edge in edges)
             foreach(JsonData edge in edges)
             {
             {
                 JsonData source = edge["source"];
                 JsonData source = edge["source"];
                 JsonData target = edge["target"];
                 JsonData target = edge["target"];
-                nodeDict.Add(source.ToString(), target.ToString());
+                EdgeList edgeListObj = new EdgeList();
+                edgeListObj.source = source.ToString();
+                edgeListObj.target = target.ToString();
+                edgeListObj.edgeData = edge;
+                edgeList.Add(edgeListObj);
+            }
+
+            string startNodeId = "start"; // 起始节点ID
+            // 获取起始节点数据
+            List<ParamList> paramList = new List<ParamList>();
+            NodeList startNode = nodeList.FirstOrDefault(x => x.nodeId == startNodeId) ?? new NodeList();
+            JsonData nodeData = startNode.nodeData;
+            JsonData input = nodeData["data"]["formData"]["input"]["value"];
+            for(int i = 0; i < input.Count; i++)
+            {
+                JsonData item = input[i];
+                string paramName = item["label"].ToString();
+                string paramType = item["type"][0].ToString();
+                object paramValue = item["value"];
+                ParamList paramListObj = new ParamList();
+                paramListObj.paramName = paramName;
+                paramListObj.paramType = paramType;
+                paramListObj.paramValue = paramValue;
+                paramList.Add(paramListObj);
+            }
+
+            // 从起始节点开始
+            sortEdge(edgeList, nodeList, paramList, startNodeId);
+        }
+
+        /// <summary>
+        /// 运行逻辑项目的Json数据
+        /// </summary>
+        /// <param name="edgeList">边列表</param>
+        /// <param name="startNodeId">起始节点ID</param>
+        public static void sortEdge(List<EdgeList> edgeList, List<NodeList> nodeList, List<ParamList> paramList, string startNodeId)
+        {
+            foreach(EdgeList item in edgeList)
+            {
+                if(item.source == startNodeId)
+                {
+                    NodeList node = nodeList.FirstOrDefault(x => x.nodeId == item.target) ?? new NodeList();
+                    switch(node.nodeType)
+                    {
+                        case "ifelse": // 如果-否则节点
+                            LogicNodeHelper.ifElse(node, paramList);
+                            break;                            
+                        case "iteration": // 迭代节点
+                            break;
+                        case "loop": // 循环节点
+                            break;
+                        case "code-execute": // 代码执行节点
+                            break;
+                        case "sql-execute": // SQL执行节点
+                            break;
+                        case "insert-data": // 插入数据节点
+                            break;
+                        case "update-data": // 更新数据节点
+                            break;
+                        case "query-data": // 查询数据节点
+                            break;
+                        case "delete-data": // 删除数据节点
+                            break;
+                        case "http-request": // HTTP请求节点
+                            break;
+                        default:
+                            break;
+                    }
+                    sortEdge(edgeList, nodeList, paramList, item.target);
+                }
             }
             }
         }
         }
     }
     }

+ 31 - 0
Util/LogicNodeHelper.cs

@@ -0,0 +1,31 @@
+using Infrastructure;
+using LitJson;
+using Model.Custom;
+
+namespace Util
+{
+    public class LogicNodeHelper
+    {
+        /// <summary>
+        /// 如果-否则节点
+        /// </summary>
+        /// <param name="node">节点数据</param>
+        /// <param name="paramList">参数列表</param>
+        public static void ifElse(NodeList node, List<ParamList> paramList)
+        {
+            JsonData nodeData = node.nodeData;
+            JsonData ifCondition = nodeData["data"]["formData"]["ifelse"]["value"]; // 如果条件
+            foreach(JsonData item in ifCondition)
+            {
+                JsonData conditions = item["conditions"]; // 条件
+                foreach(JsonData condition in conditions)
+                {
+                    string oper = condition["operator"].ToString(); // 运算符
+                    string value = condition["value"].ToString(); // 值
+                    string variable = condition["variable"].ToString(); // 变量
+                }
+            }
+        }
+
+    }
+}