优化ResponseDeal
parent
afb20960b9
commit
5a8ef40e18
|
@ -200,33 +200,15 @@ public class ResponseMappingDeal {
|
|||
throw new ResponseException(customerException);
|
||||
}
|
||||
}
|
||||
for (Map<String, Object> mainItem : mainList) {
|
||||
aliasData.put(mainDataAlias.getDataAlias(), mainItem);
|
||||
// 处理配置信息
|
||||
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);
|
||||
if(ResponseUtil.parameterIsNotNull(mainList)) {
|
||||
for (Map<String, Object> 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<String, Object> jsonObj = (Map<String, Object>) Util.getValueByKeyStr(dataPath, aliasData);
|
||||
aliasData.put(mainDataAlias.getDataAlias(), jsonObj);
|
||||
// 处理配置信息
|
||||
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);
|
||||
}
|
||||
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 !!!");
|
||||
|
@ -236,14 +218,34 @@ public class ResponseMappingDeal {
|
|||
return tableDefinition;
|
||||
}
|
||||
|
||||
private RowDefinition buildRowDefinition(List<FieldDefinition> 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<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> 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<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) {
|
||||
List<ResponseConfigAlias> responseConfigAliasList = responseConfig.getResponseConfigAliasList();
|
||||
List<ResponseConfigValueChange> valueChangeList = responseConfig.getValueChangeList();
|
||||
|
|
Loading…
Reference in New Issue