/// <summary>
        /// 查询实例
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="id">实体主键ID</param>
        /// <returns>实体</returns>
        public override T GetInstance <T>(int id)
        {
            var aim    = new ActivityInstanceManager();
            var entity = aim.GetById(Session.Connection, id, Session.Transaction);

            return(entity as T);
        }
Beispiel #2
0
        /// <summary>
        /// 获取活动实例数据
        /// </summary>
        /// <param name="activityInstanceID"></param>
        /// <returns></returns>
        public ActivityInstanceEntity GetActivityInstance(int activityInstanceID)
        {
            var aim      = new ActivityInstanceManager();
            var instance = aim.GetById(activityInstanceID);

            return(instance);
        }
Beispiel #3
0
        /// <summary>
        /// 流程返签,先检查约束条件,然后调用wfruntimeinstance执行
        /// </summary>
        /// <param name="runner">执行者</param>
        /// <param name="result">结果对象</param>
        /// <returns>运行时实例对象</returns>
        public static WfRuntimeManager CreateRuntimeInstanceReverse(WfAppRunner runner,
                                                                    ref WfExecutedResult result)
        {
            var rmins = new WfRuntimeManagerReverse();

            rmins.WfExecutedResult = result = new WfExecutedResult();
            var pim             = new ProcessInstanceManager();
            var processInstance = pim.GetProcessInstanceLatest(runner.AppInstanceID, runner.ProcessGUID);

            if (processInstance == null || processInstance.ProcessState != (short)ProcessStateEnum.Completed)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Reverse_NotInCompleted;
                result.Message       = string.Format("当前应用:{0},实例ID:{1}, 没有完成的流程实例,无法让流程重新运行!",
                                                     runner.AppName, runner.AppInstanceID);
                return(rmins);
            }

            var tim = new TransitionInstanceManager();
            var endTransitionInstance = tim.GetEndTransition(runner.AppName, runner.AppInstanceID, runner.ProcessGUID);

            var processModel = ProcessModelFactory.Create(processInstance.ProcessGUID, processInstance.Version);
            var endActivity  = processModel.GetActivity(endTransitionInstance.ToActivityGUID);

            var aim = new ActivityInstanceManager();
            var endActivityInstance = aim.GetById(endTransitionInstance.ToActivityInstanceID);

            bool hasGatewayNode           = false;
            var  lastTaskActivityInstance = tim.GetPreviousActivityInstance(endActivityInstance, false,
                                                                            out hasGatewayNode).ToList()[0];
            var lastTaskActivity = processModel.GetActivity(lastTaskActivityInstance.ActivityGUID);

            //封装返签结束点之前办理节点的任务接收人
            rmins.AppRunner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers(lastTaskActivityInstance.ActivityGUID,
                                                                                                   lastTaskActivityInstance.EndedByUserID,
                                                                                                   lastTaskActivityInstance.EndedByUserName);

            rmins.ActivityResource        = new ActivityResource(runner, rmins.AppRunner.NextActivityPerformers);
            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.BackwardContext.ProcessInstance                = processInstance;
            rmins.BackwardContext.BackwardToTaskActivity         = lastTaskActivity;
            rmins.BackwardContext.BackwardToTaskActivityInstance = lastTaskActivityInstance;
            rmins.BackwardContext.BackwardToTargetTransitionGUID =
                hasGatewayNode == false ? endTransitionInstance.TransitionGUID : String.Empty;
            rmins.BackwardContext.BackwardFromActivity         = endActivity;
            rmins.BackwardContext.BackwardFromActivityInstance = endActivityInstance;
            rmins.BackwardContext.BackwardTaskReceiver         = WfBackwardTaskReceiver.Instance(lastTaskActivityInstance.ActivityName,
                                                                                                 lastTaskActivityInstance.EndedByUserID,
                                                                                                 lastTaskActivityInstance.EndedByUserName);

            return(rmins);
        }
