Пример #1
0
        /// <summary>
        /// 寻找该节点执行人
        /// </summary>
        /// <param name="wfruntime"></param>
        /// <returns></returns>
        private string GetMakerList(FlowRuntime wfruntime)
        {
            string makerList = "";

            if (wfruntime.runtimeModel.nextNodeId == "-1")
            {
                throw (new Exception("无法寻找到下一个节点"));
            }
            if (wfruntime.runtimeModel.nextNodeType == 0)//如果是会签节点
            {
                List <string> _nodelist  = wfruntime.GetCountersigningNodeIdList(wfruntime.runtimeModel.nextNodeId);
                string        _makerList = "";
                foreach (string item in _nodelist)
                {
                    _makerList = GetMakerList(wfruntime.runtimeModel.nodes[item], wfruntime.runtimeModel.flowInstanceId);
                    if (_makerList == "-1")
                    {
                        throw (new Exception("无法寻找到会签节点的审核者,请查看流程设计是否有问题!"));
                    }
                    if (_makerList == "1")
                    {
                        throw (new Exception("会签节点的审核者不能为所有人,请查看流程设计是否有问题!"));
                    }
                    if (makerList != "")
                    {
                        makerList += ",";
                    }
                    makerList += _makerList;
                }
            }
            else
            {
                makerList = GetMakerList(wfruntime.runtimeModel.nextNode, wfruntime.runtimeModel.flowInstanceId);
                if (makerList == "-1")
                {
                    throw (new Exception("无法寻找到节点的审核者,请查看流程设计是否有问题!"));
                }
            }

            return(makerList);
        }
