优化ResponseDeal

dev
ic_excellent 2023-07-27 14:12:35 +08:00
parent afb20960b9
commit 5a8ef40e18
1 changed files with 58 additions and 39 deletions

View File

@ -200,33 +200,15 @@ public class ResponseMappingDeal {
throw new ResponseException(customerException); throw new ResponseException(customerException);
} }
} }
for (Map<String, Object> mainItem : mainList) { if(ResponseUtil.parameterIsNotNull(mainList)) {
aliasData.put(mainDataAlias.getDataAlias(), mainItem); for (Map<String, Object> mainItem : mainList) {
// 处理配置信息 RowDefinition rowDefinition = this.buildRowDefinition(mainDataAlias, tableName, isMainTable, aliasData, mainItem, valueChangeList, responseConfig, detailCallBack);
List<FieldDefinition> fieldDefinitions = parsingJsonToConfig(valueChangeList, aliasData); rowDefinitionList.add(rowDefinition);
RowDefinition rowDefinition = this.buildRowDefinition(fieldDefinitions, tableName, mainDataAlias.getAssignType(), mainDataAlias.getConditionScript(), mainDataAlias.getJudgmentScript());
rowDefinition.setMainOrDetail(ResponseConfigConstant.DETAIL_TABLE);
if (isMainTable) {
Map<String, TableDefinition> detailTable = new HashMap<>();
rowDefinition.setMainOrDetail(ResponseConfigConstant.MAIN_TABLE);
detailCallBack.apply(responseConfig, aliasData, detailTable);
rowDefinition.setDetailTableMap(detailTable);
} }
rowDefinitionList.add(rowDefinition);
} }
} else if (mainDataAlias.getDataType() == ResponseConfigConstant.JSON_OBJECT) { } else if (mainDataAlias.getDataType() == ResponseConfigConstant.JSON_OBJECT) {
Map<String, Object> jsonObj = (Map<String, Object>) Util.getValueByKeyStr(dataPath, aliasData); Map<String, Object> jsonObj = (Map<String, Object>) Util.getValueByKeyStr(dataPath, aliasData);
aliasData.put(mainDataAlias.getDataAlias(), jsonObj); RowDefinition rowDefinition = this.buildRowDefinition(mainDataAlias, tableName, isMainTable, aliasData, jsonObj, valueChangeList, responseConfig, detailCallBack);
// 处理配置信息
List<FieldDefinition> fieldDefinitions = parsingJsonToConfig(valueChangeList, aliasData);
RowDefinition rowDefinition = this.buildRowDefinition(fieldDefinitions, tableName, mainDataAlias.getAssignType(), mainDataAlias.getConditionScript(), mainDataAlias.getJudgmentScript());
rowDefinition.setMainOrDetail(ResponseConfigConstant.DETAIL_TABLE);
if (isMainTable) {
Map<String, TableDefinition> detailTable = new HashMap<>();
rowDefinition.setMainOrDetail(ResponseConfigConstant.MAIN_TABLE);
detailCallBack.apply(responseConfig, aliasData, detailTable);
rowDefinition.setDetailTableMap(detailTable);
}
rowDefinitionList.add(rowDefinition); rowDefinitionList.add(rowDefinition);
} else { } else {
throw new ResponseException("please set the primary data type !!!"); throw new ResponseException("please set the primary data type !!!");
@ -236,14 +218,34 @@ public class ResponseMappingDeal {
return tableDefinition; return tableDefinition;
} }
private RowDefinition buildRowDefinition(List<FieldDefinition> fieldDefinitionList, /**
String tableName, * json
int assignType, * @param mainDataAlias
String conditionScript, * @param tableName
String judgmentScript) { * @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<String,Object> aliasData,
Map<String,Object> jsonObj,
List<ResponseConfigValueChange> valueChangeList,
ResponseConfig responseConfig,
Bi3Function<ResponseConfig, Map<String, Object>, Map<String, TableDefinition>, String> detailCallBack){
// 将当前行的json信息放入别名map
aliasData.put(mainDataAlias.getDataAlias(), jsonObj);
//通过字段转换配置将json转为字段描述
List<FieldDefinition> fieldDefinitions = parsingJsonToConfig(valueChangeList, aliasData);
Map<String, Object> updateParam = new HashMap<>(); Map<String, Object> updateParam = new HashMap<>();
Map<String, Object> wherePram = new HashMap<>(); Map<String, Object> wherePram = new HashMap<>();
fieldDefinitionList.forEach(fieldDefinition -> { //构建用于更新和作为条件的map
fieldDefinitions.forEach(fieldDefinition -> {
int fieldType = fieldDefinition.getFieldType(); int fieldType = fieldDefinition.getFieldType();
if (fieldType == ResponseConfigConstant.WHERE_FIELD) { if (fieldType == ResponseConfigConstant.WHERE_FIELD) {
wherePram.put(fieldDefinition.getFieldName(), fieldDefinition.getFieldValue()); wherePram.put(fieldDefinition.getFieldName(), fieldDefinition.getFieldValue());
@ -252,16 +254,33 @@ public class ResponseMappingDeal {
wherePram.put(fieldDefinition.getFieldName(), fieldDefinition.getFieldValue()); wherePram.put(fieldDefinition.getFieldName(), fieldDefinition.getFieldValue());
} }
}); });
return RowDefinition.builder().assignType(assignType) //构建行描述信息
.conditionScript(conditionScript) RowDefinition rowDefinition = RowDefinition.builder().assignType(mainDataAlias.getAssignType())
.updateParam(updateParam) .conditionScript(mainDataAlias.getConditionScript())
.assignTable(tableName) .updateParam(updateParam)
.whereParam(wherePram) .assignTable(tableName)
.fieldDefinitionList(fieldDefinitionList) .whereParam(wherePram)
.rowDefinitionCallback(this.rowCallback) .fieldDefinitionList(fieldDefinitions)
.judgmentScript(judgmentScript).build(); .rowDefinitionCallback(this.rowCallback)
.judgmentScript(mainDataAlias.getJudgmentScript()).build();
rowDefinition.setMainOrDetail(ResponseConfigConstant.DETAIL_TABLE);
//判断是否为主表,为主表则需处理其明细信息
if (isMainTable) {
Map<String, TableDefinition> 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<String, Object> param, Map<String, TableDefinition> detailTable) { private String detailTableDeal(ResponseConfig responseConfig, Map<String, Object> param, Map<String, TableDefinition> detailTable) {
List<ResponseConfigAlias> responseConfigAliasList = responseConfig.getResponseConfigAliasList(); List<ResponseConfigAlias> responseConfigAliasList = responseConfig.getResponseConfigAliasList();
List<ResponseConfigValueChange> valueChangeList = responseConfig.getValueChangeList(); List<ResponseConfigValueChange> valueChangeList = responseConfig.getValueChangeList();