/// <summary>
        /// 执行
        /// </summary>
        /// <param name="flowIn">流程输入</param>
        /// <param name="connectionId">连接ID</param>
        /// <param name="comData">通用数据</param>
        /// <returns>返回信息</returns>
        public virtual ReturnInfo <bool> Execute(int flowIn, CommonUseData comData = null, string connectionId = null)
        {
            return(ExecReturnFuncAndConnectionId <bool>((reInfo, connId) =>
            {
                var workflow = WorkflowPersistence.Select(flowIn, connectionId: connId, comData: comData);
                if (workflow == null)
                {
                    reInfo.SetFailureMsg($"找不到ID[{flowIn}]的工作流");

                    return false;
                }

                workflow.WorkflowDefine = WorkflowDefinePersistence.Select(workflow.WorkflowDefineId, connectionId: connId, comData: comData);
                if (workflow.WorkflowDefine == null)
                {
                    reInfo.SetFailureMsg($"找不到ID[{flowIn}]的工作流定义");

                    return false;
                }

                workflow.Handles = WorkflowHandlePersistence.SelectByWorkflowId(flowIn, connId);

                Vali(reInfo, workflow, comData);
                if (reInfo.Failure())
                {
                    return false;
                }

                ReturnInfo <bool> reTrans = ExecTransaction(reInfo, workflow, connectionId: connId, comData: comData);
                reInfo.FromBasic(reTrans);

                if (reTrans.Failure())
                {
                    return false;
                }

                var descAttr = typeof(RemoveType).GetAttributeForEnum <DescriptionAttribute>(GetRemoveType().ToString());
                if (descAttr != null)
                {
                    reInfo.SetSuccessMsg($"此工作流已{descAttr.Description}");
                }

                return true;
            }));
        }
        /// <summary>
        /// 执行核心
        /// </summary>
        /// <param name="returnInfo">返回信息</param>
        /// <param name="workflow">工作流</param>
        /// <param name="connectionId">连接ID</param>
        protected override void ExecCore(ReturnInfo <bool> returnInfo, WorkflowInfo workflow, string connectionId = null)
        {
            // 除本人外,所有处理者都删除
            foreach (var h in workflow.Handles)
            {
                if (h.HandlerId == UserTool.CurrUser.Id)
                {
                    workflow.CurrHandlerIds            = h.HandlerId.ToString();
                    workflow.CurrHandlers              = h.Handler;
                    workflow.CurrConcreteCensorshipIds = h.ConcreteConcreteId.ToString();
                    workflow.CurrConcreteCensorships   = h.ConcreteConcrete;
                    workflow.CurrFlowCensorshipIds     = h.FlowCensorshipId.ToString();
                    workflow.FlowStatus = FlowStatusEnum.REVERSED;

                    continue;
                }

                WorkflowHandlePersistence.DeleteById(h.Id, connectionId);
            }

            WorkflowPersistence.UpdateFlowStatusAndCensorshipAndHandlerById(workflow, connectionId);
        }
 /// <summary>
 /// 执行核心
 /// </summary>
 /// <param name="returnInfo">返回信息</param>
 /// <param name="workflow">工作流</param>
 /// <param name="connectionId">连接ID</param>
 /// <param name="comData">通用数据</param>
 protected virtual void ExecCore(ReturnInfo <bool> returnInfo, WorkflowInfo workflow, CommonUseData comData = null, string connectionId = null)
 {
     WorkflowHandlePersistence.DeleteByWorkflowId(workflow.Id, connectionId);
     WorkflowPersistence.DeleteById(workflow.Id, connectionId: connectionId, comData: comData);
 }
