diff --git a/OpenAuth.App/Flow/FlowLine.cs b/OpenAuth.App/Flow/FlowLine.cs index d404caae..129cb2be 100644 --- a/OpenAuth.App/Flow/FlowLine.cs +++ b/OpenAuth.App/Flow/FlowLine.cs @@ -1,12 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace OpenAuth.App.Flow +namespace OpenAuth.App.Flow { - public class FlowLine + /// + /// 流程连线 + /// + public class FlowLine { public string id { get; set; } public string type { get; set; } diff --git a/OpenAuth.App/Flow/FlowNode.cs b/OpenAuth.App/Flow/FlowNode.cs index 13be1a7d..7e007802 100644 --- a/OpenAuth.App/Flow/FlowNode.cs +++ b/OpenAuth.App/Flow/FlowNode.cs @@ -1,11 +1,8 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace OpenAuth.App.Flow +namespace OpenAuth.App.Flow { + /// + /// 流程节点 + /// public class FlowNode { public const string START = "start round mix"; @@ -18,6 +15,30 @@ namespace OpenAuth.App.Flow public string type { get; set; } + + /// + /// 节点的附加数据项 + /// + /// The set information. + public Setinfo setInfo { get; set; } } + public class Setinfo + { + public Nodedesignatedata NodeDesignateData { get; set; } + public string NodeCode { get; set; } + public string NodeName { get; set; } + } + + /// + /// 节点执行人 + /// + public class Nodedesignatedata + { + public string[] users { get; set; } + public string[] role { get; set; } + public string[] org { get; set; } + } + + } diff --git a/OpenAuth.App/Flow/FlowRuntime.cs b/OpenAuth.App/Flow/FlowRuntime.cs index f5958c67..38ff2383 100644 --- a/OpenAuth.App/Flow/FlowRuntime.cs +++ b/OpenAuth.App/Flow/FlowRuntime.cs @@ -1,32 +1,31 @@ using System; using System.Collections.Generic; using Infrastructure; +using OpenAuth.Repository.Domain; namespace OpenAuth.App.Flow { - public class FlowRuntime + public class FlowRuntime { private FlowRuntimeModel _runtimeModel = null; /// /// 构造函数 /// - /// 流程模板 /// 当前节点 /// 表单数据 - public FlowRuntime(FlowRuntimeInitModel flowRuntimeInitModel) + /// + public FlowRuntime(FlowInstance instance) { _runtimeModel = new FlowRuntimeModel(); - dynamic schemeContentJson = flowRuntimeInitModel.schemeContent.ToJson();//获取工作流模板内容的json对象; + dynamic schemeContentJson = instance.SchemeContent.ToJson();//获取工作流模板内容的json对象; _runtimeModel.schemeContentJson = schemeContentJson;//模板流程json对象 - _runtimeModel.nodeDictionary = GetNodeDictionary(schemeContentJson);//节点集合 - _runtimeModel.lineDictionary = GetLineDictionary(schemeContentJson);//线条集合 - _runtimeModel.currentNodeId = (flowRuntimeInitModel.currentNodeId == "" ? _runtimeModel.startNodeId : flowRuntimeInitModel.currentNodeId); - _runtimeModel.currentNodeType = GetNodeStatus(_runtimeModel.currentNodeId); - _runtimeModel.frmData = flowRuntimeInitModel.frmData; - - // flowRuntimeInitModel.frmData = GetNodeFrmData(getFrmData); - + _runtimeModel.nodes = GetNodeDictionary(schemeContentJson);//节点集合 + _runtimeModel.lines = GetLineDictionary(schemeContentJson);//线条集合 + _runtimeModel.currentNodeId = (instance.ActivityId == "" ? _runtimeModel.startNodeId : instance.ActivityId); + _runtimeModel.currentNodeType = GetNodeType(_runtimeModel.currentNodeId); + //todo:要获取表单数据 + // _runtimeModel.frmData = flowRuntimeInitModel.frmData; if (_runtimeModel.currentNodeType == 0 || _runtimeModel.currentNodeType == 4) { @@ -35,13 +34,12 @@ namespace OpenAuth.App.Flow } else { - _runtimeModel.nextNodeId = GetNextNode(flowRuntimeInitModel.frmData);//下一个节点 - _runtimeModel.nextNodeType = GetNodeStatus(_runtimeModel.nextNodeId); + _runtimeModel.nextNodeId = GetNextNode(_runtimeModel.frmData);//下一个节点 + _runtimeModel.nextNodeType = GetNodeType(_runtimeModel.nextNodeId); } - _runtimeModel.previousId = flowRuntimeInitModel.previousId; - - _runtimeModel.flowInstanceId = flowRuntimeInitModel.processId.ToString(); + _runtimeModel.previousId = instance.PreviousId; + _runtimeModel.flowInstanceId = instance.Id; } @@ -51,16 +49,16 @@ namespace OpenAuth.App.Flow /// /// /// - private Dictionary GetNodeDictionary(dynamic schemeContentJson) + private Dictionary GetNodeDictionary(dynamic schemeContentJson) { - Dictionary nodeDictionary = new Dictionary(); + Dictionary nodeDictionary = new Dictionary(); foreach (var item in schemeContentJson.Flow.nodes) { if (!nodeDictionary.ContainsKey(item.id.Value)) { nodeDictionary.Add(item.id.Value, item); } - if (item.type == "startround") + if (item.type == FlowNode.START) { this._runtimeModel.startNodeId = item.id.Value; } @@ -72,15 +70,14 @@ namespace OpenAuth.App.Flow /// /// /// - private Dictionary> GetLineDictionary(dynamic schemeContentJson) + private Dictionary> GetLineDictionary(dynamic schemeContentJson) { - Dictionary> lineDictionary = new Dictionary>(); + Dictionary> lineDictionary = new Dictionary>(); foreach (var item in schemeContentJson.Flow.lines) { if (!lineDictionary.ContainsKey(item.from.Value)) { - List d = new List(); - d.Add(item); + List d = new List { item }; lineDictionary.Add(item.from.Value, d); } else @@ -95,15 +92,14 @@ namespace OpenAuth.App.Flow /// /// /// - private Dictionary> GetToLineDictionary(dynamic schemeContentJson) + private Dictionary> GetToLineDictionary(dynamic schemeContentJson) { - Dictionary> lineDictionary = new Dictionary>(); + Dictionary> lineDictionary = new Dictionary>(); foreach (var item in schemeContentJson.Flow.lines) { if (!lineDictionary.ContainsKey(item.to.Value)) { - List d = new List(); - d.Add(item); + List d = new List { item }; lineDictionary.Add(item.to.Value, d); } else @@ -113,153 +109,42 @@ namespace OpenAuth.App.Flow } return lineDictionary; } - /// - /// 工作流流转条件比较函数 - /// - /// 表单数据 - /// - /// - /// - private bool LineCompared(string frmvalue, string operation, string paramValue) - { - bool res = false; - switch (operation) - { - case "Equal"://等于 - if (decimal.Parse(frmvalue) == decimal.Parse(paramValue)) - { - res = true; - } - break; - case "NotEqual"://不等于 - if (decimal.Parse(frmvalue) != decimal.Parse(paramValue)) - { - res = true; - } - break; - case "Greater"://大于 - if (decimal.Parse(frmvalue) > decimal.Parse(paramValue)) - { - res = true; - } - break; - case "GreaterThan"://大于等于 - if (decimal.Parse(frmvalue) >= decimal.Parse(paramValue)) - { - res = true; - } - break; - case "Less"://小于 - if (decimal.Parse(frmvalue) < decimal.Parse(paramValue)) - { - res = true; - } - break; - case "LessThan"://小于等于 - if (decimal.Parse(frmvalue) <= decimal.Parse(paramValue)) - { - res = true; - } - break; - case "Null"://为空 - if (string.IsNullOrEmpty(frmvalue)) - { - res = true; - } - break; - case "NotNull"://不为空 - if (!string.IsNullOrEmpty(frmvalue)) - { - res = true; - } - break; - case "Like"://包含 - if (frmvalue.IndexOf(paramValue) != -1) - { - res = true; - } - break; - case "NotLike"://不包含 - if (frmvalue.IndexOf(paramValue) == -1) - { - res = true; - } - break; - } - return res; - } - /// /// 获取下一个节点 /// /// 表单数据(用于判断流转条件) - private string GetNextNode(string frmData,string nodeId = null) + private string GetNextNode(string frmData, string nodeId = null) { - try + List LineList = null; + if (nodeId == null) { - List LineList = null; - if (nodeId == null) - { - LineList = runtimeModel.lineDictionary[runtimeModel.currentNodeId]; - } - else - { - LineList = runtimeModel.lineDictionary[nodeId]; - } - if (LineList.Count == 1) - { - return LineList[0].to.Value; - } - else if (frmData != "") - { - frmData = frmData.ToLower();//统一转小写 - var frmDataJson = frmData.ToJObject();//获取数据内容 - bool flag = false; - foreach (var item in LineList)//轮训该节点所有连接的线路 - { - if (item.setInfo == null)//表示该线路没有设置条件,所以流转到下一个节点 - { - return item.to.Value; - } - foreach (var _item in item.setInfo.ConditionValueJson)//轮询该线条上的所有条件 - { - if (!string.IsNullOrEmpty(frmDataJson[_item.ParamName.Value.ToLower()].Value)) - { - string frmvalue = frmDataJson[_item.ParamName.Value.ToLower()].ToString(); - string operation = _item.Operation.Value; - string paramValue = _item.ParamValue.Value; - bool compareValue = LineCompared(frmvalue, operation, paramValue); + LineList = runtimeModel.lines[runtimeModel.currentNodeId]; + } + else + { + LineList = runtimeModel.lines[nodeId]; + } + if (LineList.Count == 1) //只有一条流程 + { + return LineList[0].to; + } - if (_item.Operation.Value == "AND") - { - flag = compareValue; - if (!compareValue) - { - break; - } - } - else - { - if (compareValue) - { - flag = compareValue; - } - } - } - } - if (flag)//如果满足条件, - { - return item.to.Value; - } - } - } - return "-1";//表示寻找不到节点 - } - catch + if (frmData != "") //有分支的情况 { - throw; + frmData = frmData.ToLower();//统一转小写 + var frmDataJson = frmData.ToJObject();//获取数据内容 + bool flag = false; + foreach (var item in LineList)//轮训该节点所有连接的线路 + { + + return item.to; + + + + } } + return "-1";//表示寻找不到节点 } #endregion @@ -276,52 +161,35 @@ namespace OpenAuth.App.Flow /// 获取实例接下来运行的状态 /// /// -1无法运行,0会签开始,1会签结束,2一般节点,4流程运行结束 - public int GetStatus() + public int GetNextNodeType() { if (_runtimeModel.nextNodeId != "-1") { - if (_runtimeModel.nextNode.type == "shuntnode")//会签开始节点 - { - return 0; - } - else if (_runtimeModel.nextNode.type == "confluencenode")//会签结束节点 - { - return 1; - } - else if (_runtimeModel.nextNode.type == "endround")//结束节点 - { - return 4; - } - else - { - return 2; - } - } - else - { - return -1; + return GetNodeType(_runtimeModel.nextNodeId); + } + return -1; } /// /// 获取节点类型 0会签开始,1会签结束,2一般节点,开始节点,4流程运行结束 /// /// /// - public int GetNodeStatus(string nodeId) + public int GetNodeType(string nodeId) { - if (_runtimeModel.nodeDictionary[nodeId].type == "shuntnode")//会签开始节点 + if (_runtimeModel.nodes[nodeId].type == "shuntnode")//会签开始节点 { return 0; } - else if (_runtimeModel.nodeDictionary[nodeId].type == "confluencenode")//会签结束节点 + else if (_runtimeModel.nodes[nodeId].type == "confluencenode")//会签结束节点 { return 1; } - else if (_runtimeModel.nodeDictionary[nodeId].type == "endround")//结束节点 + else if (_runtimeModel.nodes[nodeId].type == FlowNode.END)//结束节点 { return 4; } - else if (_runtimeModel.nodeDictionary[nodeId].type == "startround")//开始节点 + else if (_runtimeModel.nodes[nodeId].type == FlowNode.START)//开始节点 { return 3; } @@ -337,23 +205,16 @@ namespace OpenAuth.App.Flow /// public List GetCountersigningNodeIdList(string shuntnodeId) { - try + List list = new List(); + + List listline = _runtimeModel.lines[shuntnodeId]; + + foreach (var item in listline) { - List list = new List(); - - List listline = _runtimeModel.lineDictionary[shuntnodeId]; - - foreach (var item in listline) - { - list.Add(item.to.Value); - } - - return list; - } - catch - { - throw; + list.Add(item.to); } + + return list; } /// /// 通过节点Id获取下一个节点Id @@ -362,18 +223,11 @@ namespace OpenAuth.App.Flow /// public string GetNextNodeByNodeId(string nodeId) { - try - { - string frmData = ""; - - // frmData = GetNodeFrmData(_getFrmData, nodeId); - - return GetNextNode(frmData, nodeId); - } - catch - { - throw; - } + string frmData = ""; + + // frmData = GetNodeFrmData(_getFrmData, nodeId); + + return GetNextNode(frmData, nodeId); } /// /// 节点会签审核 @@ -381,7 +235,7 @@ namespace OpenAuth.App.Flow /// /// /// -1不通过,1等待,其它通过 - public string NodeConfluence(string nodeId, bool flag,string userId, string description = "") + public string NodeConfluence(string nodeId, bool flag, string userId, string description = "") { string res = "-1"; try @@ -398,16 +252,16 @@ namespace OpenAuth.App.Flow string _nextNodeId = GetNextNodeByNodeId(nodeId);//获取下一个节点 if (_nextNodeId != "-1") { - Dictionary> toLines = GetToLineDictionary(_runtimeModel.schemeContentJson); + Dictionary> toLines = GetToLineDictionary(_runtimeModel.schemeContentJson); int allnum = toLines[_nextNodeId].Count; int i = 0; foreach (var item in _runtimeModel.schemeContentJson.Flow.nodes) { if (item.id.Value == _nextNodeId) { - if(item.setInfo.NodeConfluenceType.Value == "")//0所有步骤通过 todo:先用空格 + if (item.setInfo.NodeConfluenceType.Value == "")//0所有步骤通过 todo:先用空格 { - if(flag) + if (flag) { if (item.setInfo.ConfluenceOk == null) { @@ -429,7 +283,7 @@ namespace OpenAuth.App.Flow } } } - else if(item.setInfo.NodeConfluenceType.Value == "1")//1一个步骤通过即可 + else if (item.setInfo.NodeConfluenceType.Value == "1")//1一个步骤通过即可 { if (flag) { @@ -510,12 +364,12 @@ namespace OpenAuth.App.Flow { MakeTagNode(_nextNodeId, 1, userId); _runtimeModel.nextNodeId = res; - _runtimeModel.nextNodeType = GetNodeStatus(res); + _runtimeModel.nextNodeType = GetNodeType(res); } else { _runtimeModel.nextNodeId = _nextNodeId; - _runtimeModel.nextNodeType = GetNodeStatus(_nextNodeId); + _runtimeModel.nextNodeType = GetNodeType(_nextNodeId); } return res; } @@ -546,7 +400,7 @@ namespace OpenAuth.App.Flow { try { - dynamic _node = _runtimeModel.nodeDictionary[nodeId]; + dynamic _node = _runtimeModel.nodes[nodeId]; if (_node.setInfo != null) { if (_node.setInfo.NodeRejectType.Value == "0") @@ -561,7 +415,7 @@ namespace OpenAuth.App.Flow { return _node.setInfo.NodeRejectStep.Value; } - else + else { return ""; } diff --git a/OpenAuth.App/Flow/FlowRuntimeInitModel.cs b/OpenAuth.App/Flow/FlowRuntimeInitModel.cs deleted file mode 100644 index 89f67916..00000000 --- a/OpenAuth.App/Flow/FlowRuntimeInitModel.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace OpenAuth.App.Flow -{ - - public class FlowRuntimeInitModel - { - /// - /// GUID - /// - public string processId { get; set; } - /// - /// 工作流模板内容 - /// - public string schemeContent { get; set; } - /// - /// 当前运行节点(默认开始节点) - /// - public string currentNodeId { get; set; } - /// - /// 提交的表单数据 - /// - public string frmData { get; set; } - /// - /// 上一个节点 - /// - public string previousId { get; set; } - } -} diff --git a/OpenAuth.App/Flow/FlowRuntimeModel.cs b/OpenAuth.App/Flow/FlowRuntimeModel.cs index d6062ad4..5f028038 100644 --- a/OpenAuth.App/Flow/FlowRuntimeModel.cs +++ b/OpenAuth.App/Flow/FlowRuntimeModel.cs @@ -24,7 +24,7 @@ namespace OpenAuth.App.Flow /// /// 当前节点的对象 /// - public dynamic currentNode { get { return this.nodeDictionary[this.currentNodeId]; } } + public dynamic currentNode { get { return nodes[currentNodeId]; } } /// /// 下一个节点 /// @@ -32,11 +32,12 @@ namespace OpenAuth.App.Flow /// /// 下一个节点类型 /// + /// The type of the next node. public int nextNodeType { get; set; } /// /// 下一个节点对象 /// - public FlowNode nextNode { get { return nodeDictionary[this.nextNodeId]; } } + public FlowNode nextNode { get { return nodes[nextNodeId]; } } /// /// 上一个节点 @@ -46,11 +47,11 @@ namespace OpenAuth.App.Flow /// /// 实例节点集合 /// - public Dictionary nodeDictionary { get; set; } + public Dictionary nodes { get; set; } /// /// 流转的线段集合 /// - public Dictionary> lineDictionary { get; set; } + public Dictionary> lines { get; set; } /// /// 模板json数据 diff --git a/OpenAuth.App/FlowInstanceApp.cs b/OpenAuth.App/FlowInstanceApp.cs index 2439fcc1..6750c9fd 100644 --- a/OpenAuth.App/FlowInstanceApp.cs +++ b/OpenAuth.App/FlowInstanceApp.cs @@ -15,99 +15,8 @@ namespace OpenAuth.App /// public class FlowInstanceApp :BaseApp { - - #region ȡ - /// - /// ȡʵϢʵ - /// - /// The key vlaue. - /// FlowInstance. - public FlowInstance GetEntity(string keyVlaue) - { - try - { - return UnitWork.FindSingle(u =>u.Id == keyVlaue); - } - catch - { - throw; - } - } - #endregion - #region ύ - /// - /// 洢ʵ(༭ݸ) - /// - /// - /// - /// - public int SaveProcess(string processId, FlowInstance flowInstance, FlowInstanceOperationHistory wfOperationHistoryEntity = null) - { - try - { - if (string.Empty ==(flowInstance.Id)) - { - UnitWork.Add(flowInstance); - } - else - { - flowInstance.Id = (processId); - UnitWork.Update(flowInstance); - } - if (wfOperationHistoryEntity != null) - { - wfOperationHistoryEntity.InstanceId = processId; - UnitWork.Add(wfOperationHistoryEntity); - } - UnitWork.Save(); - return 1; - } - catch - { - throw; - } - } - /// - /// 洢ʵ(ʵ) - /// - /// - /// - /// - /// - public int SaveProcess(FlowRuntimeModel flowRuntimeModel, FlowInstance flowInstance, FlowInstanceOperationHistory processOperationHistoryEntity, FlowInstanceTransitionHistory processTransitionHistoryEntity) - { - try - { - if (string.Empty == (flowInstance.Id)) - { - - flowInstance.Id = (string)(flowRuntimeModel.flowInstanceId); - UnitWork.Add(flowInstance); - } - else - { - flowInstance.Id =(flowInstance.Id); - UnitWork.Update(flowInstance); - } - processOperationHistoryEntity.InstanceId = flowInstance.Id; - UnitWork.Add(processOperationHistoryEntity); - - if (processTransitionHistoryEntity != null) - { - processTransitionHistoryEntity.InstanceId = flowInstance.Id; - UnitWork.Add(processTransitionHistoryEntity); - } - - UnitWork.Save(); - return 1; - } - catch - { - throw; - } - } /// /// 洢ʵ̣˲ύ /// @@ -197,82 +106,61 @@ namespace OpenAuth.App /// ע /// Ϣ /// - public bool CreateInstance(string processId, string schemeInfoId, FlowInstance FlowInstance, string frmData = null) + public bool CreateInstance(FlowInstance flowInstance, string frmData = null) { - - try + if (frmData == null) { - FlowScheme FlowScheme = UnitWork.FindSingle(u => u.Id == schemeInfoId); - - - FlowRuntimeInitModel flowRuntimeInitModel = new FlowRuntimeInitModel() - { - schemeContent = FlowScheme.SchemeContent, - currentNodeId = "", - frmData = frmData, - processId = processId - }; - FlowRuntime wfruntime = null; - - if (frmData == null) - { - throw new Exception("ԶҪύ"); - } - else - { - wfruntime = new FlowRuntime(flowRuntimeInitModel); - } - - - var user = AuthUtil.GetCurrentUser(); - #region ʵϢ - FlowInstance.ActivityId = wfruntime.runtimeModel.nextNodeId; - FlowInstance.ActivityType = wfruntime.GetStatus();//-1޷,0ǩʼ,1ǩ,2һڵ,4н - FlowInstance.ActivityName = wfruntime.runtimeModel.nextNode.name; - FlowInstance.PreviousId = wfruntime.runtimeModel.currentNodeId; - FlowInstance.SchemeType = FlowScheme.SchemeType; - FlowInstance.FrmType = FlowScheme.FrmType; - FlowInstance.Disabled = 0;//ʽ - FlowInstance.CreateUserId = user.User.Id.ToString(); - FlowInstance.CreateUserName = user.User.Account; - FlowInstance.MakerList = (wfruntime.GetStatus() != 4 ? GetMakerList(wfruntime) : "");//ǰڵִеϢ - FlowInstance.IsFinish = (wfruntime.GetStatus() == 4 ? 1 : 0); - FlowInstance.SchemeContent = FlowScheme.SchemeContent; - #endregion - - - - #region ̲¼ - FlowInstanceOperationHistory processOperationHistoryEntity = new FlowInstanceOperationHistory(); - processOperationHistoryEntity.Content = "" + user.User.Name + "һ̡̽" + FlowInstance.Code + "/" + FlowInstance.CustomName + ""; - #endregion - - #region ת¼ - FlowInstanceTransitionHistory processTransitionHistoryEntity = new FlowInstanceTransitionHistory(); - processTransitionHistoryEntity.FromNodeId = wfruntime.runtimeModel.currentNodeId; - processTransitionHistoryEntity.FromNodeName = wfruntime.runtimeModel.currentNode.name.Value; - processTransitionHistoryEntity.FromNodeType = wfruntime.runtimeModel.currentNodeType; - processTransitionHistoryEntity.ToNodeId = wfruntime.runtimeModel.nextNodeId; - processTransitionHistoryEntity.ToNodeName = wfruntime.runtimeModel.nextNode.name; - processTransitionHistoryEntity.ToNodeType = wfruntime.runtimeModel.nextNodeType; - processTransitionHistoryEntity.TransitionSate = 0; - processTransitionHistoryEntity.IsFinish = (processTransitionHistoryEntity.ToNodeType == 4 ? 1 : 0); - #endregion - - #region ίм¼ - //List delegateRecordEntitylist = GetDelegateRecordList(schemeInfoId, FlowInstance.Code, FlowInstance.CustomName, FlowInstance.MakerList); - //FlowInstance.MakerList += delegateUserList; - #endregion - - SaveProcess(wfruntime.runtimeModel, FlowInstance, processOperationHistoryEntity, processTransitionHistoryEntity); - - return true; + throw new Exception("ԶҪύ"); } - catch + var wfruntime = new FlowRuntime(flowInstance); + + + var user = AuthUtil.GetCurrentUser(); + #region ʵϢ + flowInstance.ActivityId = wfruntime.runtimeModel.nextNodeId; + flowInstance.ActivityType = wfruntime.GetNextNodeType();//-1޷,0ǩʼ,1ǩ,2һڵ,4н + flowInstance.ActivityName = wfruntime.runtimeModel.nextNode.name; + flowInstance.PreviousId = wfruntime.runtimeModel.currentNodeId; + flowInstance.CreateUserId = user.User.Id; + flowInstance.CreateUserName = user.User.Account; + flowInstance.MakerList = (wfruntime.GetNextNodeType() != 4 ? GetMakerList(wfruntime) : "");//ǰڵִеϢ + flowInstance.IsFinish = (wfruntime.GetNextNodeType() == 4 ? 1 : 0); + #endregion + + #region ̲¼ + FlowInstanceOperationHistory processOperationHistoryEntity = new FlowInstanceOperationHistory { - throw; - } + InstanceId = flowInstance.Id, + Content = "" + + user.User.Name + + "һ̡̽" + + flowInstance.Code + "/" + + flowInstance.CustomName + "" + }; + #endregion + + #region ת¼ + + FlowInstanceTransitionHistory processTransitionHistoryEntity = new FlowInstanceTransitionHistory + { + InstanceId = flowInstance.Id, + FromNodeId = wfruntime.runtimeModel.currentNodeId, + FromNodeName = wfruntime.runtimeModel.currentNode.name.Value, + FromNodeType = wfruntime.runtimeModel.currentNodeType, + ToNodeId = wfruntime.runtimeModel.nextNodeId, + ToNodeName = wfruntime.runtimeModel.nextNode.name, + ToNodeType = wfruntime.runtimeModel.nextNodeType, + TransitionSate = 0 + }; + processTransitionHistoryEntity.IsFinish = (processTransitionHistoryEntity.ToNodeType == 4 ? 1 : 0); + #endregion + + UnitWork.Add(flowInstance); + UnitWork.Add(processOperationHistoryEntity); + UnitWork.Add(processTransitionHistoryEntity); + UnitWork.Save(); + return true; } /// @@ -286,17 +174,11 @@ namespace OpenAuth.App try { string _sqlstr = "", _dbbaseId = ""; - FlowInstance FlowInstance = GetEntity(processId); + FlowInstance FlowInstance = Get(processId); FlowInstanceOperationHistory FlowInstanceOperationHistory = new FlowInstanceOperationHistory();//¼ FlowInstanceTransitionHistory processTransitionHistoryEntity = null;//ת¼ - FlowRuntimeInitModel flowRuntimeInitModel = new FlowRuntimeInitModel() - { - currentNodeId = FlowInstance.ActivityId, - previousId = FlowInstance.PreviousId, - processId = processId - }; - FlowRuntime wfruntime = new FlowRuntime(flowRuntimeInitModel); + FlowRuntime wfruntime = new FlowRuntime(FlowInstance); #region ǩ @@ -309,10 +191,10 @@ namespace OpenAuth.App string _makerList = ""; foreach (string item in _nodelist) { - _makerList = GetMakerList(wfruntime.runtimeModel.nodeDictionary[item], wfruntime.runtimeModel.flowInstanceId); + _makerList = GetMakerList(wfruntime.runtimeModel.nodes[item], wfruntime.runtimeModel.flowInstanceId); if (_makerList != "-1") { - var id = AuthUtil.GetCurrentUser().User.Id.ToString(); + var id = AuthUtil.GetCurrentUser().User.Id; foreach (string one in _makerList.Split(',')) { if (id == one || id.IndexOf(one) != -1) @@ -328,18 +210,17 @@ namespace OpenAuth.App { if (flag) { - FlowInstanceOperationHistory.Content = "" + "todo name" + "" + wfruntime.runtimeModel.nodeDictionary[_VerificationNodeId].name + "" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "ͬ,ע" + description; + FlowInstanceOperationHistory.Content = "" + "todo name" + "" + wfruntime.runtimeModel.nodes[_VerificationNodeId].name + "" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "ͬ,ע" + description; } else { - FlowInstanceOperationHistory.Content = "" + "todo name" + "" + wfruntime.runtimeModel.nodeDictionary[_VerificationNodeId].name + "" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "ͬ,ע" + description; + FlowInstanceOperationHistory.Content = "" + "todo name" + "" + wfruntime.runtimeModel.nodes[_VerificationNodeId].name + "" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "ͬ,ע" + description; } - string _Confluenceres = wfruntime.NodeConfluence(_VerificationNodeId, flag, AuthUtil.GetCurrentUser().User.Id.ToString(), description); + string _Confluenceres = wfruntime.NodeConfluence(_VerificationNodeId, flag, AuthUtil.GetCurrentUser().User.Id, description); var _data = new { - SchemeContent = wfruntime.runtimeModel.schemeContentJson.ToString(), - frmData = wfruntime.runtimeModel.frmData + SchemeContent = wfruntime.runtimeModel.schemeContentJson.ToString(), wfruntime.runtimeModel.frmData }; switch (_Confluenceres) { @@ -390,7 +271,7 @@ namespace OpenAuth.App { if (flag) { - wfruntime.MakeTagNode(wfruntime.runtimeModel.currentNodeId, 1, AuthUtil.GetCurrentUser().User.Id.ToString(), description); + wfruntime.MakeTagNode(wfruntime.runtimeModel.currentNodeId, 1, AuthUtil.GetCurrentUser().User.Id, description); FlowInstance.PreviousId = FlowInstance.ActivityId; FlowInstance.ActivityId = wfruntime.runtimeModel.nextNodeId; FlowInstance.ActivityType = wfruntime.runtimeModel.nextNodeType;//-1޷,0ǩʼ,1ǩ,2һڵ,4н @@ -431,8 +312,7 @@ namespace OpenAuth.App } var data = new { - SchemeContent = wfruntime.runtimeModel.schemeContentJson.ToString(), - frmData = wfruntime.runtimeModel.frmData + SchemeContent = wfruntime.runtimeModel.schemeContentJson.ToString(), wfruntime.runtimeModel.frmData }; } #endregion @@ -457,16 +337,11 @@ namespace OpenAuth.App { try { - FlowInstance FlowInstance = GetEntity(processId); - FlowInstanceOperationHistory FlowInstanceOperationHistory = new FlowInstanceOperationHistory(); + FlowInstance flowInstance = Get(processId); + FlowInstanceOperationHistory flowInstanceOperationHistory = new FlowInstanceOperationHistory(); FlowInstanceTransitionHistory processTransitionHistoryEntity = null; - FlowRuntimeInitModel flowRuntimeInitModel = new FlowRuntimeInitModel() - { - currentNodeId = FlowInstance.ActivityId, - previousId = FlowInstance.PreviousId, - processId = processId - }; - FlowRuntime wfruntime = new FlowRuntime(flowRuntimeInitModel); + + FlowRuntime wfruntime = new FlowRuntime(flowInstance); string resnode = ""; @@ -479,14 +354,14 @@ namespace OpenAuth.App resnode = nodeId; } wfruntime.MakeTagNode(wfruntime.runtimeModel.currentNodeId, 0, AuthUtil.GetUserName(), description); - FlowInstance.IsFinish = 4;//4ʾأҪύ + flowInstance.IsFinish = 4;//4ʾأҪύ if (resnode != "") { - FlowInstance.PreviousId = FlowInstance.ActivityId; - FlowInstance.ActivityId = resnode; - FlowInstance.ActivityType = wfruntime.GetNodeStatus(resnode);//-1޷,0ǩʼ,1ǩ,2һڵ,4н - FlowInstance.ActivityName = wfruntime.runtimeModel.nodeDictionary[resnode].name; - FlowInstance.MakerList = GetMakerList(wfruntime.runtimeModel.nodeDictionary[resnode], FlowInstance.PreviousId);//ǰڵִеϢ + flowInstance.PreviousId = flowInstance.ActivityId; + flowInstance.ActivityId = resnode; + flowInstance.ActivityType = wfruntime.GetNodeType(resnode);//-1޷,0ǩʼ,1ǩ,2һڵ,4н + flowInstance.ActivityName = wfruntime.runtimeModel.nodes[resnode].name; + flowInstance.MakerList = GetMakerList(wfruntime.runtimeModel.nodes[resnode], flowInstance.PreviousId);//ǰڵִеϢ #region ת¼ processTransitionHistoryEntity = new FlowInstanceTransitionHistory(); processTransitionHistoryEntity.FromNodeId = wfruntime.runtimeModel.currentNodeId; @@ -502,11 +377,11 @@ namespace OpenAuth.App var data = new { SchemeContent = wfruntime.runtimeModel.schemeContentJson.ToString(), - frmData = (FlowInstance.FrmType == 0 ? wfruntime.runtimeModel.frmData : null) + frmData = (flowInstance.FrmType == 0 ? wfruntime.runtimeModel.frmData : null) }; - FlowInstanceOperationHistory.Content = "" + "todo name" + "" + wfruntime.runtimeModel.currentNode.name + "" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + ",ע" + description; + flowInstanceOperationHistory.Content = "" + "todo name" + "" + wfruntime.runtimeModel.currentNode.name + "" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + ",ע" + description; - SaveProcess(FlowInstance, FlowInstanceOperationHistory, processTransitionHistoryEntity); + SaveProcess(flowInstance, flowInstanceOperationHistory, processTransitionHistoryEntity); return true; } catch @@ -536,23 +411,20 @@ namespace OpenAuth.App string _makerList = ""; foreach (string item in _nodelist) { - _makerList = GetMakerList(wfruntime.runtimeModel.nodeDictionary[item], wfruntime.runtimeModel.flowInstanceId); + _makerList = GetMakerList(wfruntime.runtimeModel.nodes[item], wfruntime.runtimeModel.flowInstanceId); if (_makerList == "-1") { throw (new Exception("޷Ѱҵǩڵ,鿴Ƿ!")); } - else if (_makerList == "1") + if (_makerList == "1") { throw (new Exception("ǩڵ߲Ϊ,鿴Ƿ!")); } - else + if (makerList != "") { - if (makerList != "") - { - makerList += ","; - } - makerList += _makerList; + makerList += ","; } + makerList += _makerList; } } else @@ -722,19 +594,11 @@ namespace OpenAuth.App throw; } } - - - public void Add(FlowInstance instance) - { - Repository.Add(instance); - } + public void Update(FlowInstance flowScheme) { - Repository.Update(u => u.Id == flowScheme.Id, u => new FlowInstance - { - //todo:Ҫ޸ĵ - }); + Repository.Update(u => u.Id == flowScheme.Id, u => new FlowInstance()); } public TableData Load(QueryFlowInstanceListReq request) diff --git a/OpenAuth.App/OpenAuth.App.csproj b/OpenAuth.App/OpenAuth.App.csproj index 38db1ecb..bbfd3b78 100644 --- a/OpenAuth.App/OpenAuth.App.csproj +++ b/OpenAuth.App/OpenAuth.App.csproj @@ -108,7 +108,6 @@ - diff --git a/OpenAuth.Mvc/Controllers/FlowInstancesController.cs b/OpenAuth.Mvc/Controllers/FlowInstancesController.cs index 4dea0db6..be3af167 100644 --- a/OpenAuth.Mvc/Controllers/FlowInstancesController.cs +++ b/OpenAuth.Mvc/Controllers/FlowInstancesController.cs @@ -47,8 +47,7 @@ namespace OpenAuth.Mvc.Controllers { try { - App.Add(obj); - + App.CreateInstance(obj, null); } catch (Exception ex) { diff --git a/OpenAuth.UnitTest/TestWorkflow.cs b/OpenAuth.UnitTest/TestWorkflow.cs index 5c1c6383..5a972dae 100644 --- a/OpenAuth.UnitTest/TestWorkflow.cs +++ b/OpenAuth.UnitTest/TestWorkflow.cs @@ -25,10 +25,7 @@ namespace OpenAuth.UnitTest [TestMethod] public void AddProcessInstance() { - string name = "请假" + DateTime.Now.ToString("yy-mm-dd_HH_mm_ss"); - string str ="{\"Code\":\"请病假\",\"CustomName\":\""+name+"\",\"wfLevel1\":\"1\",\"wfLevel2\":\"2\",\"wfLevel3\":\"3\",\"Description\":\" \",\"EnabledMark\":1,\"wfLevel\":\"2\"}"; - string frmData ="{\"4fcd4c6f-eb6b-6a6d-eb4e-7948763c5bba\":\"\",\"88061dda-642e-bcdb-909b-cea2bbe5ad69\":\" \"}"; - _runApp.CreateInstance(string.Empty, (string)("5f0ca3df-390a-4bd7-aecb-5304bf2d191c"), str.ToObject(), frmData); + } }