|
|
@ -57,60 +57,60 @@ public class ResponseMappingDeal {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* <h2>响应同步 note by youhong.ai</h2>
|
|
|
|
* <h2>响应同步 </h2>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param uniqueCode 唯一表示
|
|
|
|
* @param uniqueCode 唯一表示
|
|
|
|
* @param responseMap 响应map
|
|
|
|
* @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)));
|
|
|
|
// note by youhong.ai 自定义校验
|
|
|
|
// 自定义校验
|
|
|
|
ResponseUtil.parameterJudgment(responseConfigList, "response config is empty please check!!! ");
|
|
|
|
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
|
|
|
|
// 对查询到的多个配置进行整合,以同步表表名作为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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* <h2>note by youhong.ai 同步数据</h2>
|
|
|
|
* <h2> 同步数据</h2>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param responseConfig 配置表
|
|
|
|
* @param responseConfig 配置表
|
|
|
|
* @param responseMap 响应结果
|
|
|
|
* @param responseMap 响应结果
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void doResponseSync(ResponseConfig responseConfig, Map<String, Object> 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;
|
|
|
|
// note by youhong.ai 如果有主表配置
|
|
|
|
// 如果有主表配置
|
|
|
|
if (ResponseUtil.parameterIsNotNull(mainConfigList)) {
|
|
|
|
if (ResponseUtil.parameterIsNotNull(mainConfigList)) {
|
|
|
|
// note by youhong.ai 解析json为表描述对象
|
|
|
|
// 解析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 {
|
|
|
|
// note by youhong.ai 如果没有主表配置,纯配置明细同步
|
|
|
|
// 如果没有主表配置,纯配置明细同步
|
|
|
|
Map<String, TableDefinition> detailTable = new HashMap<>();
|
|
|
|
Map<String, TableDefinition> detailTable = new HashMap<>();
|
|
|
|
// note by youhong.ai 处理明细表
|
|
|
|
// 处理明细表
|
|
|
|
this.detailTableDeal(responseConfig, responseMap, detailTable);
|
|
|
|
this.detailTableDeal(responseConfig, responseMap, detailTable);
|
|
|
|
tableDefinition = TableDefinition.builder()
|
|
|
|
tableDefinition = TableDefinition.builder()
|
|
|
|
.detailTableMap(detailTable)
|
|
|
|
.detailTableMap(detailTable)
|
|
|
@ -123,9 +123,10 @@ public class ResponseMappingDeal {
|
|
|
|
tableDefinition.setDefaultState(stateClassKey);
|
|
|
|
tableDefinition.setDefaultState(stateClassKey);
|
|
|
|
tableDefinition.dataProcess();
|
|
|
|
tableDefinition.dataProcess();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* <h2>note by youhon.ai 解析json为表描述对象</h2>
|
|
|
|
* <h2>note by youhong.ai 解析json为表描述对象</h2>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param tableName 表名
|
|
|
|
* @param tableName 表名
|
|
|
|
* @param responseConfig 响应配置
|
|
|
|
* @param responseConfig 响应配置
|
|
|
@ -144,9 +145,9 @@ public class ResponseMappingDeal {
|
|
|
|
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());
|
|
|
|
// note by youhong.ai 主表别名有且只能有一个主数据
|
|
|
|
// 主表别名有且只能有一个主数据
|
|
|
|
if (responseConfigAliasList.size() > 1) {
|
|
|
|
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 !!! ");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -158,13 +159,11 @@ public class ResponseMappingDeal {
|
|
|
|
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 = "rootNode".equalsIgnoreCase(dataPath) ? responseMap : Util.getValueByKeyStr(dataPath, responseMap);
|
|
|
|
// node by youhong.ai 别名->值
|
|
|
|
// 别名->值
|
|
|
|
aliasData.put(dataAlias, parsingData);
|
|
|
|
aliasData.put(dataAlias, parsingData);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
// Map<Integer, List<ResponseConfigValueChange>> mainOrDetail = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getTableType));
|
|
|
|
|
|
|
|
// 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);
|
|
|
@ -180,7 +179,7 @@ public class ResponseMappingDeal {
|
|
|
|
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;
|
|
|
|
// note by youhong.ai 如果是json数组
|
|
|
|
// 如果是json数组
|
|
|
|
if (mainDataAlias.getDataType() == ResponseConfigConstant.JSON_ARRAY) {
|
|
|
|
if (mainDataAlias.getDataType() == ResponseConfigConstant.JSON_ARRAY) {
|
|
|
|
List<Map<String, Object>> mainList = (List<Map<String, Object>>) Util.getValueByKeyStr(dataPath, aliasData);
|
|
|
|
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) {
|
|
|
|