/// <summary> /// 创建一个实例 /// </summary> /// <returns></returns> public bool CreateInstance(JObject obj) { var flowInstance = obj.ToObject <FlowInstance>(); //获取提交的表单数据 var frmdata = new JObject(); foreach (var property in obj.Properties().Where(U => U.Name.Contains("data_"))) { frmdata[property.Name] = property.Value; } flowInstance.FrmData = JsonHelper.Instance.Serialize(frmdata); //创建运行实例 var wfruntime = new FlowRuntime(flowInstance); var user = _auth.GetCurrentUser(); #region 根据运行实例改变当前节点状态 flowInstance.ActivityId = wfruntime.nextNodeId; flowInstance.ActivityType = wfruntime.GetNextNodeType(); flowInstance.ActivityName = wfruntime.nextNode.name; flowInstance.PreviousId = wfruntime.currentNodeId; flowInstance.CreateUserId = user.User.Id; flowInstance.CreateUserName = user.User.Account; flowInstance.MakerList = (wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : ""); flowInstance.IsFinish = (wfruntime.GetNextNodeType() == 4 ? 1 : 0); UnitWork.Add(flowInstance); wfruntime.flowInstanceId = flowInstance.Id; #endregion 根据运行实例改变当前节点状态 #region 流程操作记录 FlowInstanceOperationHistory processOperationHistoryEntity = new FlowInstanceOperationHistory { InstanceId = flowInstance.Id, CreateUserId = user.User.Id, CreateUserName = user.User.Name, CreateDate = DateTime.Now, Content = "【创建】" + user.User.Name + "创建了一个流程进程【" + flowInstance.Code + "/" + flowInstance.CustomName + "】" }; UnitWork.Add(processOperationHistoryEntity); #endregion 流程操作记录 AddTransHistory(wfruntime); UnitWork.Save(); return(true); }
/// <summary> /// 重发一个实例 /// </summary> /// <param name="flowInstanceRepostDto"></param> /// <returns></returns> public virtual async Task RepostInstance(FlowInstanceRepostDto flowInstanceRepostDto) { var manager = Manager as FlowInstanceManager; var user = await GetCurrentUserAsync(); var flowInstance = await manager.GetByIdAsync(flowInstanceRepostDto.Id); flowInstance.FormData = flowInstanceRepostDto.FormData;//读取表单数据 //创建运行实例 var wfruntime = new FlowRuntime(flowInstance); #region 根据运行实例改变当前节点状态 flowInstance.ActivityId = wfruntime.nextNodeId; flowInstance.ActivityType = wfruntime.GetNextNodeType(); flowInstance.ActivityName = wfruntime.nextNode.name; flowInstance.PreviousId = wfruntime.currentNodeId; flowInstance.MakerList = (wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : ""); flowInstance.InstanceStatus = (wfruntime.GetNextNodeType() == 4 ? InstanceStatus.Finish : InstanceStatus.Processing); await manager.UpdateAsync(flowInstance); await CurrentUnitOfWork.SaveChangesAsync(); if (flowInstance.InstanceStatus == InstanceStatus.Finish) { await manager.FinishInstance(flowInstance);//调用流程结束事件 } wfruntime.flowInstanceId = flowInstance.Id; #endregion 根据运行实例改变当前节点状态 #region 流程操作记录 FlowInstanceOperationHistory processOperationHistoryEntity = new FlowInstanceOperationHistory { FlowInstanceId = flowInstance.Id, Content = "【重发】" + user.Name + "重发了一个流程进程【" + flowInstance.Code + "/" + flowInstance.InstanceName + "】" }; await FlowInstanceOperationHistoryRepository.InsertAsync(processOperationHistoryEntity); #endregion 流程操作记录 await AddTransHistory(wfruntime); }
/// <summary>启动流程</summary> /// <remarks> 通常是对状态为【草稿】的流程进行操作,进入运行状态 </remarks> public void Start(StartFlowInstanceReq request) { FlowInstance flowInstance = Get(request.FlowInstanceId); if (flowInstance.IsFinish != FlowInstanceStatus.Draft) { throw new Exception("当前流程不是草稿状态,不能启动"); } var wfruntime = new FlowRuntime(flowInstance); var user = _auth.GetCurrentUser(); #region 根据运行实例改变当前节点状态 flowInstance.ActivityId = wfruntime.nextNodeId; flowInstance.ActivityType = wfruntime.GetNextNodeType(); flowInstance.ActivityName = wfruntime.nextNode.name; flowInstance.PreviousId = wfruntime.currentNodeId; flowInstance.CreateUserId = user.User.Id; flowInstance.CreateUserName = user.User.Account; flowInstance.MakerList = (wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : ""); flowInstance.IsFinish = (wfruntime.GetNextNodeType() == 4 ? FlowInstanceStatus.Finished : FlowInstanceStatus.Running); UnitWork.Update(flowInstance); #endregion 根据运行实例改变当前节点状态 #region 流程操作记录 FlowInstanceOperationHistory processOperationHistoryEntity = new FlowInstanceOperationHistory { InstanceId = flowInstance.Id, CreateUserId = user.User.Id, CreateUserName = user.User.Name, CreateDate = DateTime.Now, Content = $"【启动】由用户{user.User.Name}启动" }; UnitWork.Add(processOperationHistoryEntity); #endregion 流程操作记录 AddTransHistory(wfruntime); UnitWork.Save(); }
/// <summary> /// 节点审核 /// </summary> /// <param name="instanceId"></param> /// <returns></returns> public bool NodeVerification(string instanceId, Tag tag) { FlowInstance flowInstance = Get(instanceId); FlowInstanceOperationHistory flowInstanceOperationHistory = new FlowInstanceOperationHistory { InstanceId = instanceId, CreateUserId = tag.UserId, CreateUserName = tag.UserName, CreateDate = DateTime.Now };//操作记录 FlowRuntime wfruntime = new FlowRuntime(flowInstance); #region 会签 if (flowInstance.ActivityType == 0)//当前节点是会签节点 { //TODO: 标记会签节点的状态,这个地方感觉怪怪的 wfruntime.MakeTagNode(wfruntime.currentNodeId, tag); string canCheckId = ""; //寻找当前登录用户可审核的节点Id foreach (string nodeId in wfruntime.FromNodeLines[wfruntime.currentNodeId].Select(u => u.to)) { var makerList = GetNodeMakers(wfruntime.Nodes[nodeId]); if (string.IsNullOrEmpty(makerList)) { continue; } if (makerList.Split(',').Any(one => tag.UserId == one)) { canCheckId = nodeId; } } if (canCheckId == "") { throw (new Exception("审核异常,找不到审核节点")); } flowInstanceOperationHistory.Content = "【" + wfruntime.Nodes[canCheckId].name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",备注:" + tag.Description; wfruntime.MakeTagNode(canCheckId, tag); //标记审核节点状态 string res = wfruntime.NodeConfluence(canCheckId, tag); if (res == TagState.No.ToString("D")) { flowInstance.IsFinish = 3; } else if (!string.IsNullOrEmpty(res)) { flowInstance.PreviousId = flowInstance.ActivityId; flowInstance.ActivityId = wfruntime.nextNodeId; flowInstance.ActivityType = wfruntime.nextNodeType; flowInstance.ActivityName = wfruntime.nextNode.name; flowInstance.IsFinish = (wfruntime.nextNodeType == 4 ? 1 : 0); flowInstance.MakerList = (wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime)); AddTransHistory(wfruntime); } } #endregion 会签 #region 一般审核 else { wfruntime.MakeTagNode(wfruntime.currentNodeId, tag); if (tag.Taged == (int)TagState.Ok) { flowInstance.PreviousId = flowInstance.ActivityId; flowInstance.ActivityId = wfruntime.nextNodeId; flowInstance.ActivityType = wfruntime.nextNodeType; flowInstance.ActivityName = wfruntime.nextNode.name; flowInstance.MakerList = wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime); flowInstance.IsFinish = (wfruntime.nextNodeType == 4 ? 1 : 0); AddTransHistory(wfruntime); } else { flowInstance.IsFinish = 3; //表示该节点不同意 } flowInstanceOperationHistory.Content = "【" + wfruntime.currentNode.name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",备注:" + tag.Description; } #endregion 一般审核 flowInstance.SchemeContent = JsonHelper.Instance.Serialize(wfruntime.ToSchemeObj()); UnitWork.Update(flowInstance); UnitWork.Add(flowInstanceOperationHistory); UnitWork.Save(); return(true); }
/// <summary> /// 节点审核 /// </summary> /// <param name="instanceId"></param> /// <returns></returns> public bool NodeVerification(string instanceId, bool flag, string description = "") { var user = AuthUtil.GetCurrentUser().User; FlowInstance flowInstance = Get(instanceId); FlowInstanceOperationHistory flowInstanceOperationHistory = new FlowInstanceOperationHistory { InstanceId = instanceId, CreateUserId = user.Id, CreateUserName = user.Name, CreateDate = DateTime.Now };//操作记录 FlowRuntime wfruntime = new FlowRuntime(flowInstance); var tag = new Tag { UserName = user.Name, UserId = user.Id, Description = description }; #region 会签 if (flowInstance.ActivityType == 0)//当前节点是会签节点 { tag.Taged = 1; wfruntime.MakeTagNode(wfruntime.runtimeModel.currentNodeId, tag); //标记会签节点状态 string verificationNodeId = ""; //寻找当前登陆用户可审核的节点Id List <string> nodelist = wfruntime.GetCountersigningNodeIdList(wfruntime.runtimeModel.currentNodeId); foreach (string item in nodelist) { var makerList = GetMakerList(wfruntime.runtimeModel.nodes[item] , wfruntime.runtimeModel.flowInstanceId); if (makerList == "-1") { continue; } if (makerList.Split(',').Any(one => user.Id == one)) { verificationNodeId = item; } } if (verificationNodeId != "") { if (flag) { tag.Taged = 1; flowInstanceOperationHistory.Content = "【" + wfruntime.runtimeModel.nodes[verificationNodeId].name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】同意,备注:" + description; } else { tag.Taged = -1; 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": //等待,当前节点还是会签开始节点,不跳转 break; default: //通过 flowInstance.PreviousId = flowInstance.ActivityId; flowInstance.ActivityId = wfruntime.runtimeModel.nextNodeId; flowInstance.ActivityType = wfruntime.runtimeModel.nextNodeType; //-1无法运行,0会签开始,1会签结束,2一般节点,4流程运行结束 flowInstance.ActivityName = wfruntime.runtimeModel.nextNode.name; flowInstance.IsFinish = (wfruntime.runtimeModel.nextNodeType == 4 ? 1 : 0); flowInstance.MakerList = (wfruntime.runtimeModel.nextNodeType == 4 ? "" : GetMakerList(wfruntime)); //当前节点可执行的人信息 #region 流转记录 UnitWork.Add(new FlowInstanceTransitionHistory { InstanceId = flowInstance.Id, CreateUserId = user.Id, CreateUserName = user.Name, FromNodeId = wfruntime.runtimeModel.currentNodeId, FromNodeName = wfruntime.runtimeModel.currentNode.name, FromNodeType = wfruntime.runtimeModel.currentNodeType, ToNodeId = wfruntime.runtimeModel.nextNodeId, ToNodeName = wfruntime.runtimeModel.nextNode.name, ToNodeType = wfruntime.runtimeModel.nextNodeType, IsFinish = wfruntime.runtimeModel.nextNodeType == 4?1:0, TransitionSate = 0 }); #endregion break; } } else { throw (new Exception("审核异常,找不到审核节点")); } } #endregion #region 一般审核 else//一般审核 { if (flag) { tag.Taged = 1; wfruntime.MakeTagNode(wfruntime.runtimeModel.currentNodeId, tag); flowInstance.PreviousId = flowInstance.ActivityId; flowInstance.ActivityId = wfruntime.runtimeModel.nextNodeId; flowInstance.ActivityType = wfruntime.runtimeModel.nextNodeType; flowInstance.ActivityName = wfruntime.runtimeModel.nextNode.name; flowInstance.MakerList = wfruntime.runtimeModel.nextNodeType == 4 ? "" : GetMakerList(wfruntime);//当前节点可执行的人信息 flowInstance.IsFinish = (wfruntime.runtimeModel.nextNodeType == 4 ? 1 : 0); #region 流转记录 UnitWork.Add(new FlowInstanceTransitionHistory { InstanceId = flowInstance.Id, CreateUserId = user.Id, CreateUserName = user.Name, FromNodeId = wfruntime.runtimeModel.currentNodeId, FromNodeName = wfruntime.runtimeModel.currentNode.name, FromNodeType = wfruntime.runtimeModel.currentNodeType, ToNodeId = wfruntime.runtimeModel.nextNodeId, ToNodeName = wfruntime.runtimeModel.nextNode.name, ToNodeType = wfruntime.runtimeModel.nextNodeType, IsFinish = wfruntime.runtimeModel.nextNodeType == 4 ? 1 : 0, TransitionSate = 0 }); #endregion flowInstanceOperationHistory.Content = "【" + wfruntime.runtimeModel.currentNode.name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】同意,备注:" + description; } else { flowInstance.IsFinish = 3; //表示该节点不同意 tag.Taged = -1; wfruntime.MakeTagNode(wfruntime.runtimeModel.currentNodeId, tag); flowInstanceOperationHistory.Content = "【" + wfruntime.runtimeModel.currentNode.name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】不同意,备注:" + description; } } #endregion flowInstance.SchemeContent = JsonHelper.Instance.Serialize(wfruntime.runtimeModel.schemeContentJson); UnitWork.Update(flowInstance); UnitWork.Add(flowInstanceOperationHistory); UnitWork.Save(); return(true); }
/// <summary> /// 创建一个实例 /// </summary> /// <returns></returns> public bool CreateInstance(AddFlowInstanceReq addFlowInstanceReq) { FlowScheme scheme = null; if (!string.IsNullOrEmpty(addFlowInstanceReq.SchemeId)) { scheme = _flowSchemeApp.Get(addFlowInstanceReq.SchemeId); } if ((scheme == null) && !string.IsNullOrEmpty(addFlowInstanceReq.SchemeCode)) { scheme = _flowSchemeApp.FindByCode(addFlowInstanceReq.SchemeCode); } if (scheme == null) { throw new Exception("该流程模板已不存在,请重新设计流程"); } addFlowInstanceReq.SchemeContent = scheme.SchemeContent; var form = _formApp.FindSingle(scheme.FrmId); if (form == null) { throw new Exception("该流程模板对应的表单已不存在,请重新设计流程"); } addFlowInstanceReq.FrmContentData = form.ContentData; addFlowInstanceReq.FrmContentParse = form.ContentParse; addFlowInstanceReq.FrmType = form.FrmType; addFlowInstanceReq.FrmId = form.Id; var flowInstance = addFlowInstanceReq.MapTo <FlowInstance>(); //创建运行实例 var wfruntime = new FlowRuntime(flowInstance); var user = _auth.GetCurrentUser(); #region 根据运行实例改变当前节点状态 flowInstance.ActivityId = wfruntime.nextNodeId; flowInstance.ActivityType = wfruntime.GetNextNodeType(); flowInstance.ActivityName = wfruntime.nextNode.name; flowInstance.PreviousId = wfruntime.currentNodeId; flowInstance.CreateUserId = user.User.Id; flowInstance.CreateUserName = user.User.Account; flowInstance.MakerList = (wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : ""); flowInstance.IsFinish = (wfruntime.GetNextNodeType() == 4 ? 1 : 0); UnitWork.Add(flowInstance); wfruntime.flowInstanceId = flowInstance.Id; if (flowInstance.FrmType == 1) { var t = Type.GetType("OpenAuth.App." + flowInstance.DbName + "App"); ICustomerForm icf = (ICustomerForm)_serviceProvider.GetService(t); icf.Add(flowInstance.Id, flowInstance.FrmData); } #endregion 根据运行实例改变当前节点状态 #region 流程操作记录 FlowInstanceOperationHistory processOperationHistoryEntity = new FlowInstanceOperationHistory { InstanceId = flowInstance.Id, CreateUserId = user.User.Id, CreateUserName = user.User.Name, CreateDate = DateTime.Now, Content = "【创建】" + user.User.Name + "创建了一个流程进程【" + addFlowInstanceReq.Code + "/" + addFlowInstanceReq.CustomName + "】" }; UnitWork.Add(processOperationHistoryEntity); #endregion 流程操作记录 AddTransHistory(wfruntime); UnitWork.Save(); return(true); }
/// <summary> /// 节点审核 /// </summary> /// <param name="instanceId"></param> /// <returns></returns> public bool NodeVerification(VerificationReq request) { var user = _auth.GetCurrentUser().User; var instanceId = request.FlowInstanceId; var tag = new Tag { UserName = user.Name, UserId = user.Id, Description = request.VerificationOpinion, Taged = Int32.Parse(request.VerificationFinally) }; FlowInstance flowInstance = Get(instanceId); if (flowInstance.MakerList != "1" && !flowInstance.MakerList.Contains(user.Id)) { throw new Exception("当前用户没有审批该节点权限"); } FlowInstanceOperationHistory flowInstanceOperationHistory = new FlowInstanceOperationHistory { InstanceId = instanceId, CreateUserId = tag.UserId, CreateUserName = tag.UserName, CreateDate = DateTime.Now }; //操作记录 FlowRuntime wfruntime = new FlowRuntime(flowInstance); #region 会签 if (flowInstance.ActivityType == 0) //当前节点是会签节点 { //会签时的【当前节点】一直是会签开始节点 //TODO: 标记会签节点的状态,这个地方感觉怪怪的 wfruntime.MakeTagNode(wfruntime.currentNodeId, tag); string canCheckId = ""; //寻找当前登录用户可审核的节点Id foreach (string fromForkStartNodeId in wfruntime.FromNodeLines[wfruntime.currentNodeId] .Select(u => u.to)) { var fromForkStartNode = wfruntime.Nodes[fromForkStartNodeId]; //与会前开始节点直接连接的节点 canCheckId = GetOneForkLineCanCheckNodeId(fromForkStartNode, wfruntime, tag); if (!string.IsNullOrEmpty(canCheckId)) { break; } } if (canCheckId == "") { throw (new Exception("审核异常,找不到审核节点")); } flowInstanceOperationHistory.Content = "【" + wfruntime.Nodes[canCheckId].name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",备注:" + tag.Description; wfruntime.MakeTagNode(canCheckId, tag); //标记审核节点状态 string res = wfruntime.NodeConfluence(canCheckId, tag); if (res == TagState.No.ToString("D")) { flowInstance.IsFinish = FlowInstanceStatus.Disagree; } else if (!string.IsNullOrEmpty(res)) { flowInstance.PreviousId = flowInstance.ActivityId; flowInstance.ActivityId = wfruntime.nextNodeId; flowInstance.ActivityType = wfruntime.nextNodeType; flowInstance.ActivityName = wfruntime.nextNode.name; flowInstance.IsFinish = (wfruntime.nextNodeType == 4 ? FlowInstanceStatus.Finished : FlowInstanceStatus.Running); flowInstance.MakerList = (wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime)); AddTransHistory(wfruntime); } else { //会签过程中,需要更新用户 flowInstance.MakerList = GetForkNodeMakers(wfruntime, wfruntime.currentNodeId); AddTransHistory(wfruntime); } } #endregion 会签 #region 一般审核 else { wfruntime.MakeTagNode(wfruntime.currentNodeId, tag); if (tag.Taged == (int)TagState.Ok) { flowInstance.PreviousId = flowInstance.ActivityId; flowInstance.ActivityId = wfruntime.nextNodeId; flowInstance.ActivityType = wfruntime.nextNodeType; flowInstance.ActivityName = wfruntime.nextNode.name; flowInstance.MakerList = wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime, request); flowInstance.IsFinish = (wfruntime.nextNodeType == 4 ? FlowInstanceStatus.Finished : FlowInstanceStatus.Running); AddTransHistory(wfruntime); } else { flowInstance.IsFinish = FlowInstanceStatus.Disagree; //表示该节点不同意 } flowInstanceOperationHistory.Content = "【" + wfruntime.currentNode.name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",备注:" + tag.Description; } #endregion 一般审核 flowInstance.SchemeContent = JsonHelper.Instance.Serialize(wfruntime.ToSchemeObj()); UnitWork.Update(flowInstance); UnitWork.Add(flowInstanceOperationHistory); //给流程创建人发送通知信息 _messageApp.SendMsgTo(flowInstance.CreateUserId, $"你的流程[{flowInstance.CustomName}]已被{user.Name}处理。处理情况如下:{flowInstanceOperationHistory.Content}"); UnitWork.Save(); wfruntime.NotifyThirdParty(_httpClientFactory.CreateClient(), tag); return(true); }
public async Task UpdateInstance(FlowinstanceEntity entity) { FlowschemeEntity scheme = null; if (!string.IsNullOrEmpty(entity.F_SchemeId)) { scheme = await uniwork.FindEntity <FlowschemeEntity>(entity.F_SchemeId); } if (scheme == null) { throw new Exception("该流程模板已不存在,请重新设计流程"); } entity.F_SchemeContent = scheme.F_SchemeContent; var form = await uniwork.FindEntity <FormEntity>(scheme.F_FrmId); if (form == null) { throw new Exception("该流程模板对应的表单已不存在,请重新设计流程"); } var wfruntime = new FlowRuntime(await repository.FindEntity(entity.F_Id)); entity.F_FrmContentData = form.F_ContentData; entity.F_FrmContentParse = form.F_ContentParse; entity.F_FrmType = form.F_FrmType; entity.F_FrmId = form.F_Id; entity.F_InstanceSchemeId = ""; entity.F_DbName = form.F_WebId; entity.F_FlowLevel = 0; //创建运行实例 wfruntime = new FlowRuntime(entity); var user = currentuser; #region 根据运行实例改变当前节点状态 entity.F_ActivityId = wfruntime.nextNodeId; entity.F_ActivityType = wfruntime.GetNextNodeType(); entity.F_ActivityName = wfruntime.nextNode.name; entity.F_PreviousId = wfruntime.currentNodeId; entity.F_CreatorUserName = user.UserName; entity.F_MakerList = (wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : ""); entity.F_IsFinish = (wfruntime.GetNextNodeType() == 4 ? 1 : 0); uniwork.BeginTrans(); await uniwork.Update(entity); wfruntime.flowInstanceId = entity.F_Id; //复杂表单提交 if (entity.F_FrmType == 1) { var path = AppDomain.CurrentDomain.RelativeSearchPath ?? AppDomain.CurrentDomain.BaseDirectory; var referencedAssemblies = Directory.GetFiles(path, "*.dll").Select(Assembly.LoadFrom).ToArray(); var t = referencedAssemblies .SelectMany(a => a.GetTypes().Where(t => t.FullName.Contains("WaterCloud.Service.") && t.FullName.Contains("." + entity.F_DbName + "Service"))).FirstOrDefault(); ICustomerForm icf = (ICustomerForm)GlobalContext.ServiceProvider.GetService(t); await icf.Edit(entity.F_Id, entity.F_FrmData); } #endregion #region 流程操作记录 FlowInstanceOperationHistory processOperationHistoryEntity = new FlowInstanceOperationHistory { F_Id = Utils.GuId(), F_InstanceId = entity.F_Id, F_CreatorUserId = user.UserId, F_CreatorUserName = entity.F_CreatorUserName, F_CreatorTime = DateTime.Now, F_Content = "【修改】" + entity.F_CreatorUserName + "修改了一个流程【" + entity.F_Code + "/" + entity.F_CustomName + "】" }; await uniwork.Insert(processOperationHistoryEntity); #endregion await AddTransHistory(wfruntime); MessageEntity msg = new MessageEntity(); msg.F_CreatorUserName = currentuser.UserName; msg.F_EnabledMark = true; if (entity.F_IsFinish == 1) { msg.F_MessageInfo = entity.F_CustomName + "--流程已完成"; var module = uniwork.IQueryable <ModuleEntity>(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); msg.F_Href = module.F_UrlAddress; msg.F_HrefTarget = module.F_Target; msg.F_ClickRead = true; msg.F_KeyValue = entity.F_Id; } else if (entity.F_IsFinish == 3) { msg.F_MessageInfo = entity.F_CustomName + "--流程已终止"; var module = uniwork.IQueryable <ModuleEntity>(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); msg.F_Href = module.F_UrlAddress; msg.F_HrefTarget = module.F_Target; var makerList = uniwork.IQueryable <FlowInstanceOperationHistory>(a => a.F_InstanceId == entity.F_Id && a.F_CreatorUserId != currentuser.UserId).Select(a => a.F_CreatorUserId).Distinct().ToList(); msg.F_ToUserId = entity.F_CreatorUserId; msg.F_ClickRead = true; msg.F_KeyValue = entity.F_Id; } else { msg.F_MessageInfo = entity.F_CustomName + "--流程待处理"; var module = uniwork.IQueryable <ModuleEntity>(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); msg.F_Href = module.F_UrlAddress.Remove(module.F_UrlAddress.Length - 5, 5) + "ToDoFlow"; msg.F_HrefTarget = module.F_Target; msg.F_ClickRead = false; msg.F_KeyValue = entity.F_Id; } msg.F_MessageType = 2; msg.F_ToUserId = entity.F_MakerList == "1" ? "" : entity.F_MakerList; var lastmsg = uniwork.IQueryable <MessageEntity>(a => a.F_ClickRead == false && a.F_KeyValue == entity.F_Id).OrderByDesc(a => a.F_CreatorTime).FirstOrDefault(); if (lastmsg != null && uniwork.IQueryable <MessageHistoryEntity>(a => a.F_MessageId == lastmsg.F_Id).Count() == 0) { await messageApp.ReadMsgForm(lastmsg.F_Id); } await messageApp.SubmitForm(msg); uniwork.Commit(); await CacheHelper.Remove(cacheKey + entity.F_Id); await CacheHelper.Remove(cacheKey + "list"); msg.F_ClickRead = false; msg.F_KeyValue = entity.F_Id; }
/// <summary> /// 节点审核 /// </summary> /// <param name="instanceId"></param> /// <returns></returns> public async Task <bool> NodeVerification(string instanceId, Tag tag) { FlowinstanceEntity flowInstance = GetForm(instanceId).Result; FlowInstanceOperationHistory flowInstanceOperationHistory = new FlowInstanceOperationHistory { F_Id = Utils.GuId(), F_InstanceId = instanceId, F_CreatorUserId = tag.UserId, F_CreatorUserName = tag.UserName, F_CreatorTime = DateTime.Now };//操作记录 FlowRuntime wfruntime = new FlowRuntime(flowInstance); uniwork.BeginTrans(); #region 会签 if (flowInstance.F_ActivityType == 0)//当前节点是会签节点 { //会签时的【当前节点】一直是会签开始节点 //TODO: 标记会签节点的状态,这个地方感觉怪怪的 wfruntime.MakeTagNode(wfruntime.currentNodeId, tag); string canCheckId = ""; //寻找当前登录用户可审核的节点Id foreach (string fromForkStartNodeId in wfruntime.FromNodeLines[wfruntime.currentNodeId].Select(u => u.to)) { var fromForkStartNode = wfruntime.Nodes[fromForkStartNodeId]; //与会前开始节点直接连接的节点 canCheckId = GetOneForkLineCanCheckNodeId(fromForkStartNode, wfruntime, tag); if (!string.IsNullOrEmpty(canCheckId)) { break; } } if (canCheckId == "") { throw (new Exception("审核异常,找不到审核节点")); } flowInstanceOperationHistory.F_Content = "【" + wfruntime.Nodes[canCheckId].name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",备注:" + tag.Description; wfruntime.MakeTagNode(canCheckId, tag); //标记审核节点状态 string res = wfruntime.NodeConfluence(canCheckId, tag); if (res == TagState.No.ToString("D")) { flowInstance.F_IsFinish = 3; } else if (!string.IsNullOrEmpty(res)) { flowInstance.F_PreviousId = flowInstance.F_ActivityId; flowInstance.F_ActivityId = wfruntime.nextNodeId; flowInstance.F_ActivityType = wfruntime.nextNodeType; flowInstance.F_ActivityName = wfruntime.nextNode.name; flowInstance.F_IsFinish = (wfruntime.nextNodeType == 4 ? 1 : 0); flowInstance.F_MakerList = (wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime)); await AddTransHistory(wfruntime); } else { //会签过程中,需要更新用户 flowInstance.F_MakerList = GetForkNodeMakers(wfruntime, wfruntime.currentNodeId); await AddTransHistory(wfruntime); } } #endregion 会签 #region 一般审核 else { wfruntime.MakeTagNode(wfruntime.currentNodeId, tag); if (tag.Taged == (int)TagState.Ok) { flowInstance.F_PreviousId = flowInstance.F_ActivityId; flowInstance.F_ActivityId = wfruntime.nextNodeId; flowInstance.F_ActivityType = wfruntime.nextNodeType; flowInstance.F_ActivityName = wfruntime.nextNode.name; flowInstance.F_MakerList = wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime); flowInstance.F_IsFinish = (wfruntime.nextNodeType == 4 ? 1 : 0); await AddTransHistory(wfruntime); } else { flowInstance.F_IsFinish = 3; //表示该节点不同意 } flowInstanceOperationHistory.F_Content = "【" + wfruntime.currentNode.name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",备注:" + tag.Description; } #endregion 一般审核 wfruntime.RemoveNode(wfruntime.nextNodeId); flowInstance.F_SchemeContent = wfruntime.ToSchemeObj().ToJson(); await uniwork.Update(flowInstance); await uniwork.Insert(flowInstanceOperationHistory); MessageEntity msg = new MessageEntity(); msg.F_CreatorUserName = currentuser.UserName; msg.F_EnabledMark = true; if (flowInstance.F_IsFinish == 1) { msg.F_MessageInfo = flowInstance.F_CustomName + "--流程已完成"; var module = uniwork.IQueryable <ModuleEntity>(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); msg.F_Href = module.F_UrlAddress; msg.F_HrefTarget = module.F_Target; msg.F_ToUserId = flowInstance.F_CreatorUserId; msg.F_ClickRead = true; msg.F_KeyValue = flowInstance.F_Id; } else if (flowInstance.F_IsFinish == 3) { msg.F_MessageInfo = flowInstance.F_CustomName + "--流程已终止"; var module = uniwork.IQueryable <ModuleEntity>(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); msg.F_Href = module.F_UrlAddress; msg.F_HrefTarget = module.F_Target; var makerList = uniwork.IQueryable <FlowInstanceOperationHistory>(a => a.F_InstanceId == flowInstance.F_Id && a.F_CreatorUserId != currentuser.UserId).Select(a => a.F_CreatorUserId).Distinct().ToList(); msg.F_ToUserId = flowInstance.F_CreatorUserId; msg.F_ClickRead = true; msg.F_KeyValue = flowInstance.F_Id; } else { msg.F_MessageInfo = flowInstance.F_CustomName + "--流程待处理"; var module = uniwork.IQueryable <ModuleEntity>(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault(); msg.F_Href = module.F_UrlAddress.Remove(module.F_UrlAddress.Length - 5, 5) + "ToDoFlow"; msg.F_HrefTarget = module.F_Target; msg.F_ToUserId = flowInstance.F_MakerList == "1" ? "" : flowInstance.F_MakerList; msg.F_ClickRead = false; msg.F_KeyValue = flowInstance.F_Id; } msg.F_MessageType = 2; var lastmsg = uniwork.IQueryable <MessageEntity>(a => a.F_ClickRead == false && a.F_KeyValue == flowInstance.F_Id).OrderByDesc(a => a.F_CreatorTime).FirstOrDefault(); if (lastmsg != null && uniwork.IQueryable <MessageHistoryEntity>(a => a.F_MessageId == lastmsg.F_Id).Count() == 0) { await messageApp.ReadMsgForm(lastmsg.F_Id); } await messageApp.SubmitForm(msg); uniwork.Commit(); wfruntime.NotifyThirdParty(_httpClientFactory.CreateClient(), tag); return(true); }
/// <summary> /// 创建一个实例 /// </summary> /// <returns></returns> public virtual async Task CreateInstance(FlowInstanceCreateDto flowInstanceCreateDto) { var manager = Manager as FlowInstanceManager; var user = await GetCurrentUserAsync(); var flowInstance = flowInstanceCreateDto.MapTo <FlowInstance>(); flowInstance.Code = Common.Fun.ConvertToTimeStamp(DateTime.Now).ToString(); FlowForm form = null; //1.如果流程提交数据没有FlowSchemeId,表示此流程直接由表单创建,提交即代表完成 if (flowInstanceCreateDto.FlowSchemeId == null || flowInstanceCreateDto.FlowSchemeId.Value == 0) { if (flowInstanceCreateDto.FlowFormId == null || flowInstanceCreateDto.FlowFormId.Value == 0) { throw new UserFriendlyException(L("参数错误,必须提供FlowFormId参数")); } form = await FlowFormManager.GetByIdFromCacheAsync(flowInstanceCreateDto.FlowFormId.Value); //如果表单没有内容,默认从内置表单中获取 if (string.IsNullOrWhiteSpace(form.FormContent)) { form.FormContent = Configuration.Modules.WorkFlow().DefaultForms.SingleOrDefault(o => o.FormKey == form.FormKey)?.FormContent; } flowInstance.FlowSchemeId = null; flowInstance.FormContent = form.FormContent; flowInstance.FormType = form.FormType; flowInstance.InstanceName = form.FormName; flowInstance.InstanceStatus = InstanceStatus.Finish;//直接为完成状态 await manager.InsertAsync(flowInstance); await CurrentUnitOfWork.SaveChangesAsync(); await manager.FinishInstance(flowInstance);//调用流程结束事件 return; } //2.从流程定义中复制表单id及流程内容 var flowScheme = await FlowSchemeManager.GetAll().Include(o => o.FlowForm).Where(o => o.Id == flowInstanceCreateDto.FlowSchemeId).SingleAsync(); form = await FlowFormManager.GetByIdFromCacheAsync(flowScheme.FlowFormId); flowInstance.FlowFormId = flowScheme.FlowFormId; flowInstance.FormContent = form.FormContent; flowInstance.FormType = flowScheme.FlowForm.FormType; flowInstance.SchemeContent = flowScheme.SchemeContent; flowInstance.InstanceName = flowScheme.SchemeName; //创建运行实例 var wfruntime = new FlowRuntime(flowInstance); #region 根据运行实例改变当前节点状态 flowInstance.ActivityId = wfruntime.nextNodeId; flowInstance.ActivityType = wfruntime.GetNextNodeType(); flowInstance.ActivityName = wfruntime.nextNode.name; flowInstance.PreviousId = wfruntime.currentNodeId; flowInstance.MakerList = (wfruntime.GetNextNodeType() != 4 ? GetNextMakers(wfruntime) : ""); flowInstance.InstanceStatus = (wfruntime.GetNextNodeType() == 4 ? InstanceStatus.Finish : InstanceStatus.Processing); await manager.InsertAsync(flowInstance); await CurrentUnitOfWork.SaveChangesAsync(); if (flowInstance.InstanceStatus == InstanceStatus.Finish) { await manager.FinishInstance(flowInstance);//调用流程结束事件 } wfruntime.flowInstanceId = flowInstance.Id; #endregion 根据运行实例改变当前节点状态 #region 流程操作记录 FlowInstanceOperationHistory processOperationHistoryEntity = new FlowInstanceOperationHistory { FlowInstanceId = flowInstance.Id, Content = "【创建】" + user.Name + "创建了一个流程进程【" + flowInstance.Code + "/" + flowInstance.InstanceName + "】" }; await FlowInstanceOperationHistoryRepository.InsertAsync(processOperationHistoryEntity); #endregion 流程操作记录 await AddTransHistory(wfruntime); }
/// <summary> /// 节点审核 /// </summary> /// <param name="instanceId"></param> /// <returns></returns> public virtual async Task NodeVerification(int instanceId, Tag tag) { var manager = Manager as FlowInstanceManager; FlowInstance flowInstance = await manager.GetByIdAsync(instanceId); FlowInstanceOperationHistory flowInstanceOperationHistory = new FlowInstanceOperationHistory { FlowInstanceId = instanceId };//操作记录 FlowRuntime wfruntime = new FlowRuntime(flowInstance); #region 会签 if (flowInstance.ActivityType == 0)//当前节点是会签节点 { //TODO: 标记会签节点的状态,这个地方感觉怪怪的 wfruntime.MakeTagNode(wfruntime.currentNodeId, tag); string canCheckId = ""; //寻找当前登录用户可审核的节点Id foreach (string nodeId in wfruntime.FromNodeLines[wfruntime.currentNodeId].Select(u => u.to)) { var makerList = GetNodeMakers(wfruntime.Nodes[nodeId]); if (string.IsNullOrEmpty(makerList)) { continue; } if (makerList.Contains("|" + tag.UserId + "|")) { canCheckId = nodeId; } } if (canCheckId == "") { throw (new Exception("审核异常,找不到审核节点")); } flowInstanceOperationHistory.Content = "【" + wfruntime.Nodes[canCheckId].name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】" + (tag.Taged == TagState.Ok ? "同意" : "不同意") + ",备注:" + tag.Description; wfruntime.MakeTagNode(canCheckId, tag); //标记审核节点状态 string res = wfruntime.NodeConfluence(canCheckId, tag); if (res == TagState.No.ToString("D")) { flowInstance.InstanceStatus = InstanceStatus.DisAgree; } else if (!string.IsNullOrEmpty(res)) { flowInstance.PreviousId = flowInstance.ActivityId; flowInstance.ActivityId = wfruntime.nextNodeId; flowInstance.ActivityType = wfruntime.nextNodeType; flowInstance.ActivityName = wfruntime.nextNode.name; flowInstance.InstanceStatus = (wfruntime.nextNodeType == 4 ? InstanceStatus.Finish : InstanceStatus.Processing); flowInstance.MakerList = (wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime)); await AddTransHistory(wfruntime); } } #endregion 会签 #region 一般审核 else { wfruntime.MakeTagNode(wfruntime.currentNodeId, tag); if (tag.Taged == TagState.Ok) { flowInstance.PreviousId = flowInstance.ActivityId; flowInstance.ActivityId = wfruntime.nextNodeId; flowInstance.ActivityType = wfruntime.nextNodeType; flowInstance.ActivityName = wfruntime.nextNode.name; flowInstance.MakerList = wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime); flowInstance.InstanceStatus = (wfruntime.nextNodeType == 4 ? InstanceStatus.Finish : InstanceStatus.Processing); await AddTransHistory(wfruntime); } else { flowInstance.InstanceStatus = InstanceStatus.DisAgree; //表示该节点不同意 } flowInstanceOperationHistory.Content = "【" + wfruntime.currentNode.name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】" + (tag.Taged == TagState.Ok ? "同意" : "不同意") + ",备注:" + tag.Description; } #endregion 一般审核 flowInstance.SchemeContent = Newtonsoft.Json.JsonConvert.SerializeObject(wfruntime.ToSchemeObj()); await manager.UpdateAsync(flowInstance); if (flowInstance.InstanceStatus == InstanceStatus.Finish) { await manager.FinishInstance(flowInstance);//调用流程结束事件 } await FlowInstanceOperationHistoryRepository.InsertAsync(flowInstanceOperationHistory); }
/// <summary> /// 節點審核 /// </summary> /// <param name="instanceId"></param> /// <returns></returns> public bool NodeVerification(string instanceId, Tag tag) { FlowInstance flowInstance = Get(instanceId); FlowInstanceOperationHistory flowInstanceOperationHistory = new FlowInstanceOperationHistory { InstanceId = instanceId, CreateUserId = tag.UserId, CreateUserName = tag.UserName, CreateDate = DateTime.Now };//操作記錄 FlowRuntime wfruntime = new FlowRuntime(flowInstance); #region 會簽 if (flowInstance.ActivityType == 0)//當前節點是會簽節點 { //會簽時的【當前節點】一直是會簽開始節點 //TODO: 標記會簽節點的狀態,這個地方感覺怪怪的 wfruntime.MakeTagNode(wfruntime.currentNodeId, tag); string canCheckId = ""; //尋找當前登錄使用者可審核的節點Id foreach (string fromForkStartNodeId in wfruntime.FromNodeLines[wfruntime.currentNodeId].Select(u => u.to)) { var fromForkStartNode = wfruntime.Nodes[fromForkStartNodeId]; //與會前開始節點直接連線的節點 canCheckId = GetOneForkLineCanCheckNodeId(fromForkStartNode, wfruntime, tag); if (!string.IsNullOrEmpty(canCheckId)) { break; } } if (canCheckId == "") { throw (new Exception("審核異常,找不到審核節點")); } flowInstanceOperationHistory.Content = "【" + wfruntime.Nodes[canCheckId].name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",備註:" + tag.Description; wfruntime.MakeTagNode(canCheckId, tag); //標記審核節點狀態 string res = wfruntime.NodeConfluence(canCheckId, tag); if (res == TagState.No.ToString("D")) { flowInstance.IsFinish = 3; } else if (!string.IsNullOrEmpty(res)) { flowInstance.PreviousId = flowInstance.ActivityId; flowInstance.ActivityId = wfruntime.nextNodeId; flowInstance.ActivityType = wfruntime.nextNodeType; flowInstance.ActivityName = wfruntime.nextNode.name; flowInstance.IsFinish = (wfruntime.nextNodeType == 4 ? 1 : 0); flowInstance.MakerList = (wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime)); AddTransHistory(wfruntime); } else { //會簽過程中,需要更新使用者 flowInstance.MakerList = GetForkNodeMakers(wfruntime, wfruntime.currentNodeId); AddTransHistory(wfruntime); } } #endregion 會簽 #region 一般審核 else { wfruntime.MakeTagNode(wfruntime.currentNodeId, tag); if (tag.Taged == (int)TagState.Ok) { flowInstance.PreviousId = flowInstance.ActivityId; flowInstance.ActivityId = wfruntime.nextNodeId; flowInstance.ActivityType = wfruntime.nextNodeType; flowInstance.ActivityName = wfruntime.nextNode.name; flowInstance.MakerList = wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime); flowInstance.IsFinish = (wfruntime.nextNodeType == 4 ? 1 : 0); AddTransHistory(wfruntime); } else { flowInstance.IsFinish = 3; //表示該節點不同意 } flowInstanceOperationHistory.Content = "【" + wfruntime.currentNode.name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",備註:" + tag.Description; } #endregion 一般審核 flowInstance.SchemeContent = JsonHelper.Instance.Serialize(wfruntime.ToSchemeObj()); UnitWork.Update(flowInstance); UnitWork.Add(flowInstanceOperationHistory); UnitWork.Save(); wfruntime.NotifyThirdParty(_httpClientFactory.CreateClient(), tag); return(true); }