Beispiel #4
0
        /// <summary>
        /// 读取节点的上一步节点信息
        /// </summary>
        /// <param name="runningNode">当前节点</param>
        /// <param name="isLookUpBackSource">是否退回</param>
        /// <param name="hasPassedGatewayNode">是否经由路由节点</param>
        /// <returns>活动实例列表</returns>
        internal IList <ActivityInstanceEntity> GetPreviousActivityInstanceList(ActivityInstanceEntity runningNode,
                                                                                bool isLookUpBackSource,
                                                                                out bool hasPassedGatewayNode)
        {
            hasPassedGatewayNode = false;
            var tim            = new TransitionInstanceManager();
            var transitionList = tim.GetTransitionInstanceList(runningNode.AppInstanceID,
                                                               runningNode.ProcessGUID,
                                                               runningNode.ProcessInstanceID).ToList();

            var backSrcActivityInstanceId = 0;

            if (isLookUpBackSource == true)
            {
                //退回情况下的处理
                if (runningNode.MIHostActivityInstanceID != null && runningNode.CompleteOrder.Value == 1)
                {
                    //多实例的第一个子节点,先找到主节点,再到transition记录表中找到上一步节点
                    backSrcActivityInstanceId = runningNode.MIHostActivityInstanceID.Value;
                }
                else if (runningNode.BackSrcActivityInstanceID != null)
                {
                    //节点时曾经发生退回的节点
                    backSrcActivityInstanceId = runningNode.BackSrcActivityInstanceID.Value;
                }
                else
                {
                    backSrcActivityInstanceId = runningNode.ID;
                }
            }
            else
            {
                backSrcActivityInstanceId = runningNode.ID;
            }

            var aim = new ActivityInstanceManager();
            var runningTransitionList = transitionList
                                        .Where(o => o.ToActivityInstanceID == backSrcActivityInstanceId)
                                        .ToList();

            IList <ActivityInstanceEntity> previousActivityInstanceList = new List <ActivityInstanceEntity>();

            foreach (var entity in runningTransitionList)
            {
                //如果是逻辑节点,则继续查找
                if (entity.FromActivityType == (short)ActivityTypeEnum.GatewayNode)
                {
                    GetPreviousOfGatewayActivityInstance(transitionList, entity.FromActivityInstanceID, previousActivityInstanceList);
                    hasPassedGatewayNode = true;
                }
                else
                {
                    previousActivityInstanceList.Add(aim.GetById(entity.FromActivityInstanceID));
                }
            }
            return(previousActivityInstanceList);
        }
Beispiel #5
0
        /// <summary>
        /// 设置活动实例的定时作业为完成状态
        /// (用于HangFire后台轮询任务)
        /// </summary>
        /// <param name="conn">链接</param>
        /// <param name="activityInstanceID">活动实例ID</param>
        /// <param name="trans">事务</param>
        public void SetActivityJobTimerCompleted(IDbConnection conn, int activityInstanceID, IDbTransaction trans)
        {
            var aim = new ActivityInstanceManager();
            var activityInstance = aim.GetById(conn, activityInstanceID, trans);

            activityInstance.JobTimerStatus          = (short)JobTimerStatusEnum.Completed;
            activityInstance.JobTimerTreatedDateTime = System.DateTime.Now;
            aim.Update(conn, activityInstance, trans);
        }
        /// <summary>
        /// 获取预选步骤人员列表
        /// </summary>
        /// <param name="runner">当前运行用户</param>
        /// <returns>步骤预选人员列表</returns>
        private IDictionary <string, PerformerList> GetNextActivityPerformersPriliminary(WfAppRunner runner)
        {
            IDictionary <string, PerformerList> nextSteps = null;

            var            tm       = new TaskManager();
            TaskViewEntity taskView = tm.GetTaskOfMine(runner);

            //读取活动实例中记录的步骤预选数据
            var aim = new ActivityInstanceManager();

            if (taskView.MIHostActivityInstanceID != null)
            {
                var mainActivityInstanceID = taskView.MIHostActivityInstanceID.Value;
                var mainActivityInstance   = aim.GetById(mainActivityInstanceID);
                if (mainActivityInstance != null)
                {
                    nextSteps = NextStepUtility.DeserializeNextStepPerformers(mainActivityInstance.NextStepPerformers);
                }
            }

            IProcessModel processModel = ProcessModelFactory.Create(runner.ProcessGUID, runner.Version);
            var           nextActivity = processModel.GetNextActivity(taskView.ActivityGUID);

            if (nextActivity != null)
            {
                if (nextActivity.ActivityType == ActivityTypeEnum.GatewayNode)
                {
                    //获取网关节点信息
                    var gatewayActivityInstance = aim.GetActivityInstanceLatest(taskView.ProcessInstanceID, nextActivity.ActivityGUID);
                    if (gatewayActivityInstance != null &&
                        !string.IsNullOrEmpty(gatewayActivityInstance.NextStepPerformers))
                    {
                        nextSteps = NextStepUtility.DeserializeNextStepPerformers(gatewayActivityInstance.NextStepPerformers);
                    }
                }
                else if (XPDLHelper.IsInterTimerEventComponentNode(nextActivity) == true)
                {
                    //中间Timer事件节点
                    var timerActivityInstance = aim.GetActivityInstanceLatest(taskView.ProcessInstanceID, nextActivity.ActivityGUID);
                    if (timerActivityInstance != null &&
                        !string.IsNullOrEmpty(timerActivityInstance.NextStepPerformers))
                    {
                        nextSteps = NextStepUtility.DeserializeNextStepPerformers(timerActivityInstance.NextStepPerformers);
                    }
                }
            }
            return(nextSteps);
        }
