Example #1
0
        /// <summary>
        /// 判断当前用户能否审核
        /// </summary>
        /// <param name="workflowHandle">工作流处理</param>
        /// <param name="comData">通用数据</param>
        /// <returns>当前用户能否审核</returns>
        public static BasicReturnInfo CanCurrUserAudit(WorkflowHandleInfo workflowHandle, CommonUseData comData = null)
        {
            BasicReturnInfo returnInfo = new BasicReturnInfo();
            var             user       = UserTool <int> .GetCurrUser(comData);

            if (user == null)
            {
                returnInfo.SetFailureMsg("您还未登录,请先登录系统");

                return(returnInfo);
            }

            if (workflowHandle == null)
            {
                returnInfo.SetFailureMsg("找不到处理信息");

                return(returnInfo);
            }

            if (workflowHandle.HandlerId != user.Id)
            {
                returnInfo.SetFailureMsg("Sorry,您不是此流程的处理者,无权限审核");

                return(returnInfo);
            }

            if (workflowHandle.HandleStatus == HandleStatusEnum.EFFICACYED)
            {
                returnInfo.SetFailureMsg("Sorry,您的处理信息已无效");

                return(returnInfo);
            }
            if (workflowHandle.HandleStatus == HandleStatusEnum.SENDED || workflowHandle.HandleStatus == HandleStatusEnum.RETURNED)
            {
                returnInfo.SetFailureMsg("Sorry,您的处理信息已处理,无需重复处理");

                return(returnInfo);
            }

            return(returnInfo);
        }
        /// <summary>
        /// 执行
        /// </summary>
        /// <param name="context">http上下文</param>
        /// <returns>任务</returns>
        public async Task InvokeAsync(HttpContext context)
        {
            var path = context.Request.Path.Value.ToLower();

            if (path.StartsWith(options.PfxApiPath))
            {
                try
                {
                    await next(context);
                }
                catch (Exception ex)
                {
                    _ = log.ErrorAsync(ex.Message, ex, "ApiExceptionHandleMiddleware");

                    var returnInfo = new BasicReturnInfo()
                    {
                        Code = options.ExceptionCode,
                        Msg  = options.ExceptionMsg,
                    };
                    if (options.IsDevelopment)
                    {
                        returnInfo.Ex   = ex;
                        returnInfo.Desc = ex.ToString();
                    }
                    else
                    {
                        returnInfo.Desc = ex.Message;
                    }

                    context.Response.ContentType = "text/html;charset=UTF-8";
                    context.Response.StatusCode  = options.HttpStatusCode;

                    await context.Response.WriteAsync(options.Serialization.Serialize(returnInfo));
                }
            }
            else
            {
                await next(context);
            }
        }
Example #3
0
        /// <summary>
        /// 执行
        /// </summary>
        /// <param name="param">参数</param>
        /// <param name="paramIndex">参数索引位置</param>
        /// <returns>返回信息</returns>
        public BasicReturnInfo Exec(object[] param, byte paramIndex = 0)
        {
            BasicReturnInfo returnInfo = new BasicReturnInfo();

            object model = param[paramIndex];

            if (model == null)
            {
                return(returnInfo);
            }

            foreach (IModelVali vali in modelValis)
            {
                returnInfo = vali.Vali(model);
                if (returnInfo.Failure())
                {
                    return(returnInfo);
                }
            }

            return(returnInfo);
        }
        /// <summary>
        /// 验证
        /// </summary>
        /// <param name="model">模型</param>
        /// <param name="property">属性</param>
        /// <param name="value">值</param>
        /// <returns>返回信息</returns>
        public BasicReturnInfo Vali(object model, PropertyInfo property, object value)
        {
            BasicReturnInfo returnInfo = new BasicReturnInfo();
            ValiAttrT       valiAttr   = property.GetCustomAttribute <ValiAttrT>();

            if (valiAttr == null)
            {
                return(returnInfo);
            }

            DisplayNameAttribute displayName = property.GetCustomAttribute <DisplayNameAttribute>();
            string name = displayName != null ? displayName.DisplayName : property.Name;

            string errMsg = ExecVali(model, value, name, valiAttr);

            if (string.IsNullOrWhiteSpace(errMsg))
            {
                return(returnInfo);
            }

            returnInfo.SetFailureMsg(errMsg);

            return(returnInfo);
        }
