From c642b40ce978060fc48dc96395fda38259eafb03 Mon Sep 17 00:00:00 2001 From: ic_excellent <2570192571@qq.com> Date: Wed, 12 Jul 2023 10:51:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=A2=E6=A0=A1=E5=90=8C=E6=AD=A5=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/aiyh/utils/recordset/SqlHandler.java | 73 ++++- .../response_deal/ResponseMappingDeal.java | 257 ++++++++++++++++++ .../constant/ResponseConfigConstant.java | 56 ++++ .../response_deal/entity/FieldDefinition.java | 38 +++ .../response_deal/entity/ResponseConfig.java | 48 ++++ .../entity/ResponseConfigAlias.java | 64 +++++ .../entity/ResponseConfigValueChange.java | 67 +++++ .../response_deal/entity/RowDefinition.java | 51 ++++ .../response_deal/entity/TableDefinition.java | 71 +++++ .../exception/ResponseException.java | 68 +++++ .../intfaces/DataChangeInterface.java | 24 ++ .../intfaces/FieldDefinitionCallback.java | 15 + .../intfaces/RowDefinitionCallback.java | 17 ++ .../intfaces/TableDefinitionCallback.java | 16 ++ .../response_deal/mapper/ConfigMapper.java | 104 +++++++ .../process/DataChangeProcess.java | 205 ++++++++++++++ .../process/TypeChangeProcess.java | 88 ++++++ .../state/InsertOrUpdateState.java | 71 +++++ .../utils/response_deal/state/InsertSate.java | 98 +++++++ .../aiyh/utils/response_deal/state/State.java | 33 +++ .../response_deal/state/StateFactory.java | 48 ++++ .../response_deal/state/UpdateState.java | 90 ++++++ .../response_deal/store/ResponseStore.java | 63 +++++ .../response_deal/util/ResponseUtil.java | 40 +++ .../bokang/xiao/zhenn/mapper/BankMapper.java | 12 + .../xiao/zhenn/service/BankService.java | 56 ++-- .../shtx/schedule/SyncTeachDataSchedule.java | 119 ++++++++ .../config/enumtype/GetValueTypeEnum.java | 8 +- .../config/service/DealWithMapping.java | 12 + src/test/java/bokang/xiao/NormalTest.java | 3 +- .../response_deal/ResponseMappingDeal.java | 12 +- .../response_deal/entity/TableDefinition.java | 12 +- .../response_deal/mapper/ConfigMapper.java | 2 +- .../state/InsertOrUpdateState.java | 9 +- .../xiao/response_deal/state/InsertSate.java | 2 +- .../response_deal/state/StateFactory.java | 41 ++- .../xiao/response_deal/state/UpdateState.java | 2 +- 37 files changed, 1936 insertions(+), 59 deletions(-) create mode 100644 src/main/java/aiyh/utils/response_deal/ResponseMappingDeal.java create mode 100644 src/main/java/aiyh/utils/response_deal/constant/ResponseConfigConstant.java create mode 100644 src/main/java/aiyh/utils/response_deal/entity/FieldDefinition.java create mode 100644 src/main/java/aiyh/utils/response_deal/entity/ResponseConfig.java create mode 100644 src/main/java/aiyh/utils/response_deal/entity/ResponseConfigAlias.java create mode 100644 src/main/java/aiyh/utils/response_deal/entity/ResponseConfigValueChange.java create mode 100644 src/main/java/aiyh/utils/response_deal/entity/RowDefinition.java create mode 100644 src/main/java/aiyh/utils/response_deal/entity/TableDefinition.java create mode 100644 src/main/java/aiyh/utils/response_deal/exception/ResponseException.java create mode 100644 src/main/java/aiyh/utils/response_deal/intfaces/DataChangeInterface.java create mode 100644 src/main/java/aiyh/utils/response_deal/intfaces/FieldDefinitionCallback.java create mode 100644 src/main/java/aiyh/utils/response_deal/intfaces/RowDefinitionCallback.java create mode 100644 src/main/java/aiyh/utils/response_deal/intfaces/TableDefinitionCallback.java create mode 100644 src/main/java/aiyh/utils/response_deal/mapper/ConfigMapper.java create mode 100644 src/main/java/aiyh/utils/response_deal/process/DataChangeProcess.java create mode 100644 src/main/java/aiyh/utils/response_deal/process/TypeChangeProcess.java create mode 100644 src/main/java/aiyh/utils/response_deal/state/InsertOrUpdateState.java create mode 100644 src/main/java/aiyh/utils/response_deal/state/InsertSate.java create mode 100644 src/main/java/aiyh/utils/response_deal/state/State.java create mode 100644 src/main/java/aiyh/utils/response_deal/state/StateFactory.java create mode 100644 src/main/java/aiyh/utils/response_deal/state/UpdateState.java create mode 100644 src/main/java/aiyh/utils/response_deal/store/ResponseStore.java create mode 100644 src/main/java/aiyh/utils/response_deal/util/ResponseUtil.java create mode 100644 src/main/java/weaver/bokang/xiao/shtx/schedule/SyncTeachDataSchedule.java diff --git a/src/main/java/aiyh/utils/recordset/SqlHandler.java b/src/main/java/aiyh/utils/recordset/SqlHandler.java index b1f9363..c51ced2 100644 --- a/src/main/java/aiyh/utils/recordset/SqlHandler.java +++ b/src/main/java/aiyh/utils/recordset/SqlHandler.java @@ -8,6 +8,7 @@ import aiyh.utils.excention.MethodNotFindException; import aiyh.utils.excention.ParseSqlException; import aiyh.utils.sqlUtil.sqlResult.impl.BatchSqlResultImpl; import aiyh.utils.sqlUtil.sqlResult.impl.PrepSqlResultImpl; +import aiyh.utils.tool.cn.hutool.core.collection.CollectionUtil; import org.apache.commons.lang3.StringUtils; import java.lang.reflect.InvocationTargetException; @@ -29,14 +30,18 @@ public class SqlHandler { List batchSqlArgs = new ArrayList<>(); + //change by aiyouhong + //List batchSqlArgsList = new ArrayList(); + //String batchSqlName = "item"; + + Map> batchSqlArgMap = new HashMap<>(); - List batchSqlArgsList = new ArrayList(); - - String batchSqlName = "item"; - + private final Object batchObj = null; public PrepSqlResultImpl handler(String sql, boolean custom, Method method, Object[] args) { + batchSqlArgMap.clear(); + batchSqlArgs.clear(); String findSql = findSql(sql, custom, method, args); Map methodArgNameMap = buildMethodArgNameMap(method, args); // 处理基本类型以及包装类 @@ -56,7 +61,39 @@ public class SqlHandler { private String parseBatch(String findSql, Object o) { String parse = ""; - if (!batchSqlArgsList.isEmpty()) { + if(CollectionUtil.isNotEmpty(batchSqlArgMap)){ + int length = 0; + List firstList = null; + for (Map.Entry> entry : batchSqlArgMap.entrySet()) { + List value = entry.getValue(); + if (length == 0) { + length = value.size(); + firstList = value; + }else { + if (length != value.size()) { + throw new BindingException("批量sql参数长度不一致,请检查批量sql的批量参数"); + } + } + } + if (CollectionUtil.isNotEmpty(firstList)) { + for (int i = 0; i < firstList.size(); i++) { + Map map = new HashMap<>(8); + for (Map.Entry> entry : batchSqlArgMap.entrySet()) { + map.put(entry.getKey(), entry.getValue().get(i)); + } + if(Objects.nonNull(o) && o instanceof Map && !((Map) o).isEmpty()){ + map.putAll((Map)o); + } + parse = parse(findSql, map); + List tempArgs = new ArrayList<>(); + tempArgs.addAll(sqlArgs); + batchSqlArgs.add(tempArgs); + sqlArgs.clear(); + } + } + } + //change by aiyouhong + /*if (!batchSqlArgsList.isEmpty()) { for (Object o1 : batchSqlArgsList) { Map map = new HashMap<>(8); map.put(batchSqlName, o1); @@ -67,7 +104,7 @@ public class SqlHandler { batchSqlArgs.add(tempArgs); sqlArgs.clear(); } - } + }*/ if ("".equals(parse)) { parse = findSql; } @@ -79,12 +116,17 @@ public class SqlHandler { Map methodArgNameMap = buildMethodArgNameMap(method, args); // 处理基本类型以及包装类 String parse; - if (methodArgNameMap.size() == 0) { - Object o = batchSqlArgsList.get(0); - if (o instanceof List) { - return new BatchSqlResultImpl(findSql, batchSqlArgs); - } - } + //change by aiyouhong + //if (methodArgNameMap.size() == 0) { + // + // //change by aiyouhong + // //Object o = batchSqlArgsList.get(0); + // Map.Entry> entry = batchSqlArgMap.entrySet().stream().findFirst().get(); + // Object o = entry.getValue(); + // if (o != null) { + // return new BatchSqlResultImpl(findSql, batchSqlArgs); + // } + //} parse = parseBatch(findSql, methodArgNameMap); return new BatchSqlResultImpl(parse, batchSqlArgs); } @@ -142,8 +184,11 @@ public class SqlHandler { BatchSqlArgs batchSqlArgs = parameter.getAnnotation(BatchSqlArgs.class); if (batchSqlArgs != null) { try { - this.batchSqlArgsList = (List) arg; - batchSqlName = batchSqlArgs.value(); + //change by aiyouhong + //this.batchSqlArgsList = (List) arg; + //batchSqlName = batchSqlArgs.value(); + + batchSqlArgMap.put(batchSqlArgs.value(),(List) arg); } catch (Exception e) { throw new BindingException("can not parse batchSqlArgs for " + parameter.getName() + ", param index is " + i); } diff --git a/src/main/java/aiyh/utils/response_deal/ResponseMappingDeal.java b/src/main/java/aiyh/utils/response_deal/ResponseMappingDeal.java new file mode 100644 index 0000000..db24dd2 --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/ResponseMappingDeal.java @@ -0,0 +1,257 @@ +package aiyh.utils.response_deal; + +import aiyh.utils.Util; +import aiyh.utils.function.Bi3Function; +import aiyh.utils.httpUtil.ResponeVo; +import aiyh.utils.response_deal.constant.ResponseConfigConstant; +import aiyh.utils.response_deal.entity.*; +import aiyh.utils.response_deal.exception.ResponseException; +import aiyh.utils.response_deal.intfaces.FieldDefinitionCallback; +import aiyh.utils.response_deal.intfaces.RowDefinitionCallback; +import aiyh.utils.response_deal.intfaces.TableDefinitionCallback; +import aiyh.utils.response_deal.mapper.ConfigMapper; +import aiyh.utils.response_deal.process.DataChangeProcess; +import aiyh.utils.response_deal.process.TypeChangeProcess; +import aiyh.utils.response_deal.util.ResponseUtil; +import com.alibaba.fastjson.JSON; +import lombok.Setter; +import org.apache.log4j.Logger; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * @ClassName ResponseMappingDeal + * @Author 肖博亢 + * @Date 2023/7/4 17:42 + * @Description

响应信息处理类

+ **/ +@Setter +public class ResponseMappingDeal { + + private final Logger logger = Util.getLogger("json_util"); + + private final ConfigMapper configMapper = Util.getMapper(ConfigMapper.class); + + /** 表数据回调 */ + private TableDefinitionCallback tableCallback; + + /** 行数据回调 */ + private RowDefinitionCallback rowCallback; + + /** 字段数据回调 */ + private FieldDefinitionCallback fieldDefinitionCallback; + + /** 状态map的key */ + private Class stateClassKey; + + public void doResponseSync(String uniqueCode, ResponeVo responeVo) { + Map responseMap = responeVo.getResponseMap(); + ResponseUtil.parameterJudgment(responseMap,"接口返回都为空 你处理个勾"); + this.doResponseSync(uniqueCode,responseMap); + } + + public void doResponseSync(String uniqueCode, Map responseMap) { + List responseConfigList = configMapper.queryResponseConfigByUnique(uniqueCode); + logger.info(String.format("%s 相关响应配置信息==> %s",uniqueCode, JSON.toJSONString(responseConfigList))); + ResponseUtil.parameterJudgment(responseConfigList,"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!!! "); + } + ResponseUtil.parameterJudgment(responseMap,"接口返回都为空 你处理个勾"); + tableNameConfig.forEach((key, value) -> doResponseSync(value, responseMap)); + } + + public void doResponseSync(ResponseConfig responseConfig, Map responseMap){ + List responseConfigAliasList = responseConfig.getResponseConfigAliasList(); + ResponseUtil.parameterJudgment(responseConfigAliasList,"responseConfigAliasList config is empty please check!!!"); + List valueChangeList = responseConfig.getValueChangeList(); + ResponseUtil.parameterJudgment(valueChangeList,"valueChangeList config is empty please check!!!"); + //数据信息按是否主表分组 + Map> aliasMap = responseConfigAliasList.stream().collect(Collectors.groupingBy(ResponseConfigAlias::getTableType)); + List mainConfigList = aliasMap.get(ResponseConfigConstant.MAIN_TABLE); + Map> mainOrDetail = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getTableType)); + List mainValueChangeList = mainOrDetail.get(ResponseConfigConstant.MAIN_TABLE); + TableDefinition tableDefinition; + if(ResponseUtil.parameterIsNotNull(mainConfigList)) { + tableDefinition = this.parsingJsonToTable(responseConfig.getModelTableName(), responseConfig, mainConfigList, mainValueChangeList, responseMap, true, this::detailTableDeal); + }else{ + Map detailTable = new HashMap<>(); + this.detailTableDeal(responseConfig,responseMap,detailTable); + tableDefinition = TableDefinition.builder() + .detailTableMap(detailTable) + .tableDefinitionCallback(this.tableCallback) + .tableType(responseConfig.getTableType()) + .assignType(ResponseConfigConstant.NO_HANDLE) + .assignTable(responseConfig.getModelTableName()).build(); + } + //做数据处理 + tableDefinition.setDefaultState(stateClassKey); + tableDefinition.dataProcess(); + } + + public TableDefinition parsingJsonToTable( + String tableName, + ResponseConfig responseConfig, + List responseConfigAliasList, + List valueChangeList, + Map responseMap, + boolean isMainTable, + Bi3Function,Map,String> detailCallBack) { + + List mainAliasList = responseConfigAliasList.stream().filter(item -> item.getMainData() == ResponseConfigConstant.MAIN_DATA).collect(Collectors.toList()); + if(responseConfigAliasList.size() > 1) { + throw new ResponseException("The master data cannot be multiple please check !!! "); + } + if(responseConfigAliasList.isEmpty()){ + throw new ResponseException("The configuration is missing master data please check !!! "); + } + Map aliasData = new HashMap<>(responseMap); + //处理别名数据 + responseConfigAliasList.forEach(item -> { + String dataPath = item.getDataPath(); + String dataAlias = item.getDataAlias(); + Object parsingData = Util.getValueByKeyStr(dataPath, responseMap); + aliasData.put(dataAlias,parsingData); + }); + //Map> mainOrDetail = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getTableType)); + //List 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()) + .tableType(responseConfig.getTableType()) + .mainOrDetail(tableMainOrDetail) + .tableDefinitionCallback(this.tableCallback) + .assignType(mainDataAlias.getAssignType()).build(); + String dataPath = mainDataAlias.getDataPath(); + List rowDefinitionList = new ArrayList<>(); + Map detailTable = isMainTable ? new HashMap<>() : null; + if(mainDataAlias.getDataType() == ResponseConfigConstant.JSON_ARRAY){ + List> mainList = (List>) Util.getValueByKeyStr(dataPath, aliasData); + for (Map mainItem : mainList) { + aliasData.put(mainDataAlias.getDataAlias(),mainItem); + //处理配置信息 + List fieldDefinitions = parsingJsonToConfig(valueChangeList, aliasData); + RowDefinition rowDefinition = this.buildRowDefinition(fieldDefinitions,tableName, mainDataAlias.getAssignType(), mainDataAlias.getConditionScript(), mainDataAlias.getJudgmentScript()); + rowDefinition.setMainOrDetail(ResponseConfigConstant.DETAIL_TABLE); + if(isMainTable) { + rowDefinition.setMainOrDetail(ResponseConfigConstant.MAIN_TABLE); + detailCallBack.apply(responseConfig,aliasData,detailTable); + rowDefinition.setDetailTableMap(detailTable); + } + rowDefinitionList.add(rowDefinition); + } + }else if(mainDataAlias.getDataType() == ResponseConfigConstant.JSON_OBJECT){ + Map jsonObj = (Map) Util.getValueByKeyStr(dataPath, aliasData); + aliasData.put(mainDataAlias.getDataAlias(),jsonObj); + //处理配置信息 + List fieldDefinitions = parsingJsonToConfig(valueChangeList, aliasData); + RowDefinition rowDefinition = this.buildRowDefinition(fieldDefinitions,tableName,mainDataAlias.getAssignType(), mainDataAlias.getConditionScript(), mainDataAlias.getJudgmentScript()); + rowDefinition.setMainOrDetail(ResponseConfigConstant.DETAIL_TABLE); + if(isMainTable) { + rowDefinition.setMainOrDetail(ResponseConfigConstant.MAIN_TABLE); + detailCallBack.apply(responseConfig,aliasData,detailTable); + rowDefinition.setDetailTableMap(detailTable); + } + rowDefinitionList.add(rowDefinition); + }else { + throw new ResponseException("please set the primary data type !!!"); + } + //设置表的行信息 + tableDefinition.setRowDefinitionList(rowDefinitionList); + return tableDefinition; + } + + private RowDefinition buildRowDefinition(List fieldDefinitionList, + String tableName, + int assignType, + String conditionScript, + String judgmentScript){ + Map updateParam = new HashMap<>(); + Map 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()); + } + }); + return RowDefinition.builder().assignType(assignType) + .conditionScript(conditionScript) + .updateParam(updateParam) + .assignTable(tableName) + .whereParam(wherePram) + .fieldDefinitionList(fieldDefinitionList) + .rowDefinitionCallback(this.rowCallback) + .judgmentScript(judgmentScript).build(); + } + + private String detailTableDeal(ResponseConfig responseConfig,Map param,Map detailTable){ + List responseConfigAliasList = responseConfig.getResponseConfigAliasList(); + List valueChangeList = responseConfig.getValueChangeList(); + //数据信息按是否主表分组 + Map> aliasMap = responseConfigAliasList.stream().collect(Collectors.groupingBy(ResponseConfigAlias::getTableType)); + List detailAliases = aliasMap.get(ResponseConfigConstant.DETAIL_TABLE); + //没有明细相关配置不处理 + if(ResponseUtil.parameterIsNull(detailAliases)){ + return ""; + } + Map> detailAliasMap = detailAliases.stream().collect(Collectors.groupingBy(ResponseConfigAlias::getDetailTableName)); + Map> detailValueChangeMap = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getAssignTable)); + detailAliasMap.forEach((key,value) ->{ + List detailValueChangeList = detailValueChangeMap.get(key); + TableDefinition tableDefinition = parsingJsonToTable(key, responseConfig, value, detailValueChangeList, param, false, this::detailTableDeal); + detailTable.put(key,tableDefinition); + }); + return ""; + } + + /** + * 将json参数解析成对应的字段描述信息 + * @param responseConfigValueChangeList 配置信息 + * @param parsingData json信息 + * @return 字段描述信息 + */ + public List parsingJsonToConfig(List responseConfigValueChangeList, + Map parsingData){ + Map 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); + }); + return responseConfigValueChangeList.stream().map(item ->{ + BiFunction, 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); + Function typeChangeFunction = TypeChangeProcess.MODE_METHOD_MAP.get(item.getTypeChange()); + 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()) + .tableName(item.getAssignTable()) + .fieldName(item.getAssignFieldName()) + .fieldDefinitionCallback(fieldDefinitionCallback) + .fieldValue(targetValue).build(); + }).collect(Collectors.toList()); + } + +} diff --git a/src/main/java/aiyh/utils/response_deal/constant/ResponseConfigConstant.java b/src/main/java/aiyh/utils/response_deal/constant/ResponseConfigConstant.java new file mode 100644 index 0000000..bebdcef --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/constant/ResponseConfigConstant.java @@ -0,0 +1,56 @@ +package aiyh.utils.response_deal.constant; + +/** + * @ClassName ResponseConfigConstant + * @Author 肖博亢 + * @Date 2023/7/7 10:23 + * @Description

+ **/ +public class ResponseConfigConstant { + + /** 主数据 */ + public static int MAIN_DATA = 0; + + /** 主表 */ + public static int MAIN_TABLE = 0; + + /** 明细表 */ + public static int DETAIL_TABLE = 1; + + /** json数组 */ + public static int JSON_ARRAY = 0; + + /** json对象 */ + public static int JSON_OBJECT = 1; + + /** 默认值 */ + public static int DEFAULT_VALUE = 0; + + /** 表数据无需处理 */ + public static int NO_HANDLE = -1; + + /** 表数据新增 */ + public static int INSERT = 0; + + /** 表数据更新 */ + public static int UPDATE = 1; + + /** 表数据新增或更新 */ + public static int INSERT_OR_UPDATE = 2; + + /** 流程表 */ + public static int WORKFLOW_TABLE = 1; + + /** 建模表 */ + public static int MODEL_TABLE = 0; + + /** 自定义表 */ + public static int CUS_TABLE = 2; + + /** 更新字段 */ + public static int UPDATE_FIELD = 0; + + /** 条件字段 */ + public static int WHERE_FIELD = 1; + +} diff --git a/src/main/java/aiyh/utils/response_deal/entity/FieldDefinition.java b/src/main/java/aiyh/utils/response_deal/entity/FieldDefinition.java new file mode 100644 index 0000000..74de83d --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/entity/FieldDefinition.java @@ -0,0 +1,38 @@ +package aiyh.utils.response_deal.entity; + +import aiyh.utils.response_deal.intfaces.FieldDefinitionCallback; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @ClassName FieldDefinition + * @Author 肖博亢 + * @Date 2023/7/7 14:05 + * @Description

+ **/ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class FieldDefinition { + + /** 字段名 */ + private String fieldName; + + /** 字段类型 */ + private int fieldType; + + /** 字段值 */ + private Object fieldValue; + + /** 所属表名 */ + private String tableName; + + /** 表类型 */ + private int tableType; + + private FieldDefinitionCallback fieldDefinitionCallback; + +} diff --git a/src/main/java/aiyh/utils/response_deal/entity/ResponseConfig.java b/src/main/java/aiyh/utils/response_deal/entity/ResponseConfig.java new file mode 100644 index 0000000..691589d --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/entity/ResponseConfig.java @@ -0,0 +1,48 @@ +package aiyh.utils.response_deal.entity; + +import aiyh.utils.annotation.recordset.SqlOracleDbFieldAnn; +import lombok.Data; + +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 int tableType; + + /** 模型表 */ + @SqlOracleDbFieldAnn("MODEL_TABLE") + private String modelTable; + + /** 模型表名称 */ + @SqlOracleDbFieldAnn("MODEL_TABLE_NAME") + private String modelTableName; + + /** 数据根路径 */ + @SqlOracleDbFieldAnn("ROOT_PATH") + private String rootPath; + + private String successExp; + + private List responseConfigAliasList; + + private List valueChangeList; + +} diff --git a/src/main/java/aiyh/utils/response_deal/entity/ResponseConfigAlias.java b/src/main/java/aiyh/utils/response_deal/entity/ResponseConfigAlias.java new file mode 100644 index 0000000..911d5d0 --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/entity/ResponseConfigAlias.java @@ -0,0 +1,64 @@ +package aiyh.utils.response_deal.entity; + +import aiyh.utils.annotation.recordset.SqlOracleDbFieldAnn; +import lombok.Data; + +import java.util.HashMap; +import java.util.Map; + +/** + * @ClassName ResponseConfigDtAlias + * @Author 肖博亢 + * @Date 2023/7/4 17:17 + * @Description

别名配置

+ **/ +@Data +public class ResponseConfigAlias { + + /** 数据路径 */ + @SqlOracleDbFieldAnn("DATA_PATH") + private String dataPath; + + /** 数据类型 */ + @SqlOracleDbFieldAnn("DATA_TYPE") + private int dataType; + + /** 数据别名 */ + @SqlOracleDbFieldAnn("DATA_ALIAS") + private String dataAlias; + + /** 表类型 */ + @SqlOracleDbFieldAnn("TABLE_TYPE") + private int tableType; + + /** 明细表 */ + @SqlOracleDbFieldAnn("DETAIL_TABLE") + private String detailTable; + + /** 明细表名 */ + @SqlOracleDbFieldAnn("DETAIL_TABLE_NAME") + private String detailTableName; + + /** 是否主数据 */ + @SqlOracleDbFieldAnn("MAIN_DATA") + private int mainData; + + /** 是否为拆分 */ + @SqlOracleDbFieldAnn("SPLIT_FLAG") + private int splitFlag; + + /** 判断表达式 */ + @SqlOracleDbFieldAnn("JUDGMENT_SCRIPT") + private String judgmentScript; + + /** 条件表达式 */ + @SqlOracleDbFieldAnn("CONDITION_SCRIPT") + private String conditionScript; + + /** 数据写入方式 */ + @SqlOracleDbFieldAnn("ASSIGN_TYPE") + private int assignType; + + private Map parsingData = new HashMap<>(); + +} diff --git a/src/main/java/aiyh/utils/response_deal/entity/ResponseConfigValueChange.java b/src/main/java/aiyh/utils/response_deal/entity/ResponseConfigValueChange.java new file mode 100644 index 0000000..9cc216b --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/entity/ResponseConfigValueChange.java @@ -0,0 +1,67 @@ +package aiyh.utils.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; + + /** 分配字段名 */ + @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; + + /** 接口响应值 */ + private Object jsonData; + + 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/main/java/aiyh/utils/response_deal/entity/RowDefinition.java b/src/main/java/aiyh/utils/response_deal/entity/RowDefinition.java new file mode 100644 index 0000000..42f6f80 --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/entity/RowDefinition.java @@ -0,0 +1,51 @@ +package aiyh.utils.response_deal.entity; + +import aiyh.utils.response_deal.intfaces.RowDefinitionCallback; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; +import java.util.Map; + +/** + * @ClassName RowDefinition + * @Author 肖博亢 + * @Date 2023/7/8 16:54 + * @Description

+ **/ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class RowDefinition { + + /** 数据ID执行sql后返回 */ + private int dataId; + + /** 赋值表名 **/ + private String assignTable; + + /** 主表行还是明细行 */ + private int mainOrDetail; + + /** 判断表达式 */ + private String judgmentScript; + + /** 条件表达式 */ + private String conditionScript; + + /** 数据写入方式 */ + private int assignType; + + private RowDefinitionCallback rowDefinitionCallback; + + private Map updateParam; + + private Map whereParam; + + Map detailTableMap; + + private List fieldDefinitionList; +} diff --git a/src/main/java/aiyh/utils/response_deal/entity/TableDefinition.java b/src/main/java/aiyh/utils/response_deal/entity/TableDefinition.java new file mode 100644 index 0000000..cdb72ef --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/entity/TableDefinition.java @@ -0,0 +1,71 @@ +package aiyh.utils.response_deal.entity; + +import aiyh.utils.response_deal.intfaces.TableDefinitionCallback; +import aiyh.utils.response_deal.state.State; +import aiyh.utils.response_deal.state.StateFactory; +import aiyh.utils.response_deal.util.ResponseUtil; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; +import java.util.Map; + +/** + * @ClassName TableDefinition + * @Author 肖博亢 + * @Date 2023/7/7 14:30 + * @Description

+ **/ +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class TableDefinition { + + /** 赋值表名 **/ + private String assignTable; + + /** 表类型 0:建模表;1:流程表;2:自定义表 */ + private int tableType; + + /** 主表还是明细表 */ + private int mainOrDetail; + + /** 判断表达式 */ + private String judgmentScript; + + /** 条件表达式 */ + private String conditionScript; + + /** 数据写入方式 */ + private int assignType; + + /** 数据状态 */ + private State state; + + private TableDefinitionCallback tableDefinitionCallback; + + private List rowDefinitionList; + + private Map detailTableMap; + + public void setState(State state) { + this.state = state; + if(ResponseUtil.parameterIsNotNull(state)) { + this.state.setContext(this); + } + } + + public void setDefaultState(Class classKey) { + this.state = ResponseUtil.parameterIsNull(this.state) + ? StateFactory.createState(classKey,this.getAssignType()) + : this.state; + this.state.setContext(this); + } + + public void dataProcess(){ + this.state.handle(); + } +} diff --git a/src/main/java/aiyh/utils/response_deal/exception/ResponseException.java b/src/main/java/aiyh/utils/response_deal/exception/ResponseException.java new file mode 100644 index 0000000..9b33679 --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/exception/ResponseException.java @@ -0,0 +1,68 @@ +package aiyh.utils.response_deal.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/main/java/aiyh/utils/response_deal/intfaces/DataChangeInterface.java b/src/main/java/aiyh/utils/response_deal/intfaces/DataChangeInterface.java new file mode 100644 index 0000000..c581ef8 --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/intfaces/DataChangeInterface.java @@ -0,0 +1,24 @@ +package aiyh.utils.response_deal.intfaces; + + +import aiyh.utils.response_deal.entity.ResponseConfigValueChange; + +import java.util.Map; + +/** + * @ClassName DataChangeInterface + * @Author 肖博亢 + * @Date 2023/7/7 12:10 + * @Description

+ **/ +public interface DataChangeInterface { + + /** + * 自定义转换接口 + * @param responseConfigValueChange 配置信息 + * @param param 参数信息 + * @param pathParam 路径参数 + * @return 转换后的值 + */ + Object change(ResponseConfigValueChange responseConfigValueChange, Map param, Map pathParam); +} diff --git a/src/main/java/aiyh/utils/response_deal/intfaces/FieldDefinitionCallback.java b/src/main/java/aiyh/utils/response_deal/intfaces/FieldDefinitionCallback.java new file mode 100644 index 0000000..26acdb2 --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/intfaces/FieldDefinitionCallback.java @@ -0,0 +1,15 @@ +package aiyh.utils.response_deal.intfaces; + + +import aiyh.utils.response_deal.entity.FieldDefinition; + +/** + * @ClassName FieldDefinitionCallback + * @Author 肖博亢 + * @Date 2023/7/10 13:38 + * @Description

+ **/ +public interface FieldDefinitionCallback { + + void fieldHandle(FieldDefinition fieldDefinition); +} diff --git a/src/main/java/aiyh/utils/response_deal/intfaces/RowDefinitionCallback.java b/src/main/java/aiyh/utils/response_deal/intfaces/RowDefinitionCallback.java new file mode 100644 index 0000000..7d70b12 --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/intfaces/RowDefinitionCallback.java @@ -0,0 +1,17 @@ +package aiyh.utils.response_deal.intfaces; + + +import aiyh.utils.response_deal.entity.RowDefinition; + +/** + * @ClassName RowDefinitionCallback + * @Author 肖博亢 + * @Date 2023/7/10 13:36 + * @Description

+ **/ +public interface RowDefinitionCallback { + + void rowHandle(RowDefinition rowDefinition); + + boolean judgmentRepetition(RowDefinition rowDefinition); +} diff --git a/src/main/java/aiyh/utils/response_deal/intfaces/TableDefinitionCallback.java b/src/main/java/aiyh/utils/response_deal/intfaces/TableDefinitionCallback.java new file mode 100644 index 0000000..700f5af --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/intfaces/TableDefinitionCallback.java @@ -0,0 +1,16 @@ +package aiyh.utils.response_deal.intfaces; + + +import aiyh.utils.response_deal.entity.TableDefinition; + +/** + * @ClassName DataCallbackInterface + * @Author 肖博亢 + * @Date 2023/7/10 13:04 + * @Description

+ **/ +public interface TableDefinitionCallback { + + void tableHandle(TableDefinition tableDefinition); + +} diff --git a/src/main/java/aiyh/utils/response_deal/mapper/ConfigMapper.java b/src/main/java/aiyh/utils/response_deal/mapper/ConfigMapper.java new file mode 100644 index 0000000..927d986 --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/mapper/ConfigMapper.java @@ -0,0 +1,104 @@ +package aiyh.utils.response_deal.mapper; + +import aiyh.utils.annotation.recordset.*; +import aiyh.utils.response_deal.entity.ResponseConfig; +import aiyh.utils.response_deal.entity.ResponseConfigAlias; +import aiyh.utils.response_deal.entity.ResponseConfigValueChange; + +import java.util.List; +import java.util.Map; + +/** + * @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_dt3 where mainid = #{mainId}") + @CollectionMethod(2) + List queryResponseConfigValueChange(@ParamMapper("mainId")int mainId); + + /** + *

执行自定义查询sql

+ * @param cusSql 自定义sql + * @param param 参数信息 + * @return 查询结果 + */ + @Select(custom = true) + String executeCusQuerySql(@SqlString String cusSql,@ParamMapper("whereItem") Map whereParam,@ParamMapper("param")Map param); + + /** + *

执行自定义更新sql

+ * @param cusSql 自定义sql + * @param updateParam 更新参数信息 + * @param whereParam 条件参数信息 + * @return 查询结果 + */ + @Update(custom = true) + boolean executeUpdateCusSql(@SqlString String cusSql, + @ParamMapper("updateParam")Map updateParam, + @ParamMapper("whereParam")Map whereParam); + + /** + *

执行自定义批量新增sql

+ * @param cusSql 自定义sql + * @param insertList 新镇参数信息 + * @return 处理结果 + */ + @BatchInsert(custom = true) + boolean executeInsertBatchCusSql(@SqlString String cusSql, + @BatchSqlArgs List> insertList); + + /** + *

执行自定义批量更新sql

+ * @param cusSql 自定义sql + * @param updateList 更新参数信息 + * @param whereList 条件参数信息 + * @return 处理结果 + */ + @BatchUpdate(custom = true) + boolean executeUpdateBatchCusSql(@SqlString String cusSql, + @BatchSqlArgs("upItem") List> updateList, + @BatchSqlArgs("whereItem") List> whereList); + +} diff --git a/src/main/java/aiyh/utils/response_deal/process/DataChangeProcess.java b/src/main/java/aiyh/utils/response_deal/process/DataChangeProcess.java new file mode 100644 index 0000000..d2d2703 --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/process/DataChangeProcess.java @@ -0,0 +1,205 @@ +package aiyh.utils.response_deal.process; + +import aiyh.utils.Util; +import aiyh.utils.annotation.MethodRuleNo; +import aiyh.utils.excention.CustomerException; +import aiyh.utils.response_deal.entity.ResponseConfigValueChange; +import aiyh.utils.response_deal.exception.ResponseException; +import aiyh.utils.response_deal.intfaces.DataChangeInterface; +import aiyh.utils.response_deal.mapper.ConfigMapper; +import org.apache.commons.lang3.StringUtils; +import org.apache.log4j.Logger; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.HashMap; +import java.util.Map; +import java.util.function.BiFunction; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @ClassName DataChangeProcess + * @Author 肖博亢 + * @Date 2023/7/7 10:55 + * @Description

