Ejemplo n.º 1
0
        /// <summary>
        /// 驳回
        /// </summary>
        /// <returns></returns>
        public virtual async Task NodeReject(FlowVerifySubmitDto reqest)
        {
            var user = await GetCurrentUserAsync();

            FlowInstance flowInstance = await Manager.GetByIdAsync(reqest.FlowInstanceId);

            FlowRuntime wfruntime = new FlowRuntime(flowInstance);

            string resnode = "";

            resnode = string.IsNullOrEmpty(reqest.NodeRejectStep) ? wfruntime.RejectNode() : reqest.NodeRejectStep;

            var tag = new Tag
            {
                Description = reqest.VerificationOpinion,
                Taged       = TagState.Reject,
                UserId      = user.Id,
                UserName    = user.Name
            };

            wfruntime.MakeTagNode(wfruntime.currentNodeId, tag);
            flowInstance.InstanceStatus = InstanceStatus.Reject;//4表示驳回(需要申请者重新提交表单)
            if (resnode != "")
            {
                var currentNode = wfruntime.Nodes[resnode];
                flowInstance.PreviousId   = flowInstance.ActivityId;
                flowInstance.ActivityId   = resnode;
                flowInstance.ActivityType = wfruntime.GetNodeType(resnode);
                flowInstance.ActivityName = currentNode.name;
                //如果是开始节点,则取流程实例的创建者
                flowInstance.MakerList = flowInstance.ActivityType == 3?$",{flowInstance.CreatorUserId},": GetNodeMakers(currentNode);//当前节点可执行的人信息

                await AddTransHistory(wfruntime);
            }
            flowInstance.SchemeContent = Newtonsoft.Json.JsonConvert.SerializeObject(wfruntime.ToSchemeObj());

            await Manager.UpdateAsync(flowInstance);

            await FlowInstanceOperationHistoryRepository.InsertAsync(new FlowInstanceOperationHistory
            {
                FlowInstanceId = reqest.FlowInstanceId,
                Content        = "【"
                                 + wfruntime.currentNode.name
                                 + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】驳回,备注:"
                                 + reqest.VerificationOpinion
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 节点审核
        /// </summary>
        /// <param name="instanceId"></param>
        /// <returns></returns>
        public bool NodeVerification(string instanceId, Tag tag)
        {
            FlowInstance flowInstance = Get(instanceId);
            FlowInstanceOperationHistory flowInstanceOperationHistory = new FlowInstanceOperationHistory
            {
                InstanceId     = instanceId,
                CreateUserId   = tag.UserId,
                CreateUserName = tag.UserName,
                CreateDate     = DateTime.Now
            };//操作记录
            FlowRuntime wfruntime = new FlowRuntime(flowInstance);

            #region 会签

            if (flowInstance.ActivityType == 0)//当前节点是会签节点
            {
                //TODO: 标记会签节点的状态,这个地方感觉怪怪的
                wfruntime.MakeTagNode(wfruntime.currentNodeId, tag);

                string canCheckId = ""; //寻找当前登录用户可审核的节点Id
                foreach (string nodeId in wfruntime.FromNodeLines[wfruntime.currentNodeId].Select(u => u.to))
                {
                    var makerList = GetNodeMakers(wfruntime.Nodes[nodeId]);
                    if (string.IsNullOrEmpty(makerList))
                    {
                        continue;
                    }

                    if (makerList.Split(',').Any(one => tag.UserId == one))
                    {
                        canCheckId = nodeId;
                    }
                }

                if (canCheckId == "")
                {
                    throw (new Exception("审核异常,找不到审核节点"));
                }

                flowInstanceOperationHistory.Content = "【" + wfruntime.Nodes[canCheckId].name
                                                       + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm")
                                                       + "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",备注:"
                                                       + tag.Description;

                wfruntime.MakeTagNode(canCheckId, tag); //标记审核节点状态
                string res = wfruntime.NodeConfluence(canCheckId, tag);
                if (res == TagState.No.ToString("D"))
                {
                    flowInstance.IsFinish = 3;
                }
                else if (!string.IsNullOrEmpty(res))
                {
                    flowInstance.PreviousId   = flowInstance.ActivityId;
                    flowInstance.ActivityId   = wfruntime.nextNodeId;
                    flowInstance.ActivityType = wfruntime.nextNodeType;
                    flowInstance.ActivityName = wfruntime.nextNode.name;
                    flowInstance.IsFinish     = (wfruntime.nextNodeType == 4 ? 1 : 0);
                    flowInstance.MakerList    =
                        (wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime));

                    AddTransHistory(wfruntime);
                }
            }
            #endregion 会签

            #region 一般审核

            else
            {
                wfruntime.MakeTagNode(wfruntime.currentNodeId, tag);
                if (tag.Taged == (int)TagState.Ok)
                {
                    flowInstance.PreviousId   = flowInstance.ActivityId;
                    flowInstance.ActivityId   = wfruntime.nextNodeId;
                    flowInstance.ActivityType = wfruntime.nextNodeType;
                    flowInstance.ActivityName = wfruntime.nextNode.name;
                    flowInstance.MakerList    = wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime);
                    flowInstance.IsFinish     = (wfruntime.nextNodeType == 4 ? 1 : 0);
                    AddTransHistory(wfruntime);
                }
                else
                {
                    flowInstance.IsFinish = 3; //表示该节点不同意
                }
                flowInstanceOperationHistory.Content = "【" + wfruntime.currentNode.name
                                                       + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm")
                                                       + "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",备注:"
                                                       + tag.Description;
            }

            #endregion 一般审核

            flowInstance.SchemeContent = JsonHelper.Instance.Serialize(wfruntime.ToSchemeObj());

            UnitWork.Update(flowInstance);
            UnitWork.Add(flowInstanceOperationHistory);
            UnitWork.Save();
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 节点审核
        /// </summary>
        /// <param name="instanceId"></param>
        /// <returns></returns>
        public bool NodeVerification(VerificationReq request)
        {
            var user       = _auth.GetCurrentUser().User;
            var instanceId = request.FlowInstanceId;

            var tag = new Tag
            {
                UserName    = user.Name,
                UserId      = user.Id,
                Description = request.VerificationOpinion,
                Taged       = Int32.Parse(request.VerificationFinally)
            };

            FlowInstance flowInstance = Get(instanceId);

            if (flowInstance.MakerList != "1" && !flowInstance.MakerList.Contains(user.Id))
            {
                throw new Exception("当前用户没有审批该节点权限");
            }

            FlowInstanceOperationHistory flowInstanceOperationHistory = new FlowInstanceOperationHistory
            {
                InstanceId     = instanceId,
                CreateUserId   = tag.UserId,
                CreateUserName = tag.UserName,
                CreateDate     = DateTime.Now
            }; //操作记录
            FlowRuntime wfruntime = new FlowRuntime(flowInstance);

            #region 会签

            if (flowInstance.ActivityType == 0) //当前节点是会签节点
            {
                //会签时的【当前节点】一直是会签开始节点
                //TODO: 标记会签节点的状态,这个地方感觉怪怪的
                wfruntime.MakeTagNode(wfruntime.currentNodeId, tag);

                string canCheckId = ""; //寻找当前登录用户可审核的节点Id
                foreach (string fromForkStartNodeId in wfruntime.FromNodeLines[wfruntime.currentNodeId]
                         .Select(u => u.to))
                {
                    var fromForkStartNode = wfruntime.Nodes[fromForkStartNodeId]; //与会前开始节点直接连接的节点
                    canCheckId = GetOneForkLineCanCheckNodeId(fromForkStartNode, wfruntime, tag);
                    if (!string.IsNullOrEmpty(canCheckId))
                    {
                        break;
                    }
                }

                if (canCheckId == "")
                {
                    throw (new Exception("审核异常,找不到审核节点"));
                }

                flowInstanceOperationHistory.Content = "【" + wfruntime.Nodes[canCheckId].name
                                                       + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm")
                                                       + "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",备注:"
                                                       + tag.Description;

                wfruntime.MakeTagNode(canCheckId, tag); //标记审核节点状态
                string res = wfruntime.NodeConfluence(canCheckId, tag);
                if (res == TagState.No.ToString("D"))
                {
                    flowInstance.IsFinish = FlowInstanceStatus.Disagree;
                }
                else if (!string.IsNullOrEmpty(res))
                {
                    flowInstance.PreviousId   = flowInstance.ActivityId;
                    flowInstance.ActivityId   = wfruntime.nextNodeId;
                    flowInstance.ActivityType = wfruntime.nextNodeType;
                    flowInstance.ActivityName = wfruntime.nextNode.name;
                    flowInstance.IsFinish     = (wfruntime.nextNodeType == 4
                        ? FlowInstanceStatus.Finished
                        : FlowInstanceStatus.Running);
                    flowInstance.MakerList =
                        (wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime));

                    AddTransHistory(wfruntime);
                }
                else
                {
                    //会签过程中,需要更新用户
                    flowInstance.MakerList = GetForkNodeMakers(wfruntime, wfruntime.currentNodeId);
                    AddTransHistory(wfruntime);
                }
            }

            #endregion 会签

            #region 一般审核

            else
            {
                wfruntime.MakeTagNode(wfruntime.currentNodeId, tag);
                if (tag.Taged == (int)TagState.Ok)
                {
                    flowInstance.PreviousId   = flowInstance.ActivityId;
                    flowInstance.ActivityId   = wfruntime.nextNodeId;
                    flowInstance.ActivityType = wfruntime.nextNodeType;
                    flowInstance.ActivityName = wfruntime.nextNode.name;
                    flowInstance.MakerList    = wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime, request);
                    flowInstance.IsFinish     = (wfruntime.nextNodeType == 4
                        ? FlowInstanceStatus.Finished
                        : FlowInstanceStatus.Running);
                    AddTransHistory(wfruntime);
                }
                else
                {
                    flowInstance.IsFinish = FlowInstanceStatus.Disagree; //表示该节点不同意
                }

                flowInstanceOperationHistory.Content = "【" + wfruntime.currentNode.name
                                                       + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm")
                                                       + "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",备注:"
                                                       + tag.Description;
            }

            #endregion 一般审核

            flowInstance.SchemeContent = JsonHelper.Instance.Serialize(wfruntime.ToSchemeObj());

            UnitWork.Update(flowInstance);
            UnitWork.Add(flowInstanceOperationHistory);

            //给流程创建人发送通知信息
            _messageApp.SendMsgTo(flowInstance.CreateUserId,
                                  $"你的流程[{flowInstance.CustomName}]已被{user.Name}处理。处理情况如下:{flowInstanceOperationHistory.Content}");

            UnitWork.Save();

            wfruntime.NotifyThirdParty(_httpClientFactory.CreateClient(), tag);
            return(true);
        }
        /// <summary>
        /// 节点审核
        /// </summary>
        /// <param name="instanceId"></param>
        /// <returns></returns>
        public async Task <bool> NodeVerification(string instanceId, Tag tag)
        {
            FlowinstanceEntity           flowInstance = GetForm(instanceId).Result;
            FlowInstanceOperationHistory flowInstanceOperationHistory = new FlowInstanceOperationHistory
            {
                F_Id              = Utils.GuId(),
                F_InstanceId      = instanceId,
                F_CreatorUserId   = tag.UserId,
                F_CreatorUserName = tag.UserName,
                F_CreatorTime     = DateTime.Now
            };//操作记录
            FlowRuntime wfruntime = new FlowRuntime(flowInstance);

            uniwork.BeginTrans();
            #region 会签
            if (flowInstance.F_ActivityType == 0)//当前节点是会签节点
            {
                //会签时的【当前节点】一直是会签开始节点
                //TODO: 标记会签节点的状态,这个地方感觉怪怪的
                wfruntime.MakeTagNode(wfruntime.currentNodeId, tag);

                string canCheckId = ""; //寻找当前登录用户可审核的节点Id
                foreach (string fromForkStartNodeId in wfruntime.FromNodeLines[wfruntime.currentNodeId].Select(u => u.to))
                {
                    var fromForkStartNode = wfruntime.Nodes[fromForkStartNodeId];  //与会前开始节点直接连接的节点
                    canCheckId = GetOneForkLineCanCheckNodeId(fromForkStartNode, wfruntime, tag);
                    if (!string.IsNullOrEmpty(canCheckId))
                    {
                        break;
                    }
                }

                if (canCheckId == "")
                {
                    throw (new Exception("审核异常,找不到审核节点"));
                }

                flowInstanceOperationHistory.F_Content = "【" + wfruntime.Nodes[canCheckId].name
                                                         + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm")
                                                         + "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",备注:"
                                                         + tag.Description;

                wfruntime.MakeTagNode(canCheckId, tag); //标记审核节点状态
                string res = wfruntime.NodeConfluence(canCheckId, tag);
                if (res == TagState.No.ToString("D"))
                {
                    flowInstance.F_IsFinish = 3;
                }
                else if (!string.IsNullOrEmpty(res))
                {
                    flowInstance.F_PreviousId   = flowInstance.F_ActivityId;
                    flowInstance.F_ActivityId   = wfruntime.nextNodeId;
                    flowInstance.F_ActivityType = wfruntime.nextNodeType;
                    flowInstance.F_ActivityName = wfruntime.nextNode.name;
                    flowInstance.F_IsFinish     = (wfruntime.nextNodeType == 4 ? 1 : 0);
                    flowInstance.F_MakerList    =
                        (wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime));

                    await AddTransHistory(wfruntime);
                }
                else
                {
                    //会签过程中,需要更新用户
                    flowInstance.F_MakerList = GetForkNodeMakers(wfruntime, wfruntime.currentNodeId);
                    await AddTransHistory(wfruntime);
                }
            }
            #endregion 会签

            #region 一般审核
            else
            {
                wfruntime.MakeTagNode(wfruntime.currentNodeId, tag);
                if (tag.Taged == (int)TagState.Ok)
                {
                    flowInstance.F_PreviousId   = flowInstance.F_ActivityId;
                    flowInstance.F_ActivityId   = wfruntime.nextNodeId;
                    flowInstance.F_ActivityType = wfruntime.nextNodeType;
                    flowInstance.F_ActivityName = wfruntime.nextNode.name;
                    flowInstance.F_MakerList    = wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime);
                    flowInstance.F_IsFinish     = (wfruntime.nextNodeType == 4 ? 1 : 0);
                    await AddTransHistory(wfruntime);
                }
                else
                {
                    flowInstance.F_IsFinish = 3; //表示该节点不同意
                }
                flowInstanceOperationHistory.F_Content = "【" + wfruntime.currentNode.name
                                                         + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm")
                                                         + "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",备注:"
                                                         + tag.Description;
            }
            #endregion 一般审核

            wfruntime.RemoveNode(wfruntime.nextNodeId);
            flowInstance.F_SchemeContent = wfruntime.ToSchemeObj().ToJson();
            await uniwork.Update(flowInstance);

            await uniwork.Insert(flowInstanceOperationHistory);

            MessageEntity msg = new MessageEntity();
            msg.F_CreatorUserName = currentuser.UserName;
            msg.F_EnabledMark     = true;
            if (flowInstance.F_IsFinish == 1)
            {
                msg.F_MessageInfo = flowInstance.F_CustomName + "--流程已完成";
                var module = uniwork.IQueryable <ModuleEntity>(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault();
                msg.F_Href       = module.F_UrlAddress;
                msg.F_HrefTarget = module.F_Target;
                msg.F_ToUserId   = flowInstance.F_CreatorUserId;
                msg.F_ClickRead  = true;
                msg.F_KeyValue   = flowInstance.F_Id;
            }
            else if (flowInstance.F_IsFinish == 3)
            {
                msg.F_MessageInfo = flowInstance.F_CustomName + "--流程已终止";
                var module = uniwork.IQueryable <ModuleEntity>(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault();
                msg.F_Href       = module.F_UrlAddress;
                msg.F_HrefTarget = module.F_Target;
                var makerList = uniwork.IQueryable <FlowInstanceOperationHistory>(a => a.F_InstanceId == flowInstance.F_Id && a.F_CreatorUserId != currentuser.UserId).Select(a => a.F_CreatorUserId).Distinct().ToList();
                msg.F_ToUserId  = flowInstance.F_CreatorUserId;
                msg.F_ClickRead = true;
                msg.F_KeyValue  = flowInstance.F_Id;
            }
            else
            {
                msg.F_MessageInfo = flowInstance.F_CustomName + "--流程待处理";
                var module = uniwork.IQueryable <ModuleEntity>(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault();
                msg.F_Href       = module.F_UrlAddress.Remove(module.F_UrlAddress.Length - 5, 5) + "ToDoFlow";
                msg.F_HrefTarget = module.F_Target;
                msg.F_ToUserId   = flowInstance.F_MakerList == "1" ? "" : flowInstance.F_MakerList;
                msg.F_ClickRead  = false;
                msg.F_KeyValue   = flowInstance.F_Id;
            }
            msg.F_MessageType = 2;
            var lastmsg = uniwork.IQueryable <MessageEntity>(a => a.F_ClickRead == false && a.F_KeyValue == flowInstance.F_Id).OrderByDesc(a => a.F_CreatorTime).FirstOrDefault();
            if (lastmsg != null && uniwork.IQueryable <MessageHistoryEntity>(a => a.F_MessageId == lastmsg.F_Id).Count() == 0)
            {
                await messageApp.ReadMsgForm(lastmsg.F_Id);
            }
            await messageApp.SubmitForm(msg);

            uniwork.Commit();

            wfruntime.NotifyThirdParty(_httpClientFactory.CreateClient(), tag);
            return(true);
        }
        /// <summary>
        /// 驳回
        /// 如果NodeRejectStep不为空,优先使用;否则按照NodeRejectType驳回
        /// </summary>
        /// <returns></returns>
        public async Task <bool> NodeReject(VerificationExtend reqest)
        {
            var user = currentuser;

            FlowinstanceEntity flowInstance = await GetForm(reqest.F_FlowInstanceId);

            FlowRuntime wfruntime = new FlowRuntime(flowInstance);

            string resnode = "";

            resnode = string.IsNullOrEmpty(reqest.NodeRejectStep) ? wfruntime.RejectNode(reqest.NodeRejectType) : reqest.NodeRejectStep;

            var tag = new Tag
            {
                Description = reqest.F_VerificationOpinion,
                Taged       = (int)TagState.Reject,
                UserId      = user.UserId,
                UserName    = user.UserName
            };

            wfruntime.MakeTagNode(wfruntime.currentNodeId, tag);
            flowInstance.F_IsFinish = 4;//4表示驳回(需要申请者重新提交表单)
            uniwork.BeginTrans();
            if (resnode != "")
            {
                wfruntime.RemoveNode(resnode);
                flowInstance.F_SchemeContent = wfruntime.ToSchemeObj().ToJson();
                flowInstance.F_ActivityId    = resnode;
                var prruntime = new FlowRuntime(flowInstance);
                prruntime.MakeTagNode(prruntime.currentNodeId, tag);
                flowInstance.F_PreviousId   = prruntime.previousId;
                flowInstance.F_ActivityType = prruntime.GetNodeType(resnode);
                flowInstance.F_ActivityName = prruntime.Nodes[resnode].name;
                if (resnode == wfruntime.startNodeId)
                {
                    flowInstance.F_MakerList = flowInstance.F_CreatorUserId;
                }
                else
                {
                    flowInstance.F_MakerList = await uniwork.IQueryable <FlowInstanceTransitionHistory>(a => a.F_FromNodeId == resnode && a.F_ToNodeId == prruntime.nextNodeId).OrderByDesc(a => a.F_CreatorTime).Select(a => a.F_CreatorUserId).FirstAsync();//当前节点可执行的人信息
                }
                await AddRejectTransHistory(wfruntime, prruntime);

                await repository.Update(flowInstance);
            }
            await uniwork.Insert(new FlowInstanceOperationHistory
            {
                F_Id         = Utils.GuId(),
                F_InstanceId = reqest.F_FlowInstanceId
                ,
                F_CreatorUserId = user.UserId
                ,
                F_CreatorUserName = user.UserName
                ,
                F_CreatorTime = DateTime.Now
                ,
                F_Content = "【"
                            + wfruntime.currentNode.name
                            + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "】驳回,备注:"
                            + reqest.F_VerificationOpinion
            });

            MessageEntity msg = new MessageEntity();

            if (resnode == wfruntime.startNodeId)
            {
                msg.F_MessageInfo = flowInstance.F_CustomName + "--流程驳回";
                var module = uniwork.IQueryable <ModuleEntity>(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault();
                msg.F_Href       = module.F_UrlAddress;
                msg.F_HrefTarget = module.F_Target;
                msg.F_ToUserId   = flowInstance.F_CreatorUserId;
                msg.F_ToUserName = flowInstance.F_CreatorUserName;
                msg.F_ClickRead  = true;
                msg.F_KeyValue   = flowInstance.F_Id;
            }
            else
            {
                msg.F_MessageInfo = flowInstance.F_CustomName + "--流程待处理";
                var module = uniwork.IQueryable <ModuleEntity>(a => a.F_EnCode == className.Substring(0, className.Length - 7)).FirstOrDefault();
                msg.F_Href       = module.F_UrlAddress.Remove(module.F_UrlAddress.Length - 5, 5) + "ToDoFlow";
                msg.F_HrefTarget = module.F_Target;
                msg.F_ToUserId   = flowInstance.F_MakerList == "1" ? "" : flowInstance.F_MakerList;
                msg.F_ClickRead  = false;
                msg.F_KeyValue   = flowInstance.F_Id;
            }
            msg.F_CreatorUserName = currentuser.UserName;
            msg.F_EnabledMark     = true;
            msg.F_MessageType     = 2;
            var lastmsg = uniwork.IQueryable <MessageEntity>(a => a.F_ClickRead == false && a.F_KeyValue == flowInstance.F_Id).OrderByDesc(a => a.F_CreatorTime).FirstOrDefault();

            if (lastmsg != null && uniwork.IQueryable <MessageHistoryEntity>(a => a.F_MessageId == lastmsg.F_Id).Count() == 0)
            {
                await messageApp.ReadMsgForm(lastmsg.F_Id);
            }
            await messageApp.SubmitForm(msg);

            uniwork.Commit();

            wfruntime.NotifyThirdParty(_httpClientFactory.CreateClient(), tag);

            return(true);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 节点审核
        /// </summary>
        /// <param name="instanceId"></param>
        /// <returns></returns>
        public virtual async Task NodeVerification(int instanceId, Tag tag)
        {
            var          manager      = Manager as FlowInstanceManager;
            FlowInstance flowInstance = await manager.GetByIdAsync(instanceId);

            FlowInstanceOperationHistory flowInstanceOperationHistory = new FlowInstanceOperationHistory
            {
                FlowInstanceId = instanceId
            };//操作记录
            FlowRuntime wfruntime = new FlowRuntime(flowInstance);

            #region 会签

            if (flowInstance.ActivityType == 0)//当前节点是会签节点
            {
                //TODO: 标记会签节点的状态,这个地方感觉怪怪的
                wfruntime.MakeTagNode(wfruntime.currentNodeId, tag);

                string canCheckId = ""; //寻找当前登录用户可审核的节点Id
                foreach (string nodeId in wfruntime.FromNodeLines[wfruntime.currentNodeId].Select(u => u.to))
                {
                    var makerList = GetNodeMakers(wfruntime.Nodes[nodeId]);
                    if (string.IsNullOrEmpty(makerList))
                    {
                        continue;
                    }

                    if (makerList.Contains("|" + tag.UserId + "|"))
                    {
                        canCheckId = nodeId;
                    }
                }

                if (canCheckId == "")
                {
                    throw (new Exception("审核异常,找不到审核节点"));
                }

                flowInstanceOperationHistory.Content = "【" + wfruntime.Nodes[canCheckId].name
                                                       + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm")
                                                       + "】" + (tag.Taged == TagState.Ok ? "同意" : "不同意") + ",备注:"
                                                       + tag.Description;

                wfruntime.MakeTagNode(canCheckId, tag); //标记审核节点状态
                string res = wfruntime.NodeConfluence(canCheckId, tag);
                if (res == TagState.No.ToString("D"))
                {
                    flowInstance.InstanceStatus = InstanceStatus.DisAgree;
                }
                else if (!string.IsNullOrEmpty(res))
                {
                    flowInstance.PreviousId     = flowInstance.ActivityId;
                    flowInstance.ActivityId     = wfruntime.nextNodeId;
                    flowInstance.ActivityType   = wfruntime.nextNodeType;
                    flowInstance.ActivityName   = wfruntime.nextNode.name;
                    flowInstance.InstanceStatus = (wfruntime.nextNodeType == 4 ? InstanceStatus.Finish : InstanceStatus.Processing);
                    flowInstance.MakerList      =
                        (wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime));

                    await AddTransHistory(wfruntime);
                }
            }
            #endregion 会签

            #region 一般审核

            else
            {
                wfruntime.MakeTagNode(wfruntime.currentNodeId, tag);
                if (tag.Taged == TagState.Ok)
                {
                    flowInstance.PreviousId     = flowInstance.ActivityId;
                    flowInstance.ActivityId     = wfruntime.nextNodeId;
                    flowInstance.ActivityType   = wfruntime.nextNodeType;
                    flowInstance.ActivityName   = wfruntime.nextNode.name;
                    flowInstance.MakerList      = wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime);
                    flowInstance.InstanceStatus = (wfruntime.nextNodeType == 4 ? InstanceStatus.Finish : InstanceStatus.Processing);
                    await AddTransHistory(wfruntime);
                }
                else
                {
                    flowInstance.InstanceStatus = InstanceStatus.DisAgree;  //表示该节点不同意
                }
                flowInstanceOperationHistory.Content = "【" + wfruntime.currentNode.name
                                                       + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm")
                                                       + "】" + (tag.Taged == TagState.Ok ? "同意" : "不同意") + ",备注:"
                                                       + tag.Description;
            }

            #endregion 一般审核

            flowInstance.SchemeContent = Newtonsoft.Json.JsonConvert.SerializeObject(wfruntime.ToSchemeObj());

            await manager.UpdateAsync(flowInstance);

            if (flowInstance.InstanceStatus == InstanceStatus.Finish)
            {
                await manager.FinishInstance(flowInstance);//调用流程结束事件
            }
            await FlowInstanceOperationHistoryRepository.InsertAsync(flowInstanceOperationHistory);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 節點審核
        /// </summary>
        /// <param name="instanceId"></param>
        /// <returns></returns>
        public bool NodeVerification(string instanceId, Tag tag)
        {
            FlowInstance flowInstance = Get(instanceId);
            FlowInstanceOperationHistory flowInstanceOperationHistory = new FlowInstanceOperationHistory
            {
                InstanceId     = instanceId,
                CreateUserId   = tag.UserId,
                CreateUserName = tag.UserName,
                CreateDate     = DateTime.Now
            };//操作記錄
            FlowRuntime wfruntime = new FlowRuntime(flowInstance);

            #region 會簽

            if (flowInstance.ActivityType == 0)//當前節點是會簽節點
            {
                //會簽時的【當前節點】一直是會簽開始節點
                //TODO: 標記會簽節點的狀態,這個地方感覺怪怪的
                wfruntime.MakeTagNode(wfruntime.currentNodeId, tag);

                string canCheckId = ""; //尋找當前登錄使用者可審核的節點Id
                foreach (string fromForkStartNodeId in wfruntime.FromNodeLines[wfruntime.currentNodeId].Select(u => u.to))
                {
                    var fromForkStartNode = wfruntime.Nodes[fromForkStartNodeId];  //與會前開始節點直接連線的節點
                    canCheckId = GetOneForkLineCanCheckNodeId(fromForkStartNode, wfruntime, tag);
                    if (!string.IsNullOrEmpty(canCheckId))
                    {
                        break;
                    }
                }

                if (canCheckId == "")
                {
                    throw (new Exception("審核異常,找不到審核節點"));
                }

                flowInstanceOperationHistory.Content = "【" + wfruntime.Nodes[canCheckId].name
                                                       + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm")
                                                       + "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",備註:"
                                                       + tag.Description;

                wfruntime.MakeTagNode(canCheckId, tag); //標記審核節點狀態
                string res = wfruntime.NodeConfluence(canCheckId, tag);
                if (res == TagState.No.ToString("D"))
                {
                    flowInstance.IsFinish = 3;
                }
                else if (!string.IsNullOrEmpty(res))
                {
                    flowInstance.PreviousId   = flowInstance.ActivityId;
                    flowInstance.ActivityId   = wfruntime.nextNodeId;
                    flowInstance.ActivityType = wfruntime.nextNodeType;
                    flowInstance.ActivityName = wfruntime.nextNode.name;
                    flowInstance.IsFinish     = (wfruntime.nextNodeType == 4 ? 1 : 0);
                    flowInstance.MakerList    =
                        (wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime));

                    AddTransHistory(wfruntime);
                }
                else
                {
                    //會簽過程中,需要更新使用者
                    flowInstance.MakerList = GetForkNodeMakers(wfruntime, wfruntime.currentNodeId);
                    AddTransHistory(wfruntime);
                }
            }
            #endregion 會簽

            #region 一般審核

            else
            {
                wfruntime.MakeTagNode(wfruntime.currentNodeId, tag);
                if (tag.Taged == (int)TagState.Ok)
                {
                    flowInstance.PreviousId   = flowInstance.ActivityId;
                    flowInstance.ActivityId   = wfruntime.nextNodeId;
                    flowInstance.ActivityType = wfruntime.nextNodeType;
                    flowInstance.ActivityName = wfruntime.nextNode.name;
                    flowInstance.MakerList    = wfruntime.nextNodeType == 4 ? "" : GetNextMakers(wfruntime);
                    flowInstance.IsFinish     = (wfruntime.nextNodeType == 4 ? 1 : 0);
                    AddTransHistory(wfruntime);
                }
                else
                {
                    flowInstance.IsFinish = 3; //表示該節點不同意
                }
                flowInstanceOperationHistory.Content = "【" + wfruntime.currentNode.name
                                                       + "】【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm")
                                                       + "】" + (tag.Taged == 1 ? "同意" : "不同意") + ",備註:"
                                                       + tag.Description;
            }

            #endregion 一般審核

            flowInstance.SchemeContent = JsonHelper.Instance.Serialize(wfruntime.ToSchemeObj());

            UnitWork.Update(flowInstance);
            UnitWork.Add(flowInstanceOperationHistory);
            UnitWork.Save();

            wfruntime.NotifyThirdParty(_httpClientFactory.CreateClient(), tag);
            return(true);
        }