Пример #2
0
        /// <summary>
        /// 节点审核
        /// </summary>
        /// <param name="instanceId"></param>
        /// <returns></returns>
        public bool NodeVerification(string instanceId, bool flag, string description = "")
        {
            var          user         = AuthUtil.GetCurrentUser().User;
            FlowInstance flowInstance = Get(instanceId);
            FlowInstanceOperationHistory flowInstanceOperationHistory = new FlowInstanceOperationHistory
            {
                InstanceId     = instanceId,
                CreateUserId   = user.Id,
                CreateUserName = user.Name,
                CreateDate     = DateTime.Now
            };//操作记录
            FlowRuntime wfruntime = new FlowRuntime(flowInstance);

            var tag = new Tag
            {
                UserName    = user.Name,
                UserId      = user.Id,
                Description = description
            };

            #region 会签
            if (flowInstance.ActivityType == 0)//当前节点是会签节点
            {
                tag.Taged = 1;
                wfruntime.MakeTagNode(wfruntime.runtimeModel.currentNodeId, tag); //标记会签节点状态

                string        verificationNodeId = "";                            //寻找当前登陆用户可审核的节点Id
                List <string> nodelist           = wfruntime.GetCountersigningNodeIdList(wfruntime.runtimeModel.currentNodeId);
                foreach (string item in nodelist)
                {
                    var makerList = GetMakerList(wfruntime.runtimeModel.nodes[item]
                                                 , wfruntime.runtimeModel.flowInstanceId);
                    if (makerList == "-1")
                    {
                        continue;
                    }

                    if (makerList.Split(',').Any(one => user.Id == one))
                    {
                        verificationNodeId = item;
                    }
                }

                if (verificationNodeId != "")
                {
                    if (flag)
                    {
                        tag.Taged = 1;
                        flowInstanceOperationHistory.Content = "【" + wfruntime.runtimeModel.nodes[verificationNodeId].name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】同意,备注:" + description;
                    }
                    else
                    {
                        tag.Taged = -1;
                        flowInstanceOperationHistory.Content = "【" + wfruntime.runtimeModel.nodes[verificationNodeId].name + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】不同意,备注:" + description;
                    }

                    wfruntime.MakeTagNode(verificationNodeId, tag);//标记审核节点状态
                    string confluenceres = wfruntime.NodeConfluence(verificationNodeId, tag);
                    switch (confluenceres)
                    {
                    case "-1":    //不通过
                        flowInstance.IsFinish = 3;
                        break;

                    case "1":    //等待,当前节点还是会签开始节点,不跳转
                        break;

                    default:    //通过
                        flowInstance.PreviousId   = flowInstance.ActivityId;
                        flowInstance.ActivityId   = wfruntime.runtimeModel.nextNodeId;
                        flowInstance.ActivityType = wfruntime.runtimeModel.nextNodeType;    //-1无法运行,0会签开始,1会签结束,2一般节点,4流程运行结束
                        flowInstance.ActivityName = wfruntime.runtimeModel.nextNode.name;
                        flowInstance.IsFinish     = (wfruntime.runtimeModel.nextNodeType == 4 ? 1 : 0);
                        flowInstance.MakerList    = (wfruntime.runtimeModel.nextNodeType == 4 ? "" : GetMakerList(wfruntime)); //当前节点可执行的人信息

                        #region 流转记录
                        UnitWork.Add(new FlowInstanceTransitionHistory
                        {
                            InstanceId     = flowInstance.Id,
                            CreateUserId   = user.Id,
                            CreateUserName = user.Name,
                            FromNodeId     = wfruntime.runtimeModel.currentNodeId,
                            FromNodeName   = wfruntime.runtimeModel.currentNode.name,
                            FromNodeType   = wfruntime.runtimeModel.currentNodeType,
                            ToNodeId       = wfruntime.runtimeModel.nextNodeId,
                            ToNodeName     = wfruntime.runtimeModel.nextNode.name,
                            ToNodeType     = wfruntime.runtimeModel.nextNodeType,
                            IsFinish       = wfruntime.runtimeModel.nextNodeType == 4?1:0,
                            TransitionSate = 0
                        });
                        #endregion

                        break;
                    }
                }
                else
                {
                    throw (new Exception("审核异常,找不到审核节点"));
                }
            }
            #endregion

            #region 一般审核
            else//一般审核
            {
                if (flag)
                {
                    tag.Taged = 1;
                    wfruntime.MakeTagNode(wfruntime.runtimeModel.currentNodeId, tag);
                    flowInstance.PreviousId   = flowInstance.ActivityId;
                    flowInstance.ActivityId   = wfruntime.runtimeModel.nextNodeId;
                    flowInstance.ActivityType = wfruntime.runtimeModel.nextNodeType;
                    flowInstance.ActivityName = wfruntime.runtimeModel.nextNode.name;
                    flowInstance.MakerList    = wfruntime.runtimeModel.nextNodeType == 4 ? "" : GetMakerList(wfruntime);//当前节点可执行的人信息
                    flowInstance.IsFinish     = (wfruntime.runtimeModel.nextNodeType == 4 ? 1 : 0);
                    #region 流转记录

                    UnitWork.Add(new FlowInstanceTransitionHistory
                    {
                        InstanceId     = flowInstance.Id,
                        CreateUserId   = user.Id,
                        CreateUserName = user.Name,
                        FromNodeId     = wfruntime.runtimeModel.currentNodeId,
                        FromNodeName   = wfruntime.runtimeModel.currentNode.name,
                        FromNodeType   = wfruntime.runtimeModel.currentNodeType,
                        ToNodeId       = wfruntime.runtimeModel.nextNodeId,
                        ToNodeName     = wfruntime.runtimeModel.nextNode.name,
                        ToNodeType     = wfruntime.runtimeModel.nextNodeType,
                        IsFinish       = wfruntime.runtimeModel.nextNodeType == 4 ? 1 : 0,
                        TransitionSate = 0
                    });
                    #endregion

                    flowInstanceOperationHistory.Content = "【" + wfruntime.runtimeModel.currentNode.name
                                                           + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】同意,备注:" + description;
                }
                else
                {
                    flowInstance.IsFinish = 3; //表示该节点不同意
                    tag.Taged             = -1;
                    wfruntime.MakeTagNode(wfruntime.runtimeModel.currentNodeId, tag);

                    flowInstanceOperationHistory.Content = "【"
                                                           + wfruntime.runtimeModel.currentNode.name + "】【"
                                                           + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】不同意,备注:"
                                                           + description;
                }
            }
            #endregion

            flowInstance.SchemeContent = JsonHelper.Instance.Serialize(wfruntime.runtimeModel.schemeContentJson);

            UnitWork.Update(flowInstance);
            UnitWork.Add(flowInstanceOperationHistory);
            UnitWork.Save();
            return(true);
        }