/// <summary> /// 创建一个实例 /// </summary> /// <returns></returns> public bool CreateInstance(JObject obj) { var flowInstance = obj.ToObject <FlowInstance>(); if (flowInstance.FrmType == 0) { //动态表单的数据 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; if (flowInstance.FrmType == 1) { var t = Type.GetType("OpenAuth.App." + flowInstance.DbName + "App"); ICustomerForm icf = (ICustomerForm)AutofacExt.GetFromFac(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 + "创建了一个流程进程【" + flowInstance.Code + "/" + flowInstance.CustomName + "】" }; UnitWork.Add(processOperationHistoryEntity); #endregion 流程操作记录 AddTransHistory(wfruntime); 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); }
public async Task CreateInstance(FlowinstanceEntity entity) { entity.F_EnabledMark = true; 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("该流程模板对应的表单已不存在,请重新设计流程"); } entity.F_FrmContentData = form.F_ContentData; entity.F_FrmContent = form.F_Content; entity.F_FrmContentParse = form.F_ContentParse; entity.F_FrmType = form.F_FrmType; entity.F_FrmId = form.F_Id; Dictionary <string, string> dic = JsonHelper.ToObject <Dictionary <string, string> >(entity.F_FrmData); if (!dic.ContainsKey("申请人")) { dic.Add("申请人", currentuser.UserId); } if (!dic.ContainsKey("所属部门")) { dic.Add("所属部门", currentuser.DepartmentId); } entity.F_FrmData = dic.ToJson(); entity.F_InstanceSchemeId = ""; entity.F_DbName = form.F_WebId; entity.F_FlowLevel = 0; entity.Create(); //创建运行实例 var 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.Insert(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.Add(entity.F_Id, entity.F_FrmData); } #endregion #region 流程操作记录 FlowInstanceOperationHistory processOperationHistoryEntity = new FlowInstanceOperationHistory { F_Id = Utils.GuId(), F_InstanceId = entity.F_Id, F_CreatorUserId = entity.F_CreatorUserId, F_CreatorUserName = entity.F_CreatorUserName, F_CreatorTime = entity.F_CreatorTime, 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 + "list"); }