From 99ee2d22456a4e5ed78f70f6196cc5176a055879 Mon Sep 17 00:00:00 2001 From: "youhong.ai" Date: Thu, 6 Jul 2023 09:56:25 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response_deal/ResponseMappingDeal.java | 189 +++++++++++------- .../response_deal/entity/ResponseConfig.java | 2 + 2 files changed, 121 insertions(+), 70 deletions(-) diff --git a/src/test/java/bokang/xiao/response_deal/ResponseMappingDeal.java b/src/test/java/bokang/xiao/response_deal/ResponseMappingDeal.java index 28fc932..87548b6 100644 --- a/src/test/java/bokang/xiao/response_deal/ResponseMappingDeal.java +++ b/src/test/java/bokang/xiao/response_deal/ResponseMappingDeal.java @@ -1,18 +1,19 @@ package bokang.xiao.response_deal; +import aiyh.utils.ScriptUtil; import aiyh.utils.Util; import aiyh.utils.excention.CustomerException; 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.response_deal.entity.ResponseConfig; +import bokang.xiao.response_deal.entity.ResponseConfigAlias; import bokang.xiao.response_deal.entity.ResponseConfigValueChange; import bokang.xiao.response_deal.mapper.ConfigMapper; import org.apache.log4j.Logger; import java.util.*; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import java.util.stream.Collectors; /** @@ -22,71 +23,119 @@ import java.util.stream.Collectors; * @Description

响应信息处理类

**/ public class ResponseMappingDeal { - - private final Logger logger = Util.getLogger("json-util"); - - private final ConfigMapper configMapper = Util.getMapper(ConfigMapper.class); - - - public void getConfig(String uniqueCode,ResponeVo responeVo){ - List responseConfigList = configMapper.queryResponseConfigByUnique(uniqueCode); - if(Objects.isNull(responseConfigList) || responseConfigList.isEmpty()){ - throw new ResponseException("response config is empty please check!!! "); - } - Map 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 valueChangeList = responseConfig.getValueChangeList(); - if(Objects.isNull(valueChangeList) || valueChangeList.isEmpty()){ - throw new ResponseException("valueChangeList config is empty please check!!!"); - } - Map> tableTypeMap = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getTableType)); - List mainConfig = tableTypeMap.get(0); - Map> collect = mainConfig.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getAssignTable)); - if(collect.size() > 1){ - throw new ResponseException("The primary table cannot have details please check!!! "); - } - //Map responseMap = responeVo.getResponseMap(); - //Map> 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> listValue = (List>) valueOrListByKeyStr.getValue(); - // List fieldDefinitions = listValue.stream().map(item -> FieldDefinition.builder().build()).collect(Collectors.toList()); - // mainFieldMap.put(valueOrListByKeyStr,fieldDefinitions); - // }else if(valueOrListByKeyStr.isArray()){ - // List fieldDefinitions = mainFieldMap.get(valueOrListByKeyStr); - // } - //} - //mainConfig.stream().map(item ->{ - // - //}) - List detail = tableTypeMap.get(1); - Map> tableValueMap = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getAssignTable)); - - - } - - public void responseToEntity(ResponseConfigValueChange responseConfigValueChange,Map param){ - String valuePath = responseConfigValueChange.getValuePath(); - Util.ValueOrList valueOrListByKeyStr = Util.getValueOrListByKeyStr(valuePath, param); - - } - - - - + + private final Logger logger = Util.getLogger("json-util"); + + private final ConfigMapper configMapper = Util.getMapper(ConfigMapper.class); + + + public void parseConfig(String uniqueCode, ResponeVo responeVo) { + if (responeVo.getCode() != 200) { + throw new CustomerException("你妈没成功"); + } + + List responseConfigs = configMapper.queryResponseConfigByUnique(uniqueCode); + + if (CollectionUtil.isEmpty(responseConfigs)) { + throw new CustomerException("sb"); + } + for (ResponseConfig responseConfig : responseConfigs) { + parseConfigOne(responseConfig, responeVo); + } + } + + private void parseConfigOne(ResponseConfig responseConfig, ResponeVo responeVo) { + List responseConfigAliasList = responseConfig.getResponseConfigAliasList(); + String successExp = responseConfig.getSuccessExp(); + Map responseMap = responeVo.getResponseMap(); + List> resultList = new ArrayList<>(); + if (CollectionUtil.isEmpty(responseMap)) { + // 他是一个list,尝试获取一下 + List result = responeVo.getResult(); + if (CollectionUtil.isEmpty(result)) { + throw new CustomerException("没有响应结果,你同步个J8"); + } else { + for (Map map : result) { + Map tempMap = new HashMap<>(); + for (Object entry : map.entrySet()) { + + } + resultList.add(tempMap); + } + } + } else { + resultList.add(responseMap); + } + if (StrUtil.isNotBlank(successExp)) { + for (Map map : resultList) { + boolean flag = (boolean) ScriptUtil.invokeScript(successExp, map); + if (!flag) { + throw new CustomerException("失败了!"); + } + } + } + + + } + + + public void getConfig(String uniqueCode, ResponeVo responeVo) { + List responseConfigList = configMapper.queryResponseConfigByUnique(uniqueCode); + if (Objects.isNull(responseConfigList) || responseConfigList.isEmpty()) { + throw new ResponseException("response config is empty please check!!! "); + } + Map 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 valueChangeList = responseConfig.getValueChangeList(); + if (Objects.isNull(valueChangeList) || valueChangeList.isEmpty()) { + throw new ResponseException("valueChangeList config is empty please check!!!"); + } + Map> tableTypeMap = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getTableType)); + List mainConfig = tableTypeMap.get(0); + Map> collect = mainConfig.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getAssignTable)); + if (collect.size() > 1) { + throw new ResponseException("The primary table cannot have details please check!!! "); + } + // Map responseMap = responeVo.getResponseMap(); + // Map> 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> listValue = (List>) valueOrListByKeyStr.getValue(); + // List fieldDefinitions = listValue.stream().map(item -> FieldDefinition.builder().build()).collect(Collectors.toList()); + // mainFieldMap.put(valueOrListByKeyStr,fieldDefinitions); + // }else if(valueOrListByKeyStr.isArray()){ + // List fieldDefinitions = mainFieldMap.get(valueOrListByKeyStr); + // } + //} + // mainConfig.stream().map(item ->{ + // + //}) + List detail = tableTypeMap.get(1); + Map> tableValueMap = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getAssignTable)); + + + } + + public void responseToEntity(ResponseConfigValueChange responseConfigValueChange, Map param) { + String valuePath = responseConfigValueChange.getValuePath(); + Util.ValueOrList valueOrListByKeyStr = Util.getValueOrListByKeyStr(valuePath, param); + + } + + } diff --git a/src/test/java/bokang/xiao/response_deal/entity/ResponseConfig.java b/src/test/java/bokang/xiao/response_deal/entity/ResponseConfig.java index 3620381..fb00a49 100644 --- a/src/test/java/bokang/xiao/response_deal/entity/ResponseConfig.java +++ b/src/test/java/bokang/xiao/response_deal/entity/ResponseConfig.java @@ -35,6 +35,8 @@ public class ResponseConfig { /** 模型表名称 */ @SqlOracleDbFieldAnn("model_table_name") private String modelTableName; + + private String successExp; private List responseConfigAliasList;