/// <summary> /// 复制多实例子节点数据 /// </summary> /// <param name="plist">执行人员列表</param> /// <param name="mainActivityInstance">主节点</param> /// <param name="session">数据会话</param> private void CloneChildNodeOfMI(PerformerList plist, ActivityInstanceEntity mainActivityInstance, IDbSession session) { //查询已有的子节点列表 var childNodeListOfMI = base.ActivityInstanceManager.GetValidActivityInstanceListOfMI(mainActivityInstance.ID, session); //创建活动实例 ActivityInstanceEntity entity = new ActivityInstanceEntity(); for (short i = 0; i < plist.Count; i++) { var userID = plist[i].UserID; var userName = plist[i].UserName; var isTaskExisted = IsTaskExisted(childNodeListOfMI, userID); if (isTaskExisted == true) { //如果活动或者任务已经存在,则不用创建新活动和任务 continue; } //根据主节点来复制子节点数据 entity = ActivityInstanceManager.CreateActivityInstanceObject(mainActivityInstance); entity.AssignedToUserIDs = userID; entity.AssignedToUserNames = userName; entity.MIHostActivityInstanceID = mainActivityInstance.ID; //并行串行下,多实例子节点的执行顺序设置 if (mainActivityInstance.MergeType == (short)MergeTypeEnum.Sequence) { entity.CompleteOrder = (short)(i + 1); } else if (mainActivityInstance.MergeType == (short)MergeTypeEnum.Parallel) { entity.CompleteOrder = -1; //并行模式下CompleteOrder的优先级一样,所以置为 -1 } //如果是串行会签,只有第一个节点处于运行状态,其它节点挂起 if ((i > 0) && (mainActivityInstance.MergeType.Value == (short)MergeTypeEnum.Sequence)) { entity.ActivityState = (short)ActivityStateEnum.Suspended; } //插入活动实例数据,并返回活动实例ID entity.ID = ActivityInstanceManager.Insert(entity, session); //插入任务数据 base.TaskManager.Insert(entity, plist[i], base.ActivityForwardContext.ActivityResource.AppRunner, session); } }
/// <summary> /// 复制并行分支多实例节点数据 /// </summary> /// <param name="plist">执行人员列表</param> /// <param name="transitionGUID">转移GUID</param> /// <param name="gatewayActivityInstance">网关活动实例</param> /// <param name="toActivityInstance">多实例分支节点</param> /// <param name="session">数据会话</param> private void CloneChildNodeOfAndSplitMI(PerformerList plist, string transitionGUID, ActivityInstanceEntity gatewayActivityInstance, ActivityInstanceEntity toActivityInstance, IDbSession session) { //查询已有的子节点列表 var childNodeListOfAndSplitMI = base.ActivityInstanceManager.GetValidSplitedActivityInstanceList(gatewayActivityInstance.ProcessInstanceID, gatewayActivityInstance.ID, session); //创建活动实例 ActivityInstanceEntity newChildInstance = new ActivityInstanceEntity(); for (short i = 0; i < plist.Count; i++) { var userID = plist[i].UserID; var userName = plist[i].UserName; var isTaskExisted = IsTaskExisted(childNodeListOfAndSplitMI, userID); if (isTaskExisted == true) { //如果活动或者任务已经存在,则不用创建新活动和任务 continue; } newChildInstance = ActivityInstanceManager.CreateActivityInstanceObject(toActivityInstance); newChildInstance.AssignedToUserIDs = userID; newChildInstance.AssignedToUserNames = userName; //插入活动实例数据,并返回活动实例ID newChildInstance.ID = ActivityInstanceManager.Insert(newChildInstance, session); //插入转移数据 base.InsertTransitionInstance(base.ActivityForwardContext.ProcessInstance, transitionGUID, gatewayActivityInstance, newChildInstance, TransitionTypeEnum.Forward, TransitionFlyingTypeEnum.NotFlying, base.ActivityForwardContext.ActivityResource.AppRunner, session); //插入任务数据 base.TaskManager.Insert(newChildInstance, plist[i], base.ActivityForwardContext.ActivityResource.AppRunner, session); } }
/// <summary> /// 多实例情况下(会签和加签)撤销处理 /// </summary> /// <param name="session"></param> internal override void ExecuteInstanceImp(IDbSession session) { var runningNode = BackwardContext.BackwardFromActivityInstance; //创建撤销到上一步的节点记录 var nodeMediatorBackward = new NodeMediatorBackward(base.BackwardContext, session); nodeMediatorBackward.CreateBackwardActivityTaskOfInnerMultipleInstance( base.BackwardContext.ProcessInstance, base.BackwardContext.BackwardToTaskActivityInstance, BackwardTypeEnum.WithdrawedOfMI, base.BackwardContext.BackwardFromActivityInstance.ID, base.ActivityResource, session); //置当前节点为撤销状态 var aim = new ActivityInstanceManager(); aim.Withdraw(runningNode.ID, base.ActivityResource.AppRunner, session); //创建新的一条待办状态的记录,用于下次执行 var newSuspendNode = aim.CreateActivityInstanceObject(runningNode); newSuspendNode.ActivityState = (short)ActivityStateEnum.Suspended; newSuspendNode.MIHostActivityInstanceID = runningNode.MIHostActivityInstanceID; newSuspendNode.CompleteOrder = runningNode.CompleteOrder; newSuspendNode.ComplexType = runningNode.ComplexType; newSuspendNode.SignForwardType = runningNode.SignForwardType; newSuspendNode.AssignedToUserIDs = runningNode.AssignedToUserIDs; newSuspendNode.AssignedToUserNames = runningNode.AssignedToUserNames; aim.Insert(newSuspendNode, session); //同时为此活动实例,创建新的任务 var tm = new TaskManager(); tm.Renew(base.BackwardContext.BackwardFromActivityInstance, newSuspendNode, base.AppRunner, session); //构造回调函数需要的数据 WfExecutedResult result = base.WfExecutedResult; result.BackwardTaskReciever = base.BackwardContext.BackwardTaskReciever; result.Status = WfExecutedStatus.Success; }
/// <summary> /// 会签类型的主节点, 多实例节点处理 /// 创建会签节点的主节点,以及会签主节点下的实例子节点记录 /// </summary> /// <param name="processInstance">流程实例</param> /// <param name="toActivity">活动</param> /// <param name="fromActivityInstance">起始活动实例</param> /// <param name="activityResource">资源</param> /// <param name="flyingType">跳跃类型</param> /// <param name="transitionGUID">转移GUID</param> /// <param name="transitionType">转移类型</param> /// <param name="session">数据上下文</param> internal void CreateMultipleInstance(ActivityEntity toActivity, ProcessInstanceEntity processInstance, ActivityInstanceEntity fromActivityInstance, String transitionGUID, TransitionTypeEnum transitionType, TransitionFlyingTypeEnum flyingType, ActivityResource activityResource, IDbSession session) { //实例化主节点Activity var toActivityInstance = CreateActivityInstanceObject(toActivity, processInstance, activityResource.AppRunner); //更新主节点实例数据 toActivityInstance.ActivityState = (short)ActivityStateEnum.Suspended; toActivityInstance.ComplexType = (short)ComplexTypeEnum.SignTogether; //串行或并行类型 toActivityInstance.MergeType = (short)toActivity.ActivityTypeDetail.MergeType; //主节点设置通过率 toActivityInstance.CompleteOrder = toActivity.ActivityTypeDetail.CompleteOrder; toActivityInstance.AssignedToUserIDs = GenerateActivityAssignedUserIDs( activityResource.NextActivityPerformers[toActivity.ActivityGUID]); toActivityInstance.AssignedToUserNames = GenerateActivityAssignedUserNames( activityResource.NextActivityPerformers[toActivity.ActivityGUID]); //插入主节点实例数据 ActivityInstanceManager.Insert(toActivityInstance, session); //插入主节点转移数据 InsertTransitionInstance(processInstance, transitionGUID, fromActivityInstance, toActivityInstance, transitionType, flyingType, activityResource.AppRunner, session); //插入会签子节点实例数据 var plist = activityResource.NextActivityPerformers[toActivity.ActivityGUID]; ActivityInstanceEntity entity = new ActivityInstanceEntity(); for (short i = 0; i < plist.Count; i++) { entity = ActivityInstanceManager.CreateActivityInstanceObject(toActivityInstance); entity.AssignedToUserIDs = plist[i].UserID; entity.AssignedToUserNames = plist[i].UserName; entity.MIHostActivityInstanceID = toActivityInstance.ID; //并行串行下,多实例子节点的执行顺序设置 if (toActivityInstance.MergeType == (short)MergeTypeEnum.Sequence) { entity.CompleteOrder = (short)(i + 1); } else if (toActivityInstance.MergeType == (short)MergeTypeEnum.Parallel) { entity.CompleteOrder = -1; //并行模式下CompleteOrder的优先级一样,所以置为 -1 } //如果是串行会签,只有第一个节点处于运行状态,其它节点挂起 if ((i > 0) && (toActivity.ActivityTypeDetail.MergeType == MergeTypeEnum.Sequence)) { entity.ActivityState = (short)ActivityStateEnum.Suspended; } //插入活动实例数据,并返回活动实例ID entity.ID = ActivityInstanceManager.Insert(entity, session); //插入任务数据 TaskManager.Insert(entity, plist[i], activityResource.AppRunner, session); } }
/// <summary> /// 插入实例数据 /// </summary> /// <param name="activityInstance">活动资源</param> /// <param name="session">会话</param> protected virtual void InsertActivityInstance(ActivityInstanceEntity activityInstance, IDbSession session) { ActivityInstanceManager.Insert(activityInstance, session); }
/// <summary> /// 插入实例数据 /// </summary> /// <param name="activityInstance">活动资源</param> /// <param name="session">会话</param> protected virtual int InsertActivityInstance(ActivityInstanceEntity activityInstance, IDbSession session) { return(ActivityInstanceManager.Insert(activityInstance, session)); }