/// <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> /// <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); }
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> /// <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); }