| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315 |
- // using System.Text.RegularExpressions;
- // using Common;
- // using Feign;
- // using Infrastructure;
- // using LitJson;
- // using Model.Custom;
- // using Model.Source;
- // using Services;
- // namespace Util.Logic
- // {
- // public class LogicHelperBak
- // {
- // /// <summary>
- // /// 获取逻辑项目的Json数据
- // /// </summary>
- // /// <param name="projectId">项目ID</param>
- // /// <param name="request">请求参数</param>
- // public static Dictionary<string, object> DoLogic(int projectId, string request)
- // {
- // var logicProjectService = App.GetService<ILogicProjectService>();
- // var logicProject = logicProjectService.GetById(projectId);
- // if(logicProject == null)
- // {
- // return new Dictionary<string, object>();
- // }
- // string jsonData = logicProject.setData ?? string.Empty;
- // if(string.IsNullOrEmpty(jsonData))
- // {
- // return new Dictionary<string, object>();
- // }
- // JsonData requestObj = JsonMapper.ToObject(request);
- // JsonData jsonDataObj = JsonMapper.ToObject(jsonData);
- // JsonData nodes = jsonDataObj["nodes"]; // 节点数据
- // List<NodeList> nodeList = new List<NodeList>(); // 节点列表
- // foreach(JsonData node in nodes)
- // {
- // JsonData id = node["id"];
- // JsonData type = node["type"];
- // NodeList nodeListObj = new NodeList();
- // nodeListObj.nodeId = id.ToString();
- // nodeListObj.nodeType = type.ToString();
- // nodeListObj.nodeData = node;
- // nodeList.Add(nodeListObj);
- // }
- // List<EdgeList> edgeList = new List<EdgeList>(); // 边列表
- // JsonData edges = jsonDataObj["edges"]; // 边数据
- // foreach(JsonData edge in edges)
- // {
- // JsonData source = edge["source"];
- // JsonData target = edge["target"];
- // 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();
- // string paramValue = requestObj[paramName].ToString();
- // ParamList paramListObj = new ParamList();
- // paramListObj.nodeId = startNodeId;
- // paramListObj.paramName = paramName;
- // paramListObj.paramType = paramType;
- // paramListObj.paramValue = paramValue;
- // paramListObj.paramAttribute = "startinput";
- // paramList.Add(paramListObj);
- // }
- // //获取数据库信息
- // List<string> dbIdValues = LitJsonHelper.FindAllValuesByKey(jsonDataObj, "dbId");
- // if(dbIdValues.Count > 0) dbIdValues = dbIdValues.Where(m => !string.IsNullOrEmpty(m)).Distinct().ToList();
- // List<string> dbTableIdValues = LitJsonHelper.FindAllValuesByKey(jsonDataObj, "dbTableId");
- // if(dbTableIdValues.Count > 0) dbTableIdValues = dbTableIdValues.Where(m => !string.IsNullOrEmpty(m)).Distinct().ToList();
- // string dbIdList = string.Join(",", dbIdValues);
- // List<DatabaseInfo> databaseInfos = ISource.getDatabaseInfoListByIds(dbIdList);
- // // 获取数据库表信息
- // string dbTableIdList = string.Join(",", dbTableIdValues);
- // List<DatabaseTable> tables = ISource.getDatabaseTableListByIds(dbTableIdList);
- // // 从起始节点开始
- // sortEdge(databaseInfos, tables, edgeList, nodeList, paramList, startNodeId, new Dictionary<string, int>());
- // // 返回结果
- // Dictionary<string, object> result = new Dictionary<string, object>();
- // foreach(ParamList item in paramList.Where(m => m.paramAttribute == "endoutput").ToList())
- // {
- // result.Add(item.paramName, item.paramValue);
- // }
- // return result;
- // }
- // /// <summary>
- // /// 运行逻辑项目的Json数据
- // /// </summary>
- // /// <param name="edgeList">边列表</param>
- // /// <param name="startNodeId">起始节点ID</param>
- // public static void sortEdge(List<DatabaseInfo> databaseInfos, List<DatabaseTable> tables, List<EdgeList> edgeList, List<NodeList> nodeList, List<ParamList> paramList, string startNodeId, Dictionary<string, int> doEdgeCount)
- // {
- // var edges = edgeList.Where(m => m.source == startNodeId).ToList();
- // foreach(EdgeList item in edges)
- // {
- // //记录同一层级的节点执行计数,保证当前层级的所有节点都执行完后,再执行下一层级的节点
- // if(doEdgeCount.ContainsKey(startNodeId))
- // {
- // doEdgeCount[startNodeId]++;
- // }
- // else
- // {
- // doEdgeCount.Add(startNodeId, 1);
- // }
- // int edgeCount = doEdgeCount[startNodeId];
- // NodeList node = nodeList.FirstOrDefault(x => x.nodeId == item.target) ?? new NodeList();
- // int targetEdgeCount = edgeList.Count(m => m.target == node.nodeId);
- // switch(node.nodeType)
- // {
- // case "ifelse": // 如果-否则节点
- // var ifElseResult = LogicNodeHelper.ifElse(node, paramList);
- // if(ifElseResult.Count > 0)
- // {
- // foreach(bool result in ifElseResult)
- // {
- // if(result)
- // {
- // // if (node.nodeData.ToJson().Contains("\"parentNode\""))
- // // {
- // // string pNodeId = node.nodeData["parentNode"]?.ToString() ?? string.Empty;
- // // if(edgeCount >= edges.Count) sortEdge(databaseInfos, tables, edgeList, nodeList, paramList, pNodeId + "-child-start-node", doEdgeCount);
- // // }
- // // else
- // // {
- // if(edgeCount >= edges.Count) sortEdge(databaseInfos, tables, edgeList, nodeList, paramList, item.target, doEdgeCount);
- // // }
- // break;
- // }
- // }
- // }
- // break;
- // case "iteration": // 迭代节点
- // // var iterationParamList = LogicNodeHelper.iteration(node, paramList);
- // if(edgeCount >= edges.Count || targetEdgeCount == 1)
- // {
- // bool op = true;
- // while (op)
- // {
- // sortEdge(databaseInfos, tables, edgeList, nodeList, paramList, node.nodeId + "-child-start-node", doEdgeCount);
- // op = RedisServer.Cache.Get("break_" + node.nodeId) != "1";
- // }
- // sortEdge(databaseInfos, tables, edgeList, nodeList, paramList, item.target, doEdgeCount);
- // }
- // break;
- // case "child_start": // 子流程起始节点
- // LogicNodeHelper.iterationChildStart(node, paramList);
- // if(edgeCount >= edges.Count) sortEdge(databaseInfos, tables, edgeList, nodeList, paramList, item.target, doEdgeCount);
- // break;
- // case "break": // 跳出循环
- // LogicNodeHelper.iterationBreak(node, "");
- // // 跳出循环后,继续执行循环后面的节点
- // string parentNodeId = node.nodeData["parentNode"]?.ToString() ?? string.Empty;
- // EdgeList breakEdge = edgeList.FirstOrDefault(x => x.source == parentNodeId) ?? new EdgeList();
- // if(string.IsNullOrEmpty(breakEdge.source))
- // {
- // if(edgeCount >= edges.Count) sortEdge(databaseInfos, tables, edgeList, nodeList, paramList, breakEdge.target, doEdgeCount);
- // }
- // break;
- // case "loop": // 循环节点
- // if(edgeCount >= edges.Count || targetEdgeCount == 1)
- // {
- // List<Dictionary<string, object>> loopResult = LogicNodeHelper.loop(node, paramList);
- // foreach(Dictionary<string, object> subLoop in loopResult)
- // {
- // if(RedisServer.Cache.Get("break_" + node.nodeId) == "1")
- // {
- // break;
- // }
- // else
- // {
- // foreach(string key in subLoop.Keys)
- // {
- // var loopParam = paramList.FirstOrDefault(x => x.paramName == key && x.nodeId == node.nodeId && x.paramAttribute == "loop");
- // if(loopParam != null)
- // {
- // loopParam.paramValue = subLoop[key]?.ToString();
- // }
- // else
- // {
- // paramList.Add(new ParamList()
- // {
- // nodeId = node.nodeId,
- // paramAttribute = "loop",
- // paramName = key,
- // paramType = "string",
- // paramValue = subLoop[key]?.ToString(),
- // });
- // }
- // }
- // doEdgeCount.Remove(node.nodeId + "-child-start-node");
- // sortEdge(databaseInfos, tables, edgeList, nodeList, paramList, node.nodeId + "-child-start-node", doEdgeCount);
- // }
- // }
- // sortEdge(databaseInfos, tables, edgeList, nodeList, paramList, item.target, doEdgeCount);
- // }
- // break;
- // case "code-execute": // 代码执行节点
- // LogicNodeHelper.codeExecute(node, paramList);
- // if(edgeCount >= edges.Count) sortEdge(databaseInfos, tables, edgeList, nodeList, paramList, item.target, doEdgeCount);
- // break;
- // case "sql-execute": // SQL执行节点
- // LogicDatabaseNodeHelper.dbSqlQuery(node, databaseInfos, paramList);
- // if(edgeCount >= edges.Count) sortEdge(databaseInfos, tables, edgeList, nodeList, paramList, item.target, doEdgeCount);
- // break;
- // case "insert-data": // 插入数据节点
- // break;
- // case "update-data": // 更新数据节点
- // break;
- // case "query-data": // 查询数据节点
- // LogicDatabaseNodeHelper.dbQuery(node, databaseInfos, tables, paramList);
- // if(edgeCount >= edges.Count) sortEdge(databaseInfos, tables, edgeList, nodeList, paramList, item.target, doEdgeCount);
- // break;
- // case "delete-data": // 删除数据节点
- // break;
- // case "http-request": // HTTP请求节点
- // LogicToolNodeHelper.httpRequest(node, paramList);
- // if(edgeCount >= edges.Count) sortEdge(databaseInfos, tables, edgeList, nodeList, paramList, item.target, doEdgeCount);
- // break;
- // case "var-aggregate": // 变量聚合节点
- // LogicNodeHelper.varAggregate(node, paramList);
- // if(edgeCount >= edges.Count) sortEdge(databaseInfos, tables, edgeList, nodeList, paramList, item.target, doEdgeCount);
- // break;
- // case "end": // 结束节点
- // break;
- // default:
- // if(edgeCount >= edges.Count) sortEdge(databaseInfos, tables, edgeList, nodeList, paramList, item.target, doEdgeCount);
- // break;
- // }
- // }
- // }
- // public static string GetExpressionVal(string str)
- // {
- // if(str == "#{now}#") return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- // if(str == "#{today}#") return DateTime.Now.ToString("yyyy-MM-dd");
- // if(str == "#{this_month}#") return DateTime.Now.ToString("yyyy-MM");
- // if(str.StartsWith("#{now") && str.EndsWith("DAY}#")) return DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd HH:mm:ss");
- // if(str.StartsWith("#{now") && str.EndsWith("MONTH}#")) return DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd HH:mm:ss");
- // if(str.StartsWith("#{today") && str.EndsWith("DAY}#")) return DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
- // if(str.StartsWith("#{today") && str.EndsWith("MONTH}#")) return DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd");
- // if(str.StartsWith("#{this_month") && str.EndsWith("DAY}#")) return DateTime.Now.AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
- // if(str.StartsWith("#{this_month") && str.EndsWith("MONTH}#")) return DateTime.Now.AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM");
- // if(str.StartsWith("#{") && str.EndsWith("DAY}#")) return DateTime.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[0]).AddDays(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd HH:mm:ss");
- // if(str.StartsWith("#{") && str.EndsWith("MONTH}#")) return DateTime.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[0]).AddMonths(int.Parse(str.Replace("#", "").Replace("{", "").Replace("}", "").Split(',')[1])).ToString("yyyy-MM-dd HH:mm:ss");
- // if(str.StartsWith("#{split") && str.EndsWith("}#"))
- // {
- // string[] data = str.Replace("#{", "").Replace("}#", "").Split(',');
- // string text = data[1];
- // string splitTag = data[2];
- // string index = data[3];
- // return text.Split(new string[]{ splitTag }, StringSplitOptions.None)[int.Parse(index)];
- // }
- // else if(str.StartsWith("#{") && str.EndsWith("}#"))
- // {
- // string[] data = str.Replace("#{", "").Replace("}#", "").Split(',');
- // string tag = data[0];
- // string format = data[data.Length - 1];
- // if(format.StartsWith("yyyy"))
- // {
- // if(tag == "now")
- // {
- // if(data.Length == 2)
- // {
- // return DateTime.Now.ToString(format);
- // }
- // else if(data.Length == 4)
- // {
- // if(data[2] == "DAY") return DateTime.Now.AddDays(int.Parse(data[1])).ToString(format);
- // if(data[2] == "MONTH") return DateTime.Now.AddMonths(int.Parse(data[1])).ToString(format);
- // }
- // }
- // else
- // {
- // if(data.Length == 2)
- // {
- // return DateTime.Parse(tag).ToString(format);
- // }
- // else if(data.Length == 4)
- // {
- // if(data[2] == "DAY") return DateTime.Parse(tag).AddDays(int.Parse(data[1])).ToString(format);
- // if(data[2] == "MONTH") return DateTime.Parse(tag).AddMonths(int.Parse(data[1])).ToString(format);
- // }
- // }
- // }
- // }
- // return str;
- // }
- // public static string MatchExpressionVal(string str)
- // {
- // if(string.IsNullOrEmpty(str)) return str;
- // MatchCollection mc = Regex.Matches(str, "#\\{.*?\\}#");
- // foreach(Match m in mc)
- // {
- // str = str.Replace(m.Value, GetExpressionVal(m.Value));
- // }
- // return str;
- // }
- // }
- // }
|