| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using WorkFlowApi.Utility.WorkFlowEngine.Scheme;
- using WorkFlowApi.Utility.WorkFlowEngine.Scheme.Config;
- using WorkFlowApi.Utility.WorkFlowEngine.Scheme.Line;
- using WorkFlowApi.Utility.WorkFlowEngine.Scheme.Node;
- namespace WorkFlowApi.Utility.WorkFlowEngine
- {
- /// <summary>
- /// 工作流引擎
- /// </summary>
- public class WFEngine : WFIEngine
- {
- #region 构造函数
- /// <summary>
- ///
- /// </summary>
- /// <param name="nWFEngineConfig"></param>
- public WFEngine(WFEngineConfig nWFEngineConfig)
- {
- // 初始化模板数据
- config = nWFEngineConfig;
- wfScheme = config.ParamConfig.Scheme.ToObject<WFScheme>();
- nodesMap = new Dictionary<string, WFNodeInfo>();
- foreach (var node in wfScheme.nodes)
- {
- if (!nodesMap.ContainsKey(node.id))
- {
- nodesMap.Add(node.id, node);
- }
- if (node.type == "startround")
- {
- startNode = node;
- }
- }
- }
- #endregion
- #region 模板数据信息
- private WFEngineConfig config;
- private WFScheme wfScheme = null;
- private Dictionary<string, WFNodeInfo> nodesMap = null;
- private WFNodeInfo startNode = null;
- #endregion
- #region 流程模板操作方法
- /// <summary>
- /// 获取流程模板
- /// </summary>
- /// <returns></returns>
- public string GetScheme()
- {
- return config.ParamConfig.Scheme;
- }
- /// <summary>
- /// 获取流程模板
- /// </summary>
- /// <returns></returns>
- public WFScheme GetSchemeObj()
- {
- return wfScheme;
- }
- /// <summary>
- /// 获取开始节点
- /// </summary>
- /// <returns>节点信息</returns>
- public WFNodeInfo GetStartNode()
- {
- return startNode;
- }
- /// <summary>
- /// 获取节点
- /// </summary>
- /// <param name="nodeId">流程处理节点ID</param>
- /// <returns>节点信息</returns>
- public WFNodeInfo GetNode(string nodeId)
- {
- if (nodesMap.ContainsKey(nodeId))
- {
- return nodesMap[nodeId];
- }
- else
- {
- return null;
- }
- }
- /// <summary>
- /// 获取两节点间的线条
- /// </summary>
- /// <param name="fromNodeId">开始节点</param>
- /// <param name="toNodeId">结束节点</param>
- /// <param name="list">线条列表</param>
- /// <param name="nodes"></param>
- public bool GetLines(string fromNodeId, string toNodeId, List<WFLineInfo> list, Dictionary<string, string> nodes = null)
- {
- bool res = false;
- if (nodes == null)
- {
- nodes = new Dictionary<string, string>();
- }
- foreach (var line in wfScheme.lines)
- {
- if (line.from == fromNodeId)
- {
- if (line.to == toNodeId)
- {
- list.Add(line);
- return true;
- }
- else
- {
- if (line.to == fromNodeId || nodesMap[line.to] == null || nodesMap[line.to].type == "endround")
- {
- }
- else if (!nodes.ContainsKey(line.to))
- {
- nodes.Add(line.to, "1");
- res = GetLines(line.to, toNodeId, list, nodes);
- }
- }
- if (res)
- {
- list.Add(line);
- return true;
- }
- }
- }
- return res;
- }
- /// <summary>
- /// 获取下一节点
- /// </summary>
- /// <param name="nodeId">当前节点Id</param>
- /// <param name="code">节点操作码 agree 同意 disagree 不同意 lrtimeout 超时</param>
- /// <param name="lineList"></param>
- /// <returns>节点信息列表</returns>
- public List<WFNodeInfo> GetNextNodes(string nodeId, string code, List<WFLineInfo> lineList)
- {
- List<WFNodeInfo> nextNodes = new List<WFNodeInfo>();
- // 找到与当前节点相连的线条
- foreach (var line in wfScheme.lines)
- {
- if (line.from == nodeId)
- {
- bool isOk = false;
- if (string.IsNullOrEmpty(line.strategy) || line.strategy == "1")
- {
- isOk = true;
- }
- else
- {
- var codeList = line.agreeList.Split(',');
- foreach (string _code in codeList)
- {
- if (_code == code)
- {
- isOk = true;
- break;
- }
- }
- }
- if (isOk)
- {
- if (nodesMap.ContainsKey(line.to))
- {
- nextNodes.Add(nodesMap[line.to]);
- switch (line.operationType)
- {// 绑定的操作类型
- case "sql": // sql 语句
- if (!string.IsNullOrEmpty(line.dbId) && !string.IsNullOrEmpty(line.strSql))
- {
- lineList.Add(line);
- }
- break;
- case "interface": // interface 接口
- if (!string.IsNullOrEmpty(line.strInterface))
- {
- lineList.Add(line);
- }
- break;
- case "ioc": // 依赖注入
- if (!string.IsNullOrEmpty(line.iocName))
- {
- lineList.Add(line);
- }
- break;
- }
- }
- }
- }
- }
- return nextNodes;
- }
- public string GetButonList(string nodeId, List<WFLineInfo> lineList)
- {
- string codelist = string.Empty;
- // 找到与当前节点相连的线条
- foreach (var line in wfScheme.lines)
- {
- if (line.from == nodeId)
- {
- if (!line.agreeList.IsNullOrEmpty())
- {
- codelist = codelist + ',' + line.agreeList;
- }
-
-
- }
- }
- return codelist.TrimStart(',');
- }
- /// <summary>
- /// 获取上一节点列表
- /// </summary>
- /// <param name="nodeId">当前节点Id</param>
- /// <returns></returns>
- public List<string> GetPreNodes(string nodeId)
- {
- List<string> list = new List<string>();
- // 找到与当前节点相连的线条
- foreach (var line in wfScheme.lines)
- {
- if (line.to == nodeId)
- {
- list.Add(line.from);
- }
- }
- return list;
- }
- /// <summary>
- /// 判断两节点是否连接
- /// </summary>
- /// <param name="formNodeId">开始节点</param>
- /// <param name="toNodeId">结束节点</param>
- /// <returns></returns>
- public bool IsToNode(string formNodeId, string toNodeId)
- {
- bool res = false;
- foreach (var line in wfScheme.lines)
- {
- if (line.from == formNodeId)
- {
- if (line.to == toNodeId)
- {
- res = true;
- break;
- }
- else
- {
- if (line.to == formNodeId || nodesMap[line.to] == null || nodesMap[line.to].type == "endround")
- {
- break;
- }
- else
- {
- if (IsToNode(line.to, toNodeId))
- {
- res = true;
- break;
- }
- }
- }
- }
- }
- return res;
- }
- #endregion
- #region 流程运行操作方法
- /// <summary>
- /// 获取配置参数信息
- /// </summary>
- /// <returns></returns>
- public WFEngineParamConfig GetConfig()
- {
- return config.ParamConfig;
- }
- /// <summary>
- /// 获取接下来的任务节点信息
- /// </summary>
- /// <param name="beginNode">起始节点</param>
- /// <param name="code">节点操作码 agree 同意 disagree 不同意 lrtimeout 超时</param>
- /// <param name="isGetAuditors">是否获取下一节点审核人</param>
- /// <param name="lineList">经过的线段需要执行操作的</param>
- /// <returns></returns>
- public List<WFNodeInfo> GetNextTaskNode(WFNodeInfo beginNode, string code, bool isGetAuditors, List<WFLineInfo> lineList,string branchnodeCode="")
- {
- List<WFNodeInfo> list = new List<WFNodeInfo>();
- List<WFNodeInfo> nextNodeList = GetNextNodes(beginNode.id, code, lineList);
- //Dictionary<string, string> auditers = null;
- //if (!string.IsNullOrEmpty(config.ParamConfig.Auditers))
- //{
- // auditers = config.ParamConfig.Auditers.ToObject<Dictionary<string, string>>();
- //}
- var auditers = config.ParamConfig.Auditers;
- foreach (var node in nextNodeList)
- {
- if (auditers != null && auditers.Count>0)
- {
- node.auditors = auditers;
- }
- switch (node.type)
- {
-
- case "branchnode":// 分支节点
- list.AddRange(GetNextTaskNode(node, branchnodeCode, isGetAuditors, lineList));
- break;
- case "startround":// 开始节点 需要重新审核
- list.Add(node);
- config.ParamConfig.State = 1;
- break;
- case "endround":// 结束节点
- list.Add(node);
- config.ParamConfig.State = 2;
- break;
- default: // 默认普通节点
- list.Add(node);
- break;
- }
- }
- return list;
- }
- #endregion
- }
- }
|