/// <summary>
        /// 读取节点的上一步节点信息
        /// </summary>
        /// <param name="runningNode">当前节点</param>
        /// <param name="isSendback">是否退回</param>
        /// <param name="hasPassedGatewayNode">是否经由路由节点</param>
        /// <returns>活动实例列表</returns>
        internal IList <ActivityInstanceEntity> GetPreviousActivityInstance(ActivityInstanceEntity runningNode,
                                                                            bool isSendback,
                                                                            out bool hasPassedGatewayNode)
        {
            hasPassedGatewayNode = false;
            var transitionList = GetTransitionInstanceList(runningNode.AppInstanceID,
                                                           runningNode.ProcessGUID,
                                                           runningNode.ProcessInstanceID).ToList();

            var backSrcActivityInstanceId = 0;

            if (isSendback == 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);
        }
示例#2
0
        /// <summary>
        /// 获取流程当前运行节点信息
        /// </summary>
        /// <param name="runner">执行者</param>
        /// <returns>活动实例</returns>
        internal ActivityInstanceEntity GetRunningNode(WfAppRunner runner)
        {
            var appInstanceID = runner.AppInstanceID;
            var processGUID   = runner.ProcessGUID;
            var taskID        = runner.TaskID;

            //如果流程在运行状态,则返回运行时信息
            TaskViewEntity task   = null;
            var            aim    = new ActivityInstanceManager();
            var            entity = GetRunningNode(runner, out task);

            return(entity);
        }
示例#3
0
        /// <summary>
        /// 创建新的委托任务
        /// </summary>
        /// <param name="entity">任务委托实体</param>
        /// <param name="cancalOriginalTask">是否取消原始任务</param>
        internal Boolean Entrust(TaskEntrustedEntity entity, bool cancalOriginalTask = true)
        {
            var isOk = false;

            using (var session = DbFactory.CreateSession())
            {
                var transaction = session.DbContext.Database.BeginTransaction();
                try
                {
                    var am = new ActivityInstanceManager();
                    var activityInstance = am.GetByTask(entity.TaskID, session);

                    if (activityInstance.ActivityState != (short)ActivityStateEnum.Ready &&
                        activityInstance.ActivityState != (short)ActivityStateEnum.Running)
                    {
                        throw new WorkflowException("没有可以委托的任务,因为活动实例的状态不在运行状态!");
                    }

                    //更新AssignedToUsers 信息
                    activityInstance.AssignedToUserIDs   = activityInstance.AssignedToUserIDs + "," + entity.EntrustToUserID;
                    activityInstance.AssignedToUserNames = activityInstance.AssignedToUserNames + "," + entity.EntrustToUserName;
                    activityInstance.ActivityState       = (int)ActivityStateEnum.Ready;
                    am.Update(activityInstance, session);

                    //更新原委托任务的状态为关闭
                    if (cancalOriginalTask == true)
                    {
                        var task = GetTask(entity.TaskID);
                        task.TaskState = (short)TaskStateEnum.Closed;
                        Update(task, session);
                    }

                    //插入委托任务
                    Insert(activityInstance, entity.EntrustToUserID, entity.EntrustToUserName,
                           entity.RunnerID, entity.RunnerName, session, entity.TaskID);

                    transaction.Commit();
                    isOk = true;
                }
                catch (System.Exception ex)
                {
                    transaction.Rollback();
                    throw new WorkflowException(string.Format("委托任务时出错!,详细错误:{0}", ex.Message), ex);
                }
            }
            return(isOk);
        }
        /// <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);
                }
            }
        }
