/// <summary> /// 1.预处理统一的参数验证逻辑 /// 2.根据接口信息创建查询管道上下文 /// </summary> /// <param name="queryArgs"></param> /// <returns></returns> private QueryPiplineContext PretreatmentAndCreateQueryPiplineContext(QueryArgs queryArgs) { //args check if (queryArgs == null) { throw new Exception($"Parameter invalid:queryArgs = null"); } queryArgs.QueryArgsCheck(); //argumentsDic generate Dictionary <string, object> argumentsDic = new Dictionary <string, object>(); foreach (var item in Request.Query) { argumentsDic.AddOrUpdate(item.Key.ToUpperInvariant(), item.Value); } //get interface info var interfaceAggregation = interfaceAggregationService.GetByInterfaceAggregationCode(queryArgs._interface); if (interfaceAggregation == null) { throw new Exception($"未能找到接口编码为[{queryArgs._interface}]对应的接口信息"); } //create queryContext QueryPiplineContext queryContext = new QueryPiplineContext(); queryContext.InterfaceCode = queryArgs._interface; queryContext.ArgumentsDic = argumentsDic; queryContext.ApplicationCode = interfaceAggregation.Code.Split('.')[0]; queryContext.MetaObjectId = interfaceAggregation.MetaObjectId; queryContext.SearchConditionId = interfaceAggregation.SearchConditionId; queryContext.FieldListId = interfaceAggregation.FieldListId; queryContext.DataSourceId = interfaceAggregation.DataSourceId; queryContext.InterfaceType = (InterfaceType)interfaceAggregation.InterfaceType; //设置ApplicationCode到Session SetApplictionCodeToSession(queryContext.ApplicationCode); return(queryContext); }
public IActionResult Get([FromQuery] QueryArgs queryArgs) { try { //args check if (queryArgs == null) { return(JsonResultModel.Error($"Parameter invalid:queryArgs = null")); } var checkResult = queryArgs.QueryArgsCheck(); if (!checkResult.IsSuccess) { return(checkResult.ToJsonResultModel()); } //argumentsDic generate Dictionary <string, object> argumentsDic = new Dictionary <string, object>(); foreach (var item in Request.Query) { if (!argumentsDic.ContainsKey(item.Key)) { argumentsDic.Add(item.Key.ToUpperInvariant(), item.Value); } } //get filter var interfaceAggregation = interfaceAggregationService.GetByInterfaceAggregationCode(queryArgs.interfaceCode); if (interfaceAggregation == null) { return(JsonResultModel.Error($"未能找到接口编码为[{queryArgs.interfaceCode}]对应的接口信息")); } var filter = conditionAggregationService.AnalysisConditionToFilterDefinitionByConditionId(interfaceAggregation.MetaObjectId, interfaceAggregation.SearchConditionId, argumentsDic); //get result switch ((InterfaceType)interfaceAggregation.InterfaceType) { case InterfaceType.CloudSingleObject: filter = triggerScriptEngineService.SingleObjectBefore(interfaceAggregation.MetaObjectId, interfaceAggregation.Code, filter); var singleObjectComponent = dataAccessService.GetSingleObjectComponent(interfaceAggregation.MetaObjectId, interfaceAggregation.FieldListId, filter); singleObjectComponent = triggerScriptEngineService.SingleObjectAfter(interfaceAggregation.MetaObjectId, interfaceAggregation.Code, singleObjectComponent); return(JsonResultModel.Success("get single data success", singleObjectComponent)); case InterfaceType.CloudTableList: filter = triggerScriptEngineService.TableListBefore(interfaceAggregation.MetaObjectId, interfaceAggregation.Code, filter); var sort = metaFieldService.GetSortDefinitionBySortFields(interfaceAggregation.MetaObjectId, null); var tableListComponent = dataAccessService.GetTableListComponent(interfaceAggregation.MetaObjectId, interfaceAggregation.FieldListId, filter, queryArgs.pageIndex, queryArgs.pageSize, sort, out int totalCount); tableListComponent = triggerScriptEngineService.TableListAfter(interfaceAggregation.MetaObjectId, interfaceAggregation.Code, tableListComponent); return(JsonResultModel.Success("get data list success", tableListComponent)); case InterfaceType.CloudCount: filter = triggerScriptEngineService.CountBefore(interfaceAggregation.MetaObjectId, interfaceAggregation.Code, filter); var count = dataAccessService.GetCount(interfaceAggregation.MetaObjectId, filter); count = triggerScriptEngineService.CountAfter(interfaceAggregation.MetaObjectId, interfaceAggregation.Code, count); return(JsonResultModel.Success("get data count success", count)); case InterfaceType.EnumeDataSource: break; case InterfaceType.TriggerScriptDataSource: object triggerScriptDataSourceResult = triggerScriptEngineService.TriggerScriptDataSource(interfaceAggregation.Code, argumentsDic, interfaceAggregation.Script); return(JsonResultModel.Success("get trigger script result success", triggerScriptDataSourceResult)); default: break; } return(JsonResultModel.Success("success,no data")); } catch (ArgumentNullException argNullEx) { return(JsonResultModel.Error(argNullEx.Message)); } catch (ArgumentException argEx) { return(JsonResultModel.Error(argEx.Message)); } catch (Exception ex) { return(JsonResultModel.Error(ex.Message)); } }