From 5a8ef40e184852abe291a462bf1f4cb9fcc7bc0f Mon Sep 17 00:00:00 2001 From: ic_excellent <2570192571@qq.com> Date: Thu, 27 Jul 2023 14:12:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96ResponseDeal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response_deal/ResponseMappingDeal.java | 97 +++++++++++-------- 1 file changed, 58 insertions(+), 39 deletions(-) diff --git a/src/main/java/aiyh/utils/response_deal/ResponseMappingDeal.java b/src/main/java/aiyh/utils/response_deal/ResponseMappingDeal.java index ed6ce0b..4af9252 100644 --- a/src/main/java/aiyh/utils/response_deal/ResponseMappingDeal.java +++ b/src/main/java/aiyh/utils/response_deal/ResponseMappingDeal.java @@ -200,33 +200,15 @@ public class ResponseMappingDeal { throw new ResponseException(customerException); } } - for (Map mainItem : mainList) { - aliasData.put(mainDataAlias.getDataAlias(), mainItem); - // 处理配置信息 - List fieldDefinitions = parsingJsonToConfig(valueChangeList, aliasData); - RowDefinition rowDefinition = this.buildRowDefinition(fieldDefinitions, tableName, mainDataAlias.getAssignType(), mainDataAlias.getConditionScript(), mainDataAlias.getJudgmentScript()); - rowDefinition.setMainOrDetail(ResponseConfigConstant.DETAIL_TABLE); - if (isMainTable) { - Map detailTable = new HashMap<>(); - rowDefinition.setMainOrDetail(ResponseConfigConstant.MAIN_TABLE); - detailCallBack.apply(responseConfig, aliasData, detailTable); - rowDefinition.setDetailTableMap(detailTable); + if(ResponseUtil.parameterIsNotNull(mainList)) { + for (Map mainItem : mainList) { + RowDefinition rowDefinition = this.buildRowDefinition(mainDataAlias, tableName, isMainTable, aliasData, mainItem, valueChangeList, responseConfig, detailCallBack); + rowDefinitionList.add(rowDefinition); } - rowDefinitionList.add(rowDefinition); } } else if (mainDataAlias.getDataType() == ResponseConfigConstant.JSON_OBJECT) { Map jsonObj = (Map) Util.getValueByKeyStr(dataPath, aliasData); - aliasData.put(mainDataAlias.getDataAlias(), jsonObj); - // 处理配置信息 - List fieldDefinitions = parsingJsonToConfig(valueChangeList, aliasData); - RowDefinition rowDefinition = this.buildRowDefinition(fieldDefinitions, tableName, mainDataAlias.getAssignType(), mainDataAlias.getConditionScript(), mainDataAlias.getJudgmentScript()); - rowDefinition.setMainOrDetail(ResponseConfigConstant.DETAIL_TABLE); - if (isMainTable) { - Map detailTable = new HashMap<>(); - rowDefinition.setMainOrDetail(ResponseConfigConstant.MAIN_TABLE); - detailCallBack.apply(responseConfig, aliasData, detailTable); - rowDefinition.setDetailTableMap(detailTable); - } + RowDefinition rowDefinition = this.buildRowDefinition(mainDataAlias, tableName, isMainTable, aliasData, jsonObj, valueChangeList, responseConfig, detailCallBack); rowDefinitionList.add(rowDefinition); } else { throw new ResponseException("please set the primary data type !!!"); @@ -235,15 +217,35 @@ public class ResponseMappingDeal { tableDefinition.setRowDefinitionList(rowDefinitionList); return tableDefinition; } - - private RowDefinition buildRowDefinition(List fieldDefinitionList, - String tableName, - int assignType, - String conditionScript, - String judgmentScript) { + + /** + * 将json信息转换成行描述 + * @param mainDataAlias 别名配置信息 + * @param tableName 表名 + * @param isMainTable 是否为珠宝 + * @param aliasData json别名数据 + * @param jsonObj json数据 + * @param valueChangeList 转换列表 + * @param responseConfig 配置实体 + * @param detailCallBack 明细回调方法 + * @return 行描述 + */ + private RowDefinition buildRowDefinition(ResponseConfigAlias mainDataAlias, + String tableName, + boolean isMainTable, + Map aliasData, + Map jsonObj, + List valueChangeList, + ResponseConfig responseConfig, + Bi3Function, Map, String> detailCallBack){ + // 将当前行的json信息放入别名map + aliasData.put(mainDataAlias.getDataAlias(), jsonObj); + //通过字段转换配置将json转为字段描述 + List fieldDefinitions = parsingJsonToConfig(valueChangeList, aliasData); Map updateParam = new HashMap<>(); Map wherePram = new HashMap<>(); - fieldDefinitionList.forEach(fieldDefinition -> { + //构建用于更新和作为条件的map + fieldDefinitions.forEach(fieldDefinition -> { int fieldType = fieldDefinition.getFieldType(); if (fieldType == ResponseConfigConstant.WHERE_FIELD) { wherePram.put(fieldDefinition.getFieldName(), fieldDefinition.getFieldValue()); @@ -252,16 +254,33 @@ public class ResponseMappingDeal { wherePram.put(fieldDefinition.getFieldName(), fieldDefinition.getFieldValue()); } }); - return RowDefinition.builder().assignType(assignType) - .conditionScript(conditionScript) - .updateParam(updateParam) - .assignTable(tableName) - .whereParam(wherePram) - .fieldDefinitionList(fieldDefinitionList) - .rowDefinitionCallback(this.rowCallback) - .judgmentScript(judgmentScript).build(); + //构建行描述信息 + RowDefinition rowDefinition = RowDefinition.builder().assignType(mainDataAlias.getAssignType()) + .conditionScript(mainDataAlias.getConditionScript()) + .updateParam(updateParam) + .assignTable(tableName) + .whereParam(wherePram) + .fieldDefinitionList(fieldDefinitions) + .rowDefinitionCallback(this.rowCallback) + .judgmentScript(mainDataAlias.getJudgmentScript()).build(); + rowDefinition.setMainOrDetail(ResponseConfigConstant.DETAIL_TABLE); + //判断是否为主表,为主表则需处理其明细信息 + if (isMainTable) { + Map detailTable = new HashMap<>(); + rowDefinition.setMainOrDetail(ResponseConfigConstant.MAIN_TABLE); + detailCallBack.apply(responseConfig, aliasData, detailTable); + rowDefinition.setDetailTableMap(detailTable); + } + return rowDefinition; } - + + /** + * json转明细处理 + * @param responseConfig 配置信息 + * @param param json数据 + * @param detailTable 明细表map + * @return 信息 + */ private String detailTableDeal(ResponseConfig responseConfig, Map param, Map detailTable) { List responseConfigAliasList = responseConfig.getResponseConfigAliasList(); List valueChangeList = responseConfig.getValueChangeList();