Esempio n. 4
0
        /// <summary>
        /// 审核处理
        /// </summary>
        /// <param name="returnInfo">返回信息</param>
        /// <param name="findFlowCensorshipIn">查找流程关卡输入</param>
        /// <param name="connectionId">连接ID</param>
        /// <param name="currUser">当前用户</param>
        private void AuditHandle(ReturnInfo <FlowCensorshipOutInfo> returnInfo, FlowCensorshipInInfo findFlowCensorshipIn, string connectionId = null, BasicUserInfo currUser = null)
        {
            if (findFlowCensorshipIn.CurrWorkflowHandle == null)
            {
                returnInfo.SetFailureMsg("当前工作流处理不能为null");
                return;
            }

            if (findFlowCensorshipIn.ActionType == ActionType.SAVE)
            {
                returnInfo.SetFailureMsg("审核阶段不能保存");
                return;
            }

            returnInfo.Data.Workflow = findFlowCensorshipIn.Workflow;

            FlowCensorshipInfo currFlowCens = FindFlowCensorshipByFlowCensorshipId(findFlowCensorshipIn, findFlowCensorshipIn.CurrWorkflowHandle.FlowCensorshipId);

            if (currFlowCens == null)
            {
                returnInfo.SetFailureMsg("找不到当前处理的流程关卡");
                return;
            }

            findFlowCensorshipIn.CurrWorkflowHandle.HandleTime = DateTime.Now;

            returnInfo.Data.CurrConcreteCensorship = new ConcreteCensorshipInfo()
            {
                Id              = findFlowCensorshipIn.CurrWorkflowHandle.ConcreteConcreteId,
                Name            = findFlowCensorshipIn.CurrWorkflowHandle.ConcreteConcrete,
                WorkflowHandles = new WorkflowHandleInfo[] { findFlowCensorshipIn.CurrWorkflowHandle },
                FlowCensorship  = currFlowCens
            };

            string idea = findFlowCensorshipIn.Idea;

            if (findFlowCensorshipIn.ActionType == ActionType.SEND)
            {
                if (string.IsNullOrWhiteSpace(idea))
                {
                    idea = "送件";
                }

                findFlowCensorshipIn.CurrWorkflowHandle.Idea         = idea;
                findFlowCensorshipIn.CurrWorkflowHandle.HandleStatus = HandleStatusEnum.SENDED;

                // 查找是否存在其他并行流程关卡未处理状态,如果有则只更新本次处理为已处理状态,不往下一关卡发送
                int existsOtherUnHandleCount = WorkflowHandlePersistence.CountNotFlowCensorshipIdByWorkflowIdAndHandleStatus(findFlowCensorshipIn.Workflow.Id,
                                                                                                                             HandleStatusEnum.UN_HANDLE, findFlowCensorshipIn.CurrWorkflowHandle.FlowCensorshipId, connectionId);
                if (existsOtherUnHandleCount > 0)
                {
                    return;
                }

                // 查找下一个送件流程关卡
                FlowCensorshipInfo[] nextSendFlowCensorships = FindSendNextFlowCensorships(returnInfo, findFlowCensorshipIn, findFlowCensorshipIn.CurrWorkflowHandle.FlowCensorshipId);
                if (nextSendFlowCensorships.IsNullOrLength0())
                {
                    returnInfo.SetFailureMsg("找不到下一个处理流程关卡");
                    return;
                }

                // 结束的标准关卡
                StandardCensorshipInfo endStand = FindStandardCensorshipByStandardCode(findFlowCensorshipIn, StandardCensorshipDefine.END);
                if (endStand == null)
                {
                    returnInfo.SetFailureMsg("找不到结束的标准关卡");
                    return;
                }

                // 如果下一个关卡为结束,则直接通知申请者
                foreach (var f in nextSendFlowCensorships)
                {
                    if (f.OwnerCensorshipType == CensorshipTypeEnum.STANDARD && f.OwnerCensorshipId == endStand.Id)
                    {
                        // 查找结束流程关卡ID
                        FlowCensorshipInfo     applyFlowCensors  = FindFlowCensorshipByStandardCode(findFlowCensorshipIn, StandardCensorshipDefine.END);
                        StandardCensorshipInfo applyStandCensors = FindStandardCensorshipByStandardCode(findFlowCensorshipIn, StandardCensorshipDefine.END);
                        ConcreteCensorshipInfo applyConsors      = new ConcreteCensorshipInfo()
                        {
                            Id              = applyFlowCensors.Id,
                            Code            = applyStandCensors.Code,
                            Name            = applyStandCensors.Name,
                            WorkflowHandles = new WorkflowHandleInfo[]
                            {
                                new WorkflowHandleInfo()
                                {
                                    ConcreteConcrete   = applyStandCensors.Name,
                                    ConcreteConcreteId = applyStandCensors.Id,
                                    FlowCensorshipId   = applyFlowCensors.Id,
                                    Handler            = findFlowCensorshipIn.Workflow.Creater,
                                    HandlerId          = findFlowCensorshipIn.Workflow.CreaterId,
                                    HandleStatus       = HandleStatusEnum.UN_HANDLE,
                                    HandleType         = HandleTypeEnum.NOTIFY
                                }
                            },
                            FlowCensorship = applyFlowCensors
                        };

                        applyConsors.WorkflowHandles[0].SetCreateInfo(currUser);

                        returnInfo.Data.Workflow.FlowStatus = FlowStatusEnum.AUDIT_PASS;
                        returnInfo.Data.Workflow.SetModifyInfo(currUser);

                        ConcreteCensorshipInfo[] nextConcreteCens = new ConcreteCensorshipInfo[] { applyConsors };
                        UpdateCurrWorkflowHandleInfo(nextConcreteCens, returnInfo.Data.Workflow);

                        returnInfo.Data.NextConcreteCensorshipHandles = nextConcreteCens;

                        return;
                    }
                }

                // 查找具体的送件流程关卡
                ConcreteCensorshipInfo[] concreteCensorships = FindMappingConcreteCensorships(returnInfo, findFlowCensorshipIn, nextSendFlowCensorships, connectionId, currUser);
                if (returnInfo.Failure())
                {
                    return;
                }

                UpdateCurrWorkflowHandleInfo(concreteCensorships, returnInfo.Data.Workflow);

                returnInfo.Data.NextConcreteCensorshipHandles = concreteCensorships;
            }
            else
            {
                if (string.IsNullOrWhiteSpace(idea))
                {
                    idea = "退件";
                }
                findFlowCensorshipIn.CurrWorkflowHandle.Idea = idea;

                // 查找下一个退件流程关卡
                FlowCensorshipInfo[] nextReturnFlowCensorships = FindReturnNextFlowCensorships(returnInfo, findFlowCensorshipIn, findFlowCensorshipIn.CurrWorkflowHandle.FlowCensorshipId);
                if (nextReturnFlowCensorships.IsNullOrLength0())
                {
                    returnInfo.SetFailureMsg("找不到下一个处理流程关卡");
                    return;
                }

                // 申请者的标准关卡
                StandardCensorshipInfo applyStand = FindStandardCensorshipByStandardCode(findFlowCensorshipIn, StandardCensorshipDefine.APPLICANT);
                if (applyStand == null)
                {
                    returnInfo.SetFailureMsg("找不到申请者的标准关卡");
                    return;
                }

                findFlowCensorshipIn.CurrWorkflowHandle.HandleStatus = HandleStatusEnum.RETURNED;

                // 如果下一个关卡为申请者,则直接通知申请者
                foreach (var f in nextReturnFlowCensorships)
                {
                    if (f.OwnerCensorshipType == CensorshipTypeEnum.STANDARD && applyStand.Id == f.OwnerCensorshipId)
                    {
                        // 查找申请者流程关卡ID
                        FlowCensorshipInfo     applyFlowCensors  = FindFlowCensorshipByStandardCode(findFlowCensorshipIn, StandardCensorshipDefine.APPLICANT);
                        StandardCensorshipInfo applyStandCensors = FindStandardCensorshipByStandardCode(findFlowCensorshipIn, StandardCensorshipDefine.APPLICANT);
                        ConcreteCensorshipInfo applyConsors      = new ConcreteCensorshipInfo()
                        {
                            Id              = applyFlowCensors.Id,
                            Code            = applyStandCensors.Code,
                            Name            = applyStandCensors.Name,
                            WorkflowHandles = new WorkflowHandleInfo[]
                            {
                                new WorkflowHandleInfo()
                                {
                                    ConcreteConcrete   = applyStandCensors.Name,
                                    ConcreteConcreteId = applyStandCensors.Id,
                                    FlowCensorshipId   = applyFlowCensors.Id,
                                    Handler            = findFlowCensorshipIn.Workflow.Creater,
                                    HandlerId          = findFlowCensorshipIn.Workflow.CreaterId,
                                    HandleStatus       = HandleStatusEnum.UN_HANDLE,
                                    HandleType         = HandleTypeEnum.NOTIFY
                                }
                            },
                            FlowCensorship = applyFlowCensors
                        };

                        applyConsors.WorkflowHandles[0].SetCreateInfo(currUser);

                        returnInfo.Data.Workflow.FlowStatus = FlowStatusEnum.AUDIT_NOPASS;
                        returnInfo.Data.Workflow.SetModifyInfo(currUser);

                        var nextConcreteCens = new ConcreteCensorshipInfo[] { applyConsors };
                        UpdateCurrWorkflowHandleInfo(nextConcreteCens, returnInfo.Data.Workflow);

                        returnInfo.Data.NextConcreteCensorshipHandles = nextConcreteCens;

                        return;
                    }
                }

                int[] nextFlowCIds = new int[nextReturnFlowCensorships.Length];
                for (var i = 0; i < nextFlowCIds.Length; i++)
                {
                    nextFlowCIds[i] = nextReturnFlowCensorships[i].Id;
                }
                // 退件直接找从已处理列表中的各流程关卡的处理人
                IList <WorkflowHandleInfo> returnWorkflowHandles = WorkflowHandlePersistence.SelectSendedByWorkflowIdAndFlowCensorshipIds(findFlowCensorshipIn.Workflow.Id, nextFlowCIds, connectionId);
                if (returnWorkflowHandles.IsNullOrCount0())
                {
                    returnInfo.SetFailureMsg("找不到可退件的人");
                    return;
                }

                List <ConcreteCensorshipInfo> conList = new List <ConcreteCensorshipInfo>();
                // 具体ID映射工作流处理列表
                IDictionary <int, IList <WorkflowHandleInfo> > dicConIdMapHandles = new Dictionary <int, IList <WorkflowHandleInfo> >();

                // 处理人ID列表
                IList <int> handleIds = new List <int>();

                foreach (var w in returnWorkflowHandles)
                {
                    // 过滤重复的处理人ID
                    if (handleIds.Contains(w.HandlerId))
                    {
                        continue;
                    }
                    handleIds.Add(w.HandlerId);

                    WorkflowHandleInfo newHandle = w.Clone() as WorkflowHandleInfo;
                    newHandle.HandleStatus = HandleStatusEnum.UN_HANDLE;
                    newHandle.HandleTime   = null;
                    newHandle.Idea         = null;
                    newHandle.IsReaded     = false;

                    var c = conList.Find(x => x.Id == w.ConcreteConcreteId);
                    if (c == null)
                    {
                        c = new ConcreteCensorshipInfo()
                        {
                            Id             = w.ConcreteConcreteId,
                            Name           = w.ConcreteConcrete,
                            FlowCensorship = new FlowCensorshipInfo()
                            {
                                Id = w.FlowCensorshipId
                            }
                        };

                        dicConIdMapHandles.Add(c.Id, new List <WorkflowHandleInfo>()
                        {
                            newHandle
                        });

                        conList.Add(c);
                    }
                    else
                    {
                        dicConIdMapHandles[c.Id].Add(newHandle);
                    }
                }

                foreach (var c in conList)
                {
                    foreach (KeyValuePair <int, IList <WorkflowHandleInfo> > item in dicConIdMapHandles)
                    {
                        if (c.Id == item.Key)
                        {
                            c.WorkflowHandles = item.Value.ToArray();

                            break;
                        }
                    }
                }

                ConcreteCensorshipInfo[] cons = conList.ToArray();
                UpdateCurrWorkflowHandleInfo(cons, returnInfo.Data.Workflow);

                returnInfo.Data.NextConcreteCensorshipHandles = cons;
            }
        }
