/// <summary> /// 继续流程 /// </summary> /// <param name="lastupdator"></param> public void ContinueWorkflow(string lastupdator) { ISqlMapper mapper = MapperHelper.GetMapper(); WorkflowDao workflowdao = new WorkflowDao(mapper); this.value.LastUpdator = lastupdator; this.value.Status = (int)WorkflowProcessStatus.Processing; workflowdao.Update(new WorkflowUpdateForm { Entity = new Workflow { Status = this.value.Status, LastUpdator = this.value.LastUpdator, }, WorkflowQueryForm = new WorkflowQueryForm { ID = this.value.ID } }); }
public void Remove() { var mapper = MapperHelper.GetMapper(); WorkflowDefinitionDao wfdao = new WorkflowDefinitionDao(mapper); ActivityDefinitionDao addao = new ActivityDefinitionDao(mapper); LinkDefinitionDao linkdao = new LinkDefinitionDao(mapper); ActivityAuthDefinitionDao aadd = new ActivityAuthDefinitionDao(mapper); string id = this.value.ID; wfdao.Delete(new WorkflowDefinitionQueryForm { ID = id }); addao.Delete(new ActivityDefinitionQueryForm { WorkflowDefinitionID = id }); linkdao.Delete(new LinkDefinitionQueryForm { WorkflowDefinitionID = id }); aadd.Delete(new ActivityAuthDefinitionQueryForm { WorkflowDefinitionID = id }); }
public static WorkflowDefinitionModel Load(string id) { var mapper = MapperHelper.GetMapper(); WorkflowDefinitionDao wfdao = new WorkflowDefinitionDao(mapper); ActivityDefinitionDao addao = new ActivityDefinitionDao(mapper); LinkDefinitionDao linkdao = new LinkDefinitionDao(mapper); ActivityAuthDefinitionDao aadd = new ActivityAuthDefinitionDao(mapper); WorkflowDefinition workflow = null; List <ActivityDefinition> activityList = new List <ActivityDefinition>(); List <LinkDefinition> linkList = new List <LinkDefinition>(); List <ActivityAuthDefinition> authList = new List <ActivityAuthDefinition>(); WorkflowDefinitionModel model = null; var item = cache.GetItem(id); if (item != null) { model = item.Value as WorkflowDefinitionModel; return(model); } workflow = wfdao.Query(new WorkflowDefinitionQueryForm { ID = id, Enabled = 1 }).FirstOrDefault(); activityList = addao.Query(new ActivityDefinitionQueryForm { WorkflowDefinitionID = id, Enabled = 1 }); linkList = linkdao.Query(new LinkDefinitionQueryForm { WorkflowDefinitionID = id }); authList = aadd.Query(new ActivityAuthDefinitionQueryForm { WorkflowDefinitionID = id }); if (workflow != null) { List <ActivityDefinitionModel> activityModelList = new List <ActivityDefinitionModel>(); List <LinkDefinitionModel> linkModelList = new List <LinkDefinitionModel>(); model = new WorkflowDefinitionModel { value = workflow, }; bool foundRoot = false; foreach (var link in linkList) { linkModelList.Add(new LinkDefinitionModel { Value = link, }); } foreach (var activity in activityList) { List <LinkDefinitionModel> preLinks = new List <LinkDefinitionModel>(); var preLinksTemp = linkModelList.FindAll(t => t.Value.ToActivityDefinitionID == activity.ID); List <LinkDefinitionModel> nextLinks = new List <LinkDefinitionModel>(); var nextLinksTemp = linkModelList.FindAll(t => t.Value.FromActivityDefinitionID == activity.ID); ActivityDefinitionModel activitymodel = new ActivityDefinitionModel { Value = activity, }; if (authList != null) { activitymodel.AuthDefinition = authList.FindAll(t => t.ActivityDefinitionID == activity.ID); } activitymodel.PreLinks = preLinksTemp; activitymodel.NextLinks = nextLinksTemp; activityModelList.Add(activitymodel); //没有父连接说明是根节点 if (!foundRoot && preLinksTemp.Count == 0) { model.Root = activitymodel; foundRoot = true; } } item = new CacheItem(id, model); cache.AddItem(item, 30 * 60); } return(model); }
public WorkflowModel StartNew(string creator, string processid, IWorkflowAuthority iauth) { var mapper = MapperHelper.GetMapper(); WorkflowDao workflowdao = new WorkflowDao(mapper); ActivityDao activitydao = new ActivityDao(mapper); LinkDao linkdao = new LinkDao(mapper); ActivityAuthDao aadd = new ActivityAuthDao(mapper); TaskDao taskdao = new TaskDao(mapper); WorkflowModel model = null; Workflow wf = this.value.ConvertTo <Workflow>(); wf.ID = null; wf.Creator = creator; wf.Status = (int)WorkflowProcessStatus.Started; wf.WorkflowDefinitionID = this.value.ID; wf.ProcessID = processid; workflowdao.Add(wf); var activites = this.ActivityDefinitionList; var links = this.LinkDefinitionList; List <Activity> activityEntities = new List <Activity>(); foreach (var a in activites) { Activity activity = a.Value.ConvertTo <Activity>(); activity.Creator = creator; activity.ID = null; activity.WorkflowID = wf.ID; activity.ActivityDefinitionID = a.Value.ID; activity.Title = a.Value.Title; activity.Status = (int)ActivityProcessStatus.Started; List <ActivityAuth> authList = new List <ActivityAuth>(); //如果是开始节点,就设置为已处理 if (this.Root.Equals(a)) { activity.Status = (int)ActivityProcessStatus.Processed; activity.ProcessTime = DateTime.Now; } if (this.Root.Children.Count > 0 && this.Root.Children[0].Equals(a)) { activity.Status = (int)ActivityProcessStatus.Processing; } activitydao.Add(activity); activityEntities.Add(activity); //权限处理 foreach (var ad in a.AuthDefinition) { ActivityAuth auth = ad.ConvertTo <ActivityAuth>(); auth.Creator = creator; auth.WorkflowID = wf.ID; auth.ActivityID = activity.ID; auth.ID = null; auth.ActivityAuthDefinitionID = ad.ID; aadd.Add(auth); authList.Add(auth); } //如果是第二节点,就设置成正在处理 if (this.Root.Children.Count > 0 && this.Root.Children[0].Equals(a)) { ActivityModel activitymodel = new ActivityModel { Value = activity, }; var idlist = iauth.GetUserIDList(authList); var tasklist = activitymodel.GetTask(creator, idlist); foreach (var task in tasklist) { taskdao.Add(task); } } } foreach (var l in links) { Link link = l.Value.ConvertTo <Link>(); link.Creator = creator; link.WorkflowID = wf.ID; link.ID = null; link.LinkDefinitionID = l.Value.ID; var fromactivity = activityEntities.Find(t => t.ActivityDefinitionID == l.Value.FromActivityDefinitionID); var totactivity = activityEntities.Find(t => t.ActivityDefinitionID == l.Value.ToActivityDefinitionID); if (fromactivity != null) { link.FromActivityID = fromactivity.ID; } if (totactivity != null) { link.ToAcivityID = totactivity.ID; } linkdao.Add(link); } model = WorkflowModel.Load(wf.ID); return(model); }
public void Process(ActivityModel activity, Approval approval, string processor, IWorkflowAuthority auth) { //已经处理过就不能再处理 if (activity.Value.Status == (int)ActivityProcessStatus.Processed) { return; } //MonitorCache.GetInstance().PushMessage(new CacheMessage { Message = "activityid:" + activity.Value.ID + " next activity status:" + activity.Value.Status.ToString() }, CacheEnum.FormMonitor); ISqlMapper mapper = MapperHelper.GetMapper(); ActivityDao activitydao = new ActivityDao(mapper); TaskDao taskdao = new TaskDao(mapper); //设置当前活动点状态 activity.Value.Status = (int)ActivityProcessStatus.Processed; activity.Value.ProcessTime = DateTime.Now; activity.Value.LastUpdator = processor; activitydao.Update(new ActivityUpdateForm { Entity = new Activity { Status = activity.Value.Status, ProcessTime = activity.Value.ProcessTime, LastUpdator = activity.Value.LastUpdator }, ActivityQueryForm = new ActivityQueryForm { ID = activity.Value.ID } }); var task = activity.GetUserProcessingTask(processor); if (task == null) { throw new Exception("环节中没有你的任务,无法进行审批操作"); } task.Status = (int)TaskProcessStatus.Processed; task.ProcessTime = DateTime.Now; task.LastUpdator = processor; //处理任务 taskdao.Update(new TaskUpdateForm { Entity = new Task { ProcessTime = task.ProcessTime, Status = task.Status, LastUpdator = task.LastUpdator }, TaskQueryForm = new TaskQueryForm { ID = task.ID }, }); //设置下个活动点的状态 if (activity.Children.Count > 0) { foreach (var next in activity.Children) { string nextactivityid = next.Value.ID; var nextActivityModel = next as ActivityModel; nextActivityModel.Value.Status = (int)ActivityProcessStatus.Processing; nextActivityModel.Value.LastUpdator = processor; activitydao.Update(new ActivityUpdateForm { Entity = new Activity { Status = nextActivityModel.Value.Status, LastUpdator = nextActivityModel.Value.LastUpdator }, ActivityQueryForm = new ActivityQueryForm { ID = nextactivityid }, }); List <string> useridList = auth.GetUserIDList(nextActivityModel.Auth); //新增下个活动点的任务 var tasklist = nextActivityModel.GetTask(processor, useridList); foreach (var t in tasklist) { nextActivityModel.Tasks.Add(t); taskdao.Add(t); } } } }