添加注释

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

@ -52,41 +52,66 @@ public class ResponseMappingDeal {
public void doResponseSync(String uniqueCode, ResponeVo responeVo) {
Map<String, Object> responseMap = responeVo.getResponseMap();
ResponseUtil.parameterJudgment(responseMap,"接口返回都为空 你处理个勾");
this.doResponseSync(uniqueCode,responseMap);
ResponseUtil.parameterJudgment(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) {
// note by youhong.ai 查询配置表
List<ResponseConfig> responseConfigList = configMapper.queryResponseConfigByUnique(uniqueCode);
logger.info(String.format("%s 相关响应配置信息==> %s",uniqueCode, JSON.toJSONString(responseConfigList)));
ResponseUtil.parameterJudgment(responseConfigList,"response config is empty please check!!! ");
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,"接口返回都为空 你处理个勾");
ResponseUtil.parameterJudgment(responseMap, "接口返回都为空 你处理个勾");
// note by youhong.ai 循环同步每一个表
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();
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();
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));
// 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;
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);
}else{
Map<String,TableDefinition> detailTable = new HashMap<>();
this.detailTableDeal(responseConfig,responseMap,detailTable);
} 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)
.tableDefinitionCallback(this.tableCallback)
@ -94,11 +119,23 @@ public class ResponseMappingDeal {
.assignType(ResponseConfigConstant.NO_HANDLE)
.assignTable(responseConfig.getModelTableName()).build();
}
//做数据处理
// 做数据处理
tableDefinition.setDefaultState(stateClassKey);
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,
@ -106,30 +143,33 @@ public class ResponseMappingDeal {
List<ResponseConfigValueChange> valueChangeList,
Map<String, Object> responseMap,
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());
if(responseConfigAliasList.size() > 1) {
// note by youhong.ai 主表别名有且只能有一个主数据
if (responseConfigAliasList.size() > 1) {
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 !!! ");
}
Map<String,Object> aliasData = new HashMap<>(responseMap);
//处理别名数据
Map<String, Object> aliasData = new HashMap<>(responseMap);
// 处理别名数据
responseConfigAliasList.forEach(item -> {
String dataPath = item.getDataPath();
String dataAlias = item.getDataAlias();
// node by youhong.ai 通过路径获取对应的值
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));
//List<ResponseConfigValueChange> mainValueChangeList = mainOrDetail.get(ResponseConfigConstant.MAIN_TABLE);
ResponseUtil.parameterJudgment(valueChangeList,"main table valueChangeList config is empty please check!!!");
//获取主表的主数据信息
// 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!!!");
// 获取主表的主数据信息
ResponseConfigAlias mainDataAlias = mainAliasList.get(0);
int tableMainOrDetail = isMainTable ? ResponseConfigConstant.MAIN_TABLE : ResponseConfigConstant.DETAIL_TABLE;
//构建表信息
// 构建表信息
TableDefinition tableDefinition = TableDefinition.builder().assignTable(tableName)
.conditionScript(mainDataAlias.getConditionScript())
.judgmentScript(mainDataAlias.getJudgmentScript())
@ -139,39 +179,40 @@ public class ResponseMappingDeal {
.assignType(mainDataAlias.getAssignType()).build();
String dataPath = mainDataAlias.getDataPath();
List<RowDefinition> rowDefinitionList = new ArrayList<>();
Map<String,TableDefinition> detailTable = isMainTable ? new HashMap<>() : null;
if(mainDataAlias.getDataType() == ResponseConfigConstant.JSON_ARRAY){
List<Map<String,Object>> mainList = (List<Map<String,Object>>) Util.getValueByKeyStr(dataPath, aliasData);
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) {
aliasData.put(mainDataAlias.getDataAlias(),mainItem);
//处理配置信息
aliasData.put(mainDataAlias.getDataAlias(), mainItem);
// 处理配置信息
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);
if(isMainTable) {
if (isMainTable) {
rowDefinition.setMainOrDetail(ResponseConfigConstant.MAIN_TABLE);
detailCallBack.apply(responseConfig,aliasData,detailTable);
detailCallBack.apply(responseConfig, aliasData, detailTable);
rowDefinition.setDetailTableMap(detailTable);
}
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);
//处理配置信息
} 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 rowDefinition = this.buildRowDefinition(fieldDefinitions, tableName, mainDataAlias.getAssignType(), mainDataAlias.getConditionScript(), mainDataAlias.getJudgmentScript());
rowDefinition.setMainOrDetail(ResponseConfigConstant.DETAIL_TABLE);
if(isMainTable) {
if (isMainTable) {
rowDefinition.setMainOrDetail(ResponseConfigConstant.MAIN_TABLE);
detailCallBack.apply(responseConfig,aliasData,detailTable);
detailCallBack.apply(responseConfig, aliasData, detailTable);
rowDefinition.setDetailTableMap(detailTable);
}
rowDefinitionList.add(rowDefinition);
}else {
} else {
throw new ResponseException("please set the primary data type !!!");
}
//设置表的行信息
// 设置表的行信息
tableDefinition.setRowDefinitionList(rowDefinitionList);
return tableDefinition;
}
@ -180,16 +221,16 @@ public class ResponseMappingDeal {
String tableName,
int assignType,
String conditionScript,
String judgmentScript){
Map<String,Object> updateParam = new HashMap<>();
Map<String,Object> wherePram = new HashMap<>();
String judgmentScript) {
Map<String, Object> updateParam = new HashMap<>();
Map<String, Object> wherePram = new HashMap<>();
fieldDefinitionList.forEach(fieldDefinition -> {
int fieldType = fieldDefinition.getFieldType();
if(fieldType == ResponseConfigConstant.WHERE_FIELD){
wherePram.put(fieldDefinition.getFieldName(),fieldDefinition.getFieldValue());
}else {
updateParam.put(fieldDefinition.getFieldName(),fieldDefinition.getFieldValue());
wherePram.put(fieldDefinition.getFieldName(),fieldDefinition.getFieldValue());
if (fieldType == ResponseConfigConstant.WHERE_FIELD) {
wherePram.put(fieldDefinition.getFieldName(), fieldDefinition.getFieldValue());
} else {
updateParam.put(fieldDefinition.getFieldName(), fieldDefinition.getFieldValue());
wherePram.put(fieldDefinition.getFieldName(), fieldDefinition.getFieldValue());
}
});
return RowDefinition.builder().assignType(assignType)
@ -202,48 +243,49 @@ public class ResponseMappingDeal {
.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<ResponseConfigValueChange> valueChangeList = responseConfig.getValueChangeList();
//数据信息按是否主表分组
// 数据信息按是否主表分组
Map<Integer, List<ResponseConfigAlias>> aliasMap = responseConfigAliasList.stream().collect(Collectors.groupingBy(ResponseConfigAlias::getTableType));
List<ResponseConfigAlias> detailAliases = aliasMap.get(ResponseConfigConstant.DETAIL_TABLE);
//没有明细相关配置不处理
if(ResponseUtil.parameterIsNull(detailAliases)){
// 没有明细相关配置不处理
if (ResponseUtil.parameterIsNull(detailAliases)) {
return "";
}
Map<String, List<ResponseConfigAlias>> detailAliasMap = detailAliases.stream().collect(Collectors.groupingBy(ResponseConfigAlias::getDetailTableName));
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);
TableDefinition tableDefinition = parsingJsonToTable(key, responseConfig, value, detailValueChangeList, param, false, this::detailTableDeal);
detailTable.put(key,tableDefinition);
detailTable.put(key, tableDefinition);
});
return "";
}
/**
* json
*
* @param responseConfigValueChangeList
* @param parsingData json
* @return
*/
public List<FieldDefinition> parsingJsonToConfig(List<ResponseConfigValueChange> responseConfigValueChangeList,
Map<String,Object> parsingData){
Map<String,Object> param = new HashMap<>();
responseConfigValueChangeList.forEach(item ->{
Map<String, Object> parsingData) {
Map<String, Object> param = new HashMap<>();
responseConfigValueChangeList.forEach(item -> {
Object value = item.getDataChange() == ResponseConfigConstant.DEFAULT_VALUE
? null
: Util.getValueByKeyStr(Util.null2String(item.getValuePath()), parsingData);
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());
ResponseUtil.parameterJudgment(dataChangeFunction,"The corresponding data conversion mode processing method is not found !!!");
dataChangeFunction.apply(item,param);
ResponseUtil.parameterJudgment(dataChangeFunction, "The corresponding data conversion mode processing method is not found !!!");
dataChangeFunction.apply(item, param);
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());
return FieldDefinition.builder().fieldType(item.getFieldType())
.tableType(item.getTableType())