Пример #1
0
        /// <summary>
        /// 获取上一步节点树
        /// </summary>
        /// <param name="taskID">任务ID</param>
        /// <param name="hasGatewayPassed">是否经过网关</param>
        /// <returns>上一步步骤列表</returns>
        internal IList <NodeView> GetPreviousActivityTree(int taskID, out Boolean hasGatewayPassed)
        {
            hasGatewayPassed = false;
            //首先获取当前运行节点信息
            var aim         = new ActivityInstanceManager();
            var runningNode = aim.GetByTask(taskID);
            var nodeList    = GetPreviousActivityTree(runningNode, out hasGatewayPassed);

            return(nodeList);
        }
Пример #2
0
        /// <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));
        }