示例#5
0
        /// <summary>
        /// 判断任务是否是当前节点最后一个任务
        /// 单一节点:返回True
        /// 多实例节点:根据实例个数判断
        /// </summary>
        /// <param name="taskID">任务ID</param>
        /// <returns>是否最后一条任务</returns>
        public Boolean IsLastTask(int taskID)
        {
            var isLast           = false;
            var task             = GetTask(taskID);
            var aim              = new ActivityInstanceManager();
            var activityInstance = aim.GetById(task.ActivityInstanceID);

            if (activityInstance.MIHostActivityInstanceID != null)
            {
                //多实例会签和加签处理
                //取出会签主节点实例数据
                var mainActivityInstance = aim.GetById(activityInstance.MIHostActivityInstanceID.Value);
                var complexType          = EnumHelper.ParseEnum <ComplexTypeEnum>(mainActivityInstance.ComplexType.Value.ToString());

                if (complexType == ComplexTypeEnum.SignTogether)        //会签
                {
                    var mergeType = EnumHelper.ParseEnum <MergeTypeEnum>(mainActivityInstance.MergeType.Value.ToString());
                    if (mergeType == MergeTypeEnum.Sequence)        //串行会签
                    {
                        //取出处于多实例挂起的节点列表
                        var sqList = aim.GetActivityMulitipleInstanceWithState(
                            mainActivityInstance.ID,
                            mainActivityInstance.ProcessInstanceID,
                            (short)ActivityStateEnum.Suspended).ToList <ActivityInstanceEntity>();
                        short allNum   = (short)mainActivityInstance.AssignedToUserIDs.Split(',').Length;
                        short maxOrder = 0;

                        if (sqList != null && sqList.Count > 0)
                        {
                            //取出最大执行节点
                            maxOrder = (short)sqList.Max <ActivityInstanceEntity>(t => t.CompleteOrder.Value);
                        }
                        else if (mainActivityInstance.CompleteOrder <= allNum)
                        {
                            //最后一个执行节点
                            maxOrder = (short)mainActivityInstance.CompleteOrder.Value;
                        }
                        else
                        {
                            maxOrder = allNum;
                        }
                        if (mainActivityInstance.CompareType == null ||
                            EnumHelper.ParseEnum <CompareTypeEnum>(mainActivityInstance.CompareType.Value.ToString())
                            == CompareTypeEnum.Count)
                        {
                            //串行会签通过率(按人数判断)
                            if (mainActivityInstance.CompleteOrder != null && mainActivityInstance.CompleteOrder <= maxOrder)
                            {
                                maxOrder = (short)mainActivityInstance.CompleteOrder;
                            }
                            if (activityInstance.CompleteOrder < maxOrder)
                            {
                                isLast = false;
                            }
                            else if (activityInstance.CompleteOrder == maxOrder)
                            {
                                isLast = true;
                            }
                        }
                        else
                        {
                            if (mainActivityInstance.CompleteOrder == null || mainActivityInstance.CompleteOrder > 1)//串行会签未设置通过率的判断
                            {
                                mainActivityInstance.CompleteOrder = 1;
                            }
                            if ((activityInstance.CompleteOrder * 0.01) / (allNum * 0.01) >= mainActivityInstance.CompleteOrder)
                            {
                                isLast = true;
                            }
                            else
                            {
                                isLast = false;
                            }
                        }
                    }
                    else if (mergeType == MergeTypeEnum.Parallel)        //并行会签
                    {
                        //取出处于多实例节点列表
                        var sqList = aim.GetActivityMultipleInstance(mainActivityInstance.ID,
                                                                     mainActivityInstance.ProcessInstanceID)
                                     .ToList <ActivityInstanceEntity>();
                        var allCount       = sqList.Where(x => x.ActivityState != (short)ActivityStateEnum.Withdrawed).ToList().Count();
                        var completedCount = sqList.Where <ActivityInstanceEntity>(w => w.ActivityState == (short)ActivityStateEnum.Completed ||
                                                                                   w.AssignedToUserIDs == task.AssignedToUserID)
                                             .ToList <ActivityInstanceEntity>()
                                             .Count();
                        if (mainActivityInstance.CompareType == null ||
                            (EnumHelper.ParseEnum <CompareTypeEnum>(mainActivityInstance.CompareType.Value.ToString())
                             == CompareTypeEnum.Percentage))
                        {
                            if (mainActivityInstance.CompleteOrder == null || mainActivityInstance.CompleteOrder > 1)//并行会签未设置通过率的判断
                            {
                                mainActivityInstance.CompleteOrder = 1;
                            }

                            if ((completedCount * 0.01) / (allCount * 0.01) >= mainActivityInstance.CompleteOrder)
                            {
                                isLast = true;
                            }
                            else
                            {
                                isLast = false;
                            }
                        }
                        else
                        {
                            if (mainActivityInstance.CompleteOrder == null || mainActivityInstance.CompleteOrder > allCount)
                            {
                                mainActivityInstance.CompleteOrder = allCount;
                            }
                            if (mainActivityInstance.CompleteOrder > completedCount)
                            {
                                isLast = false;
                            }
                            else if (mainActivityInstance.CompleteOrder == completedCount)
                            {
                                isLast = true;
                            }
                        }
                    }
                }
                else if (complexType == ComplexTypeEnum.SignForward)     //加签
                {
                    //判断加签是否全部完成,如果是,则流转到下一步,否则不能流转
                    var signforwardType = EnumHelper.ParseEnum <SignForwardTypeEnum>(activityInstance.SignForwardType.Value.ToString());

                    if (signforwardType == SignForwardTypeEnum.SignForwardBehind ||
                        signforwardType == SignForwardTypeEnum.SignForwardBefore)           //前加签,后加签
                    {
                        //取出处于多实例节点列表
                        var sqList = aim.GetActivityMulitipleInstanceWithState(
                            mainActivityInstance.ID,
                            mainActivityInstance.ProcessInstanceID,
                            (short)ActivityStateEnum.Suspended).ToList <ActivityInstanceEntity>();

                        short maxOrder = 0;
                        if (sqList != null && sqList.Count > 0)
                        {
                            //取出最大执行节点
                            maxOrder = (short)sqList.Max <ActivityInstanceEntity>(t => t.CompleteOrder.Value);
                        }
                        else
                        {
                            //最后一个执行节点
                            maxOrder = (short)activityInstance.CompleteOrder;// (short)mainActivityInstance.CompleteOrder.Value;
                        }
                        if (mainActivityInstance.CompareType == null ||
                            EnumHelper.ParseEnum <CompareTypeEnum>(mainActivityInstance.CompareType.Value.ToString())
                            == CompareTypeEnum.Count)
                        {
                            //加签通过率
                            if (mainActivityInstance.CompleteOrder != null && mainActivityInstance.CompleteOrder <= maxOrder)
                            {
                                maxOrder = (short)mainActivityInstance.CompleteOrder;
                            }

                            if (activityInstance.CompleteOrder == sqList.Count)
                            {
                                isLast = true;
                            }
                            else if (activityInstance.CompleteOrder < maxOrder)
                            {
                                isLast = false;
                            }
                            else if (activityInstance.CompleteOrder == maxOrder)
                            {
                                //最后一个节点执行完,主节点进入完成状态,整个流程向下执行
                                isLast = true;
                            }
                        }
                        else
                        {
                            if (mainActivityInstance.CompleteOrder == null || mainActivityInstance.CompleteOrder > 1)//串行加签未设置通过率的判断
                            {
                                mainActivityInstance.CompleteOrder = 1;
                            }
                            if ((activityInstance.CompleteOrder * 0.01) / (maxOrder * 0.01) >= mainActivityInstance.CompleteOrder)
                            {
                                isLast = true;
                            }
                            else
                            {
                                isLast = false;
                            }
                        }
                    }
                    else if (signforwardType == SignForwardTypeEnum.SignForwardParallel)        //并行加签
                    {
                        //取出处于多实例节点列表
                        var sqList = aim.GetActivityMultipleInstance(mainActivityInstance.ID,
                                                                     mainActivityInstance.ProcessInstanceID)
                                     .ToList <ActivityInstanceEntity>();

                        //并行加签,按照通过率来决定是否标识当前节点完成
                        var allCount       = sqList.Where(x => x.ActivityState != (short)ActivityStateEnum.Withdrawed).ToList().Count();
                        var completedCount = sqList.Where <ActivityInstanceEntity>(w => w.ActivityState == (short)ActivityStateEnum.Completed ||
                                                                                   w.AssignedToUserIDs == task.AssignedToUserID)
                                             .ToList <ActivityInstanceEntity>()
                                             .Count();
                        if (mainActivityInstance.CompareType == null ||
                            EnumHelper.ParseEnum <CompareTypeEnum>(mainActivityInstance.CompareType.Value.ToString())
                            == CompareTypeEnum.Percentage)
                        {
                            if (mainActivityInstance.CompleteOrder > 1)//并行加签通过率的判断
                            {
                                mainActivityInstance.CompleteOrder = 1;
                            }

                            if ((completedCount * 0.01) / (allCount * 0.01) >= mainActivityInstance.CompleteOrder)
                            {
                                isLast = true;
                            }
                            else
                            {
                                isLast = false;
                            }
                        }
                        else
                        {
                            if (mainActivityInstance.CompleteOrder == null || mainActivityInstance.CompleteOrder > allCount)
                            {
                                mainActivityInstance.CompleteOrder = allCount;
                            }
                            if (mainActivityInstance.CompleteOrder > completedCount)
                            {
                                isLast = false;
                            }
                            else if (mainActivityInstance.CompleteOrder == completedCount)
                            {
                                isLast = true;
                            }
                        }
                    }
                }
            }
            else
            {
                //单一节点类型
                isLast = true;
            }
            return(isLast);
        }
