From 585c1ba70032372c3f9ba44c1ad6db43c6e27555 Mon Sep 17 00:00:00 2001 From: ic_excellent <2570192571@qq.com> Date: Wed, 5 Jul 2023 23:30:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=93=8D=E5=BA=94=E7=BB=93=E6=9E=9C=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xiao/shtx/schedule/ExamineSchedule.java | 10 +- .../util/process/JudgmentRuleProcess.java | 2 +- .../mapper/SourceTrackingMapper.java | 2 +- .../schedule/GenerateReportSchedule.java | 4 +- src/test/java/bokang/xiao/NormalTest.java | 32 ++++++- .../bokang/xiao/entity/FieldDefinition.java | 20 ++++ .../xiao/exception/ResponseException.java | 68 ++++++++++++++ .../response_deal/ResponseMappingDeal.java | 92 +++++++++++++++++++ .../response_deal/entity/ResponseConfig.java | 43 +++++++++ .../entity/ResponseConfigAlias.java | 38 ++++++++ .../entity/ResponseConfigValueChange.java | 76 +++++++++++++++ .../response_deal/mapper/ConfigMapper.java | 61 ++++++++++++ .../response_deal/store/ResponseStore.java | 62 +++++++++++++ 13 files changed, 502 insertions(+), 8 deletions(-) create mode 100644 src/test/java/bokang/xiao/entity/FieldDefinition.java create mode 100644 src/test/java/bokang/xiao/exception/ResponseException.java create mode 100644 src/test/java/bokang/xiao/response_deal/ResponseMappingDeal.java create mode 100644 src/test/java/bokang/xiao/response_deal/entity/ResponseConfig.java create mode 100644 src/test/java/bokang/xiao/response_deal/entity/ResponseConfigAlias.java create mode 100644 src/test/java/bokang/xiao/response_deal/entity/ResponseConfigValueChange.java create mode 100644 src/test/java/bokang/xiao/response_deal/mapper/ConfigMapper.java create mode 100644 src/test/java/bokang/xiao/response_deal/store/ResponseStore.java diff --git a/src/main/java/weaver/bokang/xiao/shtx/schedule/ExamineSchedule.java b/src/main/java/weaver/bokang/xiao/shtx/schedule/ExamineSchedule.java index 144e7b2..feffecc 100644 --- a/src/main/java/weaver/bokang/xiao/shtx/schedule/ExamineSchedule.java +++ b/src/main/java/weaver/bokang/xiao/shtx/schedule/ExamineSchedule.java @@ -101,6 +101,12 @@ public class ExamineSchedule extends CusBaseCronJob { Util.commitTransMapper(ScoreMapper.class); } + @Override + public void exceptionCallback(Throwable e) { + log.error("execute cronJon failure! error detail msg \n" + Util.getErrString(e)); + Util.rollbackTransMapper(ScoreMapper.class); + } + /** * 计算专技岗分数 * @param queryParam 查询参数 @@ -115,11 +121,11 @@ public class ExamineSchedule extends CusBaseCronJob { List scoreIdList = new ArrayList<>(); if(Objects.nonNull(scoreList) && !scoreList.isEmpty()){ for (Map scoreMap : scoreList) { - int dataId = Util.getModeDataId(tableName, Util.getIntValue(scoreModeId), 1); + int dataId = Util.getModeDataId("uf_examine_score", Util.getIntValue(scoreModeId), 1); scoreIdList.add(dataId); Map whereParam = new HashMap<>(); whereParam.put("id",dataId); - String updateSql = CommonUtil.getCusUpdateSql("", scoreMap, whereParam); + String updateSql = CommonUtil.getCusUpdateSql("uf_examine_score", scoreMap, whereParam); scoreMapper.executeUpdateCusSql(updateSql,scoreMap,whereParam); } Util.rebuildModeDataShareByAsyncList(1,Util.getIntValue(scoreModeId),scoreIdList); diff --git a/src/main/java/weaver/bokang/xiao/shtx/util/process/JudgmentRuleProcess.java b/src/main/java/weaver/bokang/xiao/shtx/util/process/JudgmentRuleProcess.java index c892667..bc26407 100644 --- a/src/main/java/weaver/bokang/xiao/shtx/util/process/JudgmentRuleProcess.java +++ b/src/main/java/weaver/bokang/xiao/shtx/util/process/JudgmentRuleProcess.java @@ -58,7 +58,7 @@ public class JudgmentRuleProcess { return StringUtils.isNotBlank(conditionValue); } - @MethodRuleNo(value = 0,desc = "sql判断") + @MethodRuleNo(value = 1,desc = "sql判断") public static boolean cusSql(ExamineConfigDetail examineConfigDetail,Map param){ boolean result = false; String conditionScript = examineConfigDetail.getConditionScript(); diff --git a/src/main/java/weaver/bokang/xiao/xhny_report/mapper/SourceTrackingMapper.java b/src/main/java/weaver/bokang/xiao/xhny_report/mapper/SourceTrackingMapper.java index e90f3ef..ab6c435 100644 --- a/src/main/java/weaver/bokang/xiao/xhny_report/mapper/SourceTrackingMapper.java +++ b/src/main/java/weaver/bokang/xiao/xhny_report/mapper/SourceTrackingMapper.java @@ -23,7 +23,7 @@ public interface SourceTrackingMapper { * @param param 条件参数 * @return 询价信息列表 */ - @Select("select id,xydh,bjkssj,bjjzsj from uf_src_rfq where bjjzsj < #{endDate} and (sfypf = 1 or sfypf is null)") + @Select("select id,xydh,bjkssj,bjjzsj from uf_src_rfq where bjjzsj < #{endDate} and (sfypf = 1 or sfypf is null) and xydh is not null ") @CollectionMappings({ @CollectionMapping(property = "sourceVendorList", column = "id", id = @Id(value = Integer.class, methodId = 1)), @CollectionMapping(property = "sourceMaterialList", column = "id", id = @Id(value = Integer.class, methodId = 2)), diff --git a/src/main/java/weaver/bokang/xiao/xhny_report/schedule/GenerateReportSchedule.java b/src/main/java/weaver/bokang/xiao/xhny_report/schedule/GenerateReportSchedule.java index 8b2ede5..2d38d42 100644 --- a/src/main/java/weaver/bokang/xiao/xhny_report/schedule/GenerateReportSchedule.java +++ b/src/main/java/weaver/bokang/xiao/xhny_report/schedule/GenerateReportSchedule.java @@ -38,9 +38,9 @@ public class GenerateReportSchedule extends CusBaseCronJob { @PrintParamMark private String dataSource; - private SourceTrackingMapper sourceTrackingMapper = Util.getMapper(SourceTrackingMapper.class); + private final SourceTrackingMapper sourceTrackingMapper = Util.getMapper(SourceTrackingMapper.class); - private VendorReportMapper vendorReportMapper = Util.getTransMapper(VendorReportMapper.class); + private final VendorReportMapper vendorReportMapper = Util.getTransMapper(VendorReportMapper.class); @Override public void runCode() { diff --git a/src/test/java/bokang/xiao/NormalTest.java b/src/test/java/bokang/xiao/NormalTest.java index fc6b53d..3957a7b 100644 --- a/src/test/java/bokang/xiao/NormalTest.java +++ b/src/test/java/bokang/xiao/NormalTest.java @@ -5,7 +5,6 @@ import aiyh.utils.ScriptUtil; import aiyh.utils.Util; import aiyh.utils.httpUtil.ResponeVo; import aiyh.utils.httpUtil.util.HttpUtils; -import aiyh.utils.tool.org.apache.commons.jexl3.*; import basetest.BaseTest; import bokang.xiao.entity.CourseEntity; import bokang.xiao.entity.StudentEntity; @@ -16,6 +15,7 @@ import cn.afterturn.easypoi.excel.entity.ExportParams; import com.alibaba.excel.EasyExcel; import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.fastjson.JSON; import com.api.bokang.xiao.porsche_review.mapper.ReviewMapper; import com.api.bokang.xiao.wx_report.mapper.ReportMapper; @@ -100,10 +100,14 @@ public class NormalTest extends BaseTest { param.put("zzgxd",4); param.put("hjjb","A"); param.put("hjdj",1); + Map map = new HashMap<>(); + map.put("item","kkkgg"); List list = new ArrayList<>(); list.add("jjgjg"); param.put("list",list); - String script = " list != null && list.size() > 0"; + param.put("map",map); + //String script = " list != null && list.size() > 0"; + String script = "map.containsKey('item')"; //String script = " if (hjjb == 'A' && hjdj == 1) {x = 4}"; boolean invokeVar = (Boolean) ScriptUtil.invokeScript(script, param); System.out.println(invokeVar); @@ -116,6 +120,30 @@ public class NormalTest extends BaseTest { examineSchedule.runCode(); } + @Test + public void paramGet(){ + Map param = new HashMap<>(); + + List> list = new ArrayList<>(); + for (int i = 0; i < 3; i++) { + Map obj = new HashMap<>(); + obj.put("obj1",21); + obj.put("objstr","jjgjgk"); + obj.put("objsttr2","jjggk"); + list.add(obj); + } + Map obj = new HashMap<>(); + obj.put("obj1",21); + obj.put("objstr","jjgjgk"); + obj.put("objsttr2","jjggk"); + param.put("param1",12); + param.put("paramStr","gkgkkg"); + param.put("paramObj",obj); + param.put("param1",12); + param.put("list",list); + System.out.println(JSON.toJSON(param)); + } + @Test public void testReport1() throws FileNotFoundException { BankService bankService = new BankService(); diff --git a/src/test/java/bokang/xiao/entity/FieldDefinition.java b/src/test/java/bokang/xiao/entity/FieldDefinition.java new file mode 100644 index 0000000..d12d04e --- /dev/null +++ b/src/test/java/bokang/xiao/entity/FieldDefinition.java @@ -0,0 +1,20 @@ +package bokang.xiao.entity; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.checkerframework.checker.units.qual.A; + +/** + * @ClassName FieldDefinition + * @Author 肖博亢 + * @Date 2023/7/5 16:28 + * @Description

+ **/ +@Data +//@NoArgsConstructor +//@AllArgsConstructor +//@Builder +public class FieldDefinition { +} diff --git a/src/test/java/bokang/xiao/exception/ResponseException.java b/src/test/java/bokang/xiao/exception/ResponseException.java new file mode 100644 index 0000000..f9fbfe5 --- /dev/null +++ b/src/test/java/bokang/xiao/exception/ResponseException.java @@ -0,0 +1,68 @@ +package bokang.xiao.exception; + +import aiyh.utils.Util; +import org.apache.log4j.Logger; + +/** + * @ClassName ResponseException + * @Author 肖博亢 + * @Date 2023/7/5 16:03 + * @Description

+ **/ +public class ResponseException extends RuntimeException{ + + private final Logger logger = Util.getLogger(); + private final String msg; + private Throwable throwable; + private Integer code = -1; + + public ResponseException(Throwable throwable) { + super(throwable); + this.msg = throwable.getMessage(); + } + + public ResponseException(String msg) { + super(msg); + this.msg = msg; + } + + public ResponseException(String msg, String... obj) { + super(Util.logStr(msg, obj)); + this.msg = Util.logStr(msg, obj); + } + + public ResponseException(String msg, Integer code) { + super(msg); + this.code = code; + this.msg = msg; + } + + public ResponseException(String msg, Integer code, Throwable throwable) { + super(msg, throwable); + this.code = code; + this.msg = msg; + } + + public ResponseException(String msg, Throwable throwable) { + super(msg, throwable); + this.msg = msg; + this.throwable = throwable; + } + + @Override + public void printStackTrace() { + logger.error("二开自定义异常:" + this.msg); + if (this.throwable != null) { + logger.error("异常信息: " + Util.getErrString(this.throwable)); + } + } + + public Integer getCode() { + return this.code; + } + + @Override + public String getMessage() { + return this.msg; + } +} diff --git a/src/test/java/bokang/xiao/response_deal/ResponseMappingDeal.java b/src/test/java/bokang/xiao/response_deal/ResponseMappingDeal.java new file mode 100644 index 0000000..28fc932 --- /dev/null +++ b/src/test/java/bokang/xiao/response_deal/ResponseMappingDeal.java @@ -0,0 +1,92 @@ +package bokang.xiao.response_deal; + +import aiyh.utils.Util; +import aiyh.utils.excention.CustomerException; +import aiyh.utils.httpUtil.ResponeVo; +import bokang.xiao.entity.FieldDefinition; +import bokang.xiao.exception.ResponseException; +import bokang.xiao.response_deal.entity.ResponseConfig; +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; + +/** + * @ClassName ResponseMappingDeal + * @Author 肖博亢 + * @Date 2023/7/4 17:42 + * @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); + + } + + + + +} diff --git a/src/test/java/bokang/xiao/response_deal/entity/ResponseConfig.java b/src/test/java/bokang/xiao/response_deal/entity/ResponseConfig.java new file mode 100644 index 0000000..3620381 --- /dev/null +++ b/src/test/java/bokang/xiao/response_deal/entity/ResponseConfig.java @@ -0,0 +1,43 @@ +package bokang.xiao.response_deal.entity; + +import lombok.Data; +import aiyh.utils.annotation.recordset.SqlOracleDbFieldAnn; + +import java.util.List; + + +/** + * @ClassName ResponseConfigMain + * @Author 肖博亢 + * @Date 2023/7/4 17:16 + * @Description

响应值处理配置

+ **/ + +@Data +public class ResponseConfig { + + /** 请求唯一标识 */ + @SqlOracleDbFieldAnn("request_unique") + private String requestUnique; + + /** 配置描述 */ + @SqlOracleDbFieldAnn("config_desc") + private String configDesc; + + /** 表类型 */ + @SqlOracleDbFieldAnn("table_type") + private String tableType; + + /** 模型表 */ + @SqlOracleDbFieldAnn("model_table") + private String modelTable; + + /** 模型表名称 */ + @SqlOracleDbFieldAnn("model_table_name") + private String modelTableName; + + private List responseConfigAliasList; + + private List valueChangeList; + +} diff --git a/src/test/java/bokang/xiao/response_deal/entity/ResponseConfigAlias.java b/src/test/java/bokang/xiao/response_deal/entity/ResponseConfigAlias.java new file mode 100644 index 0000000..33dfd58 --- /dev/null +++ b/src/test/java/bokang/xiao/response_deal/entity/ResponseConfigAlias.java @@ -0,0 +1,38 @@ +package bokang.xiao.response_deal.entity; + +import lombok.Data; +import aiyh.utils.annotation.recordset.SqlOracleDbFieldAnn; + +/** + * @ClassName ResponseConfigDtAlias + * @Author 肖博亢 + * @Date 2023/7/4 17:17 + * @Description

别名配置

+ **/ +@Data +public class ResponseConfigAlias { + + /** 数据路径 */ + @SqlOracleDbFieldAnn("data_path") + private String dataPath; + + /** 数据类型 */ + @SqlOracleDbFieldAnn("data_type") + private String dataType; + + /** 数据别名 */ + @SqlOracleDbFieldAnn("data_alias") + private String dataAlias; + + /** 数据变更 */ + @SqlOracleDbFieldAnn("data_change") + private String dataChange; + + /** 自定义文本 */ + @SqlOracleDbFieldAnn("cus_text") + private String cusText; + + /** 类型变更 */ + @SqlOracleDbFieldAnn("type_change") + private String typeChange; +} diff --git a/src/test/java/bokang/xiao/response_deal/entity/ResponseConfigValueChange.java b/src/test/java/bokang/xiao/response_deal/entity/ResponseConfigValueChange.java new file mode 100644 index 0000000..2f1a7ca --- /dev/null +++ b/src/test/java/bokang/xiao/response_deal/entity/ResponseConfigValueChange.java @@ -0,0 +1,76 @@ +package bokang.xiao.response_deal.entity; + +import aiyh.utils.annotation.recordset.SqlOracleDbFieldAnn; +import lombok.Data; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @ClassName ResponseConfigValueChange + * @Author 肖博亢 + * @Date 2023/7/4 17:19 + * @Description

值转换配置

+ **/ +@Data +public class ResponseConfigValueChange { + + /** 值路径 */ + @SqlOracleDbFieldAnn("value_path") + private String valuePath; + + /** 字段类型 */ + @SqlOracleDbFieldAnn("field_type") + private int fieldType; + + /** 分配字段 */ + @SqlOracleDbFieldAnn("assign_field") + private String assignField; + + /** 分配表 */ + @SqlOracleDbFieldAnn("assign_table") + private String assignTable; + + /** 表类型 */ + @SqlOracleDbFieldAnn("table_type") + private int tableType; + + public void setTableType(int tableType){ + this.tableType = tableType == -1 ? this.judgmentIsDetail(this.assignTable) : tableType; + } + + /** 分配字段名 */ + @SqlOracleDbFieldAnn("assign_field_name") + private String assignFieldName; + + /** 分配类型 */ + @SqlOracleDbFieldAnn("assign_type") + private int assignType; + + /** 数据变更 */ + @SqlOracleDbFieldAnn("data_change") + private int dataChange; + + /** 类型变更 */ + @SqlOracleDbFieldAnn("type_change") + private int typeChange; + + /** 自定义文本 */ + @SqlOracleDbFieldAnn("cus_text") + private String cusText; + + /** 判断脚本 */ + @SqlOracleDbFieldAnn("judgment_script") + private String judgmentScript; + + /** 条件脚本 */ + @SqlOracleDbFieldAnn("condition_script") + private String conditionScript; + + public int judgmentIsDetail(String tableName){ + Pattern compiledPattern = Pattern.compile("dt_\\d+$"); + Matcher matcher = compiledPattern.matcher(tableName); + return matcher.find() ? 1 : 0; + } + +} diff --git a/src/test/java/bokang/xiao/response_deal/mapper/ConfigMapper.java b/src/test/java/bokang/xiao/response_deal/mapper/ConfigMapper.java new file mode 100644 index 0000000..5327489 --- /dev/null +++ b/src/test/java/bokang/xiao/response_deal/mapper/ConfigMapper.java @@ -0,0 +1,61 @@ +package bokang.xiao.response_deal.mapper; + +import aiyh.utils.annotation.recordset.*; +import bokang.xiao.response_deal.entity.ResponseConfig; +import bokang.xiao.response_deal.entity.ResponseConfigAlias; +import bokang.xiao.response_deal.entity.ResponseConfigValueChange; + +import java.util.List; + +/** + * @ClassName ConfigMapper + * @Author 肖博亢 + * @Date 2023/7/4 17:26 + * @Description

配置信息-数据库处理类

+ **/ +@SqlMapper +public interface ConfigMapper { + + /** + *

通过请求唯一标识查询响应配置信息

+ * @param requestUnique 唯一标识 + * @return 响应配置信息 + */ + @Select("select * from uf_response_config where request_unique = #{requestUnique}") + @CollectionMappings({ + @CollectionMapping(property = "responseConfigAliasList", column = "id", id = @Id(value = Integer.class, methodId = 1)), + @CollectionMapping(property = "valueChangeList", column = "id", id = @Id(value = Integer.class, methodId = 2)), + }) + List queryResponseConfigByUnique(@ParamMapper("requestUnique") String requestUnique); + + /** + *

通过请求唯一标识查询响应配置信息

+ * @return 响应配置信息 + */ + @Select("select * from uf_response_config") + @CollectionMappings({ + @CollectionMapping(property = "responseConfigAliasList", column = "id", id = @Id(value = Integer.class, methodId = 1)), + @CollectionMapping(property = "valueChangeList", column = "id", id = @Id(value = Integer.class, methodId = 2)), + }) + List queryResponseConfig(); + + /** + *

查询响应数据别名配置信息

+ * @param mainId 主数据id + * @return 响应数据别名配置信息列表 + */ + @Select("select * from uf_response_config_dt1 where mainid = #{mainId}") + @CollectionMethod(1) + List queryResponseConfigAlias(@ParamMapper("mainId")int mainId); + + + /** + *

查询响应数据转换配置信息

+ * @param mainId 主数据id + * @return 响应数据转换配置信息列表 + */ + @Select("select * from uf_response_config_dt2 where mainid = #{mainId}") + @CollectionMethod(2) + List queryResponseConfigValueChange(@ParamMapper("mainId")int mainId); + +} diff --git a/src/test/java/bokang/xiao/response_deal/store/ResponseStore.java b/src/test/java/bokang/xiao/response_deal/store/ResponseStore.java new file mode 100644 index 0000000..f992a69 --- /dev/null +++ b/src/test/java/bokang/xiao/response_deal/store/ResponseStore.java @@ -0,0 +1,62 @@ +package bokang.xiao.response_deal.store; + +import aiyh.utils.Util; +import bokang.xiao.response_deal.entity.ResponseConfig; +import bokang.xiao.response_deal.mapper.ConfigMapper; +import com.alibaba.fastjson.JSON; +import lombok.Getter; +import org.apache.log4j.Logger; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * @ClassName VendorStore + * @Author 肖博亢 + * @Date 2023/3/17 18:31 + * @Description

+ **/ + +@Getter +public class ResponseStore { + + private final Logger logger = Util.getLogger(); + + private List responseConfigList = new ArrayList<>(); + + private Map> responseConfigMap = new HashMap<>(); + + private final ConfigMapper configMapper = Util.getMapper(ConfigMapper.class); + + private ResponseStore(){ + this.init(); + } + + private void init(){ + try { + List responseConfigs = configMapper.queryResponseConfig(); + if (Objects.nonNull(responseConfigs) && !responseConfigs.isEmpty()) { + this.responseConfigList = responseConfigs; + this.responseConfigMap = responseConfigs.stream().collect(Collectors.groupingBy(ResponseConfig::getRequestUnique)); + } + logger.info(String.format("ResponseStore init success !!! responseConfigMap ==> %s", JSON.toJSONString(this.responseConfigMap))); + }catch (Exception exception){ + logger.error("ResponseStore init fail !!! "+Util.getErrString(exception)); + } + } + + public void refresh(){ + this.init(); + } + + public static ResponseStore getInstance(){ + return ResponseStoreHolder.RESPONSE_STORE; + } + + private static class ResponseStoreHolder{ + private ResponseStoreHolder(){ + + } + private static final ResponseStore RESPONSE_STORE = new ResponseStore(); + } +}