dev
parent
a6b7892dd6
commit
99ee2d2245
|
@ -1,18 +1,19 @@
|
||||||
package bokang.xiao.response_deal;
|
package bokang.xiao.response_deal;
|
||||||
|
|
||||||
|
import aiyh.utils.ScriptUtil;
|
||||||
import aiyh.utils.Util;
|
import aiyh.utils.Util;
|
||||||
import aiyh.utils.excention.CustomerException;
|
import aiyh.utils.excention.CustomerException;
|
||||||
import aiyh.utils.httpUtil.ResponeVo;
|
import aiyh.utils.httpUtil.ResponeVo;
|
||||||
import bokang.xiao.entity.FieldDefinition;
|
import aiyh.utils.tool.cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import aiyh.utils.tool.cn.hutool.core.util.StrUtil;
|
||||||
import bokang.xiao.exception.ResponseException;
|
import bokang.xiao.exception.ResponseException;
|
||||||
import bokang.xiao.response_deal.entity.ResponseConfig;
|
import bokang.xiao.response_deal.entity.ResponseConfig;
|
||||||
|
import bokang.xiao.response_deal.entity.ResponseConfigAlias;
|
||||||
import bokang.xiao.response_deal.entity.ResponseConfigValueChange;
|
import bokang.xiao.response_deal.entity.ResponseConfigValueChange;
|
||||||
import bokang.xiao.response_deal.mapper.ConfigMapper;
|
import bokang.xiao.response_deal.mapper.ConfigMapper;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,70 +24,118 @@ import java.util.stream.Collectors;
|
||||||
**/
|
**/
|
||||||
public class ResponseMappingDeal {
|
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);
|
||||||
|
|
||||||
|
|
||||||
public void getConfig(String uniqueCode,ResponeVo responeVo){
|
public void parseConfig(String uniqueCode, ResponeVo responeVo) {
|
||||||
List<ResponseConfig> responseConfigList = configMapper.queryResponseConfigByUnique(uniqueCode);
|
if (responeVo.getCode() != 200) {
|
||||||
if(Objects.isNull(responseConfigList) || responseConfigList.isEmpty()){
|
throw new CustomerException("你妈没成功");
|
||||||
throw new ResponseException("response config is empty please check!!! ");
|
}
|
||||||
}
|
|
||||||
Map<String, ResponseConfig> tableNameConfig;
|
|
||||||
try {
|
|
||||||
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!!! ");
|
|
||||||
}
|
|
||||||
tableNameConfig.entrySet().stream().forEach(item ->{
|
|
||||||
dealConfig(item.getValue(),responeVo);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void dealConfig(ResponseConfig responseConfig, ResponeVo responeVo){
|
List<ResponseConfig> responseConfigs = configMapper.queryResponseConfigByUnique(uniqueCode);
|
||||||
List<ResponseConfigValueChange> valueChangeList = responseConfig.getValueChangeList();
|
|
||||||
if(Objects.isNull(valueChangeList) || valueChangeList.isEmpty()){
|
if (CollectionUtil.isEmpty(responseConfigs)) {
|
||||||
throw new ResponseException("valueChangeList config is empty please check!!!");
|
throw new CustomerException("sb");
|
||||||
}
|
}
|
||||||
Map<Integer, List<ResponseConfigValueChange>> tableTypeMap = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getTableType));
|
for (ResponseConfig responseConfig : responseConfigs) {
|
||||||
List<ResponseConfigValueChange> mainConfig = tableTypeMap.get(0);
|
parseConfigOne(responseConfig, responeVo);
|
||||||
Map<String, List<ResponseConfigValueChange>> collect = mainConfig.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getAssignTable));
|
}
|
||||||
if(collect.size() > 1){
|
}
|
||||||
throw new ResponseException("The primary table cannot have details please check!!! ");
|
|
||||||
}
|
private void parseConfigOne(ResponseConfig responseConfig, ResponeVo responeVo) {
|
||||||
//Map<String, Object> responseMap = responeVo.getResponseMap();
|
List<ResponseConfigAlias> responseConfigAliasList = responseConfig.getResponseConfigAliasList();
|
||||||
//Map<Util.ValueOrList,List<FieldDefinition>> mainFieldMap = new HashMap<>();
|
String successExp = responseConfig.getSuccessExp();
|
||||||
//for (ResponseConfigValueChange responseConfigValueChange : mainConfig) {
|
Map<String, Object> responseMap = responeVo.getResponseMap();
|
||||||
// String valuePath = responseConfigValueChange.getValuePath();
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
||||||
// Util.ValueOrList valueOrListByKeyStr = Util.getValueOrListByKeyStr(valuePath, responseMap);
|
if (CollectionUtil.isEmpty(responseMap)) {
|
||||||
// if(valueOrListByKeyStr.isArray() && !mainFieldMap.isEmpty() && !mainFieldMap.containsKey(valueOrListByKeyStr)){
|
// 他是一个list,尝试获取一下
|
||||||
// throw new ResponseException("The primary table cannot contain multiple List data please check!!!");
|
List<Map> result = responeVo.getResult();
|
||||||
// }else if(valueOrListByKeyStr.isArray() && mainFieldMap.isEmpty()){
|
if (CollectionUtil.isEmpty(result)) {
|
||||||
// List<Map<String, Object>> listValue = (List<Map<String, Object>>) valueOrListByKeyStr.getValue();
|
throw new CustomerException("没有响应结果,你同步个J8");
|
||||||
// List<FieldDefinition> fieldDefinitions = listValue.stream().map(item -> FieldDefinition.builder().build()).collect(Collectors.toList());
|
} else {
|
||||||
// mainFieldMap.put(valueOrListByKeyStr,fieldDefinitions);
|
for (Map map : result) {
|
||||||
// }else if(valueOrListByKeyStr.isArray()){
|
Map<String, Object> tempMap = new HashMap<>();
|
||||||
// List<FieldDefinition> fieldDefinitions = mainFieldMap.get(valueOrListByKeyStr);
|
for (Object entry : map.entrySet()) {
|
||||||
// }
|
|
||||||
//}
|
}
|
||||||
//mainConfig.stream().map(item ->{
|
resultList.add(tempMap);
|
||||||
//
|
}
|
||||||
//})
|
}
|
||||||
List<ResponseConfigValueChange> detail = tableTypeMap.get(1);
|
} else {
|
||||||
Map<String, List<ResponseConfigValueChange>> tableValueMap = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getAssignTable));
|
resultList.add(responseMap);
|
||||||
|
}
|
||||||
|
if (StrUtil.isNotBlank(successExp)) {
|
||||||
|
for (Map<String, Object> map : resultList) {
|
||||||
|
boolean flag = (boolean) ScriptUtil.invokeScript(successExp, map);
|
||||||
|
if (!flag) {
|
||||||
|
throw new CustomerException("失败了!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void responseToEntity(ResponseConfigValueChange responseConfigValueChange,Map<String,Object> param){
|
|
||||||
String valuePath = responseConfigValueChange.getValuePath();
|
|
||||||
Util.ValueOrList valueOrListByKeyStr = Util.getValueOrListByKeyStr(valuePath, param);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
public void getConfig(String uniqueCode, ResponeVo responeVo) {
|
||||||
|
List<ResponseConfig> responseConfigList = configMapper.queryResponseConfigByUnique(uniqueCode);
|
||||||
|
if (Objects.isNull(responseConfigList) || responseConfigList.isEmpty()) {
|
||||||
|
throw new ResponseException("response config is empty please check!!! ");
|
||||||
|
}
|
||||||
|
Map<String, ResponseConfig> tableNameConfig;
|
||||||
|
try {
|
||||||
|
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!!! ");
|
||||||
|
}
|
||||||
|
tableNameConfig.entrySet().stream().forEach(item -> {
|
||||||
|
dealConfig(item.getValue(), responeVo);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dealConfig(ResponseConfig responseConfig, ResponeVo responeVo) {
|
||||||
|
List<ResponseConfigValueChange> valueChangeList = responseConfig.getValueChangeList();
|
||||||
|
if (Objects.isNull(valueChangeList) || valueChangeList.isEmpty()) {
|
||||||
|
throw new ResponseException("valueChangeList config is empty please check!!!");
|
||||||
|
}
|
||||||
|
Map<Integer, List<ResponseConfigValueChange>> tableTypeMap = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getTableType));
|
||||||
|
List<ResponseConfigValueChange> mainConfig = tableTypeMap.get(0);
|
||||||
|
Map<String, List<ResponseConfigValueChange>> collect = mainConfig.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getAssignTable));
|
||||||
|
if (collect.size() > 1) {
|
||||||
|
throw new ResponseException("The primary table cannot have details please check!!! ");
|
||||||
|
}
|
||||||
|
// Map<String, Object> responseMap = responeVo.getResponseMap();
|
||||||
|
// Map<Util.ValueOrList,List<FieldDefinition>> mainFieldMap = new HashMap<>();
|
||||||
|
// for (ResponseConfigValueChange responseConfigValueChange : mainConfig) {
|
||||||
|
// String valuePath = responseConfigValueChange.getValuePath();
|
||||||
|
// Util.ValueOrList valueOrListByKeyStr = Util.getValueOrListByKeyStr(valuePath, responseMap);
|
||||||
|
// if(valueOrListByKeyStr.isArray() && !mainFieldMap.isEmpty() && !mainFieldMap.containsKey(valueOrListByKeyStr)){
|
||||||
|
// throw new ResponseException("The primary table cannot contain multiple List data please check!!!");
|
||||||
|
// }else if(valueOrListByKeyStr.isArray() && mainFieldMap.isEmpty()){
|
||||||
|
// List<Map<String, Object>> listValue = (List<Map<String, Object>>) valueOrListByKeyStr.getValue();
|
||||||
|
// List<FieldDefinition> fieldDefinitions = listValue.stream().map(item -> FieldDefinition.builder().build()).collect(Collectors.toList());
|
||||||
|
// mainFieldMap.put(valueOrListByKeyStr,fieldDefinitions);
|
||||||
|
// }else if(valueOrListByKeyStr.isArray()){
|
||||||
|
// List<FieldDefinition> fieldDefinitions = mainFieldMap.get(valueOrListByKeyStr);
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
// mainConfig.stream().map(item ->{
|
||||||
|
//
|
||||||
|
//})
|
||||||
|
List<ResponseConfigValueChange> detail = tableTypeMap.get(1);
|
||||||
|
Map<String, List<ResponseConfigValueChange>> tableValueMap = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getAssignTable));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void responseToEntity(ResponseConfigValueChange responseConfigValueChange, Map<String, Object> param) {
|
||||||
|
String valuePath = responseConfigValueChange.getValuePath();
|
||||||
|
Util.ValueOrList valueOrListByKeyStr = Util.getValueOrListByKeyStr(valuePath, param);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,8 @@ public class ResponseConfig {
|
||||||
@SqlOracleDbFieldAnn("model_table_name")
|
@SqlOracleDbFieldAnn("model_table_name")
|
||||||
private String modelTableName;
|
private String modelTableName;
|
||||||
|
|
||||||
|
private String successExp;
|
||||||
|
|
||||||
private List<ResponseConfigAlias> responseConfigAliasList;
|
private List<ResponseConfigAlias> responseConfigAliasList;
|
||||||
|
|
||||||
private List<ResponseConfigValueChange> valueChangeList;
|
private List<ResponseConfigValueChange> valueChangeList;
|
||||||
|
|
Loading…
Reference in New Issue