Beispiel #7
0
        /// <summary>
        /// 获取网关节点前的节点
        /// </summary>
        /// <param name="transitionList">转移列表</param>
        /// <param name="toActivityInstanceID">流转到的活动实例ID</param>
        /// <param name="previousActivityInstanceList">前节点实例列表</param>
        private void GetPreviousOfGatewayActivityInstance(IList <TransitionInstanceEntity> transitionList,
                                                          int toActivityInstanceID,
                                                          IList <ActivityInstanceEntity> previousActivityInstanceList)
        {
            var previousTransitionList = transitionList
                                         .Where(o => o.ToActivityInstanceID == toActivityInstanceID)
                                         .ToList();

            var aim = new ActivityInstanceManager();

            foreach (var entity in previousTransitionList)
            {
                var activityType = EnumHelper.ParseEnum <ActivityTypeEnum>(entity.FromActivityType.ToString());
                if (XPDLHelper.IsSimpleComponentNode(activityType) == true)
                {
                    previousActivityInstanceList.Add(aim.GetById(entity.FromActivityInstanceID));
                }
                else if (entity.FromActivityType == (short)ActivityTypeEnum.GatewayNode)
                {
                    GetPreviousOfGatewayActivityInstance(transitionList, entity.FromActivityInstanceID, previousActivityInstanceList);
                }
            }
        }
        /// <summary>
        /// 获取预选步骤人员列表
        /// </summary>
        /// <param name="nextActivityTree">下一步活动节点树</param>
        /// <param name="runner">当前运行用户</param>
        /// <returns>步骤预选人员列表</returns>
        private IDictionary <string, PerformerList> GetNextActivityPerformers(IList <NodeView> nextActivityTree,
                                                                              WfAppRunner runner)
        {
            IDictionary <string, PerformerList> nextSteps = null;

            var            tm       = new TaskManager();
            TaskViewEntity taskView = tm.GetTaskOfMine(runner);

            //读取活动实例中记录的步骤预选数据
            var aim = new ActivityInstanceManager();

            if (taskView.MIHostActivityInstanceID != null)
            {
                var mainActivityInstanceID = taskView.MIHostActivityInstanceID.Value;
                var mainActivityInstance   = aim.GetById(mainActivityInstanceID);
                if (mainActivityInstance != null)
                {
                    nextSteps = NextStepUtility.DeserializeNextStepPerformers(mainActivityInstance.NextStepPerformers);
                }
            }

            //获取网关节点信息
            IProcessModel processModel = ProcessModelFactory.Create(runner.ProcessGUID, runner.Version);
            var           nextActivity = processModel.GetNextActivity(taskView.ActivityGUID);

            if (nextActivity.ActivityType == ActivityTypeEnum.GatewayNode)
            {
                var gatewayActivityInstance = aim.GetActivityInstanceLatest(taskView.ProcessInstanceID, nextActivity.ActivityGUID);
                if (gatewayActivityInstance != null &&
                    !string.IsNullOrEmpty(gatewayActivityInstance.NextStepPerformers))
                {
                    nextSteps = NextStepUtility.DeserializeNextStepPerformers(gatewayActivityInstance.NextStepPerformers);
                }
            }
            return(nextSteps);
        }
