添加注释
parent
b23aadb572
commit
e3e696b165
|
@ -37,68 +37,105 @@ public class ResponseMappingDeal {
|
||||||
private final Logger logger = Util.getLogger("json_util");
|
private final Logger logger = Util.getLogger("json_util");
|
||||||
|
|
||||||
private final ConfigMapper configMapper = Util.getMapper(ConfigMapper.class);
|
private final ConfigMapper configMapper = Util.getMapper(ConfigMapper.class);
|
||||||
|
|
||||||
/** 表数据回调 */
|
/** 表数据回调 */
|
||||||
private TableDefinitionCallback tableCallback;
|
private TableDefinitionCallback tableCallback;
|
||||||
|
|
||||||
/** 行数据回调 */
|
/** 行数据回调 */
|
||||||
private RowDefinitionCallback rowCallback;
|
private RowDefinitionCallback rowCallback;
|
||||||
|
|
||||||
/** 字段数据回调 */
|
/** 字段数据回调 */
|
||||||
private FieldDefinitionCallback fieldDefinitionCallback;
|
private FieldDefinitionCallback fieldDefinitionCallback;
|
||||||
|
|
||||||
/** 状态map的key */
|
/** 状态map的key */
|
||||||
private Class<?> stateClassKey;
|
private Class<?> stateClassKey;
|
||||||
|
|
||||||
public void doResponseSync(String uniqueCode, ResponeVo responeVo) {
|
public void doResponseSync(String uniqueCode, ResponeVo responeVo) {
|
||||||
Map<String, Object> responseMap = responeVo.getResponseMap();
|
Map<String, Object> responseMap = responeVo.getResponseMap();
|
||||||
ResponseUtil.parameterJudgment(responseMap,"接口返回都为空 你处理个勾");
|
ResponseUtil.parameterJudgment(responseMap, "接口返回都为空 你处理个勾");
|
||||||
this.doResponseSync(uniqueCode,responseMap);
|
this.doResponseSync(uniqueCode, responseMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>响应同步 note by youhong.ai</h2>
|
||||||
|
*
|
||||||
|
* @param uniqueCode 唯一表示
|
||||||
|
* @param responseMap 响应map
|
||||||
|
*/
|
||||||
public void doResponseSync(String uniqueCode, Map<String, Object> responseMap) {
|
public void doResponseSync(String uniqueCode, Map<String, Object> responseMap) {
|
||||||
|
// note by youhong.ai 查询配置表
|
||||||
List<ResponseConfig> responseConfigList = configMapper.queryResponseConfigByUnique(uniqueCode);
|
List<ResponseConfig> responseConfigList = configMapper.queryResponseConfigByUnique(uniqueCode);
|
||||||
logger.info(String.format("%s 相关响应配置信息==> %s",uniqueCode, JSON.toJSONString(responseConfigList)));
|
logger.info(String.format("%s 相关响应配置信息==> %s", uniqueCode, JSON.toJSONString(responseConfigList)));
|
||||||
ResponseUtil.parameterJudgment(responseConfigList,"response config is empty please check!!! ");
|
// note by youhong.ai 自定义校验
|
||||||
|
ResponseUtil.parameterJudgment(responseConfigList, "response config is empty please check!!! ");
|
||||||
Map<String, ResponseConfig> tableNameConfig;
|
Map<String, ResponseConfig> tableNameConfig;
|
||||||
try {
|
try {
|
||||||
|
// note by youhong.ai 对查询到的多个配置进行整合,以同步表表名作为key 配置作为value
|
||||||
tableNameConfig = responseConfigList.stream().collect(Collectors.toMap(ResponseConfig::getModelTableName, v -> v));
|
tableNameConfig = responseConfigList.stream().collect(Collectors.toMap(ResponseConfig::getModelTableName, v -> v));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("response config error please check!!! " + Util.getErrString(e));
|
logger.error("response config error please check!!! " + Util.getErrString(e));
|
||||||
throw new ResponseException("response config error please check!!! ");
|
throw new ResponseException("response config error please check!!! ");
|
||||||
}
|
}
|
||||||
ResponseUtil.parameterJudgment(responseMap,"接口返回都为空 你处理个勾");
|
ResponseUtil.parameterJudgment(responseMap, "接口返回都为空 你处理个勾");
|
||||||
|
// note by youhong.ai 循环同步每一个表
|
||||||
tableNameConfig.forEach((key, value) -> doResponseSync(value, responseMap));
|
tableNameConfig.forEach((key, value) -> doResponseSync(value, responseMap));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doResponseSync(ResponseConfig responseConfig, Map<String, Object> responseMap){
|
/**
|
||||||
|
* <h2>note by youhong.ai 同步数据</h2>
|
||||||
|
*
|
||||||
|
* @param responseConfig 配置表
|
||||||
|
* @param responseMap 响应结果
|
||||||
|
*/
|
||||||
|
public void doResponseSync(ResponseConfig responseConfig, Map<String, Object> responseMap) {
|
||||||
|
// note by youhong.ai 获取别名配置明细数据
|
||||||
List<ResponseConfigAlias> responseConfigAliasList = responseConfig.getResponseConfigAliasList();
|
List<ResponseConfigAlias> responseConfigAliasList = responseConfig.getResponseConfigAliasList();
|
||||||
ResponseUtil.parameterJudgment(responseConfigAliasList,"responseConfigAliasList config is empty please check!!!");
|
ResponseUtil.parameterJudgment(responseConfigAliasList, "responseConfigAliasList config is empty please check!!!");
|
||||||
|
// note by youhong.ai 获取转换值配置明细
|
||||||
List<ResponseConfigValueChange> valueChangeList = responseConfig.getValueChangeList();
|
List<ResponseConfigValueChange> valueChangeList = responseConfig.getValueChangeList();
|
||||||
ResponseUtil.parameterJudgment(valueChangeList,"valueChangeList config is empty please check!!!");
|
ResponseUtil.parameterJudgment(valueChangeList, "valueChangeList config is empty please check!!!");
|
||||||
//数据信息按是否主表分组
|
// 数据信息按是否主表分组
|
||||||
Map<Integer, List<ResponseConfigAlias>> aliasMap = responseConfigAliasList.stream().collect(Collectors.groupingBy(ResponseConfigAlias::getTableType));
|
Map<Integer, List<ResponseConfigAlias>> aliasMap = responseConfigAliasList.stream().collect(Collectors.groupingBy(ResponseConfigAlias::getTableType));
|
||||||
|
// note by youhong.ai 获取主表别名配置数据
|
||||||
List<ResponseConfigAlias> mainConfigList = aliasMap.get(ResponseConfigConstant.MAIN_TABLE);
|
List<ResponseConfigAlias> mainConfigList = aliasMap.get(ResponseConfigConstant.MAIN_TABLE);
|
||||||
|
// note by youhong.ai 按照表类型分组
|
||||||
Map<Integer, List<ResponseConfigValueChange>> mainOrDetail = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getTableType));
|
Map<Integer, List<ResponseConfigValueChange>> mainOrDetail = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getTableType));
|
||||||
|
// note by youhong.ai 获取主表值配置
|
||||||
List<ResponseConfigValueChange> mainValueChangeList = mainOrDetail.get(ResponseConfigConstant.MAIN_TABLE);
|
List<ResponseConfigValueChange> mainValueChangeList = mainOrDetail.get(ResponseConfigConstant.MAIN_TABLE);
|
||||||
TableDefinition tableDefinition;
|
TableDefinition tableDefinition;
|
||||||
if(ResponseUtil.parameterIsNotNull(mainConfigList)) {
|
// note by youhong.ai 如果有主表配置
|
||||||
|
if (ResponseUtil.parameterIsNotNull(mainConfigList)) {
|
||||||
|
// note by youhong.ai 解析json为表描述对象
|
||||||
tableDefinition = this.parsingJsonToTable(responseConfig.getModelTableName(), responseConfig, mainConfigList, mainValueChangeList, responseMap, true, this::detailTableDeal);
|
tableDefinition = this.parsingJsonToTable(responseConfig.getModelTableName(), responseConfig, mainConfigList, mainValueChangeList, responseMap, true, this::detailTableDeal);
|
||||||
}else{
|
} else {
|
||||||
Map<String,TableDefinition> detailTable = new HashMap<>();
|
// note by youhong.ai 如果没有主表配置,纯配置明细同步
|
||||||
this.detailTableDeal(responseConfig,responseMap,detailTable);
|
Map<String, TableDefinition> detailTable = new HashMap<>();
|
||||||
|
// note by youhong.ai 处理明细表
|
||||||
|
this.detailTableDeal(responseConfig, responseMap, detailTable);
|
||||||
tableDefinition = TableDefinition.builder()
|
tableDefinition = TableDefinition.builder()
|
||||||
.detailTableMap(detailTable)
|
.detailTableMap(detailTable)
|
||||||
.tableDefinitionCallback(this.tableCallback)
|
.tableDefinitionCallback(this.tableCallback)
|
||||||
.tableType(responseConfig.getTableType())
|
.tableType(responseConfig.getTableType())
|
||||||
.assignType(ResponseConfigConstant.NO_HANDLE)
|
.assignType(ResponseConfigConstant.NO_HANDLE)
|
||||||
.assignTable(responseConfig.getModelTableName()).build();
|
.assignTable(responseConfig.getModelTableName()).build();
|
||||||
}
|
}
|
||||||
//做数据处理
|
// 做数据处理
|
||||||
tableDefinition.setDefaultState(stateClassKey);
|
tableDefinition.setDefaultState(stateClassKey);
|
||||||
tableDefinition.dataProcess();
|
tableDefinition.dataProcess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <h2>note by youhon.ai 解析json为表描述对象</h2>
|
||||||
|
*
|
||||||
|
* @param tableName 表名
|
||||||
|
* @param responseConfig 响应配置
|
||||||
|
* @param responseConfigAliasList 别名配置
|
||||||
|
* @param valueChangeList 值同步配置
|
||||||
|
* @param responseMap 响应结果
|
||||||
|
* @param isMainTable 是否主表
|
||||||
|
* @param detailCallBack 明细处理回调
|
||||||
|
* @return 表描述
|
||||||
|
*/
|
||||||
public TableDefinition parsingJsonToTable(
|
public TableDefinition parsingJsonToTable(
|
||||||
String tableName,
|
String tableName,
|
||||||
ResponseConfig responseConfig,
|
ResponseConfig responseConfig,
|
||||||
|
@ -106,152 +143,157 @@ public class ResponseMappingDeal {
|
||||||
List<ResponseConfigValueChange> valueChangeList,
|
List<ResponseConfigValueChange> valueChangeList,
|
||||||
Map<String, Object> responseMap,
|
Map<String, Object> responseMap,
|
||||||
boolean isMainTable,
|
boolean isMainTable,
|
||||||
Bi3Function<ResponseConfig,Map<String, Object>,Map<String,TableDefinition>,String> detailCallBack) {
|
Bi3Function<ResponseConfig, Map<String, Object>, Map<String, TableDefinition>, String> detailCallBack) {
|
||||||
|
// note by youhong.ai 过滤出主表别名主数据配置
|
||||||
List<ResponseConfigAlias> mainAliasList = responseConfigAliasList.stream().filter(item -> item.getMainData() == ResponseConfigConstant.MAIN_DATA).collect(Collectors.toList());
|
List<ResponseConfigAlias> mainAliasList = responseConfigAliasList.stream().filter(item -> item.getMainData() == ResponseConfigConstant.MAIN_DATA).collect(Collectors.toList());
|
||||||
if(responseConfigAliasList.size() > 1) {
|
// note by youhong.ai 主表别名有且只能有一个主数据
|
||||||
|
if (responseConfigAliasList.size() > 1) {
|
||||||
throw new ResponseException("The master data cannot be multiple please check !!! ");
|
throw new ResponseException("The master data cannot be multiple please check !!! ");
|
||||||
}
|
}
|
||||||
if(responseConfigAliasList.isEmpty()){
|
if (responseConfigAliasList.isEmpty()) {
|
||||||
throw new ResponseException("The configuration is missing master data please check !!! ");
|
throw new ResponseException("The configuration is missing master data please check !!! ");
|
||||||
}
|
}
|
||||||
Map<String,Object> aliasData = new HashMap<>(responseMap);
|
Map<String, Object> aliasData = new HashMap<>(responseMap);
|
||||||
//处理别名数据
|
// 处理别名数据
|
||||||
responseConfigAliasList.forEach(item -> {
|
responseConfigAliasList.forEach(item -> {
|
||||||
String dataPath = item.getDataPath();
|
String dataPath = item.getDataPath();
|
||||||
String dataAlias = item.getDataAlias();
|
String dataAlias = item.getDataAlias();
|
||||||
|
// node by youhong.ai 通过路径获取对应的值
|
||||||
Object parsingData = Util.getValueByKeyStr(dataPath, responseMap);
|
Object parsingData = Util.getValueByKeyStr(dataPath, responseMap);
|
||||||
aliasData.put(dataAlias,parsingData);
|
// node by youhong.ai 别名->值
|
||||||
|
aliasData.put(dataAlias, parsingData);
|
||||||
});
|
});
|
||||||
//Map<Integer, List<ResponseConfigValueChange>> mainOrDetail = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getTableType));
|
// Map<Integer, List<ResponseConfigValueChange>> mainOrDetail = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getTableType));
|
||||||
//List<ResponseConfigValueChange> mainValueChangeList = mainOrDetail.get(ResponseConfigConstant.MAIN_TABLE);
|
// List<ResponseConfigValueChange> mainValueChangeList = mainOrDetail.get(ResponseConfigConstant.MAIN_TABLE);
|
||||||
ResponseUtil.parameterJudgment(valueChangeList,"main table valueChangeList config is empty please check!!!");
|
ResponseUtil.parameterJudgment(valueChangeList, "main table valueChangeList config is empty please check!!!");
|
||||||
//获取主表的主数据信息
|
// 获取主表的主数据信息
|
||||||
ResponseConfigAlias mainDataAlias = mainAliasList.get(0);
|
ResponseConfigAlias mainDataAlias = mainAliasList.get(0);
|
||||||
int tableMainOrDetail = isMainTable ? ResponseConfigConstant.MAIN_TABLE : ResponseConfigConstant.DETAIL_TABLE;
|
int tableMainOrDetail = isMainTable ? ResponseConfigConstant.MAIN_TABLE : ResponseConfigConstant.DETAIL_TABLE;
|
||||||
//构建表信息
|
// 构建表信息
|
||||||
TableDefinition tableDefinition = TableDefinition.builder().assignTable(tableName)
|
TableDefinition tableDefinition = TableDefinition.builder().assignTable(tableName)
|
||||||
.conditionScript(mainDataAlias.getConditionScript())
|
.conditionScript(mainDataAlias.getConditionScript())
|
||||||
.judgmentScript(mainDataAlias.getJudgmentScript())
|
.judgmentScript(mainDataAlias.getJudgmentScript())
|
||||||
.tableType(responseConfig.getTableType())
|
.tableType(responseConfig.getTableType())
|
||||||
.mainOrDetail(tableMainOrDetail)
|
.mainOrDetail(tableMainOrDetail)
|
||||||
.tableDefinitionCallback(this.tableCallback)
|
.tableDefinitionCallback(this.tableCallback)
|
||||||
.assignType(mainDataAlias.getAssignType()).build();
|
.assignType(mainDataAlias.getAssignType()).build();
|
||||||
String dataPath = mainDataAlias.getDataPath();
|
String dataPath = mainDataAlias.getDataPath();
|
||||||
List<RowDefinition> rowDefinitionList = new ArrayList<>();
|
List<RowDefinition> rowDefinitionList = new ArrayList<>();
|
||||||
Map<String,TableDefinition> detailTable = isMainTable ? new HashMap<>() : null;
|
Map<String, TableDefinition> detailTable = isMainTable ? new HashMap<>() : null;
|
||||||
if(mainDataAlias.getDataType() == ResponseConfigConstant.JSON_ARRAY){
|
// note by youhong.ai 如果是json数组
|
||||||
List<Map<String,Object>> mainList = (List<Map<String,Object>>) Util.getValueByKeyStr(dataPath, aliasData);
|
if (mainDataAlias.getDataType() == ResponseConfigConstant.JSON_ARRAY) {
|
||||||
|
List<Map<String, Object>> mainList = (List<Map<String, Object>>) Util.getValueByKeyStr(dataPath, aliasData);
|
||||||
for (Map<String, Object> mainItem : mainList) {
|
for (Map<String, Object> mainItem : mainList) {
|
||||||
aliasData.put(mainDataAlias.getDataAlias(),mainItem);
|
aliasData.put(mainDataAlias.getDataAlias(), mainItem);
|
||||||
//处理配置信息
|
// 处理配置信息
|
||||||
List<FieldDefinition> fieldDefinitions = parsingJsonToConfig(valueChangeList, aliasData);
|
List<FieldDefinition> fieldDefinitions = parsingJsonToConfig(valueChangeList, aliasData);
|
||||||
RowDefinition rowDefinition = this.buildRowDefinition(fieldDefinitions,tableName, mainDataAlias.getAssignType(), mainDataAlias.getConditionScript(), mainDataAlias.getJudgmentScript());
|
RowDefinition rowDefinition = this.buildRowDefinition(fieldDefinitions, tableName, mainDataAlias.getAssignType(), mainDataAlias.getConditionScript(), mainDataAlias.getJudgmentScript());
|
||||||
rowDefinition.setMainOrDetail(ResponseConfigConstant.DETAIL_TABLE);
|
rowDefinition.setMainOrDetail(ResponseConfigConstant.DETAIL_TABLE);
|
||||||
if(isMainTable) {
|
if (isMainTable) {
|
||||||
rowDefinition.setMainOrDetail(ResponseConfigConstant.MAIN_TABLE);
|
rowDefinition.setMainOrDetail(ResponseConfigConstant.MAIN_TABLE);
|
||||||
detailCallBack.apply(responseConfig,aliasData,detailTable);
|
detailCallBack.apply(responseConfig, aliasData, detailTable);
|
||||||
rowDefinition.setDetailTableMap(detailTable);
|
rowDefinition.setDetailTableMap(detailTable);
|
||||||
}
|
}
|
||||||
rowDefinitionList.add(rowDefinition);
|
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);
|
aliasData.put(mainDataAlias.getDataAlias(), jsonObj);
|
||||||
//处理配置信息
|
// 处理配置信息
|
||||||
List<FieldDefinition> fieldDefinitions = parsingJsonToConfig(valueChangeList, aliasData);
|
List<FieldDefinition> fieldDefinitions = parsingJsonToConfig(valueChangeList, aliasData);
|
||||||
RowDefinition rowDefinition = this.buildRowDefinition(fieldDefinitions,tableName,mainDataAlias.getAssignType(), mainDataAlias.getConditionScript(), mainDataAlias.getJudgmentScript());
|
RowDefinition rowDefinition = this.buildRowDefinition(fieldDefinitions, tableName, mainDataAlias.getAssignType(), mainDataAlias.getConditionScript(), mainDataAlias.getJudgmentScript());
|
||||||
rowDefinition.setMainOrDetail(ResponseConfigConstant.DETAIL_TABLE);
|
rowDefinition.setMainOrDetail(ResponseConfigConstant.DETAIL_TABLE);
|
||||||
if(isMainTable) {
|
if (isMainTable) {
|
||||||
rowDefinition.setMainOrDetail(ResponseConfigConstant.MAIN_TABLE);
|
rowDefinition.setMainOrDetail(ResponseConfigConstant.MAIN_TABLE);
|
||||||
detailCallBack.apply(responseConfig,aliasData,detailTable);
|
detailCallBack.apply(responseConfig, aliasData, detailTable);
|
||||||
rowDefinition.setDetailTableMap(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 !!!");
|
||||||
}
|
}
|
||||||
//设置表的行信息
|
// 设置表的行信息
|
||||||
tableDefinition.setRowDefinitionList(rowDefinitionList);
|
tableDefinition.setRowDefinitionList(rowDefinitionList);
|
||||||
return tableDefinition;
|
return tableDefinition;
|
||||||
}
|
}
|
||||||
|
|
||||||
private RowDefinition buildRowDefinition(List<FieldDefinition> fieldDefinitionList,
|
private RowDefinition buildRowDefinition(List<FieldDefinition> fieldDefinitionList,
|
||||||
String tableName,
|
String tableName,
|
||||||
int assignType,
|
int assignType,
|
||||||
String conditionScript,
|
String conditionScript,
|
||||||
String judgmentScript){
|
String judgmentScript) {
|
||||||
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 -> {
|
fieldDefinitionList.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());
|
||||||
}else {
|
} else {
|
||||||
updateParam.put(fieldDefinition.getFieldName(),fieldDefinition.getFieldValue());
|
updateParam.put(fieldDefinition.getFieldName(), fieldDefinition.getFieldValue());
|
||||||
wherePram.put(fieldDefinition.getFieldName(),fieldDefinition.getFieldValue());
|
wherePram.put(fieldDefinition.getFieldName(), fieldDefinition.getFieldValue());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return RowDefinition.builder().assignType(assignType)
|
return RowDefinition.builder().assignType(assignType)
|
||||||
.conditionScript(conditionScript)
|
.conditionScript(conditionScript)
|
||||||
.updateParam(updateParam)
|
.updateParam(updateParam)
|
||||||
.assignTable(tableName)
|
.assignTable(tableName)
|
||||||
.whereParam(wherePram)
|
.whereParam(wherePram)
|
||||||
.fieldDefinitionList(fieldDefinitionList)
|
.fieldDefinitionList(fieldDefinitionList)
|
||||||
.rowDefinitionCallback(this.rowCallback)
|
.rowDefinitionCallback(this.rowCallback)
|
||||||
.judgmentScript(judgmentScript).build();
|
.judgmentScript(judgmentScript).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
//数据信息按是否主表分组
|
// 数据信息按是否主表分组
|
||||||
Map<Integer, List<ResponseConfigAlias>> aliasMap = responseConfigAliasList.stream().collect(Collectors.groupingBy(ResponseConfigAlias::getTableType));
|
Map<Integer, List<ResponseConfigAlias>> aliasMap = responseConfigAliasList.stream().collect(Collectors.groupingBy(ResponseConfigAlias::getTableType));
|
||||||
List<ResponseConfigAlias> detailAliases = aliasMap.get(ResponseConfigConstant.DETAIL_TABLE);
|
List<ResponseConfigAlias> detailAliases = aliasMap.get(ResponseConfigConstant.DETAIL_TABLE);
|
||||||
//没有明细相关配置不处理
|
// 没有明细相关配置不处理
|
||||||
if(ResponseUtil.parameterIsNull(detailAliases)){
|
if (ResponseUtil.parameterIsNull(detailAliases)) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
Map<String, List<ResponseConfigAlias>> detailAliasMap = detailAliases.stream().collect(Collectors.groupingBy(ResponseConfigAlias::getDetailTableName));
|
Map<String, List<ResponseConfigAlias>> detailAliasMap = detailAliases.stream().collect(Collectors.groupingBy(ResponseConfigAlias::getDetailTableName));
|
||||||
Map<String, List<ResponseConfigValueChange>> detailValueChangeMap = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getAssignTable));
|
Map<String, List<ResponseConfigValueChange>> detailValueChangeMap = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getAssignTable));
|
||||||
detailAliasMap.forEach((key,value) ->{
|
detailAliasMap.forEach((key, value) -> {
|
||||||
List<ResponseConfigValueChange> detailValueChangeList = detailValueChangeMap.get(key);
|
List<ResponseConfigValueChange> detailValueChangeList = detailValueChangeMap.get(key);
|
||||||
TableDefinition tableDefinition = parsingJsonToTable(key, responseConfig, value, detailValueChangeList, param, false, this::detailTableDeal);
|
TableDefinition tableDefinition = parsingJsonToTable(key, responseConfig, value, detailValueChangeList, param, false, this::detailTableDeal);
|
||||||
detailTable.put(key,tableDefinition);
|
detailTable.put(key, tableDefinition);
|
||||||
});
|
});
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将json参数解析成对应的字段描述信息
|
* 将json参数解析成对应的字段描述信息
|
||||||
|
*
|
||||||
* @param responseConfigValueChangeList 配置信息
|
* @param responseConfigValueChangeList 配置信息
|
||||||
* @param parsingData json信息
|
* @param parsingData json信息
|
||||||
* @return 字段描述信息
|
* @return 字段描述信息
|
||||||
*/
|
*/
|
||||||
public List<FieldDefinition> parsingJsonToConfig(List<ResponseConfigValueChange> responseConfigValueChangeList,
|
public List<FieldDefinition> parsingJsonToConfig(List<ResponseConfigValueChange> responseConfigValueChangeList,
|
||||||
Map<String,Object> parsingData){
|
Map<String, Object> parsingData) {
|
||||||
Map<String,Object> param = new HashMap<>();
|
Map<String, Object> param = new HashMap<>();
|
||||||
responseConfigValueChangeList.forEach(item ->{
|
responseConfigValueChangeList.forEach(item -> {
|
||||||
Object value = item.getDataChange() == ResponseConfigConstant.DEFAULT_VALUE
|
Object value = item.getDataChange() == ResponseConfigConstant.DEFAULT_VALUE
|
||||||
? null
|
? null
|
||||||
: Util.getValueByKeyStr(Util.null2String(item.getValuePath()), parsingData);
|
: Util.getValueByKeyStr(Util.null2String(item.getValuePath()), parsingData);
|
||||||
item.setJsonData(value);
|
item.setJsonData(value);
|
||||||
param.put(item.getAssignFieldName(),value);
|
param.put(item.getAssignFieldName(), value);
|
||||||
});
|
});
|
||||||
return responseConfigValueChangeList.stream().map(item ->{
|
return responseConfigValueChangeList.stream().map(item -> {
|
||||||
BiFunction<ResponseConfigValueChange, Map<String, Object>, String> dataChangeFunction = DataChangeProcess.MODE_METHOD_MAP.get(item.getDataChange());
|
BiFunction<ResponseConfigValueChange, Map<String, Object>, String> dataChangeFunction = DataChangeProcess.MODE_METHOD_MAP.get(item.getDataChange());
|
||||||
ResponseUtil.parameterJudgment(dataChangeFunction,"The corresponding data conversion mode processing method is not found !!!");
|
ResponseUtil.parameterJudgment(dataChangeFunction, "The corresponding data conversion mode processing method is not found !!!");
|
||||||
dataChangeFunction.apply(item,param);
|
dataChangeFunction.apply(item, param);
|
||||||
Function<Object, Object> typeChangeFunction = TypeChangeProcess.MODE_METHOD_MAP.get(item.getTypeChange());
|
Function<Object, Object> typeChangeFunction = TypeChangeProcess.MODE_METHOD_MAP.get(item.getTypeChange());
|
||||||
ResponseUtil.parameterJudgment(typeChangeFunction,"The corresponding type conversion method could not be found !!!");
|
ResponseUtil.parameterJudgment(typeChangeFunction, "The corresponding type conversion method could not be found !!!");
|
||||||
Object targetValue = typeChangeFunction.apply(item.getJsonData());
|
Object targetValue = typeChangeFunction.apply(item.getJsonData());
|
||||||
return FieldDefinition.builder().fieldType(item.getFieldType())
|
return FieldDefinition.builder().fieldType(item.getFieldType())
|
||||||
.tableType(item.getTableType())
|
.tableType(item.getTableType())
|
||||||
.tableName(item.getAssignTable())
|
.tableName(item.getAssignTable())
|
||||||
.fieldName(item.getAssignFieldName())
|
.fieldName(item.getAssignFieldName())
|
||||||
.fieldDefinitionCallback(fieldDefinitionCallback)
|
.fieldDefinitionCallback(fieldDefinitionCallback)
|
||||||
.fieldValue(targetValue).build();
|
.fieldValue(targetValue).build();
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue