/// <summary> /// 处理流程 /// </summary> /// <param name="executeModel">处理实体</param> /// <returns></returns> public Data.Model.WorkFlowExecute.Result Execute(Data.Model.WorkFlowExecute.Execute executeModel) { result = new Data.Model.WorkFlowExecute.Result(); nextTasks = new List <Data.Model.WorkFlowTask>(); if (executeModel.FlowID == Guid.Empty) { result.DebugMessages = "流程ID错误"; result.IsSuccess = false; result.Messages = "执行参数错误"; return(result); } wfInstalled = bWorkFlow.GetWorkFlowRunModel(executeModel.FlowID); if (wfInstalled == null) { result.DebugMessages = "未找到流程运行时实体"; result.IsSuccess = false; result.Messages = "流程运行时为空"; return(result); } switch (executeModel.ExecuteType) { case Data.Model.WorkFlowExecute.EnumType.ExecuteType.Back: executeBack(executeModel); break; case Data.Model.WorkFlowExecute.EnumType.ExecuteType.Completed: executeComplete(executeModel); break; case Data.Model.WorkFlowExecute.EnumType.ExecuteType.Save: executeSave(executeModel); break; case Data.Model.WorkFlowExecute.EnumType.ExecuteType.Submit: executeSubmit(executeModel); break; case Data.Model.WorkFlowExecute.EnumType.ExecuteType.Redirect: executeRedirect(executeModel); break; default: result.DebugMessages = "流程处理类型为空"; result.IsSuccess = false; result.Messages = "流程处理类型为空"; return(result); } result.NextTasks = nextTasks; return(result); }
/// <summary> /// 管理员强制退回任务 /// </summary> /// <param name="taskID"></param> /// <returns></returns> public string BackTask(Guid taskID) { var task = Get(taskID); if (task == null) { return("未找到任务"); } else if (task.Status.In(2, 3, 4)) { return("该任务已处理"); } if (wfInstalled == null) { wfInstalled = bWorkFlow.GetWorkFlowRunModel(task.FlowID); } Data.Model.WorkFlowExecute.Execute executeModel = new Data.Model.WorkFlowExecute.Execute(); executeModel.ExecuteType = Data.Model.WorkFlowExecute.EnumType.ExecuteType.Back; executeModel.FlowID = task.FlowID; executeModel.GroupID = task.GroupID; executeModel.InstanceID = task.InstanceID; executeModel.Note = "管理员退回"; executeModel.Sender = new Users().Get(task.ReceiveID); executeModel.StepID = task.StepID; executeModel.TaskID = task.ID; executeModel.Title = task.Title; var steps = wfInstalled.Steps.Where(p => p.ID == task.StepID); if (steps.Count() == 0) { return("未找到步骤"); } else if (steps.First().Behavior.BackType == 2 && steps.First().Behavior.BackStepID == Guid.Empty) { return("未设置退回步骤"); } Dictionary <Guid, List <Data.Model.Users> > execSteps = new Dictionary <Guid, List <Data.Model.Users> >(); var backsteps = GetBackSteps(taskID, steps.First().Behavior.BackType, task.StepID, wfInstalled); foreach (var back in backsteps) { execSteps.Add(back.Key, new List <Data.Model.Users>()); } executeModel.Steps = execSteps; var result = Execute(executeModel); return(result.Messages); }
/// <summary> /// 创建第一个任务 /// </summary> /// <param name="executeModel"></param> private Data.Model.WorkFlowTask createFirstTask(Data.Model.WorkFlowExecute.Execute executeModel) { if (wfInstalled == null) { wfInstalled = bWorkFlow.GetWorkFlowRunModel(executeModel.FlowID); } var nextSteps = wfInstalled.Steps.Where(p => p.ID == wfInstalled.FirstStepID); if (nextSteps.Count() == 0) { return(null); } Data.Model.WorkFlowTask task = new Data.Model.WorkFlowTask(); if (nextSteps.First().WorkTime > 0) { task.CompletedTime = Utility.DateTimeNew.Now.AddHours((double)nextSteps.First().WorkTime); } task.FlowID = executeModel.FlowID; task.GroupID = Guid.NewGuid(); task.ID = Guid.NewGuid(); task.Type = 0; task.InstanceID = executeModel.InstanceID; if (!executeModel.Note.IsNullOrEmpty()) { task.Note = executeModel.Note; } task.PrevID = Guid.Empty; task.PrevStepID = Guid.Empty; task.ReceiveID = executeModel.Sender.ID; task.ReceiveName = executeModel.Sender.Name; task.ReceiveTime = Utility.DateTimeNew.Now; task.SenderID = executeModel.Sender.ID; task.SenderName = executeModel.Sender.Name; task.SenderTime = task.ReceiveTime; task.Status = 0; task.StepID = wfInstalled.FirstStepID; task.StepName = nextSteps.First().Name; task.Sort = 1; if (!executeModel.Title.IsNullOrEmpty()) { task.Title = executeModel.Title; } Add(task); return(task); }
/// <summary> /// 得到一个任务可以退回的步骤 /// </summary> /// <param name="taskID">当前任务ID</param> /// <param name="backType">退回类型</param> /// <param name="stepID"></param> /// <returns></returns> public Dictionary <Guid, string> GetBackSteps(Guid taskID, int backType, Guid stepID, Data.Model.WorkFlowInstalled wfInstalled) { Dictionary <Guid, string> dict = new Dictionary <Guid, string>(); switch (backType) { case 0: //退回前一步 var task = Get(taskID); if (task != null) { dict.Add(task.PrevStepID, bWorkFlow.GetStepName(task.PrevStepID, wfInstalled)); } break; case 1: //退回第一步 dict.Add(wfInstalled.FirstStepID, bWorkFlow.GetStepName(wfInstalled.FirstStepID, wfInstalled)); break; case 2: //退回某一步 var steps = wfInstalled.Steps.Where(p => p.ID == stepID); if (steps.Count() > 0 && steps.First().Behavior.BackType == 2 && steps.First().Behavior.BackStepID != Guid.Empty) { dict.Add(steps.First().Behavior.BackStepID, bWorkFlow.GetStepName(steps.First().Behavior.BackStepID, wfInstalled)); } else { var task0 = Get(taskID); if (task0 != null) { var taskList = GetTaskList(task0.FlowID, task0.GroupID).Where(p => p.Status.In(2, 3, 4)).OrderBy(p => p.Sort); foreach (var task1 in taskList) { if (!dict.Keys.Contains(task1.StepID) && task1.StepID != stepID) { dict.Add(task1.StepID, bWorkFlow.GetStepName(task1.StepID, wfInstalled)); } } } } break; } return(dict); }