Beispiel #9
0
        /// <summary>
        /// 根据不同撤销场景创建运行时管理器
        /// </summary>
        /// <param name="runningActivityInstanceList">运行节点列表</param>
        /// <param name="withdrawOperation">撤销类型</param>
        /// <param name="runner">执行者</param>
        /// <param name="result">结果对象</param>
        /// <returns>运行时管理器</returns>
        private static WfRuntimeManager CreateRuntimeInstanceWithdrawByCase(
            List <ActivityInstanceEntity> runningActivityInstanceList,
            WithdrawOperationTypeEnum withdrawOperation,
            WfAppRunner runner,
            ref WfExecutedResult result)
        {
            WfRuntimeManager rmins = new WfRuntimeManagerWithdraw();

            rmins.WfExecutedResult = result = new WfExecutedResult();

            //根据当前运行节点获取
            ActivityInstanceEntity runningNode     = runningActivityInstanceList[0];
            ProcessInstanceEntity  processInstance = (new ProcessInstanceManager()).GetById(runningNode.ProcessInstanceID);
            IProcessModel          processModel    = ProcessModelFactory.Create(processInstance.ProcessGUID, processInstance.Version);

            //不同撤销的分支场景处理
            var aim = new ActivityInstanceManager();

            //以下处理,需要知道上一步是独立节点的信息
            //获取上一步流转节点信息,可能经过And, Or等路由节点
            var  tim            = new TransitionInstanceManager();
            bool hasGatewayNode = false;
            var  currentNode    = runningNode;

            if (runningNode.MIHostActivityInstanceID != null)
            {
                //如果当前运行节点是多实例子节点,则需要找到它的主节点的Transiton记录
                currentNode = aim.GetById(runningNode.MIHostActivityInstanceID.Value);
            }
            var lastActivityInstanceList = tim.GetPreviousActivityInstance(currentNode, false, out hasGatewayNode).ToList();

            if (lastActivityInstanceList == null || lastActivityInstanceList.Count > 1)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Withdraw_HasTooMany;
                result.Message       = "当前没有可以撤销回去的节点,或者有多个可以撤销回去的节点,无法选择!";

                return(rmins);
            }

            TransitionInstanceEntity lastTaskTransitionInstance = null;

            if (hasGatewayNode == false)
            {
                lastTaskTransitionInstance = tim.GetLastTaskTransition(runner.AppName,
                                                                       runner.AppInstanceID, runner.ProcessGUID);
                if (lastTaskTransitionInstance.TransitionType == (short)TransitionTypeEnum.Loop)
                {
                    result.Status        = WfExecutedStatus.Exception;
                    result.ExceptionType = WfExceptionType.Withdraw_IsLoopNode;
                    result.Message       = "当前流转是自循环,无需撤销!";

                    return(rmins);
                }
            }

            var previousActivityInstance = lastActivityInstanceList[0];

            if (previousActivityInstance.EndedByUserID != runner.UserID)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Withdraw_NotCreatedByMine;
                result.Message       = string.Format("上一步节点的任务办理人跟当前登录用户不一致,无法撤销回上一步!节点办理人:{0}",
                                                     previousActivityInstance.EndedByUserName);

                return(rmins);
            }

            if (previousActivityInstance.ActivityType == (short)ActivityTypeEnum.EndNode)
            {
                result.Status        = WfExecutedStatus.Exception;
                result.ExceptionType = WfExceptionType.Withdraw_PreviousIsEndNode;
                result.Message       = "上一步是结束节点,无法撤销!";

                return(rmins);
            }

            //当前运行节点是普通节点
            if (withdrawOperation == WithdrawOperationTypeEnum.Normal)
            {
                //简单串行模式下的退回
                rmins = new WfRuntimeManagerWithdraw();
                rmins.WfExecutedResult = result = new WfExecutedResult();

                rmins.ProcessModel                    = processModel;
                rmins.AppRunner.ProcessGUID           = runner.ProcessGUID;
                rmins.BackwardContext.ProcessInstance = processInstance;
                rmins.BackwardContext.BackwardToTargetTransitionGUID =
                    hasGatewayNode == false ? lastTaskTransitionInstance.TransitionGUID : String.Empty;
                rmins.BackwardContext.BackwardToTaskActivity         = processModel.GetActivity(previousActivityInstance.ActivityGUID);
                rmins.BackwardContext.BackwardToTaskActivityInstance = previousActivityInstance;
                rmins.BackwardContext.BackwardFromActivity           = processModel.GetActivity(runningNode.ActivityGUID);
                rmins.BackwardContext.BackwardFromActivityInstance   = runningNode; //准备状态的接收节点
                rmins.BackwardContext.BackwardTaskReceiver           = WfBackwardTaskReceiver.Instance(
                    previousActivityInstance.ActivityName,
                    previousActivityInstance.EndedByUserID,
                    previousActivityInstance.EndedByUserName);

                //封装AppUser对象
                rmins.AppRunner.AppName                = runner.AppName;
                rmins.AppRunner.AppInstanceID          = runner.AppInstanceID;
                rmins.AppRunner.UserID                 = runner.UserID;
                rmins.AppRunner.UserName               = runner.UserName;
                rmins.AppRunner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers(
                    previousActivityInstance.ActivityGUID,
                    runner.UserID,
                    runner.UserName);
                rmins.ActivityResource = new ActivityResource(runner, rmins.AppRunner.NextActivityPerformers);

                return(rmins);
            }

            //如果有其它模式,没有处理到,则直接抛出异常
            throw new WorkflowException("未知的撤销场景,请报告给技术支持人员!");
        }
        /// <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="session"></param>
        internal override void ExecuteInstanceImp(IDbSession session)
        {
            var nodeMediatorBackward = new NodeMediatorBackward(base.BackwardContext, session);
            var aim = new ActivityInstanceManager();
            var backMostPreviouslyActivityInstanceID = GetBackwardMostPreviouslyActivityInstanceID();
            var previousActvityInstance = aim.GetById(backMostPreviouslyActivityInstanceID);

            if (previousActvityInstance.MIHostActivityInstanceID != null)
            {
                //上一步节点是会签节点的退回处理
                var mainPrevousActivityInstance = aim.GetById(previousActvityInstance.MIHostActivityInstanceID.Value);
                if (mainPrevousActivityInstance.ComplexType.Value == (short)ComplexTypeEnum.SignTogether)
                {
                    //如果是会签节点,则需要重新实例化会签节点上的所有办理人的任务
                    nodeMediatorBackward.CreateBackwardActivityTaskRepeatedSignTogetherMultipleInstance(
                        base.BackwardContext.ProcessInstance,
                        base.BackwardContext.BackwardToTaskActivity,
                        base.BackwardContext.BackwardFromActivityInstance,
                        BackwardTypeEnum.Sendback,
                        mainPrevousActivityInstance,
                        base.BackwardContext.BackwardToTargetTransitionGUID,
                        TransitionTypeEnum.Sendback,
                        TransitionFlyingTypeEnum.NotFlying,
                        base.ActivityResource,
                        session);

                    //更新当前办理节点的状态(从准备或运行状态更新为退回状态)
                    aim.SendBack(base.BackwardContext.BackwardFromActivityInstance.ID,
                                 base.ActivityResource.AppRunner,
                                 session);
                }
                else if (mainPrevousActivityInstance.ComplexType.Value == (short)ComplexTypeEnum.SignForward)
                {
                    //上一步节点是加签节点的退回处理
                    nodeMediatorBackward.CreateBackwardActivityTaskRepateSignForwardMainNodeOnly(base.BackwardContext.ProcessInstance,
                                                                                                 base.BackwardContext.BackwardToTaskActivity,
                                                                                                 base.BackwardContext.BackwardFromActivityInstance,
                                                                                                 BackwardTypeEnum.Sendback,
                                                                                                 mainPrevousActivityInstance,
                                                                                                 base.BackwardContext.BackwardToTargetTransitionGUID,
                                                                                                 TransitionTypeEnum.Sendback,
                                                                                                 TransitionFlyingTypeEnum.NotFlying,
                                                                                                 base.ActivityResource,
                                                                                                 session);

                    //更新当前办理节点的状态(从准备或运行状态更新为退回状态)
                    aim.SendBack(base.BackwardContext.BackwardFromActivityInstance.ID,
                                 base.ActivityResource.AppRunner,
                                 session);
                }
            }
            else
            {
                //上一步节点是普通节点的退回处理
                nodeMediatorBackward.CreateBackwardActivityTaskTransitionInstance(base.BackwardContext.ProcessInstance,
                                                                                  base.BackwardContext.BackwardFromActivityInstance,
                                                                                  BackwardTypeEnum.Sendback,
                                                                                  backMostPreviouslyActivityInstanceID,
                                                                                  base.BackwardContext.BackwardToTargetTransitionGUID,
                                                                                  TransitionTypeEnum.Sendback,
                                                                                  TransitionFlyingTypeEnum.NotFlying,
                                                                                  base.ActivityResource,
                                                                                  session);

                //更新当前办理节点的状态(从准备或运行状态更新为退回状态)
                aim.SendBack(base.BackwardContext.BackwardFromActivityInstance.ID,
                             base.ActivityResource.AppRunner,
                             session);
            }

            //构造回调函数需要的数据
            WfExecutedResult result = base.WfExecutedResult;

            result.BackwardTaskReciever = base.BackwardContext.BackwardTaskReciever;
            result.Status = WfExecutedStatus.Success;
        }
