public virtual ReturnInfo <WorkflowInfo> FindAuditDetail([DisplayName2("ID"), Id] int id, [DisplayName2("处理ID"), Id] int handleId, string connectionId = null, BasicUserInfo currUser = null) { ReturnInfo <WorkflowInfo> returnInfo = FindContainHandlesAndAllConfigs(id, connectionId, currUser); if (returnInfo.Failure()) { return(returnInfo); } WorkflowHandleInfo currHandle = null; foreach (var h in returnInfo.Data.Handles) { if (h.Id == handleId) { currHandle = h; break; } } BasicReturnInfo basicReturn = WorkflowUtil.CanCurrUserAudit(currHandle, currUser); if (basicReturn.Failure()) { returnInfo.FromBasic(basicReturn); } return(returnInfo); }
/// <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, ValiAttribute attr, out bool isExecProceeded) { isExecProceeded = false; if (attr.Handlers.IsNullOrLength0()) { return; } for (int i = 0; i < attr.Handlers.Length; i++) { Type type = attr.Handlers[i]; IValiHandler vali = type.CreateInstance <IValiHandler>() as IValiHandler; if (vali == null) { basicReturn.SetFailureMsg($"{type.FullName}未实现IValiable接口"); return; } BasicReturnInfo reInfo = vali.Exec(invocation.Arguments, attr.Indexs[i]); if (basicReturn.Failure()) { basicReturn.FromBasic(reInfo); return; } } }
/// <summary> /// 执行 /// </summary> /// <param name="param">参数</param> /// <param name="paramIndex">参数索引位置</param> /// <returns>返回信息</returns> public BasicReturnInfo Exec(object[] param, byte paramIndex = 0) { BasicReturnInfo returnInfo = new BasicReturnInfo(); int length = param.Length - paramIndex; for (byte i = paramIndex, row = 1; i < length; i++, row++) { object model = param[i]; if (model == null) { returnInfo.SetFailureMsg($"第{row}行:模型不能为null"); return(returnInfo); } returnInfo = modelComVali.Exec(param, i); if (returnInfo.Failure()) { returnInfo.SetMsg($"第{row}行:{returnInfo.Msg}", $"第{row}行:{returnInfo.Desc}"); return(returnInfo); } } return(returnInfo); }
/// <summary> /// 执行 /// </summary> /// <param name="param">参数</param> /// <param name="paramIndex">参数索引位置</param> /// <returns>返回信息</returns> public BasicReturnInfo Exec(object[] param, byte paramIndex = 0) { BasicReturnInfo returnInfo = new BasicReturnInfo(); if (param[paramIndex] == null) { return(returnInfo); } System.Collections.IEnumerable list = param[paramIndex] as System.Collections.IEnumerable; int row = 1; foreach (var model in list) { if (model == null) { returnInfo.SetFailureMsg($"第{row}行:模型不能为null"); return(returnInfo); } returnInfo = modelComVali.Exec(new object[] { model }, 0); if (returnInfo.Failure()) { returnInfo.SetMsg($"第{row}行:{returnInfo.Msg}", $"第{row}行:{returnInfo.Desc}"); return(returnInfo); } row++; } return(returnInfo); }
/// <summary> /// 验证 /// </summary> /// <param name="model">模型</param> /// <returns>返回信息</returns> public BasicReturnInfo Vali(object model) { BasicReturnInfo returnInfo = new BasicReturnInfo(); Type type = model.GetType(); PropertyInfo[] properties = type.GetProperties(); if (properties.IsNullOrLength0()) { return(returnInfo); } foreach (PropertyInfo pf in properties) { if (pf.CanRead) { foreach (IPropVali pv in propValis) { returnInfo = pv.Vali(model, pf, pf.GetValue(model)); if (returnInfo.Failure()) { return(returnInfo); } } } } return(returnInfo); }
/// <summary> /// 执行操作 /// </summary> /// <param name="value">值</param> /// <param name="valiAttr">验证特性</param> /// <param name="displayName">显示名</param> /// <returns>错误消息</returns> protected override string ExecOper(object value, MultiModelAttribute valiAttr, string displayName) { if (value == null) { return(null); } System.Collections.IEnumerable list = value as System.Collections.IEnumerable; int row = 1; foreach (var model in list) { if (model == null) { return($"第{row}行:模型不能为null"); } BasicReturnInfo returnInfo = modelCom.Exec(new object[] { model }, 0); if (returnInfo.Failure()) { return($"第{row}行:{returnInfo.Msg}"); } row++; } return(null); }
/// <summary> /// 根据工作流编码读取工作流定义信息的所有配置 /// </summary> /// <param name="workflowCode">工作流编码</param> /// <param name="connectionId">连接ID</param> /// <param name="comData">通用数据</param> /// <returns>返回信息</returns> public virtual ReturnInfo <WorkflowDefineInfo> ReaderAllConfig([DisplayName2("工作流编码"), Required] string workflowCode, CommonUseData comData = null, string connectionId = null) { return(ExecReturnFuncAndConnectionId <WorkflowDefineInfo>((reInfo, connId) => { WorkflowDefineInfo workflowDefine = Persistence.SelectByCode(workflowCode, connId); BasicReturnInfo basicReturn = ReaderOtherConfig(workflowDefine, connectionId: connId, comData: comData); if (basicReturn.Failure()) { reInfo.FromBasic(basicReturn); return null; } return workflowDefine; }, null, connectionId, AccessMode.SLAVE)); }
/// <summary> /// 执行操作 /// </summary> /// <param name="value">值</param> /// <param name="valiAttr">验证特性</param> /// <param name="displayName">显示名</param> /// <returns>错误消息</returns> protected override string ExecOper(object value, ModelAttribute valiAttr, string displayName) { if (value == null) { return(null); } BasicReturnInfo basicReturn = modelCom.Exec(new object[] { value }); if (basicReturn.Failure()) { return(basicReturn.Msg); } return(null); }
/// <summary> /// 根据工作流定义ID读取工作流定义信息的所有配置 /// </summary> /// <param name="workflowDefineId">工作流定义ID</param> /// <param name="connectionId">连接ID</param> /// <param name="currUser">当前用户</param> /// <returns>返回信息</returns> public virtual ReturnInfo <WorkflowDefineInfo> ReaderAllConfig([DisplayName2("工作流定义ID"), Id] int workflowDefineId, string connectionId = null, BasicUserInfo <int> currUser = null) { return(ExecReturnFuncAndConnectionId <WorkflowDefineInfo>((reInfo, connId) => { WorkflowDefineInfo workflowDefine = Persistence.Select(workflowDefineId, connId); BasicReturnInfo basicReturn = ReaderOtherConfig(workflowDefine, connId, currUser); if (basicReturn.Failure()) { reInfo.FromBasic(basicReturn); return null; } return workflowDefine; }, null, connectionId, AccessMode.SLAVE)); }
/// <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="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="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); } }