protected void RunEndFlowEvent(FlowContent flowContent) { if (this.endFlow != null) { this.endFlow(flowContent); } }
/// <summary> /// 获取申请节点后的节点 /// </summary> /// <returns></returns> private List <FlowNode> GetFirstNode() { List <FlowNode> firstNodeList = new List <FlowNode>(); List <WF_TemplateNode> nodelist = nodebll.getAllByTmpKey(this.Tmpkey); List <WF_Rule> rulelist = rulebll.getAllByTmpKey(this.Tmpkey); WF_TemplateNode beginNode = null; if (nodelist != null && nodelist.Count > 0) { foreach (WF_TemplateNode item in nodelist) { if (item.NodeType == (int)WFNodeType.BeginNode) { beginNode = item; break; } } } if (beginNode != null) { FlowNode firstnode = NodeFactory.getFlowNode(beginNode.Tmpkey, beginNode.Nodekey, this.endFlow); FlowContent flowcontent = new FlowContent(); flowcontent.CurrentInstanceID = this.InstanceID; firstNodeList = firstnode.GetNextNode(flowcontent); } return(firstNodeList); }
public List <FlowNode> GetNextNode(FlowContent flowContent) { List <WF_Rule> ruleList = rulebll.getRuleByTmpKeyAndBeginNodeKey(this.TmpKey, this.NodeKey); List <WF_InstanceVariable> varlist = varbll.getbyInstanceID(flowContent.CurrentInstanceID); List <WF_Rule> enableRule = new List <WF_Rule>(); List <Val> val = new List <Val>(); List <WF_TemplateNode> tmpNodeList = new List <WF_TemplateNode>(); List <FlowNode> flowNodeList = new List <FlowNode>(); if (varlist != null && varlist.Count > 0) { foreach (WF_InstanceVariable item in varlist) { Val v = new Val(); v.name = item.VarName; v.type = item.VarType; v.value = item.DefaultValue; val.Add(v); } } if (ruleList != null && ruleList.Count > 0) { foreach (WF_Rule item in ruleList) { if (RuleEngine.IsConformExpress(val, item.Expression)) { enableRule.Add(item); } } } if (enableRule != null && enableRule.Count > 0) { foreach (WF_Rule item in enableRule) { WF_TemplateNode afternode = nodebll.getByNodeKey(this.TmpKey, item.EndNodekey); tmpNodeList.Add(afternode); } } if (tmpNodeList != null && tmpNodeList.Count > 0) { foreach (WF_TemplateNode item in tmpNodeList) { FlowNode fn = NodeFactory.getFlowNode(item.Tmpkey, item.Nodekey, this.endFlow); flowNodeList.Add(fn); } } return(flowNodeList); }
public abstract NodeReturn Run(FlowContent flowContent);
/// <summary> /// 流程启动 /// </summary> /// <param name="vallist">流程实例变量</param> /// <param name="applyUserCode">申请人员工编号</param> /// <param name="writerUserCode">填表人员工编号</param> /// <param name="formID">单据编号</param> public void StartFlow(Dictionary <string, string> vallist, string applyUserCode, string writerUserCode, string formID) { //插入流程实例 int instanceID = this.InsertInstance((int)WF.Common.InstanceState.Enable, formID, this.CurrenUserCode, writerUserCode, applyUserCode); WF_Template tmp = tmpbll.getByKey(this.Tmpkey); this.InstanceID = instanceID; this.ApplyUserCode = applyUserCode; this.WriterUserCode = writerUserCode; this.FormID = formID; this.InstanceState = (int)WF.Common.InstanceState.Enable; //触发启动前事件 FlowContent flowcontent = new FlowContent(); flowcontent.CurrenUserCode = this.CurrenUserCode; flowcontent.TmpKey = this.Tmpkey; flowcontent.CurrentInstanceID = instanceID; flowcontent.OperationType = (int)Common.Operation.Start; flowcontent.TaskName = tmp.TmpName; flowcontent.InstanceState = (int)WF.Common.InstanceState.Enable; flowcontent.CurrentNodeKey = ""; flowcontent.FormID = formID; if (this.beforStartFlow != null) { this.beforStartFlow(flowcontent); } //更新流程变量 FlowVar var = new FlowVar(this.Tmpkey, instanceID); //先将流程模板变量copy到流程实例 var.copyVarByTmpKey(this.CurrenUserCode); //更新流程实例的变量 var.UpdateVal(vallist, this.CurrenUserCode); //获取第一个节点 List <FlowNode> firstNode = this.GetFirstNode(); //获取当前待办人的编号 List <string> newtodis = new List <string>(); List <string> newnodekey = new List <string>(); if (firstNode != null && firstNode.Count > 0) { foreach (FlowNode node in firstNode) { NodeReturn noderet = node.Run(flowcontent); if (!noderet.isOver) { newnodekey.Add(node.NodeKey); List <string> userCodeList = noderet.ToDoUserList; //循环遍历插入待办 if (userCodeList != null && userCodeList.Count > 0) { foreach (string item in userCodeList) { int todoid = ToDoHandle.InsertTodo(item.Trim(), instanceID, (int)TodoIsShow.Show, -1, flowcontent.TaskName, (int)TodoType.Normal, node, node.NodeKey, CurrenUserCode); newtodis.Add(todoid.ToString()); } } } } } operationbll.Insert(instanceID, -1, CurrenUserCode, (int)Common.Operation.Start, "启动流程"); flowcontent.CurrentNodeKey = string.Join(", ", newnodekey);; flowcontent.CurrentTodoID = string.Join(", ", newtodis); //触发启动后事件 if (this.afterStartFlow != null) { this.afterStartFlow(flowcontent); } }
/// <summary> /// 加签 /// </summary> /// <param name="vallist"></param> /// <param name="befortodoID"></param> /// <param name="operationUserCode"></param> /// <param name="operationType"></param> /// <param name="common"></param> /// <param name="flowcontent"></param> /// <param name="node"></param> /// <param name="toNodeKey"></param> private void Add(Dictionary <string, string> vallist, int befortodoID, string operationUserCode, Operation operationType, string common, FlowContent flowcontent, FlowNode node, string todoUserCode) { ToDoHandle.DealTodo((int)operationType, operationUserCode, befortodoID); FlowVar var = new FlowVar(flowcontent.TmpKey, flowcontent.CurrentInstanceID); var.UpdateVal(vallist, this.CurrenUserCode); //获取当前待办人的编号 List <string> newtodis = new List <string>(); List <string> newnodekey = new List <string>(); int todoid = ToDoHandle.InsertTodo(todoUserCode.Trim(), flowcontent.CurrentInstanceID, (int)TodoIsShow.Show, befortodoID, flowcontent.TaskName, (int)TodoType.Add, node, node.NodeKey, CurrenUserCode); newtodis.Add(todoid.ToString()); flowcontent.CurrentTodoID = string.Join(", ", newtodis); flowcontent.CurrentNodeKey = node.NodeKey; operationbll.Insert(flowcontent.CurrentInstanceID, befortodoID, CurrenUserCode, (int)operationType, common); //插入转签历史记录 WF_Sign sign = new WF_Sign(); sign.AfterToDoID = todoid; sign.beforeToDoID = befortodoID; sign.IsDelete = (int)IsDelete.UnDelete; sign.State = (int)State.Enable; sign.OperationTime = DateTime.Now; sign.OperationUserCode = operationUserCode; Employee emp = empbll.getbyUserCode(operationUserCode); if (emp != null) { sign.OperationUserName = emp.UserName; } signbll.save(sign); }
/// <summary> /// 驳回 /// </summary> /// <param name="vallist"></param> /// <param name="todoID"></param> /// <param name="operationUserCode"></param> /// <param name="operationType"></param> /// <param name="common"></param> /// <param name="flowcontent"></param> /// <param name="node"></param> /// <param name="toNodeKey"></param> private void Reject(Dictionary <string, string> vallist, int todoID, string operationUserCode, Operation operationType, string common, FlowContent flowcontent, FlowNode node, string toNodeKey) { ToDoHandle.DealTodo((int)operationType, operationUserCode, todoID); FlowVar var = new FlowVar(flowcontent.TmpKey, flowcontent.CurrentInstanceID); var.UpdateVal(vallist, this.CurrenUserCode); List <WF_ToDo> undolist = todobll.getList(flowcontent.CurrentInstanceID, node.NodeKey, (int)TodoState.UnDo); if (undolist != null && undolist.Count > 0) { foreach (WF_ToDo item in undolist) { ToDoHandle.DeleteTodo((int)operationType, operationUserCode, item.ID); } } WF_TemplateNode tmpnode = nodebll.getByNodeKey(flowcontent.TmpKey, node.NodeKey); if (tmpnode.IsGoBack == 0) { throw new Exception("改节点禁止退回"); } if (tmpnode.GoBackType == "every") { if (string.IsNullOrWhiteSpace(toNodeKey)) { throw new Exception("请选择需要退回到哪一个节点"); } } else { toNodeKey = tmpnode.GoBackType; } FlowNode toNode = NodeFactory.getFlowNode(flowcontent.TmpKey, toNodeKey, this.endFlow); NodeReturn ret = toNode.Run(flowcontent); //获取当前待办人的编号 List <string> newtodis = new List <string>(); List <string> newnodekey = new List <string>(); if (!ret.isOver) { List <string> userCodeList = ret.ToDoUserList; //循环遍历插入待办 if (userCodeList != null && userCodeList.Count > 0) { foreach (string user in userCodeList) { int todoid = ToDoHandle.InsertTodo(user.Trim(), flowcontent.CurrentInstanceID, (int)TodoIsShow.Show, -1, flowcontent.TaskName, (int)TodoType.Normal, toNode, toNode.NodeKey, CurrenUserCode); newtodis.Add(todoid.ToString()); } } flowcontent.CurrentTodoID = string.Join(", ", newtodis); flowcontent.CurrentNodeKey = toNodeKey; } operationbll.Insert(flowcontent.CurrentInstanceID, todoID, CurrenUserCode, (int)operationType, common); }
/// <summary> /// 跳转 /// </summary> /// <param name="vallist"></param> /// <param name="todoID"></param> /// <param name="operationUserCode"></param> /// <param name="operationType"></param> /// <param name="common"></param> /// <param name="flowcontent"></param> /// <param name="node"></param> private void GoTo(Dictionary <string, string> vallist, int todoID, string operationUserCode, Operation operationType, string common, FlowContent flowcontent, FlowNode node, string toNodeKey) { ToDoHandle.DealTodo((int)operationType, operationUserCode, todoID); FlowVar var = new FlowVar(flowcontent.TmpKey, flowcontent.CurrentInstanceID); var.UpdateVal(vallist, this.CurrenUserCode); List <WF_ToDo> undolist = todobll.getList(flowcontent.CurrentInstanceID, node.NodeKey, (int)TodoState.UnDo); if (undolist != null && undolist.Count > 0) { foreach (WF_ToDo item in undolist) { ToDoHandle.DeleteTodo((int)operationType, operationUserCode, item.ID); } } FlowNode toNode = NodeFactory.getFlowNode(flowcontent.TmpKey, toNodeKey, this.endFlow); NodeReturn ret = toNode.Run(flowcontent); //获取当前待办人的编号 List <string> newtodis = new List <string>(); List <string> newnodekey = new List <string>(); if (!ret.isOver) { List <string> userCodeList = ret.ToDoUserList; //循环遍历插入待办 if (userCodeList != null && userCodeList.Count > 0) { foreach (string user in userCodeList) { int todoid = ToDoHandle.InsertTodo(user.Trim(), flowcontent.CurrentInstanceID, (int)TodoIsShow.Show, -1, flowcontent.TaskName, (int)TodoType.Normal, toNode, toNode.NodeKey, CurrenUserCode); newtodis.Add(todoid.ToString()); } } flowcontent.CurrentTodoID = string.Join(", ", newtodis); flowcontent.CurrentNodeKey = toNodeKey; } operationbll.Insert(flowcontent.CurrentInstanceID, todoID, CurrenUserCode, (int)operationType, common); }
/// <summary> /// 同意转签类型 /// </summary> /// <param name="vallist"></param> /// <param name="todoID"></param> /// <param name="operationUserCode"></param> /// <param name="operationType"></param> /// <param name="common"></param> /// <param name="flowcontent"></param> /// <param name="node"></param> private void ApplyTransfer(Dictionary <string, string> vallist, int todoID, string operationUserCode, Operation operationType, string common, FlowContent flowcontent, FlowNode node) { //NodeReturn ret = node.Run(flowcontent); WF_ToDo preTodo = todobll.getPreTransferTodo(todoID); if (preTodo != null) { //int newtodiid = ToDoHandle.Reopen(preTodo.ResponseUserCode, preTodo.InstanceID, preTodo.IsShow, preTodo.PrevID, preTodo.ToDoName, preTodo.TodoType, node, preTodo.Nodekey, operationUserCode); //flowcontent.CurrentTodoID = string.Join(", ", newtodiid); if (preTodo.TodoType == (int)TodoType.Normal) { FlowNode befornode = NodeFactory.getFlowNode(flowcontent.TmpKey, preTodo.Nodekey, this.endFlow); NodeReturn ret = befornode.Run(flowcontent); //获取当前待办人的编号 List <string> newtodis = new List <string>(); List <string> newnodekey = new List <string>(); if (ret.isOver) { List <FlowNode> nextNode = befornode.GetNextNode(flowcontent); if (nextNode != null && nextNode.Count > 0) { foreach (FlowNode nxitem in nextNode) { NodeReturn noderet = nxitem.Run(flowcontent); if (!noderet.isOver) { newnodekey.Add(nxitem.NodeKey); List <string> userCodeList = noderet.ToDoUserList; //循环遍历插入待办 if (userCodeList != null && userCodeList.Count > 0) { foreach (string user in userCodeList) { int todoid = ToDoHandle.InsertTodo(user.Trim(), flowcontent.CurrentInstanceID, (int)TodoIsShow.Show, -1, flowcontent.TaskName, (int)TodoType.Normal, nxitem, nxitem.NodeKey, CurrenUserCode); newtodis.Add(todoid.ToString()); } } } } } flowcontent.CurrentNodeKey = string.Join(", ", newnodekey); flowcontent.CurrentTodoID = string.Join(", ", newtodis); } else { List <string> userCodeList = ret.ToDoUserList; //循环遍历插入待办 if (userCodeList != null && userCodeList.Count > 0) { foreach (string user in userCodeList) { int todoid = ToDoHandle.InsertTodo(user.Trim(), flowcontent.CurrentInstanceID, (int)TodoIsShow.Show, -1, flowcontent.TaskName, (int)TodoType.Normal, befornode, befornode.NodeKey, CurrenUserCode); newtodis.Add(todoid.ToString()); } } newnodekey.Add(befornode.NodeKey); flowcontent.CurrentNodeKey = string.Join(", ", newnodekey); flowcontent.CurrentTodoID = string.Join(", ", newtodis); } } if (preTodo.TodoType == (int)TodoType.Add) { WF_ToDo beforTodo = todobll.getPreAddTodo(todoID); while (beforTodo.TodoType == (int)TodoType.Add) { beforTodo = todobll.getPreAddTodo(beforTodo.ID); } FlowNode befornode = NodeFactory.getFlowNode(flowcontent.TmpKey, beforTodo.Nodekey, this.endFlow); int newtodiid = ToDoHandle.Reopen(beforTodo.ResponseUserCode, beforTodo.InstanceID, beforTodo.IsShow, beforTodo.PrevID, beforTodo.ToDoName, beforTodo.TodoType, befornode, beforTodo.Nodekey, operationUserCode); flowcontent.CurrentTodoID = string.Join(", ", newtodiid); } if (preTodo.TodoType == (int)TodoType.Redirect) { ApplyTransfer(vallist, preTodo.ID, operationUserCode, operationType, common, flowcontent, node); } } }
/// <summary> /// 同意 /// </summary> /// <param name="vallist"></param> /// <param name="todoID"></param> /// <param name="operationUserCode"></param> /// <param name="operationType"></param> /// <param name="common"></param> /// <param name="flowcontent"></param> /// <param name="node"></param> private void Apply(Dictionary <string, string> vallist, int todoID, string operationUserCode, Operation operationType, string common, FlowContent flowcontent, FlowNode node) { ToDoHandle.DealTodo((int)operationType, operationUserCode, todoID); FlowVar var = new FlowVar(flowcontent.TmpKey, flowcontent.CurrentInstanceID); var.UpdateVal(vallist, this.CurrenUserCode); WF_ToDo todo = todobll.getByID(todoID); // 加签类型 if (todo.TodoType == (int)TodoType.Add) { WF_ToDo nextodo = todobll.getPreAddTodo(todoID); int newtodiid = ToDoHandle.Reopen(nextodo.ResponseUserCode, nextodo.InstanceID, nextodo.IsShow, nextodo.PrevID, nextodo.ToDoName, nextodo.TodoType, node, nextodo.Nodekey, operationUserCode); flowcontent.CurrentTodoID = string.Join(", ", newtodiid); } //todo 转签处理,如果找到最近一个加签类型,然后生成加签待办,如果不是从加签转过来的,就直接到下一个节点 if (todo.TodoType == (int)TodoType.Redirect) { ApplyTransfer(vallist, todoID, operationUserCode, operationType, common, flowcontent, node); } // 一般同意 转签类型 if (todo.TodoType == (int)TodoType.Normal) { NodeReturn ret = node.Run(flowcontent); //获取当前待办人的编号 List <string> newtodis = new List <string>(); List <string> newnodekey = new List <string>(); if (ret.isOver) { List <FlowNode> nextNode = node.GetNextNode(flowcontent); if (nextNode != null && nextNode.Count > 0) { foreach (FlowNode nxitem in nextNode) { NodeReturn noderet = nxitem.Run(flowcontent); if (!noderet.isOver) { newnodekey.Add(nxitem.NodeKey); List <string> userCodeList = noderet.ToDoUserList; //循环遍历插入待办 if (userCodeList != null && userCodeList.Count > 0) { foreach (string user in userCodeList) { int todoid = ToDoHandle.InsertTodo(user.Trim(), flowcontent.CurrentInstanceID, (int)TodoIsShow.Show, -1, flowcontent.TaskName, (int)TodoType.Normal, nxitem, nxitem.NodeKey, CurrenUserCode); newtodis.Add(todoid.ToString()); } } } } } flowcontent.CurrentNodeKey = string.Join(", ", newnodekey); flowcontent.CurrentTodoID = string.Join(", ", newtodis); } else { List <string> userCodeList = ret.ToDoUserList; //循环遍历插入待办 if (userCodeList != null && userCodeList.Count > 0) { foreach (string user in userCodeList) { int todoid = ToDoHandle.InsertTodo(user.Trim(), flowcontent.CurrentInstanceID, (int)TodoIsShow.Show, -1, flowcontent.TaskName, (int)TodoType.Normal, node, node.NodeKey, CurrenUserCode); newtodis.Add(todoid.ToString()); } } newnodekey.Add(node.NodeKey); flowcontent.CurrentNodeKey = string.Join(", ", newnodekey); flowcontent.CurrentTodoID = string.Join(", ", newtodis); } } operationbll.Insert(flowcontent.CurrentInstanceID, todoID, CurrenUserCode, (int)operationType, common); }
/// <summary> /// 待办处理操作 /// </summary> /// <param name="vallist">流程实例变量</param> /// <param name="todoID">待办id</param> /// <param name="operationUserCode">操作人工号 </param> /// <param name="operationType">操作类型</param> public void Operation(Dictionary <string, string> vallist, int todoID, string operationUserCode, Operation operationType, string common = null, string toNodeKey = null, string todoUserCode = null) { //禁止流程启动 if (operationType == Common.Operation.Start) { throw new Exception("不能执行流程启动操作"); } WF_ToDo todo = todobll.getByID(todoID); WF_Instance instance = instancebll.getByID(todo.InstanceID); if (instance.State != (int)Common.InstanceState.Enable) { throw new Exception("当前流程实例状态不是启用状态"); } if (todo.ResponseUserCode != operationUserCode) { List <WF_Agent> agentlist = agentBll.getAgentByOrg(todo.ResponseUserCode); if (agentlist == null || agentlist.Count == 0 || agentlist.Where(p => p.AgentUserCode == operationUserCode).Count() == 0) { throw new Exception("当前操作人不是待办责任人,也不是待办责任人的代理人"); } } if (todo.State != (int)Common.TodoState.UnDo) { throw new Exception("当前待办已经被处理了"); } FlowContent flowcontent = new FlowContent(); flowcontent.CurrenUserCode = operationUserCode; flowcontent.TmpKey = this.Tmpkey; flowcontent.CurrentInstanceID = todo.InstanceID; flowcontent.OperationType = (int)Common.Operation.Start; flowcontent.TaskName = todo.ToDoName; flowcontent.InstanceState = instance.State; flowcontent.CurrentNodeKey = todo.Nodekey; flowcontent.OperationType = (int)operationType; flowcontent.CurrentTodoID = todo.ID.ToString(); flowcontent.FormID = instance.FormID; if (this.beforOperation != null) { this.beforOperation(flowcontent); } FlowNode node = NodeFactory.getFlowNode(instance.TmpKey, todo.Nodekey, this.endFlow); // 处理 同意 if (operationType == Common.Operation.Agree) { this.Apply(vallist, todoID, operationUserCode, operationType, common, flowcontent, node); } //todo 处理 撤回 //if (operationType == Common.Operation.CallBack) //{ //this.Apply(vallist, todoID, operationUserCode, operationType, common, flowcontent, node); //} // 处理 流程跳转 if (operationType == Common.Operation.GoTo) { this.GoTo(vallist, todoID, operationUserCode, operationType, common, flowcontent, node, toNodeKey); } //todo 处理 传阅 //if (operationType == Common.Operation.Read) //{ // this.Apply(vallist, todoID, operationUserCode, operationType, common, flowcontent, node); //} // 处理 驳回 if (operationType == Common.Operation.Reject) { this.Reject(vallist, todoID, operationUserCode, operationType, common, flowcontent, node, toNodeKey); } // 处理 转签 if (operationType == Common.Operation.Redirect) { this.Redirect(vallist, todoID, operationUserCode, operationType, common, flowcontent, node, todoUserCode); } // 处理 加签 if (operationType == Common.Operation.Add) { this.Add(vallist, todoID, operationUserCode, operationType, common, flowcontent, node, todoUserCode); } if (this.afterOperation != null) { this.afterOperation(flowcontent); } }