Example #5
0
        /// <summary>
        /// 读取其他配置
        /// </summary>
        /// <param name="workflowDefine">工作流定义</param>
        /// <param name="connectionId">连接ID</param>
        /// <param name="comData">通用数据</param>
        private BasicReturnInfo ReaderOtherConfig(WorkflowDefineInfo workflowDefine, string connectionId, CommonUseData comData = null)
        {
            BasicReturnInfo basicReturn = new BasicReturnInfo();

            if (workflowDefine == null)
            {
                basicReturn.SetFailureMsg("找不到工作流定义信息");
                return(basicReturn);
            }

            #region 查找流程/表单/流程关卡

            ReturnInfo <FlowInfo> reFlow = FlowService.Find(workflowDefine.FlowId, connectionId: connectionId, comData: comData);
            if (reFlow.Failure())
            {
                basicReturn.FromBasic(reFlow);
                return(basicReturn);
            }
            if (reFlow.Data == null)
            {
                basicReturn.SetFailureMsg("找不到工作流的流程信息");
                return(basicReturn);
            }

            ReturnInfo <FormInfo> reForm = FormService.Find(workflowDefine.FormId, connectionId: connectionId, comData: comData);

            workflowDefine.Flow = reFlow.Data;

            if (reForm.Failure())
            {
                basicReturn.FromBasic(reForm);
                return(basicReturn);
            }
            if (reForm.Data == null)
            {
                basicReturn.SetFailureMsg("找不到工作流的表单信息");
                return(basicReturn);
            }
            workflowDefine.Form = reForm.Data;

            ReturnInfo <IList <FlowCensorshipInfo> > reFlowCensorships = FlowCensorshipService.QueryByFlowId(workflowDefine.FlowId, connectionId: connectionId, comData: comData);
            if (reFlowCensorships.Failure())
            {
                basicReturn.FromBasic(reFlowCensorships);
                return(basicReturn);
            }
            if (reFlowCensorships.Data.IsNullOrCount0())
            {
                basicReturn.SetFailureMsg("找不到工作流的流程关卡信息");
                return(basicReturn);
            }
            workflowDefine.Flow.FlowCensorships = reFlowCensorships.Data.ToArray();

            // 构造流程关卡ID数组
            int[]       flowCensorshipIds   = new int[workflowDefine.Flow.FlowCensorships.Length];
            IList <int> stFlowCensorshipIds = new List <int>();
            for (var i = 0; i < flowCensorshipIds.Length; i++)
            {
                var f = workflowDefine.Flow.FlowCensorships[i];
                flowCensorshipIds[i] = f.Id;

                if (f.OwnerCensorshipType == CensorshipTypeEnum.STANDARD)
                {
                    stFlowCensorshipIds.Add(f.OwnerCensorshipId);
                }
            }
            #endregion

            #region 查找送件/退件路线/标准关卡

            IList <StandardCensorshipInfo> standardCensorships = null;
            // 标准关卡
            if (!stFlowCensorshipIds.IsNullOrCount0())
            {
                ReturnInfo <IList <StandardCensorshipInfo> > reStand = StandardCensorshipService.Find(stFlowCensorshipIds.ToArray(), connectionId: connectionId, comData: comData);
                if (reStand.Failure())
                {
                    basicReturn.FromBasic(reStand);
                    return(basicReturn);
                }
                if (reStand.Data.IsNullOrCount0())
                {
                    basicReturn.SetFailureMsg("找不到标准关卡信息");
                    return(basicReturn);
                }

                standardCensorships = reStand.Data;
            }

            ReturnInfo <IList <SendFlowRouteInfo> > reSend = SendFlowRouteService.QueryByFlowCensorshipIds(flowCensorshipIds, connectionId: connectionId, comData: comData);
            if (reSend.Failure())
            {
                basicReturn.FromBasic(reSend);
                return(basicReturn);
            }
            if (reSend.Data.IsNullOrCount0())
            {
                basicReturn.SetFailureMsg("找不到工作流的送件路线信息");
            }

            ReturnInfo <IList <ReturnFlowRouteInfo> > reReturn = ReturnFlowRouteService.QueryByFlowCensorshipIds(flowCensorshipIds, connectionId: connectionId, comData: comData);
            if (reReturn.Failure())
            {
                basicReturn.FromBasic(reReturn);
                return(basicReturn);
            }

            foreach (var f in workflowDefine.Flow.FlowCensorships)
            {
                switch (f.OwnerCensorshipType)
                {
                case CensorshipTypeEnum.STANDARD:
                    IList <StandardCensorshipInfo> stdList = new List <StandardCensorshipInfo>();
                    foreach (var s in standardCensorships)
                    {
                        if (f.OwnerCensorshipId == s.Id)
                        {
                            stdList.Add(s);
                        }
                    }

                    if (stdList.Count == 0)
                    {
                        basicReturn.SetFailureMsg($"找不到归属ID为{f.OwnerCensorshipId}的标准关卡信息");
                        return(basicReturn);
                    }

                    f.StandardCensorships = stdList.ToArray();

                    break;
                }

                IList <SendFlowRouteInfo> sendRotes = new List <SendFlowRouteInfo>();
                foreach (var send in reSend.Data)
                {
                    if (f.Id == send.FlowCensorshipId)
                    {
                        sendRotes.Add(send);
                    }
                }

                if (!sendRotes.IsNullOrCount0())
                {
                    f.SendFlowRoutes = sendRotes.ToArray();
                }

                if (!reReturn.Data.IsNullOrCount0())
                {
                    IList <ReturnFlowRouteInfo> returnRotes = new List <ReturnFlowRouteInfo>();
                    foreach (var re in reReturn.Data)
                    {
                        if (f.Id == re.FlowCensorshipId)
                        {
                            returnRotes.Add(re);
                        }
                    }

                    if (!returnRotes.IsNullOrCount0())
                    {
                        f.ReturnFlowRoutes = returnRotes.ToArray();
                    }
                }
            }

            #endregion

            return(basicReturn);
        }