Beispiel #12
0
        /// <summary>
        /// 执行普通任务节点
        /// 1. 当设置任务完成时,同时设置活动完成
        /// 2. 当实例化活动数据时,产生新的任务数据
        /// </summary>
        internal override void ExecuteWorkItem()
        {
            try
            {
                //执行前Action列表
                OnBeforeExecuteWorkItem();

                //先取出原始退回节点信息
                var backSrcActivityInstanceID = base.ActivityForwardContext.FromActivityInstance.BackSrcActivityInstanceID;
                if (backSrcActivityInstanceID != null)
                {
                    //完成当前的任务节点
                    bool canContinueForwardCurrentNode = CompleteWorkItem(ActivityForwardContext.TaskID,
                                                                          ActivityForwardContext.ActivityResource,
                                                                          this.Session);

                    if (canContinueForwardCurrentNode == true)
                    {
                        var aim = new ActivityInstanceManager();
                        var backSrcActivityInstance = aim.GetById(backSrcActivityInstanceID.Value);

                        //取出下一步办理人员信息
                        var nextStep      = base.ActivityForwardContext.ActivityResource.AppRunner.NextActivityPerformers;
                        var performerList = nextStep[backSrcActivityInstance.ActivityGUID];

                        //判断不同的修订模式
                        var mainActivityInstanceID = backSrcActivityInstance.MIHostActivityInstanceID;
                        if (mainActivityInstanceID != null)
                        {
                            //会签模式
                            //复制与会签子节点相同的活动实例和任务记录
                            var mainActivityInstance = aim.GetById(mainActivityInstanceID.Value);
                            CloneChildNodeOfMI(performerList, mainActivityInstance, base.Session);
                        }
                        else
                        {
                            //并行分支(多实例)的情况
                            var transitionList = ActivityForwardContext.ProcessModel.GetBackwardTransitionList(backSrcActivityInstance.ActivityGUID);
                            if (transitionList != null && transitionList.Count == 1)
                            {
                                var transition  = transitionList[0];
                                var gatewayNode = ActivityForwardContext.ProcessModel.GetActivity(transition.FromActivityGUID);
                                if (gatewayNode.GatewayDirectionType == GatewayDirectionEnum.AndSplitMI)
                                {
                                    //复制并行分支多实例
                                    var gatewayActivityInstance = base.ActivityInstanceManager.GetActivityInstanceLatest(
                                        backSrcActivityInstance.ProcessInstanceID,
                                        gatewayNode.ActivityGUID, base.Session);
                                    CloneChildNodeOfAndSplitMI(performerList, transition.TransitionGUID, gatewayActivityInstance, backSrcActivityInstance, base.Session);
                                }
                                else
                                {
                                    throw new WorkflowException("当前节点不满足并行分支多实例(AndSplitMI)的流程修订,暂不支持!请联系技术人员!");
                                }
                            }
                            else
                            {
                                throw new WorkflowException("当前不是会签或者并行分支多实例(AndSplitMI)的流程修订,暂不支持!请联系技术人员!");
                            }
                        }
                    }
                    else
                    {
                        throw new WorkflowException("虽然能够完成当前任务节点,但是不能继续向下流转,请联系技术人员!");
                    }
                }
                else
                {
                    throw new WorkflowException("流程无法修订,因为没有退回来源节点数据!");
                }
                //执行后Action列表
                OnAfterExecuteWorkItem();
            }
            catch (System.Exception ex)
            {
                throw;
            }
        }