+ **/ +public class DataChangeProcess { + + public static final Map,String>> MODE_METHOD_MAP = new HashMap<>(); + + private static final ConfigMapper CONFIG_MAPPER = Util.getMapper(ConfigMapper.class); + + public static final Logger logger = Util.getLogger(); + + static { + try { + Class dataChangeProcessClass = DataChangeProcess.class; + Method[] methods = dataChangeProcessClass.getDeclaredMethods(); + for (Method method : methods) { + if (method.isAnnotationPresent(MethodRuleNo.class)) { + MethodRuleNo annotation = method.getAnnotation(MethodRuleNo.class); + int value = annotation.value(); + MODE_METHOD_MAP.put(value, (responseConfigValueChange,param) -> { + try { + return (String) method.invoke(null,responseConfigValueChange,param); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + }); + } + } + }catch (Exception exception){ + logger.error("DataChangeProcess init error !!! "+Util.getErrString(exception)); + } + } + + /** + * 默认值处理方式 + * @param responseConfigValueChange 赋值转换配置信息 + * @param param 参数 + * @return 结果 + */ + @MethodRuleNo(value = 0, desc = "默认值") + public static String defaultValue(ResponseConfigValueChange responseConfigValueChange,Map param){ + String cusText = responseConfigValueChange.getCusText(); + cusText = Util.dbc2sbcCase(cusText); + responseConfigValueChange.setJsonData(cusText); + return ""; + } + + /** + * sql转换处理方式 + * @param responseConfigValueChange 赋值转换配置信息 + * @param param 参数 + * @return 结果 + */ + @MethodRuleNo(value = 1, desc = "sql转换") + public static String sqlChange(ResponseConfigValueChange responseConfigValueChange,Map param){ + String cusText = responseConfigValueChange.getCusText(); + cusText = Util.dbc2sbcCase(cusText); + if(StringUtils.isBlank(cusText)){ + throw new CustomerException("when selecting Custom sql, the sql string cannot be empty !!!"); + } + if(!cusText.startsWith("select ")){ + throw new CustomerException("When you select custom sql, you are not allowed to perform dangerous operations other than SELECT !!!"); + } + String tempValue = CONFIG_MAPPER.executeCusQuerySql(cusText, param,new HashMap<>()); + responseConfigValueChange.setJsonData(tempValue); + return ""; + } + + /** + * 日期转换处理方式 + * @param responseConfigValueChange 赋值转换配置信息 + * @param param 参数 + * @return 结果 + */ + @MethodRuleNo(value = 2, desc = "日期转换") + public static String dateChange(ResponseConfigValueChange responseConfigValueChange,Map param){ + String cusText = responseConfigValueChange.getCusText(); + Object jsonData = responseConfigValueChange.getJsonData(); + cusText = Util.dbc2sbcCase(cusText); + String fromStr = getDateFormat(cusText,"from:\\{(.*?)\\}"); + String toStr = getDateFormat(cusText,"to:\\{(.*?)\\}"); + responseConfigValueChange.setJsonData(formatDateTime(Util.null2String(jsonData),fromStr,toStr)); + return ""; + } + + /** + * 自定义接口处理方式 + * @param responseConfigValueChange 赋值转换配置信息 + * @param param 参数 + * @return 结果 + */ + @MethodRuleNo(value = 3, desc = "自定义接口") + public static String cusInterface(ResponseConfigValueChange responseConfigValueChange,Map param){ + String cusText = responseConfigValueChange.getCusText(); + cusText = Util.dbc2sbcCase(cusText); + if(StringUtils.isBlank(cusText)){ + throw new CustomerException("The operation full path cannot be empty !!!"); + } + Map pathParam = new HashMap<>(); + try { + DataChangeInterface cusInterfaceObj = getCusInterfaceObj(cusText, DataChangeInterface.class, pathParam); + Object change = cusInterfaceObj.change(responseConfigValueChange, param, pathParam); + responseConfigValueChange.setJsonData(change); + }catch (Exception e){ + logger.error("自定义处理类执行异常 ==>"+Util.getErrString(e)); + throw new ResponseException(e); + } + return ""; + } + + /** + * 日期转换处理方式 + * @param responseConfigValueChange 赋值转换配置信息 + * @param param 参数 + * @return 结果 + */ + @MethodRuleNo(value = 4, desc = "无需转换") + public static String noChange(ResponseConfigValueChange responseConfigValueChange,Map param){ + return ""; + } + + /** + *

+ * @param path 全路径类名 + * @param clazz 父类接口 + * @param pathParamMap 路径参数 + * @return 接口实现类 + * @param 泛型 + */ + public static T getCusInterfaceObj(String path, Class clazz, Map pathParamMap) { + + path = Util.sbc2dbcCase(path); + String[] split = path.split("\\?"); + String classPath = split[0]; + Class aClass; + try { + aClass = Class.forName(classPath); + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException("未能找到自定义接口:" + classPath); + } + if (!clazz.isAssignableFrom(aClass)) { + throw new IllegalArgumentException("自定义接口:" + classPath + " 不是" + + clazz.getName() + "的子类或实现类!"); + } + Constructor constructor; + try { + constructor = aClass.getConstructor(); + } catch (NoSuchMethodException e) { + throw new IllegalArgumentException(classPath + "没有空参构造方法,无法获取构造方法对象!"); + } + T o; + try { + o = (T) constructor.newInstance(); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { + throw new IllegalArgumentException("无法构造" + classPath + "对象!"); + } + pathParamMap.putAll(Util.parseCusInterfacePathParam(path)); + return o; + } + + private static String getDateFormat(String cusText,String regex){ + String formatStr = ""; + Pattern fromPattern = Pattern.compile(regex); + Matcher fromMatcher = fromPattern.matcher(cusText); + if (fromMatcher.find()) { + formatStr = fromMatcher.group(1); + } + return formatStr; + } + + public static String formatDateTime(String dateTimeString, String originalFormat, String targetFormat) { + DateTimeFormatter originalFormatter = DateTimeFormatter.ofPattern(originalFormat); + DateTimeFormatter targetFormatter = DateTimeFormatter.ofPattern(targetFormat); + + LocalDateTime dateTime = LocalDateTime.parse(dateTimeString, originalFormatter); + + return dateTime.format(targetFormatter); + } +} diff --git a/src/main/java/aiyh/utils/response_deal/process/TypeChangeProcess.java b/src/main/java/aiyh/utils/response_deal/process/TypeChangeProcess.java new file mode 100644 index 0000000..d691497 --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/process/TypeChangeProcess.java @@ -0,0 +1,88 @@ +package aiyh.utils.response_deal.process; + +import aiyh.utils.Util; +import aiyh.utils.annotation.MethodRuleNo; +import org.apache.log4j.Logger; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Function; + +/** + * @ClassName TypeChangeProcess + * @Author 肖博亢 + * @Date 2023/7/7 13:30 + * @Description

+ **/ +public class TypeChangeProcess { + + public static final Map> MODE_METHOD_MAP = new HashMap<>(); + + public static final Logger logger = Util.getLogger(); + + static { + try { + Class typeChangeProcessClass = TypeChangeProcess.class; + Method[] methods = typeChangeProcessClass.getDeclaredMethods(); + for (Method method : methods) { + if (method.isAnnotationPresent(MethodRuleNo.class)) { + MethodRuleNo annotation = method.getAnnotation(MethodRuleNo.class); + int value = annotation.value(); + MODE_METHOD_MAP.put(value, (sourceValue) -> { + try { + return method.invoke(null,sourceValue); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + }); + } + } + }catch (Exception exception){ + logger.error("typeChangeProcessClass init error !!! "+ Util.getErrString(exception)); + } + } + + /** + * String类型 + * @param sourceValue 原值 + * @return 结果 + */ + @MethodRuleNo(value = 0, desc = "String类型") + public static Object changString(Object sourceValue){ + return Util.null2String(sourceValue); + } + + /** + * int类型 + * @param sourceValue 原值 + * @return 结果 + */ + @MethodRuleNo(value = 1, desc = "int类型") + public static Object changInt(Object sourceValue){ + return Util.getIntValue(Util.null2String(sourceValue)); + } + + /** + * boolean类型 + * @param sourceValue 原值 + * @return 结果 + */ + @MethodRuleNo(value = 2, desc = "boolean类型") + public static Object changBoolean(Object sourceValue){ + return sourceValue; + } + + /** + * double类型 + * @param sourceValue 原值 + * @return 结果 + */ + @MethodRuleNo(value = 3, desc = "double类型") + public static Object changDouble(Object sourceValue){ + return Util.getDoubleValue(Util.null2String(sourceValue)); + } + + +} diff --git a/src/main/java/aiyh/utils/response_deal/state/InsertOrUpdateState.java b/src/main/java/aiyh/utils/response_deal/state/InsertOrUpdateState.java new file mode 100644 index 0000000..549969d --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/state/InsertOrUpdateState.java @@ -0,0 +1,71 @@ +package aiyh.utils.response_deal.state; + +import aiyh.utils.response_deal.constant.ResponseConfigConstant; +import aiyh.utils.response_deal.entity.RowDefinition; +import aiyh.utils.response_deal.entity.TableDefinition; +import aiyh.utils.response_deal.intfaces.RowDefinitionCallback; +import aiyh.utils.response_deal.util.ResponseUtil; +import aiyh.utils.tool.cn.hutool.core.bean.BeanUtil; +import aiyh.utils.tool.cn.hutool.core.util.StrUtil; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** + * @ClassName InsertOrUpdateState + * @Author 肖博亢 + * @Date 2023/7/9 23:34 + * @Description

+ **/ +public class InsertOrUpdateState extends State{ + + @Override + public void handle() { + if(ResponseUtil.parameterIsNotNull(this.context.getTableDefinitionCallback())){ + this.context.getTableDefinitionCallback().tableHandle(this.context); + } + List rowDefinitionList = this.context.getRowDefinitionList(); + List updateRowList = new ArrayList<>(); + List insertRowList = new ArrayList<>(); + for (RowDefinition rowDefinition : rowDefinitionList) { + boolean isRepetition = false; + if(ResponseUtil.parameterIsNotNull(rowDefinition.getRowDefinitionCallback())){ + RowDefinitionCallback rowDefinitionCallback = rowDefinition.getRowDefinitionCallback(); + isRepetition = rowDefinitionCallback.judgmentRepetition(rowDefinition); + }else { + isRepetition = this.judgmentRepetition(rowDefinition); + } + if(isRepetition){ + updateRowList.add(rowDefinition); + }else { + insertRowList.add(rowDefinition); + } + } + if(ResponseUtil.parameterIsNotNull(updateRowList)){ + this.tableProcess(ResponseConfigConstant.UPDATE,updateRowList); + } + if(ResponseUtil.parameterIsNotNull(insertRowList)){ + this.tableProcess(ResponseConfigConstant.INSERT,insertRowList); + } + } + + private void tableProcess(int assignType,List rowDefinitionList){ + TableDefinition tableDefinition = new TableDefinition(); + BeanUtil.copyProperties(this.context,tableDefinition); + tableDefinition.setState(null); + tableDefinition.setRowDefinitionList(rowDefinitionList); + tableDefinition.setTableDefinitionCallback(null); + tableDefinition.setAssignType(assignType); + tableDefinition.setDefaultState(null); + tableDefinition.dataProcess(); + } + + private boolean judgmentRepetition(RowDefinition rowDefinition){ + String conditionScript = rowDefinition.getConditionScript(); + String cusQuerySql = "select id from " + rowDefinition.getAssignTable() + " where " + conditionScript; + String dataId = this.configMapper.executeCusQuerySql(cusQuerySql, rowDefinition.getWhereParam(),new HashMap<>()); + return StrUtil.isNotBlank(dataId); + } + +} diff --git a/src/main/java/aiyh/utils/response_deal/state/InsertSate.java b/src/main/java/aiyh/utils/response_deal/state/InsertSate.java new file mode 100644 index 0000000..5d8aba1 --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/state/InsertSate.java @@ -0,0 +1,98 @@ +package aiyh.utils.response_deal.state; + +import aiyh.utils.Util; +import aiyh.utils.recordset.MapperBuilderSql; +import aiyh.utils.response_deal.constant.ResponseConfigConstant; +import aiyh.utils.response_deal.entity.RowDefinition; +import aiyh.utils.response_deal.entity.TableDefinition; +import aiyh.utils.response_deal.intfaces.RowDefinitionCallback; +import aiyh.utils.response_deal.util.ResponseUtil; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * @ClassName InsertSate + * @Author 肖博亢 + * @Date 2023/7/9 23:32 + * @Description

+ **/ +public class InsertSate extends State{ + @Override + public void handle() { + int tableType = this.context.getTableType(); + int mainOrDetail = this.context.getMainOrDetail(); + List rowDefinitionList = this.context.getRowDefinitionList(); + Map detailTableMap = ResponseUtil.parameterIsNull(this.context.getDetailTableMap()) ? + new HashMap<>() : this.context.getDetailTableMap(); + String assignTable = this.context.getAssignTable(); + if(ResponseUtil.parameterIsNull(rowDefinitionList)){ + logger.info(String.format("表:%s 没有数据需要新增",assignTable)); + return; + } + if(ResponseUtil.parameterIsNotNull(this.context.getTableDefinitionCallback())){ + this.context.getTableDefinitionCallback().tableHandle(this.context); + } + rowDefinitionList.forEach(item ->{ + if(ResponseUtil.parameterIsNotNull(item.getRowDefinitionCallback())){ + RowDefinitionCallback rowDefinitionCallback = item.getRowDefinitionCallback(); + rowDefinitionCallback.rowHandle(item); + } + }); + RowDefinition tempRowDefinition = rowDefinitionList.get(0); + if(tableType == ResponseConfigConstant.MODEL_TABLE && mainOrDetail == ResponseConfigConstant.MAIN_TABLE){ + List> updateList = new ArrayList<>(); + List> whereList = new ArrayList<>(); + List dataIdList = new ArrayList<>(); + for (RowDefinition rowDefinition : rowDefinitionList) { + int dataId = Util.getModeDataId(assignTable, 1); + rowDefinition.getWhereParam().put("id",dataId); + updateList.add(rowDefinition.getUpdateParam()); + whereList.add(rowDefinition.getWhereParam()); + rowDefinition.setDataId(dataId); + if(mainOrDetail == ResponseConfigConstant.MAIN_TABLE){ + detailTableDeal(rowDefinition,detailTableMap); + } + dataIdList.add(dataId); + } + String updateSql = MapperBuilderSql.builderUpdateSql(assignTable, tempRowDefinition.getUpdateParam(),"upItem"); + updateSql = updateSql + " where id = #{whereItem.id}"; + boolean flag = this.configMapper.executeUpdateBatchCusSql(updateSql, updateList, whereList); + String modeId = Util.getModeIdByTableName(assignTable); + Util.rebuildModeDataShareByAsyncList(1,modeId,dataIdList); + if(ResponseUtil.parameterIsNotNull(detailTableMap) && flag){ + detailTableMap.forEach((key,value)->{ + value.setDefaultState(null); + value.dataProcess(); + }); + } + }else { + String insertSql = MapperBuilderSql.builderInsertSql(assignTable, tempRowDefinition.getUpdateParam(),"item"); + List> insertList = rowDefinitionList.stream().map(RowDefinition::getUpdateParam).collect(Collectors.toList()); + boolean flag = this.configMapper.executeInsertBatchCusSql(insertSql, insertList); + } + } + + private void detailTableDeal(RowDefinition rowDefinition,Map mainDetailMap){ + int mainId = rowDefinition.getDataId(); + Map detailTableMap = rowDefinition.getDetailTableMap(); + detailTableMap.forEach((key,value) ->{ + List rowDefinitionList = value.getRowDefinitionList(); + if(ResponseUtil.parameterIsNull(rowDefinitionList)){ + return; + } + rowDefinitionList.forEach(item ->{ + item.getUpdateParam().put("mainid",mainId); + }); + if(mainDetailMap.containsKey(key)){ + TableDefinition tableDefinition = mainDetailMap.get(key); + tableDefinition.getRowDefinitionList().addAll(rowDefinitionList); + }else { + mainDetailMap.put(key,value); + } + }); + } +} diff --git a/src/main/java/aiyh/utils/response_deal/state/State.java b/src/main/java/aiyh/utils/response_deal/state/State.java new file mode 100644 index 0000000..6bea1b3 --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/state/State.java @@ -0,0 +1,33 @@ +package aiyh.utils.response_deal.state; + +import aiyh.utils.Util; +import aiyh.utils.response_deal.entity.TableDefinition; +import aiyh.utils.response_deal.mapper.ConfigMapper; +import org.apache.log4j.Logger; + +/** + * @ClassName State + * @Author 肖博亢 + * @Date 2023/7/9 23:27 + * @Description

+ **/ +public abstract class State { + + protected final ConfigMapper configMapper = Util.getMapper(ConfigMapper.class); + + /** 日志对象 */ + protected final Logger logger = Util.getLogger(); + + /** 上下文对象 */ + protected TableDefinition context; + + public void setContext(TableDefinition context) { + this.context = context; + } + + /** + * 抽象处理方法 + */ + public abstract void handle(); + +} diff --git a/src/main/java/aiyh/utils/response_deal/state/StateFactory.java b/src/main/java/aiyh/utils/response_deal/state/StateFactory.java new file mode 100644 index 0000000..b846f12 --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/state/StateFactory.java @@ -0,0 +1,48 @@ +package aiyh.utils.response_deal.state; + +import aiyh.utils.response_deal.constant.ResponseConfigConstant; +import aiyh.utils.response_deal.entity.ResponseConfig; +import aiyh.utils.response_deal.util.ResponseUtil; + +import java.util.HashMap; +import java.util.Map; + +/** + * @ClassName StateFactory + * @Author 肖博亢 + * @Date 2023/7/9 23:34 + * @Description

+ **/ +public class StateFactory { + + private static final Map,Map> CLASS_STATE_MAP = new HashMap<>(); + + private static final Map STATE_MAP = new HashMap<>(); + + static { + STATE_MAP.put(ResponseConfigConstant.INSERT,new InsertSate()); + STATE_MAP.put(ResponseConfigConstant.UPDATE,new UpdateState()); + STATE_MAP.put(ResponseConfigConstant.INSERT_OR_UPDATE,new InsertOrUpdateState()); + } + + public static State createState(Class aclass,int assignType){ + Map stateMap = CLASS_STATE_MAP.get(aclass); + State state = null; + if(ResponseUtil.parameterIsNotNull(stateMap)) { + state = stateMap.get(assignType); + } + if(ResponseUtil.parameterIsNull(state)){ + state = STATE_MAP.get(assignType); + } + ResponseUtil.parameterJudgment(state,"Please set the data assignment method !!!"); + return state; + } + + public static synchronized void clearStateMap(){ + CLASS_STATE_MAP.clear(); + } + + public static synchronized void registerSate(Class aclass,Map stateMap){ + CLASS_STATE_MAP.put(aclass,stateMap); + } +} diff --git a/src/main/java/aiyh/utils/response_deal/state/UpdateState.java b/src/main/java/aiyh/utils/response_deal/state/UpdateState.java new file mode 100644 index 0000000..8cd27d6 --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/state/UpdateState.java @@ -0,0 +1,90 @@ +package aiyh.utils.response_deal.state; + +import aiyh.utils.ScriptUtil; +import aiyh.utils.recordset.MapperBuilderSql; +import aiyh.utils.response_deal.constant.ResponseConfigConstant; +import aiyh.utils.response_deal.entity.RowDefinition; +import aiyh.utils.response_deal.entity.TableDefinition; +import aiyh.utils.response_deal.exception.ResponseException; +import aiyh.utils.response_deal.util.ResponseUtil; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @ClassName UpdateState + * @Author 肖博亢 + * @Date 2023/7/9 23:33 + * @Description

+ **/ +public class UpdateState extends State { + @Override + public void handle() { + if(ResponseUtil.parameterIsNotNull(this.context.getTableDefinitionCallback())){ + this.context.getTableDefinitionCallback().tableHandle(this.context); + } + int mainOrDetail = this.context.getMainOrDetail(); + Map detailTableMap = ResponseUtil.parameterIsNull(this.context.getDetailTableMap()) ? + new HashMap<>() : this.context.getDetailTableMap(); + List rowDefinitionList = this.context.getRowDefinitionList(); + String assignTable = this.context.getAssignTable(); + String conditionScript = this.context.getConditionScript(); + if(ResponseUtil.parameterIsNull(conditionScript)){ + throw new ResponseException(String.format("table:%s Unconditional updates are not allowed !!!",assignTable)); + } + try { + boolean res = (boolean) ScriptUtil.invokeScript(conditionScript, new HashMap<>()); + if(res){ + throw new ResponseException(String.format("table:%s The expression cannot be an identity !!!",assignTable)); + } + }catch (Exception e){ + logger.info("表达式不为恒等式"); + } + if(ResponseUtil.parameterIsNull(rowDefinitionList)){ + logger.info(String.format("表:%s 没有数据需要新增",assignTable)); + } + List> updateList = new ArrayList<>(); + List> whereList = new ArrayList<>(); + for (RowDefinition definition : rowDefinitionList) { + if(ResponseUtil.parameterIsNotNull(definition.getRowDefinitionCallback())){ + definition.getRowDefinitionCallback().rowHandle(definition); + } + updateList.add(definition.getUpdateParam()); + updateList.add(definition.getWhereParam()); + } + RowDefinition rowDefinition = rowDefinitionList.get(0); + String updateSql = MapperBuilderSql.builderUpdateSql(assignTable, rowDefinition.getUpdateParam(),"upItem"); + updateSql = updateSql + " " + conditionScript; + boolean flag = this.configMapper.executeUpdateBatchCusSql(updateSql, updateList, whereList); + logger.info("批量更新处理结果 ==>"+flag); + //如果为主表则处理明细数据 + if(mainOrDetail == ResponseConfigConstant.MAIN_TABLE){ + detailTableDeal(detailTableMap); + if(ResponseUtil.parameterIsNotNull(detailTableMap)){ + detailTableMap.forEach((key,value)->{ + value.setDefaultState(null); + value.dataProcess(); + }); + } + } + } + + private void detailTableDeal(Map mainDetailMap){ + List rowDefinitionList = this.context.getRowDefinitionList(); + rowDefinitionList.forEach(item ->{ + Map detailTableMap = item.getDetailTableMap(); + if(ResponseUtil.parameterIsNull(detailTableMap)){ + return; + } + detailTableMap.forEach((key,value) ->{ + if(mainDetailMap.containsKey(key)){ + mainDetailMap.get(key).getRowDefinitionList().addAll(value.getRowDefinitionList()); + }else { + mainDetailMap.put(key,value); + } + }); + }); + } +} diff --git a/src/main/java/aiyh/utils/response_deal/store/ResponseStore.java b/src/main/java/aiyh/utils/response_deal/store/ResponseStore.java new file mode 100644 index 0000000..f245fd7 --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/store/ResponseStore.java @@ -0,0 +1,63 @@ +package aiyh.utils.response_deal.store; + +import aiyh.utils.Util; + +import aiyh.utils.response_deal.entity.ResponseConfig; +import aiyh.utils.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 ResponseStore + * @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(); + } +} diff --git a/src/main/java/aiyh/utils/response_deal/util/ResponseUtil.java b/src/main/java/aiyh/utils/response_deal/util/ResponseUtil.java new file mode 100644 index 0000000..d11c3c6 --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/util/ResponseUtil.java @@ -0,0 +1,40 @@ +package aiyh.utils.response_deal.util; + + +import aiyh.utils.response_deal.exception.ResponseException; + +import java.util.List; +import java.util.Map; + +/** + * @ClassName ResponseUtil + * @Author 肖博亢 + * @Date 2023/7/6 18:08 + * @Description

+ **/ +public class ResponseUtil { + + public static void parameterJudgment(Object o,String message){ + if(parameterIsNull(o)) {throw new ResponseException(message);} + } + + public static boolean parameterIsNull(Object o){ + if(o == null){ + return true; + } + if(o instanceof List){ + List list = (List) o; + return list.isEmpty(); + } + if(o instanceof Map){ + Map map = (Map) o; + return map.isEmpty(); + } + return false; + } + + public static boolean parameterIsNotNull(Object o){ + return !parameterIsNull(o); + } + +} diff --git a/src/main/java/com/api/bokang/xiao/zhenn/mapper/BankMapper.java b/src/main/java/com/api/bokang/xiao/zhenn/mapper/BankMapper.java index ab334d7..8bbed02 100644 --- a/src/main/java/com/api/bokang/xiao/zhenn/mapper/BankMapper.java +++ b/src/main/java/com/api/bokang/xiao/zhenn/mapper/BankMapper.java @@ -120,6 +120,18 @@ public interface BankMapper { " AND $t{currencyField} = #{currency}") List> queryOaOtherList(Map param); + /** + *

查询托收等付款信息

+ * @param param 查询参数 + * @return 付款信息列表 + */ + @Select("select $t{requestIdField} requestId,$t{amountField} amount,$t{amountField} outAmount," + + " $t{inCompany} inCompany,$t{outDateField} outDate,$t{bankFlowField} bankFlow " + + "from $t{tableName} t " + + "where $t{bankFlowField} is not null " + + " and $t{outDateField} BETWEEN #{beginDate} AND #{endDate} ") + List> queryOaOutOtherList(Map param); + /** *

查询流程付款信息

* @param param 查询参数 diff --git a/src/main/java/com/api/bokang/xiao/zhenn/service/BankService.java b/src/main/java/com/api/bokang/xiao/zhenn/service/BankService.java index ca20c93..b9835a9 100644 --- a/src/main/java/com/api/bokang/xiao/zhenn/service/BankService.java +++ b/src/main/java/com/api/bokang/xiao/zhenn/service/BankService.java @@ -12,10 +12,7 @@ import weaver.bokang.xiao.common.mapper.WorkflowMapper; import weaver.hrm.User; import java.io.OutputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -106,30 +103,41 @@ public class BankService { return tempOutList.stream(); }) .collect(Collectors.toList()); + //List> oaOutOtherList = outOtherParam.stream().flatMap(item -> { + // item.put("beginDate", Util.null2String(param.get("beginDate"))); + // item.put("endDate", Util.null2String(param.get("endDate"))); + // String detailId = Util.null2String(item.get("detailId")); + // if(StringUtils.isNotBlank(detailId)){ + // String table = Util.null2String(item.get("tableName")); + // String detailTale = table + "_" + detailId; + // item.put("detailTable",detailTale); + // return bankMapper.queryOaOtherDetailList(item).stream(); + // } + // return bankMapper.queryOaOtherList(item).stream(); + //}).collect(Collectors.toList()); + //获取托收等其他不走银企直联的付款信息 List> oaOutOtherList = outOtherParam.stream().flatMap(item -> { item.put("beginDate", Util.null2String(param.get("beginDate"))); item.put("endDate", Util.null2String(param.get("endDate"))); - String detailId = Util.null2String(item.get("detailId")); - if(StringUtils.isNotBlank(detailId)){ - String table = Util.null2String(item.get("tableName")); - String detailTale = table + "_" + detailId; - item.put("detailTable",detailTale); - return bankMapper.queryOaOtherDetailList(item).stream(); - } - return bankMapper.queryOaOtherList(item).stream(); - }).collect(Collectors.toList()); - List> oaInOtherList = inOtherParam.stream().flatMap(item -> { - item.put("beginDate", Util.null2String(param.get("beginDate"))); - item.put("endDate", Util.null2String(param.get("endDate"))); - String detailId = Util.null2String(item.get("detailId")); - if(StringUtils.isNotBlank(detailId)){ - String table = Util.null2String(item.get("tableName")); - String detailTale = table + "_" + detailId; - item.put("detailTable",detailTale); - return bankMapper.queryOaOtherDetailList(item).stream(); - } - return bankMapper.queryOaOtherList(item).stream(); + return bankMapper.queryOaOutOtherList(item).stream(); }).collect(Collectors.toList()); + //获取其他收款信息 + List> oaInOtherList = new ArrayList<>(); + if(Objects.nonNull(inOtherParam) && !inOtherParam.isEmpty()) { + oaInOtherList = inOtherParam.stream().flatMap(item -> { + item.put("beginDate", Util.null2String(param.get("beginDate"))); + item.put("endDate", Util.null2String(param.get("endDate"))); + String detailId = Util.null2String(item.get("detailId")); + if (StringUtils.isNotBlank(detailId)) { + String table = Util.null2String(item.get("tableName")); + String detailTale = table + "_" + detailId; + item.put("detailTable", detailTale); + return bankMapper.queryOaOtherDetailList(item).stream(); + } + return bankMapper.queryOaOtherList(item).stream(); + }).collect(Collectors.toList()); + } + //获取银企直联收款信息 List> oaInList = inParam.stream() .flatMap(item -> { item.put("currentBankAccount",bankAccount); diff --git a/src/main/java/weaver/bokang/xiao/shtx/schedule/SyncTeachDataSchedule.java b/src/main/java/weaver/bokang/xiao/shtx/schedule/SyncTeachDataSchedule.java new file mode 100644 index 0000000..af32dd3 --- /dev/null +++ b/src/main/java/weaver/bokang/xiao/shtx/schedule/SyncTeachDataSchedule.java @@ -0,0 +1,119 @@ +package weaver.bokang.xiao.shtx.schedule; + +import aiyh.utils.Util; +import aiyh.utils.action.CusBaseCronJob; +import aiyh.utils.annotation.ActionDesc; +import aiyh.utils.annotation.PrintParamMark; +import aiyh.utils.annotation.RequiredMark; +import aiyh.utils.httpUtil.ResponeVo; +import aiyh.utils.httpUtil.util.HttpUtils; +import aiyh.utils.response_deal.ResponseMappingDeal; +import aiyh.utils.tool.cn.hutool.core.util.StrUtil; +import lombok.Setter; +import weaver.xiao.commons.config.entity.RequestMappingConfig; +import weaver.xiao.commons.config.service.DealWithMapping; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +/** + * @ClassName SyncTeachDataSchedule + * @Author 肖博亢 + * @Date 2023/7/11 14:27 + * @Description

同步教研资数据定时任务

+ **/ +@Setter +@ActionDesc(value = "同步教研资数据", author = "bokang.xiao") +public class SyncTeachDataSchedule extends CusBaseCronJob { + + @RequiredMark("教学情况汇总表同步唯一标识") + @PrintParamMark + private String teachingSituationUnique; + + @RequiredMark("课时研发表同步唯一标识") + @PrintParamMark + private String classResearchUnique; + + @RequiredMark("校内外教研资活动同步唯一标识") + @PrintParamMark + private String schoolInOutUnique; + + @RequiredMark("科研与资政同步唯一标识") + @PrintParamMark + private String scientificResearch; + + @RequiredMark("科研课题同步唯一标识") + @PrintParamMark + private String subjectUnique; + + @RequiredMark("科研成功唯一标识") + @PrintParamMark + private String resultUnique; + + private final HttpUtils httpUtils = new HttpUtils(); + + private final DealWithMapping dealWithMapping = new DealWithMapping(); + + private final ResponseMappingDeal responseMappingDeal = new ResponseMappingDeal(); + + @Override + public void runCode() throws IOException { + // 同步教学情况汇总表 + if (StrUtil.isNotBlank(teachingSituationUnique)) { + this.syncDeal(teachingSituationUnique); + } + + // 同步课时研发表 + if (StrUtil.isNotBlank(classResearchUnique)) { + this.syncDeal(classResearchUnique); + } + + // 同步校内外教研资活动 + if (StrUtil.isNotBlank(schoolInOutUnique)) { + this.syncDeal(schoolInOutUnique); + } + + // 同步科研与资政 + if (StrUtil.isNotBlank(scientificResearch)) { + this.syncDeal(scientificResearch); + } + + // 同步科研课题 + if (StrUtil.isNotBlank(subjectUnique)) { + this.syncDeal(subjectUnique); + } + + // 同步科研成功 + if (StrUtil.isNotBlank(resultUnique)) { + this.syncDeal(resultUnique); + } + } + + /** + * 执行同步操作 + * + * @param requestUnique 请求唯一标识 + * @throws IOException IO异常 + */ + private void syncDeal(String requestUnique) throws IOException { + // 根据请求唯一标识获取请求配置 + RequestMappingConfig requestMappingConfig = dealWithMapping.treeDealWithUniqueCode(requestUnique); + // 获取请求参数 + Map requestParam = dealWithMapping.getRequestParam(new HashMap<>(), requestMappingConfig); + // 发起API POST请求 + ResponeVo responeVo = httpUtils.apiPost(requestMappingConfig.getRequestUrl(), requestParam); + if (responeVo.getCode() == 200) { + Map responseMap = responeVo.getResponseMap(); + String code = Util.null2String(responseMap.get("code")); + if ("0".equals(code)) { + // 处理响应数据 + responseMappingDeal.doResponseSync(requestUnique, responseMap); + } else { + log.error("教研资接口调用失败,code不为0"); + } + } else { + log.error("教研资接口调用失败,接口状态不为200"); + } + } +} diff --git a/src/main/java/weaver/xiao/commons/config/enumtype/GetValueTypeEnum.java b/src/main/java/weaver/xiao/commons/config/enumtype/GetValueTypeEnum.java index 1b27887..c6ef734 100644 --- a/src/main/java/weaver/xiao/commons/config/enumtype/GetValueTypeEnum.java +++ b/src/main/java/weaver/xiao/commons/config/enumtype/GetValueTypeEnum.java @@ -34,7 +34,13 @@ public enum GetValueTypeEnum { CUS_FIELD("10"), /** 自定义mapper sql */ - CUS_MAPPER_SQL("11"); + CUS_MAPPER_SQL("11"), + + /** 前一天 */ + LAST_DAY("12"), + + /** 前一月 */ + LAST_MONTH("13"); private static final Map LOOK_UP = new HashMap<>(8); diff --git a/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java b/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java index a2bbf69..8f47295 100644 --- a/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java +++ b/src/main/java/weaver/xiao/commons/config/service/DealWithMapping.java @@ -16,6 +16,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; import weaver.conn.RecordSet; import weaver.file.ImageFileManager; +import weaver.general.TimeUtil; import weaver.general.Util; import weaver.xiao.commons.config.dao.ConfigMappingCMD; import weaver.xiao.commons.config.entity.*; @@ -808,6 +809,17 @@ public class DealWithMapping extends ToolUtil { value = mapper.selectCustomSql(valueContext, param); } break; + case LAST_DAY:{ + String currentDateString = TimeUtil.getCurrentDateString(); + currentDateString = TimeUtil.dateAdd(currentDateString,-1); + value = currentDateString; + }break; + case LAST_MONTH:{ + Calendar calendar = Calendar.getInstance(); + calendar.setTime(new Date()); + calendar.set(Calendar.MONTH,calendar.get(Calendar.MONTH) - 1); + value = calendar.getTime(); + }break; default: throw new ValueDealException("不支持的取值方式"); } diff --git a/src/test/java/bokang/xiao/NormalTest.java b/src/test/java/bokang/xiao/NormalTest.java index ee14f66..1803b34 100644 --- a/src/test/java/bokang/xiao/NormalTest.java +++ b/src/test/java/bokang/xiao/NormalTest.java @@ -5,11 +5,11 @@ import aiyh.utils.ScriptUtil; import aiyh.utils.Util; import aiyh.utils.httpUtil.ResponeVo; import aiyh.utils.httpUtil.util.HttpUtils; +import aiyh.utils.response_deal.ResponseMappingDeal; import basetest.BaseTest; import bokang.xiao.entity.CourseEntity; import bokang.xiao.entity.StudentEntity; import bokang.xiao.entity.TeacherEntity; -import bokang.xiao.response_deal.ResponseMappingDeal; import bokang.xiao.util.XmlParser; import cn.afterturn.easypoi.excel.ExcelExportUtil; import cn.afterturn.easypoi.excel.entity.ExportParams; @@ -58,7 +58,6 @@ import weaver.bokang.xiao.zxyh.RepeatSubmitAction; import weaver.conn.RecordSet; import weaver.general.StaticObj; import weaver.hrm.User; -import weaver.integration.util.SessionUtil; import weaver.interfaces.datasource.DataSource; import weaver.workflow.workflow.WfForceOver; import weaver.workflow.workflow.WorkflowVersion; diff --git a/src/test/java/bokang/xiao/response_deal/ResponseMappingDeal.java b/src/test/java/bokang/xiao/response_deal/ResponseMappingDeal.java index 6d36c07..b84dced 100644 --- a/src/test/java/bokang/xiao/response_deal/ResponseMappingDeal.java +++ b/src/test/java/bokang/xiao/response_deal/ResponseMappingDeal.java @@ -34,12 +34,18 @@ public class ResponseMappingDeal { private final ConfigMapper configMapper = Util.getMapper(ConfigMapper.class); + /** 表数据回调 */ private TableDefinitionCallback tableCallback; + /** 行数据回调 */ private RowDefinitionCallback rowCallback; + /** 字段数据回调 */ private FieldDefinitionCallback fieldDefinitionCallback; + /** 状态map的key */ + private Class stateClassKey; + public void doResponseSync(String uniqueCode, ResponeVo responeVo) { Map responseMap = responeVo.getResponseMap(); ResponseUtil.parameterJudgment(responseMap,"接口返回都为空 你处理个勾"); @@ -78,12 +84,13 @@ public class ResponseMappingDeal { this.detailTableDeal(responseConfig,responseMap,detailTable); tableDefinition = TableDefinition.builder() .detailTableMap(detailTable) + .tableDefinitionCallback(this.tableCallback) .tableType(responseConfig.getTableType()) .assignType(ResponseConfigConstant.NO_HANDLE) .assignTable(responseConfig.getModelTableName()).build(); } //做数据处理 - tableDefinition.setDefaultState(); + tableDefinition.setDefaultState(stateClassKey); tableDefinition.dataProcess(); } @@ -123,6 +130,7 @@ public class ResponseMappingDeal { .judgmentScript(mainDataAlias.getJudgmentScript()) .tableType(responseConfig.getTableType()) .mainOrDetail(tableMainOrDetail) + .tableDefinitionCallback(this.tableCallback) .assignType(mainDataAlias.getAssignType()).build(); String dataPath = mainDataAlias.getDataPath(); List rowDefinitionList = new ArrayList<>(); @@ -185,6 +193,7 @@ public class ResponseMappingDeal { .assignTable(tableName) .whereParam(wherePram) .fieldDefinitionList(fieldDefinitionList) + .rowDefinitionCallback(this.rowCallback) .judgmentScript(judgmentScript).build(); } @@ -235,6 +244,7 @@ public class ResponseMappingDeal { .tableType(item.getTableType()) .tableName(item.getAssignTable()) .fieldName(item.getAssignFieldName()) + .fieldDefinitionCallback(fieldDefinitionCallback) .fieldValue(targetValue).build(); }).collect(Collectors.toList()); } diff --git a/src/test/java/bokang/xiao/response_deal/entity/TableDefinition.java b/src/test/java/bokang/xiao/response_deal/entity/TableDefinition.java index d8d8e39..5b32d01 100644 --- a/src/test/java/bokang/xiao/response_deal/entity/TableDefinition.java +++ b/src/test/java/bokang/xiao/response_deal/entity/TableDefinition.java @@ -1,8 +1,10 @@ package bokang.xiao.response_deal.entity; +import bokang.xiao.response_deal.ResponseMappingDeal; import bokang.xiao.response_deal.intfaces.TableDefinitionCallback; import bokang.xiao.response_deal.state.State; import bokang.xiao.response_deal.state.StateFactory; +import bokang.xiao.response_deal.util.ResponseUtil; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -52,11 +54,15 @@ public class TableDefinition { public void setState(State state) { this.state = state; - this.state.setContext(this); + if(ResponseUtil.parameterIsNotNull(state)) { + this.state.setContext(this); + } } - public void setDefaultState() { - this.state = StateFactory.createState(this.getAssignType()); + public void setDefaultState(Class classKey) { + this.state = ResponseUtil.parameterIsNull(this.state) + ? StateFactory.createState(classKey,this.getAssignType()) + : this.state; this.state.setContext(this); } diff --git a/src/test/java/bokang/xiao/response_deal/mapper/ConfigMapper.java b/src/test/java/bokang/xiao/response_deal/mapper/ConfigMapper.java index 24b80bb..2b820d5 100644 --- a/src/test/java/bokang/xiao/response_deal/mapper/ConfigMapper.java +++ b/src/test/java/bokang/xiao/response_deal/mapper/ConfigMapper.java @@ -96,7 +96,7 @@ public interface ConfigMapper { * @param whereList 条件参数信息 * @return 处理结果 */ - @BatchInsert(custom = true) + @BatchUpdate(custom = true) boolean executeUpdateBatchCusSql(@SqlString String cusSql, @BatchSqlArgs("upItem") List> updateList, @BatchSqlArgs("whereItem") List> whereList); diff --git a/src/test/java/bokang/xiao/response_deal/state/InsertOrUpdateState.java b/src/test/java/bokang/xiao/response_deal/state/InsertOrUpdateState.java index 1852a60..1de2769 100644 --- a/src/test/java/bokang/xiao/response_deal/state/InsertOrUpdateState.java +++ b/src/test/java/bokang/xiao/response_deal/state/InsertOrUpdateState.java @@ -2,6 +2,7 @@ package bokang.xiao.response_deal.state; import aiyh.utils.tool.cn.hutool.core.bean.BeanUtil; import aiyh.utils.tool.cn.hutool.core.util.StrUtil; +import bokang.xiao.response_deal.constant.ResponseConfigConstant; import bokang.xiao.response_deal.entity.RowDefinition; import bokang.xiao.response_deal.entity.TableDefinition; import bokang.xiao.response_deal.intfaces.RowDefinitionCallback; @@ -18,6 +19,7 @@ import java.util.List; * @Description

**/ public class InsertOrUpdateState extends State{ + @Override public void handle() { if(ResponseUtil.parameterIsNotNull(this.context.getTableDefinitionCallback())){ @@ -41,20 +43,21 @@ public class InsertOrUpdateState extends State{ } } if(ResponseUtil.parameterIsNotNull(updateRowList)){ - this.tableProcess(1,updateRowList); + this.tableProcess(ResponseConfigConstant.UPDATE,updateRowList); } if(ResponseUtil.parameterIsNotNull(insertRowList)){ - this.tableProcess(0,insertRowList); + this.tableProcess(ResponseConfigConstant.INSERT,insertRowList); } } private void tableProcess(int assignType,List rowDefinitionList){ TableDefinition tableDefinition = new TableDefinition(); BeanUtil.copyProperties(this.context,tableDefinition); + tableDefinition.setState(null); tableDefinition.setRowDefinitionList(rowDefinitionList); tableDefinition.setTableDefinitionCallback(null); tableDefinition.setAssignType(assignType); - tableDefinition.setDefaultState(); + tableDefinition.setDefaultState(null); tableDefinition.dataProcess(); } diff --git a/src/test/java/bokang/xiao/response_deal/state/InsertSate.java b/src/test/java/bokang/xiao/response_deal/state/InsertSate.java index 5055875..449ce68 100644 --- a/src/test/java/bokang/xiao/response_deal/state/InsertSate.java +++ b/src/test/java/bokang/xiao/response_deal/state/InsertSate.java @@ -65,7 +65,7 @@ public class InsertSate extends State{ Util.rebuildModeDataShareByAsyncList(1,modeId,dataIdList); if(ResponseUtil.parameterIsNotNull(detailTableMap) && flag){ detailTableMap.forEach((key,value)->{ - value.setDefaultState(); + value.setDefaultState(null); value.dataProcess(); }); } diff --git a/src/test/java/bokang/xiao/response_deal/state/StateFactory.java b/src/test/java/bokang/xiao/response_deal/state/StateFactory.java index cfe08a2..53d1a19 100644 --- a/src/test/java/bokang/xiao/response_deal/state/StateFactory.java +++ b/src/test/java/bokang/xiao/response_deal/state/StateFactory.java @@ -1,6 +1,10 @@ package bokang.xiao.response_deal.state; -import org.docx4j.wml.U; +import bokang.xiao.response_deal.constant.ResponseConfigConstant; +import bokang.xiao.response_deal.util.ResponseUtil; + +import java.util.HashMap; +import java.util.Map; /** * @ClassName StateFactory @@ -10,13 +14,34 @@ import org.docx4j.wml.U; **/ public class StateFactory { - public static State createState(int assignType){ - if(assignType == 0){ - return new InsertSate(); - }else if(assignType == 1){ - return new UpdateState(); - }else { - return new InsertOrUpdateState(); + private static final Map,Map> CLASS_STATE_MAP = new HashMap<>(); + + private static final Map STATE_MAP = new HashMap<>(); + + static { + STATE_MAP.put(ResponseConfigConstant.INSERT,new InsertSate()); + STATE_MAP.put(ResponseConfigConstant.UPDATE,new UpdateState()); + STATE_MAP.put(ResponseConfigConstant.INSERT_OR_UPDATE,new InsertOrUpdateState()); + } + + public static State createState(Class aclass,int assignType){ + Map stateMap = CLASS_STATE_MAP.get(aclass); + State state = null; + if(ResponseUtil.parameterIsNotNull(stateMap)) { + state = stateMap.get(assignType); } + if(ResponseUtil.parameterIsNull(state)){ + state = STATE_MAP.get(assignType); + } + ResponseUtil.parameterJudgment(state,"Please set the data assignment method !!!"); + return state; + } + + public static synchronized void clearStateMap(){ + CLASS_STATE_MAP.clear(); + } + + public static synchronized void registerSate(Class aclass,Map stateMap){ + CLASS_STATE_MAP.put(aclass,stateMap); } } diff --git a/src/test/java/bokang/xiao/response_deal/state/UpdateState.java b/src/test/java/bokang/xiao/response_deal/state/UpdateState.java index 62c78ec..17bdcaa 100644 --- a/src/test/java/bokang/xiao/response_deal/state/UpdateState.java +++ b/src/test/java/bokang/xiao/response_deal/state/UpdateState.java @@ -64,7 +64,7 @@ public class UpdateState extends State{ detailTableDeal(detailTableMap); if(ResponseUtil.parameterIsNotNull(detailTableMap)){ detailTableMap.forEach((key,value)->{ - value.setDefaultState(); + value.setDefaultState(null); value.dataProcess(); }); }