/// <summary> /// 判断是否是我的任务 /// </summary> /// <param name="entity"></param> /// <param name="userID"></param> /// <returns></returns> public bool IsMineTask(ActivityInstanceEntity entity, string userID) { var aim = new ActivityInstanceManager(); bool isMine = aim.IsMineTask(entity, userID); return(isMine); }
/// <summary> /// 退回操作 /// </summary> /// <param name="runner">执行者</param> /// <param name="result">结果对象</param> /// <returns>运行时实例对象</returns> internal static WfRuntimeManager CreateRuntimeInstanceSendBack(WfAppRunner runner, ref WfExecutedResult result) { WfRuntimeManager rmins = new WfRuntimeManagerSendBack(); rmins.WfExecutedResult = result = new WfExecutedResult(); var aim = new ActivityInstanceManager(); var runningActivityInstanceList = aim.GetRunningActivityInstanceList(runner.AppInstanceID, runner.ProcessGUID).ToList(); SendbackOpertaionTypeEnum sendbackOperation = SendbackOpertaionTypeEnum.Default; //当前没有运行状态的节点存在,流程不存在,或者已经结束或取消 if (runningActivityInstanceList == null || runningActivityInstanceList.Count() == 0) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotInRunning; result.Message = "当前没有运行状态的节点存在,流程不存在,或者已经结束或取消"; return(rmins); } if (runningActivityInstanceList.Count() == 1) //如果只有1个运行节点 { var runningNode = runningActivityInstanceList[0]; var activityType = EnumHelper.ParseEnum <ActivityTypeEnum>(runningNode.ActivityType.ToString()); if (XPDLHelper.IsSimpleComponentNode(activityType) == false) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotTaskNode; result.Message = "当前节点不是任务类型的节点,无法退回上一步节点!"; return(rmins); } if (aim.IsMineTask(runningNode, runner.UserID) == false) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotMineTask; result.Message = "不是登录用户的任务,无法退回!"; return(rmins); } sendbackOperation = SendbackOpertaionTypeEnum.Normal; } else if (runningActivityInstanceList.Count() > 1) { //有其它非多实例的并行节点,暂时不处理,后期实现该功能 result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NullOrHasTooMany; result.Message = "有多个可以退回的节点,而且不是多实例节点,此功能暂时不支持!"; return(rmins); } //根据不同分支场景,创建不同撤销运行时管理器 return(CreateRuntimeInstanceSendbackByCase(runningActivityInstanceList, sendbackOperation, runner, ref result)); }
/// <summary> /// 退回操作 /// </summary> /// <param name="runner">执行者</param> /// <param name="result">结果对象</param> /// <returns>运行时实例对象</returns> internal static WfRuntimeManager CreateRuntimeInstanceSendBack(WfAppRunner runner, ref WfExecutedResult result) { WfRuntimeManager rmins = new WfRuntimeManagerSendBack(); rmins.WfExecutedResult = result = new WfExecutedResult(); var aim = new ActivityInstanceManager(); var runningActivityInstanceList = aim.GetRunningActivityInstanceList(runner.AppInstanceID, runner.ProcessGUID).ToList(); SendbackOperationTypeEnum sendbackOperation = SendbackOperationTypeEnum.Default; //当前没有运行状态的节点存在,流程不存在,或者已经结束或取消 if (runningActivityInstanceList == null || runningActivityInstanceList.Count() == 0) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotInRunning; result.Message = "当前没有运行状态的节点存在,流程不存在,或者已经结束或取消"; return(rmins); } if (runningActivityInstanceList.Count() == 1) //如果只有1个运行节点 { var runningNode = runningActivityInstanceList[0]; var activityType = EnumHelper.ParseEnum <ActivityTypeEnum>(runningNode.ActivityType.ToString()); if (XPDLHelper.IsSimpleComponentNode(activityType) == false) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotTaskNode; result.Message = "当前节点不是任务类型的节点,无法退回上一步节点!"; return(rmins); } if (aim.IsMineTask(runningNode, runner.UserID) == false) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotMineTask; result.Message = "不是登录用户的任务,无法退回!"; return(rmins); } //判断当前节点是否是多实例节点 if (runningNode.MIHostActivityInstanceID != null) { if (runningNode.CompleteOrder == 1) { //只有串行模式下有CompleteOrder的值为 1 //串行模式多实例的第一个执行节点,此时可退回到上一步 sendbackOperation = SendbackOperationTypeEnum.MISFirstOneIsRunning; } else if (runningNode.CompleteOrder > 1) { //已经是中间节点,只能退回到上一步多实例子节点 sendbackOperation = SendbackOperationTypeEnum.MISOneIsRunning; } else if (runningNode.CompleteOrder == -1) { sendbackOperation = SendbackOperationTypeEnum.MIPOneIsRunning; } } else { sendbackOperation = SendbackOperationTypeEnum.Normal; } } else if (runningActivityInstanceList.Count() > 1) { var firstActivityInstance = runningActivityInstanceList[0]; if (firstActivityInstance.MIHostActivityInstanceID != null) { //判断多实例主节点下的子节点是否都处于待办状态,如果是,则可以退回到上一步 bool isAllInReadyState = true; var allChildNodeList = aim.GetActivityMultipleInstance(firstActivityInstance.MIHostActivityInstanceID.Value, firstActivityInstance.ProcessInstanceID); int runningCount = 0; foreach (var ai in allChildNodeList) { if (ai.ActivityState != (short)ActivityStateEnum.Ready && ai.ActivityState != (short)ActivityStateEnum.Suspended) { if (ai.ActivityState == (short)ActivityStateEnum.Running) { runningCount++; } else { isAllInReadyState = false; break; } } } if (runningCount > 1) { isAllInReadyState = false; } if (isAllInReadyState == false) { //部分子节点有完成的 sendbackOperation = SendbackOperationTypeEnum.MIPSeveralIsRunning; } else if (runningCount == 1) { if (firstActivityInstance.CompleteOrder == -1) { sendbackOperation = SendbackOperationTypeEnum.MIPOneIsRunning; } else { //第一个子节点处于待办状态 sendbackOperation = SendbackOperationTypeEnum.MISFirstOneIsRunning; } } else if (isAllInReadyState) { //子节点全部处于待办状态 sendbackOperation = SendbackOperationTypeEnum.MIPAllIsInReadyState; } } else { //有其它非多实例的并行节点,暂时不处理,后期实现该功能 result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NullOrHasTooMany; result.Message = "有多个可以退回的节点,而且不是多实例节点,此功能暂时不支持!"; return(rmins); } } //根据不同分支场景,创建不同撤销运行时管理器 return(CreateRuntimeInstanceSendbackByCase(runningActivityInstanceList, sendbackOperation, runner, ref result)); }
/// <summary> /// 退回操作 /// </summary> /// <param name="runner">执行者</param> /// <param name="result">结果对象</param> /// <returns>运行时实例对象</returns> internal static WfRuntimeManager CreateRuntimeInstanceSendBack(WfAppRunner runner, ref WfExecutedResult result) { var rmins = new WfRuntimeManagerSendBack(); rmins.WfExecutedResult = result = new WfExecutedResult(); var sendbackOperation = SendbackOperationTypeEnum.Default; //先查找当前用户正在办理的运行节点 var aim = new ActivityInstanceManager(); var runningNode = runner.TaskID != null?aim.GetByTask(runner.TaskID.Value) : aim.GetRunningNode(runner); if (runningNode == null) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotInRunning; result.Message = "当前没有运行状态的节点存在,流程不存在,或者已经结束或取消"; return(rmins); } if (aim.IsMineTask(runningNode, runner.UserID) == false) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotMineTask; result.Message = "不是当前登录用户的任务,无法退回!"; return(rmins); } var activityType = EnumHelper.ParseEnum <ActivityTypeEnum>(runningNode.ActivityType.ToString()); if (XPDLHelper.IsSimpleComponentNode(activityType) == false) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotTaskNode; result.Message = "当前节点不是任务类型的节点,无法退回上一步节点!"; return(rmins); } //获取当前运行主节点信息 var currentNode = runningNode; if (runningNode.MIHostActivityInstanceID != null) { currentNode = aim.GetById(runningNode.MIHostActivityInstanceID.Value); } //获取上一步流转节点信息,可能经过And, Or等路由节点 //判断前置步骤是否经过Gateway节点 var hasGatewayPassed = false; var processInstance = (new ProcessInstanceManager()).GetById(runningNode.ProcessInstanceID); var processModel = ProcessModelFactory.Create(processInstance.ProcessGUID, processInstance.Version); var previousActivityList = aim.GetPreviousActivityList(runningNode, processModel, out hasGatewayPassed); if (previousActivityList == null || previousActivityList.Count == 0) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_IsNull; result.Message = "当前没有可以退回的节点,请检查流程数据!"; return(null); } //多个退回节点存在的有效退回判断 IList <ActivityEntity> sendbackPreviousActivityList = new List <ActivityEntity>(); if (previousActivityList.Count > 1) { if (runner.NextActivityPerformers == null || runner.NextActivityPerformers.Count == 0) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_IsTooManyPrevious; result.Message = "当前有多个可以退回的节点,无法选择,请明确指定!"; return(rmins); } //明确指定的退回节点,需要判断处理 var isInvalidSendBack = IsInvalidStepsInPrevousActivityList(previousActivityList, runner.NextActivityPerformers, sendbackPreviousActivityList); if (isInvalidSendBack == true) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotContainedInPreviousOrStartNode; result.Message = "指定的退回节点不在上一步节点运行列表中,或者上一步是开始节点,无法退回!"; return(rmins); } } else { //只有一个要退回去的节点 sendbackPreviousActivityList.Add(previousActivityList[0]); } //判断当前节点是否是多实例节点 if (runningNode.MIHostActivityInstanceID != null) { if (runningNode.CompleteOrder == 1) { //只有串行模式下有CompleteOrder的值为 1 //串行模式多实例的第一个执行节点,此时可退回到上一步 sendbackOperation = SendbackOperationTypeEnum.MISFirstOneIsRunning; } else if (runningNode.CompleteOrder > 1) { //已经是中间节点,只能退回到上一步多实例子节点 sendbackOperation = SendbackOperationTypeEnum.MISOneIsRunning; } else if (runningNode.CompleteOrder == -1) { sendbackOperation = SendbackOperationTypeEnum.MIPOneIsRunning; } } if (hasGatewayPassed == true) { sendbackOperation = SendbackOperationTypeEnum.GatewayFollowedByParalleledNodes; } else { sendbackOperation = SendbackOperationTypeEnum.Normal; } //根据不同分支场景,创建不同撤销运行时管理器 return(CreateRuntimeInstanceSendbackByCase(runningNode, processModel, processInstance, sendbackPreviousActivityList, hasGatewayPassed, sendbackOperation, runner, ref result)); }
/// <summary> /// 退回操作 /// </summary> /// <param name="appName"></param> /// <param name="appInstanceID"></param> /// <param name="processGUID"></param> /// <param name="userID"></param> /// <param name="userName"></param> /// <param name="result"></param> /// <returns></returns> public static WfRuntimeManager CreateRuntimeInstanceSendBack(WfAppRunner runner, ref WfExecutedResult result) { //检查当前运行节点信息 var rmins = new WfRuntimeManagerSendBack(); rmins.WfExecutedResult = result = new WfExecutedResult(); var aim = new ActivityInstanceManager(); var runningNode = aim.GetRunningNodeOfMine(runner); if (runningNode.ActivityType != (short)ActivityTypeEnum.TaskNode) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotTaskNode; result.Message = "当前节点不是任务节点,无法退回上一步节点!"; return(rmins); } if (!(runningNode.ActivityState == (short)ActivityStateEnum.Ready || runningNode.ActivityState == (short)ActivityStateEnum.Running)) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotInRunning; result.Message = string.Format("当前节点的状态不在运行状态,无法退回上一步节点!当前节点状态:{0}", runningNode.ActivityState); return(rmins); } if (aim.IsMineTask(runningNode, runner.UserID) == false) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotMineTask; result.Message = "不是登录用户的任务,无法退回!"; return(rmins); } var tim = new TransitionInstanceManager(); var lastTaskTransitionInstance = tim.GetLastTaskTransition(runner.AppName, runner.AppInstanceID, runner.ProcessGUID); if (lastTaskTransitionInstance.TransitionType == (short)TransitionTypeEnum.Loop) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_IsLoopNode; result.Message = "当前流转是自循环,无需退回!"; return(rmins); } //设置退回节点的相关信息 bool hasGatewayNode = false; var sendbackToActivityInstance = tim.GetPreviousActivityInstance(runningNode, true, out hasGatewayNode).ToList()[0]; if (sendbackToActivityInstance.ActivityType == (short)ActivityTypeEnum.StartNode) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_PreviousIsStartNode; result.Message = "上一步是开始节点,无需退回!"; return(rmins); } var processModel = (new ProcessModel(runner.ProcessGUID)); rmins.ProcessModel = processModel; rmins.BackwardContext.ProcessInstance = (new ProcessInstanceManager()).GetById(lastTaskTransitionInstance.ProcessInstanceID); rmins.BackwardContext.BackwardToTaskActivity = processModel.GetActivity(sendbackToActivityInstance.ActivityGUID); rmins.BackwardContext.BackwardToTaskActivityInstance = sendbackToActivityInstance; rmins.BackwardContext.BackwardToTargetTransitionGUID = hasGatewayNode == false ? lastTaskTransitionInstance.TransitionGUID : String.Empty; //如果中间有Gateway节点,则没有直接相连的TransitonGUID rmins.BackwardContext.BackwardFromActivity = processModel.GetActivity(runningNode.ActivityGUID); rmins.BackwardContext.BackwardFromActivityInstance = runningNode; rmins.BackwardContext.BackwardTaskReciever = WfBackwardTaskReciever.Instance(sendbackToActivityInstance.ActivityName, sendbackToActivityInstance.EndedByUserID, sendbackToActivityInstance.EndedByUserName); //封装AppUser对象 rmins.AppRunner.AppName = runner.AppName; rmins.AppRunner.AppInstanceID = runner.AppInstanceID; rmins.AppRunner.ProcessGUID = runner.ProcessGUID; rmins.AppRunner.UserID = runner.UserID; rmins.AppRunner.UserName = runner.UserName; rmins.AppRunner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers(sendbackToActivityInstance.ActivityGUID, sendbackToActivityInstance.EndedByUserID, sendbackToActivityInstance.EndedByUserName); rmins.ActivityResource = new ActivityResource(runner, rmins.AppRunner.NextActivityPerformers); return(rmins); }
/// <summary> /// 退回操作 /// </summary> /// <param name="runner">执行者</param> /// <param name="result">结果对象</param> /// <returns>运行时实例对象</returns> internal static WfRuntimeManager CreateRuntimeInstanceSendBack(WfAppRunner runner, ref WfExecutedResult result) { var rmins = new WfRuntimeManagerSendBack(); rmins.WfExecutedResult = result = new WfExecutedResult(); //没有指定退回节点信息 if (runner.NextPerformerType != NextPerformerIntTypeEnum.Traced && (runner.NextActivityPerformers == null || runner.NextActivityPerformers.Count == 0)) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_IsNull; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceSendBack.null.error"); return(rmins); } //先查找当前用户正在办理的运行节点 var aim = new ActivityInstanceManager(); TaskViewEntity taskView = null; var runningNode = aim.GetRunningNode(runner, out taskView); if (runningNode == null) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotInRunning; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceSendBack.nonerun.error"); return(rmins); } if (aim.IsMineTask(runningNode, runner.UserID) == false) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotMineTask; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceSendBack.nonetask.error"); return(rmins); } var activityType = EnumHelper.ParseEnum <ActivityTypeEnum>(runningNode.ActivityType.ToString()); if (XPDLHelper.IsSimpleComponentNode(activityType) == false) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_NotTaskNode; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceSendBack.nottask.error"); return(rmins); } //获取上一步节点信息 var hasGatewayPassed = false; var processInstance = (new ProcessInstanceManager()).GetById(runningNode.ProcessInstanceID); var processModel = ProcessModelFactory.Create(processInstance.ProcessGUID, processInstance.Version); var previousStepChecker = new PreviousStepChecker(); var previousActivityList = previousStepChecker.GetPreviousActivityList(runningNode, processModel, out hasGatewayPassed); //判断退回是否有效 if (previousActivityList == null || previousActivityList.Count == 0) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_IsNull; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceSendBack.empty.error"); return(rmins); } //前端用户指定退回步骤的模式 if (runner.NextPerformerType != NextPerformerIntTypeEnum.Traced) { if (runner.NextActivityPerformers == null || runner.NextActivityPerformers.Count == 0) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_IsNull; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceSendBack.noneperformer.error"); return(rmins); } //检查节点是否一致 if (previousActivityList.Count == 1) { var onlyActivityGUID = previousActivityList[0].ActivityGUID; var isOnly = true; foreach (var step in runner.NextActivityPerformers) { if (step.Key != onlyActivityGUID) { isOnly = false; break; } } //存在不一致的退回节点 if (isOnly == false) { result.Status = WfExecutedStatus.Exception; result.ExceptionType = WfExceptionType.Sendback_IsTooManyPrevious; result.Message = LocalizeHelper.GetEngineMessage("wfruntimemanagerfactory.CreateRuntimeInstanceSendBack.notunique.error"); return(rmins); } } } else { //Traced 用于直接返回上一步使用,测试模式 var prevActivity = previousActivityList[0]; var performerList = PerformerBuilder.CreatePerformerList(runningNode.CreatedByUserID, runningNode.CreatedByUserName); runner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers(prevActivity.ActivityGUID, performerList); } //创建运行时 rmins.TaskView = taskView; rmins.RunningActivityInstance = runningNode; rmins.ProcessInstanceID = runningNode.ProcessInstanceID; rmins.ProcessInstance = processInstance; rmins.ProcessModel = processModel; rmins.AppRunner.AppName = runner.AppName; rmins.AppRunner.AppInstanceID = runner.AppInstanceID; rmins.AppRunner.UserID = runner.UserID; rmins.AppRunner.UserName = runner.UserName; rmins.AppRunner.NextActivityPerformers = runner.NextActivityPerformers; //设置退回选项类 var sendbackOperation = new SendBackOperation(); sendbackOperation.BackwardType = BackwardTypeEnum.Sendback; sendbackOperation.ProcessInstance = processInstance; sendbackOperation.BackwardFromActivityInstance = runningNode; sendbackOperation.HasGatewayPassed = hasGatewayPassed; sendbackOperation.ActivityResource = new ActivityResource(runner, rmins.AppRunner.NextActivityPerformers); sendbackOperation.ProcessModel = processModel; sendbackOperation.IsCancellingBrothersNode = (runner.ControlParameterSheet != null && runner.ControlParameterSheet.IsCancellingBrothersNode == 1) ? true : false; rmins.SendBackOperation = sendbackOperation; return(rmins); }