Example #6
0
        /// <summary>
        /// 判断是否拥有权限
        /// </summary>
        /// <param name="context">上下文</param>
        /// <param name="controller">控制器信息</param>
        /// <param name="action">动作信息</param>
        /// <param name="basicReturn">基本返回</param>
        /// <returns>获取是否拥有权限</returns>
        protected override bool IsHavePermission(HttpContext context, RoutePermissionInfo controller, ActionInfo action, BasicReturnInfo basicReturn)
        {
            if (string.IsNullOrWhiteSpace(controller.Code) || action.Codes.IsNullOrLength0())
            {
                return(true);
            }
            ReturnInfo <bool> perReInfo = userService.IsCurrUserPermission(controller.Code, action.Codes, comData: context.CreateCommonUseData(comDataFactory, key: action.ResourceKey, menuCode: controller.Code, functionCodes: action.Codes));

            if (perReInfo.Failure())
            {
                basicReturn.FromBasic(perReInfo);
                return(false);
            }

            return(perReInfo.Data);
        }
Example #7
0
        /// <summary>
        /// 拦截
        /// </summary>
        /// <param name="basicReturn">基本返回</param>
        /// <param name="invocation">拦截参数</param>
        /// <param name="attr">特性</param>
        /// <param name="isExecProceeded">是否已执行</param>
        protected override void Intercept(BasicReturnInfo basicReturn, IInvocation invocation, TransactionAttribute attr, out bool isExecProceeded)
        {
            isExecProceeded = true;
            BasicReturnInfo returnInfo = new BasicReturnInfo();
            object          connId     = null;

            if (attr.ConnectionIdIndex == -1)
            {
                connId = invocation.GetArgumentValue(attr.ConnectionIdIndex);
            }
            IGetObject <IPersistenceConnection> getPerConn = AutofacTool.Resolve(invocation.TargetType) as IGetObject <IPersistenceConnection>;

            if (getPerConn == null)
            {
                basicReturn.SetFailureMsg("未实现IGetObject<IPersistenceConnection>接口");
                return;
            }

            IPersistenceConnection perConn = getPerConn.Get();
            string connectionId            = null;

            // 当有连接ID传过来,判断是否存在该连接事务,存在则不开启新事务
            if (connId != null)
            {
                string connIdStr = connId.ToString();
                if (perConn.GetDbTransaction(connIdStr) != null)
                {
                    invocation.Proceed();
                    return;
                }

                connectionId = connIdStr;
            }
            else
            {
                connectionId = perConn.NewConnectionId();
            }
            IDbTransaction dbTransaction = null;

            try
            {
                dbTransaction = perConn.BeginTransaction(connectionId, attr);

                invocation.SetArgumentValue(attr.ConnectionIdIndex, connectionId);

                invocation.Proceed();

                // 如果返回值为失败标识,也回滚
                Type returnType = invocation.Method.ReturnType;
                if (invocation.Method.ReturnType.IsReturnType())
                {
                    BasicReturnInfo basicReturnInfo = invocation.ReturnValue as BasicReturnInfo;
                    if (basicReturnInfo.Failure())
                    {
                        dbTransaction.Rollback();

                        return;
                    }
                }

                dbTransaction.Commit();
            }
            catch (Exception ex)
            {
                if (dbTransaction != null)
                {
                    dbTransaction.Rollback();
                }
                throw new Exception(ex.Message, ex);
            }
            finally
            {
                perConn.Release(connectionId);
            }
        }
 /// <summary>
 /// 拦截
 /// </summary>
 /// <param name="basicReturn">基本返回</param>
 /// <param name="invocation">拦截参数</param>
 /// <param name="attr">特性</param>
 /// <param name="isExecProceeded">是否已执行</param>
 protected abstract void Intercept(BasicReturnInfo basicReturn, IInvocation invocation, AttrT attr, out bool isExecProceeded);