Esempio n. 5
0
 /// <summary>
 /// 执行核心
 /// </summary>
 /// <param name="returnInfo">返回信息</param>
 /// <param name="workflow">工作流</param>
 /// <param name="connectionId">连接ID</param>
 /// <param name="currUser">当前用户</param>
 protected virtual void ExecCore(ReturnInfo <bool> returnInfo, WorkflowInfo workflow, string connectionId = null, BasicUserInfo currUser = null)
 {
     WorkflowHandlePersistence.DeleteByWorkflowId(workflow.Id, connectionId);
     WorkflowPersistence.DeleteById(workflow.Id, connectionId);
 }
        /// <summary>
        /// 执行核心
        /// </summary>
        /// <param name="returnInfo">返回信息</param>
        /// <param name="flowIn">流程输入</param>
        /// <param name="findFlowCensorshipOut">查找流程关卡输出</param>
        /// <param name="connectionId">连接ID</param>
        protected override void ExecCore(ReturnInfo <bool> returnInfo, FlowInInfo <FlowAuditInfo> flowIn,
                                         FlowCensorshipOutInfo findFlowCensorshipOut, string connectionId = null)
        {
            // 更新工作流状态
            WorkflowPersistence.UpdateFlowStatusAndCensorshipAndHandlerById(findFlowCensorshipOut.Workflow, connectionId);

            // 更新当前工作流处理状态
            WorkflowHandlePersistence.UpdateHandleStatusById(findFlowCensorshipOut.CurrConcreteCensorship.WorkflowHandles[0], connectionId);

            string actionStr = flowIn.Flow.ActionType == ActionType.SEND ? "送件" : "退件";

            if (findFlowCensorshipOut.NextConcreteCensorshipHandles.IsNullOrLength0())
            {
                returnInfo.SetSuccessMsg($"申请单号[{findFlowCensorshipOut.Workflow.ApplyNo}]已{actionStr},等待其他人处理");
                return;
            }
            else
            {
                WorkflowHandleInfo updateEf = new WorkflowHandleInfo()
                {
                    Id = flowIn.Flow.HandleId,
                    FlowCensorshipId   = flowIn.Flow.WorkflowHandle.FlowCensorshipId,
                    ConcreteConcreteId = flowIn.Flow.WorkflowHandle.ConcreteConcreteId,
                    WorkflowId         = flowIn.Flow.WorkflowHandle.WorkflowId
                };
                updateEf.SetModifyInfo();

                if (flowIn.Flow.ActionType == ActionType.SEND)
                {
                    WorkflowHandlePersistence.UpdateEfficacyedNotIdByWorkflowIdAndFlowCensorshipId(updateEf, connectionId);
                }
                else
                {
                    WorkflowHandlePersistence.UpdateEfficacyedNotIdByWorkflowId(updateEf, connectionId);
                }

                // 插入下一个处理者
                IList <WorkflowHandleInfo> handlers = new List <WorkflowHandleInfo>();
                foreach (var c in findFlowCensorshipOut.NextConcreteCensorshipHandles)
                {
                    foreach (var h in c.WorkflowHandles)
                    {
                        h.WorkflowId = findFlowCensorshipOut.Workflow.Id;
                        handlers.Add(h);
                    }
                }

                ReturnInfo <bool> reHandle = WorkflowHandle.Add(handlers, connectionId);
                if (reHandle.Failure())
                {
                    returnInfo.FromBasic(reHandle);
                    return;
                }
            }

            StringBuilder msg = new StringBuilder($"申请单号[{findFlowCensorshipOut.Workflow.ApplyNo}]");

            if (findFlowCensorshipOut.ActionType == ActionType.SEND)
            {
                msg.AppendFormat("已送到[{0}]", findFlowCensorshipOut.Workflow.CurrHandlers);
                if (findFlowCensorshipOut.IsNextEndCensorship())
                {
                    msg.Append(",审核通过,流程结束");
                }
                else
                {
                    msg.Append("审核");
                }
            }
            else
            {
                msg.AppendFormat("已退给[{0}]", findFlowCensorshipOut.Workflow.CurrHandlers);
                if (findFlowCensorshipOut.IsNextApplicantCensorship())
                {
                    msg.Append(",审核驳回,流程结束");
                }
                else
                {
                    msg.Append("审核");
                }
            }

            returnInfo.SetMsg(msg.ToString());
        }