Beispiel #13
0
        public WfRuntimeManager GetRuntimeInstanceWithdraw(string appName,
                                                           int appInstanceID,
                                                           Guid processGUID,
                                                           int userID,
                                                           string userName)
        {
            //是否可撤销的条件检查
            var lastTaskTransitionInstance = (new TransitionInstanceManager()).GetLastTaskTransition(appName, appInstanceID, processGUID);

            if (lastTaskTransitionInstance.FromActivityType != (short)NodeTypeEnum.TaskNode)
            {
                throw new WfRuntimeException("当前撤销位置节点不是任务节点,无法撤销回到上一步!");
            }
            else if (lastTaskTransitionInstance.TransitionType == (short)TransitionTypeEnum.Loop)
            {
                throw new WfRuntimeException("当前流转是自循环,无需撤销!");
            }

            var aim = new ActivityInstanceManager();
            var withdrawActivityInstance = aim.GetById(lastTaskTransitionInstance.FromActivityInstanceGUID);

            if (withdrawActivityInstance.EndedByUserID.Value != userID)
            {
                throw new WfRuntimeException(string.Format("上一步节点的任务办理人跟当前登录用户不一致,无法撤销回上一步!节点办理人:{0}",
                                                           withdrawActivityInstance.EndedByUserName));
            }
            else if (withdrawActivityInstance.State != (short)NodeStateEnum.Completed)
            {
                throw new WfRuntimeException(string.Format("上一步节点的任务办理状态不是完成状态,无法撤销回来!上一步节点最终状态:{0}",
                                                           withdrawActivityInstance.State));
            }

            var acceptedActivityInstance = aim.GetById(lastTaskTransitionInstance.ToActivityInstanceGUID);

            if (acceptedActivityInstance.State != (short)NodeStateEnum.Ready)
            {
                throw new WfRuntimeException(string.Format("接收节点的状态不在准备状态,无法撤销到上一步,接收节点状态:{0}",
                                                           acceptedActivityInstance.State));
            }

            //准备撤销节点的相关信息
            var processModel = (new ProcessModel(processGUID));

            this.ProcessModel                                   = processModel;
            this.AppRunner.ProcessGUID                          = processGUID;
            this.BackwardContext.ProcessInstance                = (new ProcessInstanceManager()).GetById(lastTaskTransitionInstance.ProcessInstanceGUID);
            this.BackwardContext.BackwardToTargetTransition     = processModel.GetTransition(lastTaskTransitionInstance.TransitionGUID);
            this.BackwardContext.BackwardToTaskActivity         = processModel.GetActivity(lastTaskTransitionInstance.FromActivityGUID);
            this.BackwardContext.BackwardToTaskActivityInstance = withdrawActivityInstance;
            this.BackwardContext.FromActivity                   = processModel.GetActivity(acceptedActivityInstance.ActivityGUID);
            this.BackwardContext.FromActivityInstance           = acceptedActivityInstance; //准备状态的接收节点

            //封装AppUser对象
            this.AppRunner.AppName                = appName;
            this.AppRunner.AppInstanceID          = appInstanceID;
            this.AppRunner.UserID                 = userID;
            this.AppRunner.UserName               = userName;
            this.AppRunner.NextActivityPerformers = ActivityResource.CreateNextActivityPerformers(lastTaskTransitionInstance.FromActivityGUID,
                                                                                                  userID,
                                                                                                  userName);
            this.ActivityResource = new ActivityResource(userID, userName, this.AppRunner.NextActivityPerformers);


            return(this);
        }