Example #9
0
        /// <summary>
        /// 写入返回信息
        /// </summary>
        /// <param name="context">http上下文</param>
        /// <param name="options">Api异常处理选项配置</param>
        /// <param name="reInfo">返回信息</param>
        /// <returns>任务</returns>
        private static async Task WriteReturnInfo(HttpContext context, ApiExceptionHandleOptions options, BasicReturnInfo reInfo)
        {
            context.Response.ContentType = "application/json;charset=UTF-8";
            context.Response.StatusCode  = options.HttpStatusCode;

            await context.Response.WriteAsync(options.Serialization.Serialize(reInfo));
        }
 /// <summary>
 /// 拦截
 /// </summary>
 /// <param name="basicReturn">基本返回</param>
 /// <param name="invocation">拦截参数</param>
 /// <param name="attr">特性</param>
 /// <param name="isExecProceeded">是否已执行</param>
 protected override void Intercept(BasicReturnInfo basicReturn, IInvocation invocation, DisabledAttribute attr, out bool isExecProceeded)
 {
     isExecProceeded = false;
     basicReturn.SetFailureMsg("Sorry,此功能禁止访问");
 }
Example #11
0
        /// <summary>
        /// 接收消息
        /// </summary>
        /// <param name="receiveMessageFun">接收消息回调</param>
        public void Receive(Func <byte[], byte[]> receiveMessageFun)
        {
            channel.QueueDeclare(queue: amqpQueue.Queue.Name, durable: amqpQueue.Persistent, exclusive: false, autoDelete: amqpQueue.Queue.AutoDelQueue, arguments: null);
            if (amqpQueue.Queue.Qos != null)
            {
                channel.BasicQos(0, amqpQueue.Queue.Qos.GetValueOrDefault(), false);
            }

            channel.QueueBind(amqpQueue.Queue.Name, amqpQueue.ExchangeName, amqpQueue.Queue.Name);

            var consumer = new EventingBasicConsumer(channel);

            channel.BasicConsume(queue: amqpQueue.Queue.Name, autoAck: false, consumer: consumer);

            consumer.Received += (model, ea) =>
            {
                // 错误返回信息
                BasicReturnInfo errorReturn = null;

                // 返回给客户端的数据
                byte[] outData = null;

                // 关联ID
                string           correlationId = null;
                IBasicProperties props         = null;
                IBasicProperties replyProps    = null;
                try
                {
                    props      = ea.BasicProperties;
                    replyProps = channel.CreateBasicProperties();
                    replyProps.CorrelationId = props.CorrelationId;
                    correlationId            = props.CorrelationId;

                    byte[] inData = ea.Body.IsEmpty ? null : ea.Body.ToArray();
                    try
                    {
                        outData = receiveMessageFun(inData);
                    }
                    catch (Exception ex)
                    {
                        var busEx = AmqpUtil.BuilderBusinessException(ex, null, amqpQueue, log, ex.Message);
                        ExceptionHandle.Handle(busEx);

                        log.ErrorAsync("RpcServer回调业务处理出现异常", ex, typeof(RabbitRpcServer).Name, correlationId);

                        errorReturn = new BasicReturnInfo();
                        errorReturn.SetFailureMsg("业务处理出现异常", ex.Message);

                        outData = Encoding.UTF8.GetBytes(JsonUtil.SerializeIgnoreNull(errorReturn));
                    }
                }
                catch (Exception ex)
                {
                    log.ErrorAsync("RpcServer接收消息处理出现异常", ex, typeof(RabbitRpcServer).Name, correlationId);

                    errorReturn = new BasicReturnInfo();
                    errorReturn.SetFailureMsg("RpcServer接收消息处理出现异常", ex.Message);

                    outData = Encoding.UTF8.GetBytes(JsonUtil.SerializeIgnoreNull(errorReturn));
                }
                finally
                {
                    if (props != null && replyProps != null)
                    {
                        channel.BasicPublish(exchange: amqpQueue.ExchangeName, routingKey: props.ReplyTo, basicProperties: replyProps, body: outData);
                        channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                    }
                }
            };
        }
        /// <summary>
        /// 执行
        /// </summary>
        /// <param name="context">http上下文</param>
        /// <returns>任务</returns>
        public async Task InvokeAsync(HttpContext context)
        {
            var path = context.Request.Path.Value.ToLower();

            if (path.StartsWith(options.PfxApiPath))
            {
                var routeValue = context.Request.RouteValues;
                var routes     = routeValue.GetControllerAction();
                if (routes.IsNullOrLength0())
                {
                    await next(context);

                    return;
                }

                var routePermisses = reader.Reader();
                if (routePermisses.IsNullOrLength0())
                {
                    await next(context);

                    return;
                }

                var controllerConfig = routePermisses.Where(p => p.Controller == routes[0]).FirstOrDefault();
                if (controllerConfig == null)
                {
                    await next(context);

                    return;
                }
                if (controllerConfig.Disabled)
                {
                    var tempReturn = new BasicReturnInfo();
                    tempReturn.SetFailureMsg(localize.Get(CommonCodeDefine.DISABLED_ACCESS_CULTURE_KEY, "此功能已禁用"));
                    await WriteContent(context, tempReturn);

                    return;
                }
                if (controllerConfig.Actions.IsNullOrLength0())
                {
                    await next(context);

                    return;
                }

                var actionConfig = controllerConfig.Actions.Where(p => p.Action == routes[1]).FirstOrDefault();
                if (actionConfig == null)
                {
                    await next(context);

                    return;
                }
                if (actionConfig.Disabled)
                {
                    var tempReturn = new BasicReturnInfo();
                    tempReturn.SetFailureMsg(localize.Get(CommonCodeDefine.DISABLED_ACCESS_CULTURE_KEY, "此功能已禁用"));
                    await WriteContent(context, tempReturn);

                    return;
                }

                var basicReturn = new BasicReturnInfo();
                var isPer       = IsHavePermission(context, controllerConfig, actionConfig, basicReturn);
                if (basicReturn.Failure())
                {
                    await WriteContent(context, basicReturn);

                    return;
                }
                if (isPer)
                {
                    await next(context);
                }
                else
                {
                    await NotPermissionHandle(context);
                }
            }
            else
            {
                await next(context);
            }
        }
 /// <summary>
 /// 写入内容
 /// </summary>
 /// <param name="context">http上下文</param>
 /// <param name="basicReturn">基本返回</param>
 /// <returns>任务</returns>
 protected async Task WriteContent(HttpContext context, BasicReturnInfo basicReturn)
 {
     context.Response.ContentType = "application/json;charset=UTF-8";
     await context.Response.WriteAsync(basicReturn.ToJsonString());
 }
 /// <summary>
 /// 判断是否拥有权限
 /// </summary>
 /// <param name="context">上下文</param>
 /// <param name="controller">控制器信息</param>
 /// <param name="action">动作信息</param>
 /// <param name="basicReturn">基本返回</param>
 /// <returns>获取是否拥有权限</returns>
 protected abstract bool IsHavePermission(HttpContext context, RoutePermissionInfo controller, ActionInfo action, BasicReturnInfo basicReturn);