示例#6
0
        /// <summary>
        /// 获取流程当前运行节点信息
        /// </summary>
        /// <param name="runner">执行者</param>
        /// <param name="taskView">任务视图</param>
        /// <returns>活动实例</returns>
        internal ActivityInstanceEntity GetRunningNode(WfAppRunner runner,
                                                       out TaskViewEntity taskView)
        {
            var appInstanceID = runner.AppInstanceID;
            var processGUID   = runner.ProcessGUID;
            var taskID        = runner.TaskID;

            taskView = null;
            ActivityInstanceEntity activityInstance = null;

            //如果流程在运行状态,则返回运行时信息
            var tm = new TaskManager();

            var aim = new ActivityInstanceManager();
            var activityInstanceList = aim.GetRunningActivityInstanceList(runner.AppInstanceID, runner.ProcessGUID).ToList();

            if ((activityInstanceList != null) && (activityInstanceList.Count == 1))
            {
                activityInstance = activityInstanceList[0];
                taskView         = tm.GetTaskOfMine(activityInstance.ID, runner.UserID);
            }
            else if (activityInstanceList.Count > 0)
            {
                if (runner.TaskID != null && runner.TaskID.Value != 0)
                {
                    taskView = tm.GetTaskView(taskID.Value);

                    foreach (var ai in activityInstanceList)
                    {
                        if (ai.ID == taskView.ActivityInstanceID)
                        {
                            activityInstance = ai;
                            break;
                        }
                    }

                    //判断是否有并行节点存在,如果有并行节点存在,取并行节点的主节点(并行会签)
                    if (activityInstance == null && activityInstanceList[0].MIHostActivityInstanceID != null)
                    {
                        var mainActivityInstanceID = activityInstanceList[0].MIHostActivityInstanceID;
                        activityInstance = aim.GetById(mainActivityInstanceID.Value);
                    }
                }
                else
                {
                    //并行模式处理
                    //根据当前执行者身份取出(他或她)要办理的活动实例(并行模式下有多个处于待办或运行状态的节点)
                    foreach (var ai in activityInstanceList)
                    {
                        if (ai.AssignedToUserIDs == runner.UserID)
                        {
                            activityInstance = ai;
                            break;
                        }
                    }

                    if (activityInstance != null)
                    {
                        //获取taskview
                        taskView = tm.GetTaskOfMine(activityInstance.ID, runner.UserID);
                    }
                    else
                    {
                        //当前用户的待办任务不唯一,抛出异常,需要TaskID唯一界定
                        var e = new WorkflowException("当前流程有多个运行节点,但没有TaskID传入,状态异常!");
                        LogManager.RecordLog("获取当前运行节点信息异常", LogEventType.Exception, LogPriority.Normal, null, e);
                        throw e;
                    }
                }
            }
            else
            {
                //当前没有运行状态的节点存在,流程不存在,或者已经结束或取消
                var e = new WorkflowException("当前流程没有运行节点,状态异常!");
                LogManager.RecordLog("获取当前运行节点信息异常", LogEventType.Exception, LogPriority.Normal, null, e);
                throw e;
            }
            return(activityInstance);
        }