添加注释

dev
youhong.ai 2023-07-15 09:20:28 +08:00
parent b23aadb572
commit e3e696b165
1 changed files with 148 additions and 106 deletions

View File

@ -56,36 +56,61 @@ public class ResponseMappingDeal {
this.doResponseSync(uniqueCode, responseMap);
}
/**
* <h2> note by youhong.ai</h2>
*
* @param uniqueCode
* @param responseMap map
*/
public void doResponseSync(String uniqueCode, Map<String, Object> responseMap) {
// note by youhong.ai 查询配置表
List<ResponseConfig> responseConfigList = configMapper.queryResponseConfigByUnique(uniqueCode);
logger.info(String.format("%s 相关响应配置信息==> %s", uniqueCode, JSON.toJSONString(responseConfigList)));
// note by youhong.ai 自定义校验
ResponseUtil.parameterJudgment(responseConfigList, "response config is empty please check!!! ");
Map<String, ResponseConfig> tableNameConfig;
try {
// note by youhong.ai 对查询到的多个配置进行整合以同步表表名作为key 配置作为value
tableNameConfig = responseConfigList.stream().collect(Collectors.toMap(ResponseConfig::getModelTableName, v -> v));
} catch (Exception e) {
logger.error("response config error please check!!! " + Util.getErrString(e));
throw new ResponseException("response config error please check!!! ");
}
ResponseUtil.parameterJudgment(responseMap, "接口返回都为空 你处理个勾");
// note by youhong.ai 循环同步每一个表
tableNameConfig.forEach((key, value) -> doResponseSync(value, 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();
ResponseUtil.parameterJudgment(responseConfigAliasList, "responseConfigAliasList config is empty please check!!!");
// note by youhong.ai 获取转换值配置明细
List<ResponseConfigValueChange> valueChangeList = responseConfig.getValueChangeList();
ResponseUtil.parameterJudgment(valueChangeList, "valueChangeList config is empty please check!!!");
// 数据信息按是否主表分组
Map<Integer, List<ResponseConfigAlias>> aliasMap = responseConfigAliasList.stream().collect(Collectors.groupingBy(ResponseConfigAlias::getTableType));
// note by youhong.ai 获取主表别名配置数据
List<ResponseConfigAlias> mainConfigList = aliasMap.get(ResponseConfigConstant.MAIN_TABLE);
// note by youhong.ai 按照表类型分组
Map<Integer, List<ResponseConfigValueChange>> mainOrDetail = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getTableType));
// note by youhong.ai 获取主表值配置
List<ResponseConfigValueChange> mainValueChangeList = mainOrDetail.get(ResponseConfigConstant.MAIN_TABLE);
TableDefinition tableDefinition;
// 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);
} else {
// note by youhong.ai 如果没有主表配置,纯配置明细同步
Map<String, TableDefinition> detailTable = new HashMap<>();
// note by youhong.ai 处理明细表
this.detailTableDeal(responseConfig, responseMap, detailTable);
tableDefinition = TableDefinition.builder()
.detailTableMap(detailTable)
@ -99,6 +124,18 @@ public class ResponseMappingDeal {
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(
String tableName,
ResponseConfig responseConfig,
@ -107,8 +144,9 @@ public class ResponseMappingDeal {
Map<String, Object> responseMap,
boolean isMainTable,
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());
// note by youhong.ai 主表别名有且只能有一个主数据
if (responseConfigAliasList.size() > 1) {
throw new ResponseException("The master data cannot be multiple please check !!! ");
}
@ -120,7 +158,9 @@ public class ResponseMappingDeal {
responseConfigAliasList.forEach(item -> {
String dataPath = item.getDataPath();
String dataAlias = item.getDataAlias();
// node by youhong.ai 通过路径获取对应的值
Object parsingData = Util.getValueByKeyStr(dataPath, responseMap);
// node by youhong.ai 别名->值
aliasData.put(dataAlias, parsingData);
});
// Map<Integer, List<ResponseConfigValueChange>> mainOrDetail = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getTableType));
@ -140,6 +180,7 @@ public class ResponseMappingDeal {
String dataPath = mainDataAlias.getDataPath();
List<RowDefinition> rowDefinitionList = new ArrayList<>();
Map<String, TableDefinition> detailTable = isMainTable ? new HashMap<>() : null;
// note by youhong.ai 如果是json数组
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) {
@ -224,6 +265,7 @@ public class ResponseMappingDeal {
/**
* json
*
* @param responseConfigValueChangeList
* @param parsingData json
* @return