/// <summary> /// 删除该流程 /// </summary> public void Remove() { ISqlMapper mapper = MapperHelper.GetMapper(); WorkflowDao wfdao = new WorkflowDao(mapper); ActivityDao activitydao = new ActivityDao(mapper); LinkDao linkDao = new LinkDao(mapper); ActivityAuthDao authdao = new ActivityAuthDao(mapper); ApprovalDao approvalDao = new ApprovalDao(mapper); TaskDao taskdao = new TaskDao(mapper); string id = this.value.ID; var activities = activitydao.Query(new ActivityQueryForm { WorkflowID = id }); taskdao.Delete(new TaskQueryForm { WorkflowID = id }); wfdao.Delete(new WorkflowQueryForm { ID = id }); activitydao.Delete(new ActivityQueryForm { WorkflowID = id }); linkDao.Delete(new LinkQueryForm { WorkflowID = id }); approvalDao.Delete(new ApprovalQueryForm { WorkflowID = id }); authdao.Delete(new ActivityAuthQueryForm { WorkflowID = id }); }
public void ReadTask(string taskid, string proccessor) { ISqlMapper mapper = MapperHelper.GetMapper(); TaskDao taskdao = new TaskDao(mapper); var task = this.Tasks.Find(t => t.ID == taskid); if (this.Value.Status == (int)ActivityProcessStatus.Processed) { task.Status = (int)TaskProcessStatus.Processed; } else { task.Status = (int)TaskProcessStatus.Read; } task.ReadTime = DateTime.Now; task.LastUpdator = proccessor; taskdao.Update(new TaskUpdateForm { Entity = new Task { ReadTime = task.ReadTime, Status = task.Status, LastUpdator = task.LastUpdator }, TaskQueryForm = new TaskQueryForm { ID = task.ID } }); }
/// <summary> /// 作废(停止)流程 /// </summary> /// <param name="taskid"></param> /// <param name="processor"></param> public void Stop(string processor) { if (this.CurrentActivity != null) { ISqlMapper mapper = MapperHelper.GetMapper(); WorkflowDao wfdao = new WorkflowDao(mapper); TaskDao taskdao = new TaskDao(mapper); this.value.Status = (int)WorkflowProcessStatus.Stoped; this.value.LastUpdator = processor; wfdao.Update(new WorkflowUpdateForm { Entity = new Workflow { LastUpdator = this.value.LastUpdator, Status = this.value.Status, }, WorkflowQueryForm = new WorkflowQueryForm { ID = this.value.ID, } }); taskdao.Update(new TaskUpdateForm { Entity = new Task { Status = (int)TaskProcessStatus.Stoped }, TaskQueryForm = new TaskQueryForm { ActivityID = this.CurrentActivity.Value.ID } }); } }
/// <summary> /// 从数据库读取流程信息 /// </summary> /// <param name="workflowids"></param> /// <returns></returns> public static List <WorkflowModel> Load(WorkflowQueryForm form) { List <WorkflowModel> models = new List <WorkflowModel>(); if (form == null) { return(models); } #region query data ISqlMapper mapper = MapperHelper.GetMapper(); WorkflowDao wfdao = new WorkflowDao(mapper); ActivityDao activitydao = new ActivityDao(mapper); LinkDao linkDao = new LinkDao(mapper); ActivityAuthDao authdao = new ActivityAuthDao(mapper); ApprovalDao approvalDao = new ApprovalDao(mapper); TaskDao taskdao = new TaskDao(mapper); List <Activity> activityList = new List <Activity>(); List <Link> linkList = new List <Link>(); List <ActivityAuth> authList = new List <ActivityAuth>(); List <Approval> approvalList = new List <Approval>(); List <Task> taskList = new List <Task>(); List <Workflow> workflows = new List <Workflow>(); //先从缓存取值 //var item = cache.GetItem(id); //if (item != null) //{ // model = item.Value as WorkflowModel; // return model; //} workflows = wfdao.Query(form); var workflowids = (from wf in workflows select wf.ID).ToList(); activityList = activitydao.Query(new ActivityQueryForm { WorkflowIDs = workflowids }); linkList = linkDao.Query(new LinkQueryForm { WorkflowIDs = workflowids }); approvalList = approvalDao.Query(new ApprovalQueryForm { WorkflowIDs = workflowids }); authList = authdao.Query(new ActivityAuthQueryForm { WorkflowIDs = workflowids }); taskList = taskdao.Query(new TaskQueryForm { WorkflowIDs = workflowids }); #endregion foreach (var workflow in workflows) { var model = BuildWorkflow(workflow, activityList, linkList, authList, approvalList, taskList); models.Add(model); } return(models); }
public bool DeleteItem(string itemid) { ISqlMapper mapper = MapperHelper.GetMapper(); DataDictionaryDao dicdao = new DataDictionaryDao(mapper); dicdao.Delete(new DataDictionaryQueryForm { ID = itemid }); return(true); }
/// <summary> /// 新增数据字典组 /// </summary> /// <param name="group"></param> /// <param name="items"></param> /// <returns></returns> public string AddGroup(DataDictionaryGroup group) { if (group == null) { throw new Exception("数据字典分组不能为null"); } ISqlMapper mapper = MapperHelper.GetMapper(); DataDictionaryGroupDao groupdao = new DataDictionaryGroupDao(mapper); string id = groupdao.Add(group); return(id); }
/// <summary> /// 把流程实体新增到数据库 /// </summary> /// <returns></returns> public bool Create() { ISqlMapper mapper = MapperHelper.GetMapper(); WorkflowDao workflowdao = new WorkflowDao(mapper); ActivityDao activitydao = new ActivityDao(mapper); LinkDao linkdao = new LinkDao(mapper); ActivityAuthDao authdao = new ActivityAuthDao(mapper); workflowdao.Add(this.Value); var activities = this.Root.GetList(); List <Link> linkList = new List <Link>(); //保存节点 foreach (var activity in activities) { activitydao.Add(activity.Value); var activityinstance = activity as ActivityModel; //保存连接 if (activityinstance.PreLinks != null) { foreach (var link in activityinstance.PreLinks) { if (!linkList.Contains(link.Value)) { linkList.Add(link.Value); } } } if (activityinstance.NextLinks != null) { foreach (var link in activityinstance.NextLinks) { if (!linkList.Contains(link.Value)) { linkList.Add(link.Value); } } } //保存权限 foreach (var auth in activityinstance.Auth) { authdao.Add(auth); } } foreach (var link in linkList) { linkdao.Add(link); } return(true); }
/// <summary> /// 更新数据字典 /// </summary> /// <param name="group"></param> /// <param name="items"></param> /// <returns></returns> public List <DataDictionary> Update(DataDictionaryGroup group, List <DataDictionary> items) { if (group == null) { throw new Exception("数据字典分组不能为null"); } ISqlMapper mapper = MapperHelper.GetMapper(); DataDictionaryGroupDao groupdao = new DataDictionaryGroupDao(mapper); DataDictionaryDao dicdao = new DataDictionaryDao(mapper); groupdao.Update(new DataDictionaryGroupUpdateForm { Entity = group, DataDictionaryGroupQueryForm = new DataDictionaryGroupQueryForm { ID = group.ID, } }); if (items != null) { foreach (var item in items) { if (string.IsNullOrEmpty(item.ID)) { dicdao.Add(item); } else { var dic = dicdao.Query(new DataDictionaryQueryForm { ID = item.ID }); if (dic == null) { dicdao.Add(item); } else { dicdao.Update(new DataDictionaryUpdateForm { Entity = item, DataDictionaryQueryForm = new DataDictionaryQueryForm { ID = item.ID, } }); } } } } return(items); }
public bool Delete(string groupid) { ISqlMapper mapper = MapperHelper.GetMapper(); DataDictionaryGroupDao groupdao = new DataDictionaryGroupDao(mapper); DataDictionaryDao dicdao = new DataDictionaryDao(mapper); groupdao.Delete(new DataDictionaryGroupQueryForm { ID = groupid }); dicdao.Delete(new DataDictionaryQueryForm { DataDictionaryGroupID = groupid }); return(true); }
public bool Save() { ISqlMapper mapper = MapperHelper.GetMapper(); WorkflowDefinitionDao wddao = new WorkflowDefinitionDao(mapper); ActivityDefinitionDao addao = new ActivityDefinitionDao(mapper); LinkDefinitionDao linkdao = new LinkDefinitionDao(mapper); ActivityAuthDefinitionDao aadd = new ActivityAuthDefinitionDao(mapper); var workflowdefinition = wddao.Query(new WorkflowDefinitionQueryForm { ID = this.value.ID }).FirstOrDefault(); if (workflowdefinition == null) { wddao.Add(this.value); } else { wddao.Update(new WorkflowDefinitionUpdateForm { Entity = this.value, WorkflowDefinitionQueryForm = new WorkflowDefinitionQueryForm { ID = this.value.ID } }); } var activityList = this.Root.GetList(); foreach (var a in activityList) { var acitivitydefinitioninstance = a as ActivityDefinitionModel; acitivitydefinitioninstance.Save(mapper); } foreach (var link in LinkDefinitionList) { link.Save(mapper); } var item = cache.GetItem(this.value.ID); if (item == null) { item = new CacheItem(this.value.ID, this); cache.AddItem(item, 30 * 60); } else { item.Value = this; cache.UpdateItem(item); } return(true); }
/// <summary> /// 新增数据字典明细 /// </summary> /// <param name="items"></param> /// <returns>返回数据组回传加上了id</returns> public List <DataDictionary> AddItems(List <DataDictionary> items) { ISqlMapper mapper = MapperHelper.GetMapper(); DataDictionaryDao dicdao = new DataDictionaryDao(mapper); if (items != null) { foreach (var item in items) { dicdao.Add(item); } } return(items); }
public static WorkflowDefinitionModel LoadByName(string name) { var mapper = MapperHelper.GetMapper(); WorkflowDefinitionModel wfdm = null; WorkflowDefinitionDao wfdao = new WorkflowDefinitionDao(mapper); var wfd = wfdao.Query(new WorkflowDefinitionQueryForm { Name = name }).FirstOrDefault(); if (wfd != null) { wfdm = Load(wfd.ID); } return(wfdm); }
/// <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 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); } } } }
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); }