From fc5893722cd8fb6b479eff4ab042eac65a3a12b6 Mon Sep 17 00:00:00 2001 From: yubao Date: Sat, 7 Apr 2018 22:00:29 +0800 Subject: [PATCH] check bugs --- OpenAuth.App/Flow/FlowRuntime.cs | 309 +++++++++++++------------------ OpenAuth.App/FlowInstanceApp.cs | 22 +-- 2 files changed, 141 insertions(+), 190 deletions(-) diff --git a/OpenAuth.App/Flow/FlowRuntime.cs b/OpenAuth.App/Flow/FlowRuntime.cs index 3e1c4d70..754ccc0f 100644 --- a/OpenAuth.App/Flow/FlowRuntime.cs +++ b/OpenAuth.App/Flow/FlowRuntime.cs @@ -24,7 +24,7 @@ namespace OpenAuth.App.Flow _runtimeModel.frmData = instance.FrmData; _runtimeModel.schemeContentJson = schemeContentJson;//模板流程json对象 _runtimeModel.nodes = GetNodes(schemeContentJson);//节点集合 - _runtimeModel.lines = GetLineDictionary(schemeContentJson);//线条集合 + _runtimeModel.lines = GetFromLines(schemeContentJson);//线条集合 _runtimeModel.currentNodeId = (instance.ActivityId == "" ? _runtimeModel.startNodeId : instance.ActivityId); _runtimeModel.currentNodeType = GetNodeType(_runtimeModel.currentNodeId); @@ -36,7 +36,7 @@ namespace OpenAuth.App.Flow } else { - _runtimeModel.nextNodeId = GetNextNode(_runtimeModel.frmData);//下一个节点 + _runtimeModel.nextNodeId = GetNextNodeId(_runtimeModel.frmData);//下一个节点 _runtimeModel.nextNodeType = GetNodeType(_runtimeModel.nextNodeId); } @@ -69,57 +69,56 @@ namespace OpenAuth.App.Flow return nodes; } /// - /// 获取工作流线段的字典列表:key开始节点id,value线条实体列表 + /// 获取工作流节点及以节点为出发点的流程 /// /// /// - private Dictionary> GetLineDictionary(dynamic schemeContentJson) + private Dictionary> GetFromLines(dynamic schemeContentJson) { - Dictionary> lineDictionary = new Dictionary>(); + Dictionary> lines = new Dictionary>(); foreach (JObject item in schemeContentJson.lines) { var line = item.ToObject(); - if (!lineDictionary.ContainsKey(line.from)) + if (!lines.ContainsKey(line.from)) { List d = new List { line }; - lineDictionary.Add(line.from, d); + lines.Add(line.from, d); } else { - lineDictionary[line.from].Add(line); + lines[line.from].Add(line); } } - return lineDictionary; + return lines; } /// - /// 获取工作流线段的字典列表:key开始节点id,value线条实体列表 + /// 获取工作流节点的入口流程列表 /// /// /// - private Dictionary> GetToLineDictionary(dynamic schemeContentJson) + private Dictionary> GetToLines(dynamic schemeContentJson) { - Dictionary> lineDictionary = new Dictionary>(); + Dictionary> lines = new Dictionary>(); foreach (JObject item in schemeContentJson.lines) { var line = item.ToObject(); - if (!lineDictionary.ContainsKey(line.to)) + if (!lines.ContainsKey(line.to)) { List d = new List { line }; - lineDictionary.Add(line.to, d); + lines.Add(line.to, d); } else { - lineDictionary[line.to].Add(line); + lines[line.to].Add(line); } } - return lineDictionary; + return lines; } /// /// 获取下一个节点 /// - /// 表单数据(用于判断流转条件) - private string GetNextNode(string frmData, string nodeId = null) + private string GetNextNodeId(string frmData, string nodeId=null) { List LineList = null; if (nodeId == null) @@ -142,15 +141,25 @@ namespace OpenAuth.App.Flow bool flag = false; foreach (var item in LineList)//轮训该节点所有连接的线路 { - return item.to; - - - } } return "-1";//表示寻找不到节点 } + + /// + /// 通过节点Id获取下一个节点Id + /// + /// + /// + public string GetNextNode(string nodeId) + { + string frmData = ""; + + // frmData = GetNodeFrmData(_getFrmData, nodeId); + + return GetNextNodeId(frmData, nodeId); + } #endregion #region 工作流实例流转API @@ -171,7 +180,7 @@ namespace OpenAuth.App.Flow if (_runtimeModel.nextNodeId != "-1") { return GetNodeType(_runtimeModel.nextNodeId); - + } return -1; } @@ -206,172 +215,117 @@ namespace OpenAuth.App.Flow /// /// 获取会签下面需要审核的ID列表 /// - /// + /// 会签开始节点 /// - public List GetCountersigningNodeIdList(string shuntnodeId) + public List GetCountersigningNodeIdList(string forknodeId) { - List list = new List(); - - List listline = _runtimeModel.lines[shuntnodeId]; - - foreach (var item in listline) - { - list.Add(item.to); - } - - return list; - } - /// - /// 通过节点Id获取下一个节点Id - /// - /// - /// - public string GetNextNodeByNodeId(string nodeId) - { - string frmData = ""; - - // frmData = GetNodeFrmData(_getFrmData, nodeId); - - return GetNextNode(frmData, nodeId); + return _runtimeModel.lines[forknodeId].Select(item => item.to).ToList(); } + /// /// 节点会签审核 /// /// - /// + /// /// -1不通过,1等待,其它通过 public string NodeConfluence(string nodeId, Tag tag) { string res = "-1"; - string nextNodeId = GetNextNodeByNodeId(nodeId);//获取下一个节点 - if (nextNodeId != "-1") + string joinNodeId = GetNextNode(nodeId); //获取回签的合流节点 + + if (joinNodeId == "-1") { - Dictionary> toLines = GetToLineDictionary(_runtimeModel.schemeContentJson); - int allnum = toLines[nextNodeId].Count; - int i = 0; - foreach (var item in _runtimeModel.schemeContentJson.nodes) - { - if (item.id == nextNodeId) - { - if (string.IsNullOrEmpty(item.setInfo.NodeConfluenceType))//0所有步骤通过 todo:先用空格 - { - if (tag.Taged == 1) - { - if (item.setInfo.ConfluenceOk == null) - { - _runtimeModel.schemeContentJson.nodes[i].setInfo.ConfluenceOk = 1; - res = "1"; - } - else if (item.setInfo.ConfluenceOk == (allnum - 1)) - { - res = GetNextNodeByNodeId(nextNodeId); - if (res == "-1") - { - throw (new Exception("会签成功寻找不到下一个节点")); - } - } - else - { - _runtimeModel.schemeContentJson.nodes[i].setInfo.ConfluenceOk++; - res = "1"; - } - } - } - else if (item.setInfo.NodeConfluenceType == "1")//1一个步骤通过即可 - { - if (tag.Taged ==1) - { - res = GetNextNodeByNodeId(nextNodeId); - if (res == "-1") - { - throw (new Exception("会签成功寻找不到下一个节点")); - } - } - else - { - if (item.setInfo.ConfluenceNo == null) - { - _runtimeModel.schemeContentJson.nodes[i].setInfo.ConfluenceNo = 1; - res = "1"; - } - else if (item.setInfo.ConfluenceNo == (allnum - 1)) - { - res = "-1"; - } - else - { - _runtimeModel.schemeContentJson.nodes[i].setInfo.ConfluenceNo++; - res = "1"; - } - } - } - else//2按百分比计算 - { - if (tag.Taged == 1) - { - if (item.setInfo.ConfluenceOk == null) - { - _runtimeModel.schemeContentJson.nodes[i].setInfo.ConfluenceOk = 1; - } - else - { - _runtimeModel.schemeContentJson.nodes[i].setInfo.ConfluenceOk++; - } - } - else - { - if (item.setInfo.ConfluenceNo == null) - { - _runtimeModel.schemeContentJson.nodes[i].setInfo.ConfluenceNo = 1; - } - else - { - _runtimeModel.schemeContentJson.nodes[i].setInfo.ConfluenceNo++; - } - } - if ((item.setInfo.ConfluenceNo + item.setInfo.ConfluenceOk) / allnum * 100 > int.Parse(item.setInfo.NodeConfluenceRate)) - { - res = GetNextNodeByNodeId(nextNodeId); - if (res == "-1") - { - throw (new Exception("会签成功寻找不到下一个节点")); - } - } - else if ((item.setInfo.ConfluenceNo + item.setInfo.ConfluenceOk) == allnum) - { - res = "-1"; - } - else - { - res = "1"; - } - } - break; - } - i++; - } - if (res == "-1") - { - tag.Taged = -1; - MakeTagNode(nextNodeId, tag); - } - else if (res != "1") //则时res是会签结束节点的ID - { - tag.Taged = 1; - MakeTagNode(nextNodeId,tag); - _runtimeModel.nextNodeId = res; - _runtimeModel.nextNodeType = GetNodeType(res); - } - else - { - _runtimeModel.nextNodeId = nextNodeId; - _runtimeModel.nextNodeType = GetNodeType(nextNodeId); - } - return res; + throw (new Exception("寻找不到会签下合流节点")); } - throw (new Exception("寻找不到会签下合流节点")); + Dictionary> toLines = GetToLines(_runtimeModel.schemeContentJson); + int allnum = toLines[joinNodeId].Count; //总会签数量 + + int i = 0; + foreach (var item in _runtimeModel.schemeContentJson.nodes) + { + if (item.id != joinNodeId) + { + i++; + continue; + } + + if (string.IsNullOrEmpty(item.setInfo.NodeConfluenceType)) //默认所有步骤通过 + { + if (tag.Taged == 1) + { + if (item.setInfo.ConfluenceOk == null) + { + _runtimeModel.schemeContentJson.nodes[i].setInfo.ConfluenceOk = 1; + res = "1"; + } + else if (item.setInfo.ConfluenceOk == (allnum - 1)) //会签成功 + { + res = GetNextNode(joinNodeId); + if (res == "-1") + { + throw (new Exception("会签成功寻找不到下一个节点")); + } + } + else + { + _runtimeModel.schemeContentJson.nodes[i].setInfo.ConfluenceOk++; + res = "1"; + } + } + } + //else if (item.setInfo.NodeConfluenceType == "1") //1一个步骤通过即可 + //{ + // if (tag.Taged == 1) + // { + // res = GetNextNodeId(nextNodeId); + // if (res == "-1") + // { + // throw (new Exception("会签成功寻找不到下一个节点")); + // } + // } + // else + // { + // if (item.setInfo.ConfluenceNo == null) + // { + // _runtimeModel.schemeContentJson.nodes[i].setInfo.ConfluenceNo = 1; + // res = "1"; + // } + // else if (item.setInfo.ConfluenceNo == (allnum - 1)) + // { + // res = "-1"; + // } + // else + // { + // _runtimeModel.schemeContentJson.nodes[i].setInfo.ConfluenceNo++; + // res = "1"; + // } + // } + //} + } + + + + if (res == "-1") + { + tag.Taged = -1; + MakeTagNode(joinNodeId, tag); + } + else if (res != "1") //这时res是会签结束节点后面的一个节点 + { + tag.Taged = 1; + MakeTagNode(joinNodeId, tag); + _runtimeModel.nextNodeId = res; + _runtimeModel.nextNodeType = GetNodeType(res); + } + else + { + _runtimeModel.nextNodeId = joinNodeId; + _runtimeModel.nextNodeType = GetNodeType(joinNodeId); + } + return res; } + /// /// 驳回节点0"前一步"1"第一步"2"某一步" 3"不处理" /// @@ -392,7 +346,7 @@ namespace OpenAuth.App.Flow } if (node.setInfo.NodeRejectType == "1") { - return GetNextNodeByNodeId(_runtimeModel.startNodeId); + return GetNextNode(_runtimeModel.startNodeId); } if (node.setInfo.NodeRejectType == "2") { @@ -402,7 +356,7 @@ namespace OpenAuth.App.Flow } return _runtimeModel.previousId; } - /// + /// /// 标记节点1通过,-1不通过,0驳回 /// /// @@ -423,6 +377,7 @@ namespace OpenAuth.App.Flow i++; } } - #endregion } + #endregion } + diff --git a/OpenAuth.App/FlowInstanceApp.cs b/OpenAuth.App/FlowInstanceApp.cs index e1e0be55..aae01a8d 100644 --- a/OpenAuth.App/FlowInstanceApp.cs +++ b/OpenAuth.App/FlowInstanceApp.cs @@ -115,27 +115,22 @@ namespace OpenAuth.App Description = description }; #region 会签 - if (flowInstance.ActivityType == 0)//会签 + if (flowInstance.ActivityType == 0)//当前节点是会签节点 { tag.Taged = 1; - wfruntime.MakeTagNode(wfruntime.runtimeModel.currentNodeId, tag);//标记当前节点通过 + wfruntime.MakeTagNode(wfruntime.runtimeModel.currentNodeId, tag);//标记会签节点状态 - string verificationNodeId = ""; //寻找需要审核的节点Id + string verificationNodeId = ""; //寻找当前登陆用户可审核的节点Id List nodelist = wfruntime.GetCountersigningNodeIdList(wfruntime.runtimeModel.currentNodeId); foreach (string item in nodelist) { var makerList = GetMakerList(wfruntime.runtimeModel.nodes[item] , wfruntime.runtimeModel.flowInstanceId); - if (makerList != "-1") + if (makerList == "-1") continue; + + if (makerList.Split(',').Any(one => user.Id == one)) { - foreach (string one in makerList.Split(',')) - { - if (user.Id == one || user.Id.IndexOf(one) != -1) - { - verificationNodeId = item; - break; - } - } + verificationNodeId = item; } } @@ -152,13 +147,14 @@ namespace OpenAuth.App flowInstanceOperationHistory.Content = "【" + wfruntime.runtimeModel.nodes[verificationNodeId].name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】不同意,备注:" + description; } + wfruntime.MakeTagNode(verificationNodeId, tag);//标记审核节点状态 string confluenceres = wfruntime.NodeConfluence(verificationNodeId, tag); switch (confluenceres) { case "-1"://不通过 flowInstance.IsFinish = 3; break; - case "1"://等待 + case "1"://等待,当前节点还是会签开始节点,不跳转 break; default://通过 flowInstance.PreviousId = flowInstance.ActivityId;