public IActionResult Post([FromQuery] QueryArgs queryArgs, [FromBody] JObject jObj) { try { var json = jObj.ToString(); var bson = BsonDocument.Parse(json); if (bson == null || !bson.Any()) { return(JsonResultModel.Error("Parameter invalid:jObj = null 业务数据为空")); } //Pretreatment create queryContext QueryPiplineContext queryContext = PretreatmentAndCreateQueryPiplineContext(queryArgs); queryContext.MetaObject = metaObjectService.GetById(queryContext.MetaObjectId); if (queryContext.MetaObject == null) { return(JsonResultModel.Error($"未能找到对象Id为[{queryContext.MetaObjectId}]对应的对象信息")); } //缓存某个服务下的全部触发器脚本,包括before和after queryContext.TriggerScriptsOfOneServiceType = _triggerScriptService.GetTriggerScriptsUnDeletedByMetaObjectIdAndServiceType(queryContext.MetaObjectId, (int)ServiceType.Interface_Add); //trigger before bson = _triggerScriptService.RunTriggerScript(queryContext, TriggerPoint.Before, TriggerScriptService.FunctionName_MetaObject_Interface_Add_Before, bson, CurrentApplicationContext, queryContext.InterfaceCode, bson); //check data by form if (queryContext.FormId != default(int)) { var formCheckResult = _formMetaFieldService.ValidateFormData(queryContext.FormId, bson); if (!formCheckResult.IsSuccess) { return(formCheckResult.ToJsonResultModel()); } } //add data var addResult = dataAccessService.Add(queryContext.TenantId, queryContext.MetaObject, bson); //trigger after _triggerScriptService.RunTriggerScript(queryContext, TriggerPoint.After, TriggerScriptService.FunctionName_MetaObject_Interface_Add_After, bson, CurrentApplicationContext, queryContext.InterfaceCode, bson); return(addResult.ToJsonResultModel()); } catch (ArgumentNullException argNullEx) { return(JsonResultModel.Error(argNullEx.Message)); } catch (ArgumentException argEx) { return(JsonResultModel.Error(argEx.Message)); } catch (Exception ex) { return(JsonResultModel.Error(ex.Message)); } }
public IActionResult Update([FromQuery] QueryArgs queryArgs, [FromBody] JObject jObj) { try { var json = jObj.ToString(); var bson = BsonDocument.Parse(json); if (bson == null || !bson.Any()) { return(JsonResultModel.Error("Parameter invalid:jObj = null 业务数据为空")); } //Pretreatment create queryContext QueryPiplineContext queryContext = PretreatmentAndCreateQueryPiplineContext(queryArgs); //缓存某个服务下的全部触发器脚本,包括before和after queryContext.TriggerScriptsOfOneServiceType = _triggerScriptService.GetTriggerScriptsUnDeletedByMetaObjectIdAndServiceType(queryContext.MetaObjectId, (int)ServiceType.Interface_Update); //查询条件 FilterDefinition <BsonDocument> filter = conditionAggregationService.AnalysisConditionToFilterDefinitionByConditionId(queryContext, queryContext.ArgumentsDic); //trigger before bson = _triggerScriptService.RunTriggerScript(queryContext, TriggerPoint.Before, TriggerScriptService.FunctionName_MetaObject_Interface_Update_Before, bson, CurrentApplicationContext, queryContext.InterfaceCode, bson, filter); //check data by form if (queryContext.FormId != default(int)) { var formCheckResult = _formMetaFieldService.ValidateFormData(queryContext.FormId, bson); if (!formCheckResult.IsSuccess) { return(formCheckResult.ToJsonResultModel()); } } //update data dataAccessService.Update(queryContext.TenantId, queryContext.MetaObjectId, filter, bson); //trigger after _triggerScriptService.RunTriggerScript(queryContext, TriggerPoint.After, TriggerScriptService.FunctionName_MetaObject_Interface_Update_After, bson, CurrentApplicationContext, queryContext.InterfaceCode, bson); return(JsonResultModel.Success("success")); } catch (ArgumentNullException argNullEx) { return(JsonResultModel.Error(argNullEx.Message)); } catch (ArgumentException argEx) { return(JsonResultModel.Error(argEx.Message)); } catch (Exception ex) { return(JsonResultModel.Error(ex.Message)); } }
public IActionResult Update(string conditionCode, [FromBody] JObject jObj) { try { //args check if (string.IsNullOrEmpty(conditionCode)) { return(JsonResultModel.Error($"Parameter invalid:conditionCode = null")); } if (jObj == null) { return(JsonResultModel.Error($"Parameter invalid:data = null")); } //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 searchCondition = searchConditionService.GetByCode(conditionCode); if (searchCondition == null) { return(JsonResultModel.Error($"SearchCondition not found by conditionCode[{searchCondition}]")); } var filter = conditionAggregationService.AnalysisConditionToFilterDefinitionByConditionId(searchCondition.MetaObjectId, searchCondition.Id, argumentsDic); //get object var json = jObj.ToString(); var bson = BsonDocument.Parse(json); //update before filter = triggerScriptEngineService.UpdateBefore(searchCondition.MetaObjectId, searchCondition.Code, filter); //update data dataAccessService.Update(searchCondition.MetaObjectId, filter, bson); return(JsonResultModel.Success("success")); } catch (Exception ex) { return(JsonResultModel.Error(ex.ToString())); } }
public IActionResult Delete([FromQuery] QueryArgs queryArgs) { try { //Pretreatment create queryContext QueryPiplineContext queryContext = PretreatmentAndCreateQueryPiplineContext(queryArgs); //缓存某个服务下的全部触发器脚本,包括before和after queryContext.TriggerScriptsOfOneServiceType = _triggerScriptService.GetTriggerScriptsUnDeletedByMetaObjectIdAndServiceType(queryContext.MetaObjectId, (int)ServiceType.Interface_Delete); //查询条件 FilterDefinition <BsonDocument> filter = conditionAggregationService.AnalysisConditionToFilterDefinitionByConditionId(queryContext, queryContext.ArgumentsDic); //trigger before filter = _triggerScriptService.RunTriggerScript(queryContext, TriggerPoint.Before, TriggerScriptService.FunctionName_MetaObject_Interface_Delete_Before, filter, CurrentApplicationContext, queryContext.InterfaceCode, filter); //queryResult var queryDatas = dataAccessService.GetList(queryContext.TenantId, queryContext.MetaObjectId, filter, null); //delete dataAccessService.Delete(queryContext.TenantId, queryContext.MetaObjectId, filter); //trigger after _triggerScriptService.RunTriggerScript(queryContext, TriggerPoint.After, TriggerScriptService.FunctionName_MetaObject_Interface_Delete_After, filter, CurrentApplicationContext, queryContext.InterfaceCode, queryDatas); return(JsonResultModel.Success("success")); } catch (ArgumentNullException argNullEx) { return(JsonResultModel.Error(argNullEx.Message)); } catch (ArgumentException argEx) { return(JsonResultModel.Error(argEx.Message)); } catch (Exception ex) { return(JsonResultModel.Error(ex.Message)); } }
public IActionResult Post(string metaObjectCode, [FromBody] JObject jObj) { try { if (string.IsNullOrEmpty(metaObjectCode)) { return(JsonResultModel.Error($"Parameter invalid:metaObjectCode = null")); } if (jObj == null) { return(JsonResultModel.Error($"Parameter invalid:data = null")); } var json = jObj.ToString(); var bson = BsonDocument.Parse(json); //get metaObject var metaObject = metaObjectService.GetByCode(metaObjectCode); if (metaObject == null) { return(JsonResultModel.Error($"未能找到对象编码为[{metaObjectCode}]对应的对象信息")); } //trigger before bson = triggerScriptEngineService.AddBefore(metaObject.Id, metaObjectCode, bson); //add data var addResult = dataAccessService.Add(metaObject, bson); return(addResult.ToJsonResultModel()); } catch (Exception ex) { return(JsonResultModel.Error(ex.ToString())); } }
public IActionResult Post([FromBody] UIIndexPageQueryArgs queryArgs) { try { //args check if (queryArgs == null) { return(JsonResultModel.Error($"Parameter invalid:queryArgs = null")); } var checkResult = queryArgs.ArgsCheck(); 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 indexView = indexViewService.GetByCode(queryArgs.ViewName); if (indexView == null) { return(JsonResultModel.Error($"未能找到视图编码为[{queryArgs.ViewName}]对应的视图信息")); } //分析搜索条件,是否忽略参数校验为true,如果参数没传递则不抛出异常且处理为忽略参数 var filter = conditionAggregationService.AnalysisConditionToFilterDefinitionByConditionId(indexView.MetaObjectId, indexView.SearchConditionId, argumentsDic, true); //如果参数都没传递或者其他原因导致条件没有,则直接返回全部 if (filter == null) { filter = Builders <BsonDocument> .Filter.Empty; } //filter = triggerScriptEngineService.TableListBefore(indexView.MetaObjectId, indexView.Code, filter); //var sort = metaFieldService.GetSortDefinitionBySortFields(indexView.MetaObjectId, queryArgs.SortFields); //var tableListComponent = dataAccessService.GetTableListComponent(indexView.MetaObjectId, indexView.FieldListId, filter, queryArgs.PageIndex, queryArgs.PageSize, sort, out int totalCount); //tableListComponent = triggerScriptEngineService.TableListAfter(indexView.MetaObjectId, indexView.Code, tableListComponent); return(JsonResultModel.Success("get data list success", null)); } catch (ArgumentNullException argNullEx) { return(JsonResultModel.Error(argNullEx.Message)); } catch (ArgumentException argEx) { return(JsonResultModel.Error(argEx.Message)); } catch (Exception ex) { return(JsonResultModel.Error(ex.Message)); } }
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)); } }
public IActionResult Post([FromQuery] QueryArgs queryArgs, [FromBody] JArray jArray) { try { if (jArray == null || !jArray.Any()) { return(JsonResultModel.Error($"Parameter invalid:data = null")); } //Pretreatment create queryContext QueryPiplineContext queryContext = PretreatmentAndCreateQueryPiplineContext(queryArgs); queryContext.MetaObject = metaObjectService.GetById(queryContext.MetaObjectId); if (queryContext.MetaObject == null) { return(JsonResultModel.Error($"未能找到对象Id为[{queryContext.MetaObjectId}]对应的对象信息")); } int successCount = 0; int errorCount = 0; List <BsonDocument> documents = new List <BsonDocument>(); foreach (var item in jArray) { try { var json = item.ToString(); documents.Add(BsonDocument.Parse(json)); successCount++; } catch (Exception) { errorCount++; } } //缓存某个服务下的全部触发器脚本,包括before和after queryContext.TriggerScriptsOfOneServiceType = _triggerScriptService.GetTriggerScriptsUnDeletedByMetaObjectIdAndServiceType(queryContext.MetaObjectId, (int)ServiceType.Interface_BatchAdd); //trigger before documents = _triggerScriptService.RunTriggerScript(queryContext, TriggerPoint.Before, TriggerScriptService.FunctionName_MetaObject_Interface_BatchAdd_Before, documents, CurrentApplicationContext, queryContext.InterfaceCode, documents); //check data by form if (queryContext.FormId != default(int)) { var formCheckResult = _formMetaFieldService.ValidateFormData(queryContext.FormId, documents); if (!formCheckResult.IsSuccess) { return(formCheckResult.ToJsonResultModel()); } } //add data var addResult = dataAccessService.BatchAdd(queryContext.TenantId, queryContext.MetaObject, documents); //trigger after _triggerScriptService.RunTriggerScript(queryContext, TriggerPoint.After, TriggerScriptService.FunctionName_MetaObject_Interface_BatchAdd_After, documents, CurrentApplicationContext, queryContext.InterfaceCode, documents); return(addResult.ToJsonResultModel()); } catch (ArgumentNullException argNullEx) { return(JsonResultModel.Error(argNullEx.Message)); } catch (ArgumentException argEx) { return(JsonResultModel.Error(argEx.Message)); } catch (Exception ex) { return(JsonResultModel.Error(ex.Message)); } }
public IActionResult Get([FromQuery] QueryArgs queryArgs) { try { //Pretreatment create queryContext QueryPiplineContext queryContext = PretreatmentAndCreateQueryPiplineContext(queryArgs); //查询条件 FilterDefinition <BsonDocument> filter = FilterDefinition <BsonDocument> .Empty; //【SingleObject,TableList,Count】预处理一些逻辑 if (new InterfaceType[] { InterfaceType.SingleObject, InterfaceType.TableList, InterfaceType.Count }.Contains(queryContext.InterfaceType)) { //缓存对象下的全部未删除字段信息 queryContext.MetaFieldsUnDeleted = metaFieldService.GetEntitiesUnDeletedByMetaObjectId(queryContext.MetaObjectId); //组织查询条件 filter = conditionAggregationService.AnalysisConditionToFilterDefinitionByConditionId(queryContext, queryContext.ArgumentsDic); //缓存列字段信息 if (queryContext.InterfaceType == InterfaceType.SingleObject || queryContext.InterfaceType == InterfaceType.TableList) { queryContext.FieldListMetaFieldsOfFieldListId = _fieldListMetaFieldService.GetByFieldListId(queryContext.FieldListId); } } switch (queryContext.InterfaceType) { case InterfaceType.SingleObject: //缓存某个服务下的全部触发器脚本,包括before和after queryContext.TriggerScriptsOfOneServiceType = _triggerScriptService.GetTriggerScriptsUnDeletedByMetaObjectIdAndServiceType(queryContext.MetaObjectId, (int)ServiceType.Interface_SingleObject); filter = _triggerScriptService.RunTriggerScript(queryContext, TriggerPoint.Before, TriggerScriptService.FunctionName_MetaObject_Interface_SingleObject_Before, filter, CurrentApplicationContext, queryContext.InterfaceCode, filter); var singleObjectComponent = dataAccessService.GetSingleObjectComponent(queryContext, filter); singleObjectComponent = _triggerScriptService.RunTriggerScript(queryContext, TriggerPoint.After, TriggerScriptService.FunctionName_MetaObject_Interface_SingleObject_After, singleObjectComponent, CurrentApplicationContext, queryContext.InterfaceCode, singleObjectComponent); return(JsonResultModel.Success("get single data success", singleObjectComponent)); case InterfaceType.TableList: //缓存某个服务下的全部触发器脚本,包括before和after queryContext.TriggerScriptsOfOneServiceType = _triggerScriptService.GetTriggerScriptsUnDeletedByMetaObjectIdAndServiceType(queryContext.MetaObjectId, (int)ServiceType.Interface_TableList); filter = _triggerScriptService.RunTriggerScript(queryContext, TriggerPoint.Before, TriggerScriptService.FunctionName_MetaObject_Interface_TableList_Before, filter, CurrentApplicationContext, queryContext.InterfaceCode, filter); var sort = metaFieldService.GetSortDefinitionBySortFields(queryContext, new[] { new SortField { Column = "ModifyTime", IsDesc = true } }); var tableListComponent = dataAccessService.GetTableListComponent(queryContext, filter, queryArgs._pageIndex, queryArgs._pageSize, sort, out int totalCount); tableListComponent = _triggerScriptService.RunTriggerScript(queryContext, TriggerPoint.After, TriggerScriptService.FunctionName_MetaObject_Interface_TableList_After, tableListComponent, CurrentApplicationContext, queryContext.InterfaceCode, tableListComponent); return(JsonResultModel.Success("get data list success", tableListComponent)); case InterfaceType.Count: //缓存某个服务下的全部触发器脚本,包括before和after queryContext.TriggerScriptsOfOneServiceType = _triggerScriptService.GetTriggerScriptsUnDeletedByMetaObjectIdAndServiceType(queryContext.MetaObjectId, (int)ServiceType.Interface_Count); filter = _triggerScriptService.RunTriggerScript(queryContext, TriggerPoint.Before, TriggerScriptService.FunctionName_MetaObject_Interface_Count_Before, filter, CurrentApplicationContext, queryContext.InterfaceCode, filter); var count = dataAccessService.GetCount(queryContext.TenantId, queryContext.MetaObjectId, filter); count = _triggerScriptService.RunTriggerScript(queryContext, TriggerPoint.After, TriggerScriptService.FunctionName_MetaObject_Interface_Count_After, count, CurrentApplicationContext, queryContext.InterfaceCode, filter, count); return(JsonResultModel.Success("get data count success", count)); case InterfaceType.JsonDataSource: return(new JsonResult(Newtonsoft.Json.JsonConvert.DeserializeObject(_dataSourceService.GetById(queryContext.DataSourceId).Script))); case InterfaceType.ExecutableScriptDataSource: object triggerScriptDataSourceResult = _triggerScriptService.RunDataSourceScript(queryContext, CurrentApplicationContext, queryContext.InterfaceCode, queryContext.ArgumentsDic); 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)); } }
public IActionResult Post(string metaObjectCode, [FromBody] JArray jArray) { try { if (string.IsNullOrEmpty(metaObjectCode)) { return(JsonResultModel.Error($"Parameter invalid:metaObjectCode = null")); } if (jArray == null) { return(JsonResultModel.Error($"Parameter invalid:data = null")); } if (jArray.Any()) { //get metaObject var metaObject = metaObjectService.GetByCode(metaObjectCode); if (metaObject == null) { return(JsonResultModel.Error($"未能找到对象编码为[{metaObjectCode}]对应的对象信息")); } int successCount = 0; int errorCount = 0; List <BsonDocument> documents = new List <BsonDocument>(); foreach (var item in jArray) { try { var json = item.ToString(); documents.Add(BsonDocument.Parse(json)); successCount++; } catch (Exception) { errorCount++; } } //trigger before documents = triggerScriptEngineService.BatchAddBefore(metaObject.Id, metaObjectCode, documents); //add data var addResult = dataAccessService.BatchAdd(metaObject, documents); if (addResult.IsSuccess) { return(JsonResultModel.Error($"插入成功!日志信息:成功[{successCount}]条,失败[{errorCount}]条")); } else { return(JsonResultModel.Error("插入失败")); } } return(JsonResultModel.Error("插入失败")); } catch (Exception ex) { return(JsonResultModel.Error(ex.ToString())); } }