团校同步功能
parent
8740a1bfa6
commit
c642b40ce9
|
@ -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<List> batchSqlArgs = new ArrayList<>();
|
||||
|
||||
//change by aiyouhong
|
||||
//List<Object> batchSqlArgsList = new ArrayList();
|
||||
//String batchSqlName = "item";
|
||||
|
||||
List<Object> batchSqlArgsList = new ArrayList();
|
||||
Map<String, List<Object>> batchSqlArgMap = new HashMap<>();
|
||||
|
||||
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<String, Object> 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<Object> firstList = null;
|
||||
for (Map.Entry<String, List<Object>> entry : batchSqlArgMap.entrySet()) {
|
||||
List<Object> 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<String, Object> map = new HashMap<>(8);
|
||||
for (Map.Entry<String, List<Object>> entry : batchSqlArgMap.entrySet()) {
|
||||
map.put(entry.getKey(), entry.getValue().get(i));
|
||||
}
|
||||
if(Objects.nonNull(o) && o instanceof Map && !((Map<?, ?>) o).isEmpty()){
|
||||
map.putAll((Map<String, Object>)o);
|
||||
}
|
||||
parse = parse(findSql, map);
|
||||
List<Object> tempArgs = new ArrayList<>();
|
||||
tempArgs.addAll(sqlArgs);
|
||||
batchSqlArgs.add(tempArgs);
|
||||
sqlArgs.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
//change by aiyouhong
|
||||
/*if (!batchSqlArgsList.isEmpty()) {
|
||||
for (Object o1 : batchSqlArgsList) {
|
||||
Map<String, Object> 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<String, Object> 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<String, List<Object>> 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<Object>) arg;
|
||||
batchSqlName = batchSqlArgs.value();
|
||||
//change by aiyouhong
|
||||
//this.batchSqlArgsList = (List<Object>) arg;
|
||||
//batchSqlName = batchSqlArgs.value();
|
||||
|
||||
batchSqlArgMap.put(batchSqlArgs.value(),(List<Object>) arg);
|
||||
} catch (Exception e) {
|
||||
throw new BindingException("can not parse batchSqlArgs for " + parameter.getName() + ", param index is " + i);
|
||||
}
|
||||
|
|
|
@ -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 <h1>响应信息处理类</h1>
|
||||
**/
|
||||
@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<String, Object> responseMap = responeVo.getResponseMap();
|
||||
ResponseUtil.parameterJudgment(responseMap,"接口返回都为空 你处理个勾");
|
||||
this.doResponseSync(uniqueCode,responseMap);
|
||||
}
|
||||
|
||||
public void doResponseSync(String uniqueCode, Map<String, Object> responseMap) {
|
||||
List<ResponseConfig> responseConfigList = configMapper.queryResponseConfigByUnique(uniqueCode);
|
||||
logger.info(String.format("%s 相关响应配置信息==> %s",uniqueCode, JSON.toJSONString(responseConfigList)));
|
||||
ResponseUtil.parameterJudgment(responseConfigList,"response config is empty please check!!! ");
|
||||
Map<String, ResponseConfig> tableNameConfig;
|
||||
try {
|
||||
tableNameConfig = responseConfigList.stream().collect(Collectors.toMap(ResponseConfig::getModelTableName, v -> v));
|
||||
} catch (Exception e) {
|
||||
logger.error("response config error please check!!! " + Util.getErrString(e));
|
||||
throw new ResponseException("response config error please check!!! ");
|
||||
}
|
||||
ResponseUtil.parameterJudgment(responseMap,"接口返回都为空 你处理个勾");
|
||||
tableNameConfig.forEach((key, value) -> doResponseSync(value, responseMap));
|
||||
}
|
||||
|
||||
public void doResponseSync(ResponseConfig responseConfig, Map<String, Object> responseMap){
|
||||
List<ResponseConfigAlias> responseConfigAliasList = responseConfig.getResponseConfigAliasList();
|
||||
ResponseUtil.parameterJudgment(responseConfigAliasList,"responseConfigAliasList config is empty please check!!!");
|
||||
List<ResponseConfigValueChange> valueChangeList = responseConfig.getValueChangeList();
|
||||
ResponseUtil.parameterJudgment(valueChangeList,"valueChangeList config is empty please check!!!");
|
||||
//数据信息按是否主表分组
|
||||
Map<Integer, List<ResponseConfigAlias>> aliasMap = responseConfigAliasList.stream().collect(Collectors.groupingBy(ResponseConfigAlias::getTableType));
|
||||
List<ResponseConfigAlias> mainConfigList = aliasMap.get(ResponseConfigConstant.MAIN_TABLE);
|
||||
Map<Integer, List<ResponseConfigValueChange>> mainOrDetail = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getTableType));
|
||||
List<ResponseConfigValueChange> 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<String,TableDefinition> 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<ResponseConfigAlias> responseConfigAliasList,
|
||||
List<ResponseConfigValueChange> valueChangeList,
|
||||
Map<String, Object> responseMap,
|
||||
boolean isMainTable,
|
||||
Bi3Function<ResponseConfig,Map<String, Object>,Map<String,TableDefinition>,String> detailCallBack) {
|
||||
|
||||
List<ResponseConfigAlias> 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<String,Object> 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<Integer, List<ResponseConfigValueChange>> mainOrDetail = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getTableType));
|
||||
//List<ResponseConfigValueChange> mainValueChangeList = mainOrDetail.get(ResponseConfigConstant.MAIN_TABLE);
|
||||
ResponseUtil.parameterJudgment(valueChangeList,"main table valueChangeList config is empty please check!!!");
|
||||
//获取主表的主数据信息
|
||||
ResponseConfigAlias mainDataAlias = mainAliasList.get(0);
|
||||
int tableMainOrDetail = isMainTable ? ResponseConfigConstant.MAIN_TABLE : ResponseConfigConstant.DETAIL_TABLE;
|
||||
//构建表信息
|
||||
TableDefinition tableDefinition = TableDefinition.builder().assignTable(tableName)
|
||||
.conditionScript(mainDataAlias.getConditionScript())
|
||||
.judgmentScript(mainDataAlias.getJudgmentScript())
|
||||
.tableType(responseConfig.getTableType())
|
||||
.mainOrDetail(tableMainOrDetail)
|
||||
.tableDefinitionCallback(this.tableCallback)
|
||||
.assignType(mainDataAlias.getAssignType()).build();
|
||||
String dataPath = mainDataAlias.getDataPath();
|
||||
List<RowDefinition> rowDefinitionList = new ArrayList<>();
|
||||
Map<String,TableDefinition> detailTable = isMainTable ? new HashMap<>() : null;
|
||||
if(mainDataAlias.getDataType() == ResponseConfigConstant.JSON_ARRAY){
|
||||
List<Map<String,Object>> mainList = (List<Map<String,Object>>) Util.getValueByKeyStr(dataPath, aliasData);
|
||||
for (Map<String, Object> mainItem : mainList) {
|
||||
aliasData.put(mainDataAlias.getDataAlias(),mainItem);
|
||||
//处理配置信息
|
||||
List<FieldDefinition> 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<String,Object> jsonObj = (Map<String, Object>) Util.getValueByKeyStr(dataPath, aliasData);
|
||||
aliasData.put(mainDataAlias.getDataAlias(),jsonObj);
|
||||
//处理配置信息
|
||||
List<FieldDefinition> fieldDefinitions = parsingJsonToConfig(valueChangeList, aliasData);
|
||||
RowDefinition rowDefinition = this.buildRowDefinition(fieldDefinitions,tableName,mainDataAlias.getAssignType(), mainDataAlias.getConditionScript(), mainDataAlias.getJudgmentScript());
|
||||
rowDefinition.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<FieldDefinition> fieldDefinitionList,
|
||||
String tableName,
|
||||
int assignType,
|
||||
String conditionScript,
|
||||
String judgmentScript){
|
||||
Map<String,Object> updateParam = new HashMap<>();
|
||||
Map<String,Object> wherePram = new HashMap<>();
|
||||
fieldDefinitionList.forEach(fieldDefinition -> {
|
||||
int fieldType = fieldDefinition.getFieldType();
|
||||
if(fieldType == ResponseConfigConstant.WHERE_FIELD){
|
||||
wherePram.put(fieldDefinition.getFieldName(),fieldDefinition.getFieldValue());
|
||||
}else {
|
||||
updateParam.put(fieldDefinition.getFieldName(),fieldDefinition.getFieldValue());
|
||||
wherePram.put(fieldDefinition.getFieldName(),fieldDefinition.getFieldValue());
|
||||
}
|
||||
});
|
||||
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<String, Object> param,Map<String,TableDefinition> detailTable){
|
||||
List<ResponseConfigAlias> responseConfigAliasList = responseConfig.getResponseConfigAliasList();
|
||||
List<ResponseConfigValueChange> valueChangeList = responseConfig.getValueChangeList();
|
||||
//数据信息按是否主表分组
|
||||
Map<Integer, List<ResponseConfigAlias>> aliasMap = responseConfigAliasList.stream().collect(Collectors.groupingBy(ResponseConfigAlias::getTableType));
|
||||
List<ResponseConfigAlias> detailAliases = aliasMap.get(ResponseConfigConstant.DETAIL_TABLE);
|
||||
//没有明细相关配置不处理
|
||||
if(ResponseUtil.parameterIsNull(detailAliases)){
|
||||
return "";
|
||||
}
|
||||
Map<String, List<ResponseConfigAlias>> detailAliasMap = detailAliases.stream().collect(Collectors.groupingBy(ResponseConfigAlias::getDetailTableName));
|
||||
Map<String, List<ResponseConfigValueChange>> detailValueChangeMap = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getAssignTable));
|
||||
detailAliasMap.forEach((key,value) ->{
|
||||
List<ResponseConfigValueChange> 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<FieldDefinition> parsingJsonToConfig(List<ResponseConfigValueChange> responseConfigValueChangeList,
|
||||
Map<String,Object> parsingData){
|
||||
Map<String,Object> param = new HashMap<>();
|
||||
responseConfigValueChangeList.forEach(item ->{
|
||||
Object value = item.getDataChange() == ResponseConfigConstant.DEFAULT_VALUE
|
||||
? null
|
||||
: Util.getValueByKeyStr(Util.null2String(item.getValuePath()), parsingData);
|
||||
item.setJsonData(value);
|
||||
param.put(item.getAssignFieldName(),value);
|
||||
});
|
||||
return responseConfigValueChangeList.stream().map(item ->{
|
||||
BiFunction<ResponseConfigValueChange, Map<String, Object>, String> dataChangeFunction = DataChangeProcess.MODE_METHOD_MAP.get(item.getDataChange());
|
||||
ResponseUtil.parameterJudgment(dataChangeFunction,"The corresponding data conversion mode processing method is not found !!!");
|
||||
dataChangeFunction.apply(item,param);
|
||||
Function<Object, Object> 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());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package aiyh.utils.response_deal.constant;
|
||||
|
||||
/**
|
||||
* @ClassName ResponseConfigConstant
|
||||
* @Author 肖博亢
|
||||
* @Date 2023/7/7 10:23
|
||||
* @Description <h1></h1>
|
||||
**/
|
||||
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;
|
||||
|
||||
}
|
|
@ -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 <h1></h1>
|
||||
**/
|
||||
@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;
|
||||
|
||||
}
|
|
@ -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 <h1>响应值处理配置</h1>
|
||||
**/
|
||||
|
||||
@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<ResponseConfigAlias> responseConfigAliasList;
|
||||
|
||||
private List<ResponseConfigValueChange> valueChangeList;
|
||||
|
||||
}
|
|
@ -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 <h1>别名配置</h1>
|
||||
**/
|
||||
@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<String,Object> parsingData = new HashMap<>();
|
||||
|
||||
}
|
|
@ -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 <h1>值转换配置</h1>
|
||||
**/
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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 <h1></h1>
|
||||
**/
|
||||
@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<String,Object> updateParam;
|
||||
|
||||
private Map<String,Object> whereParam;
|
||||
|
||||
Map<String, TableDefinition> detailTableMap;
|
||||
|
||||
private List<FieldDefinition> fieldDefinitionList;
|
||||
}
|
|
@ -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 <h1></h1>
|
||||
**/
|
||||
@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<RowDefinition> rowDefinitionList;
|
||||
|
||||
private Map<String,TableDefinition> 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();
|
||||
}
|
||||
}
|
|
@ -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 <h1></h1>
|
||||
**/
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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 <h1></h1>
|
||||
**/
|
||||
public interface DataChangeInterface {
|
||||
|
||||
/**
|
||||
* 自定义转换接口
|
||||
* @param responseConfigValueChange 配置信息
|
||||
* @param param 参数信息
|
||||
* @param pathParam 路径参数
|
||||
* @return 转换后的值
|
||||
*/
|
||||
Object change(ResponseConfigValueChange responseConfigValueChange, Map<String,Object> param, Map<String,String> pathParam);
|
||||
}
|
|
@ -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 <h1></h1>
|
||||
**/
|
||||
public interface FieldDefinitionCallback {
|
||||
|
||||
void fieldHandle(FieldDefinition fieldDefinition);
|
||||
}
|
|
@ -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 <h1></h1>
|
||||
**/
|
||||
public interface RowDefinitionCallback {
|
||||
|
||||
void rowHandle(RowDefinition rowDefinition);
|
||||
|
||||
boolean judgmentRepetition(RowDefinition rowDefinition);
|
||||
}
|
|
@ -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 <h1></h1>
|
||||
**/
|
||||
public interface TableDefinitionCallback {
|
||||
|
||||
void tableHandle(TableDefinition tableDefinition);
|
||||
|
||||
}
|
|
@ -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 <h1>配置信息-数据库处理类</h1>
|
||||
**/
|
||||
@SqlMapper
|
||||
public interface ConfigMapper {
|
||||
|
||||
/**
|
||||
* <h2>通过请求唯一标识查询响应配置信息</h2>
|
||||
* @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<ResponseConfig> queryResponseConfigByUnique(@ParamMapper("requestUnique") String requestUnique);
|
||||
|
||||
/**
|
||||
* <h2>通过请求唯一标识查询响应配置信息</h2>
|
||||
* @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<ResponseConfig> queryResponseConfig();
|
||||
|
||||
/**
|
||||
* <h2>查询响应数据别名配置信息</h2>
|
||||
* @param mainId 主数据id
|
||||
* @return 响应数据别名配置信息列表
|
||||
*/
|
||||
@Select("select * from uf_response_config_dt1 where mainid = #{mainId}")
|
||||
@CollectionMethod(1)
|
||||
List<ResponseConfigAlias> queryResponseConfigAlias(@ParamMapper("mainId")int mainId);
|
||||
|
||||
/**
|
||||
* <h2>查询响应数据转换配置信息</h2>
|
||||
* @param mainId 主数据id
|
||||
* @return 响应数据转换配置信息列表
|
||||
*/
|
||||
@Select("select * from uf_response_config_dt3 where mainid = #{mainId}")
|
||||
@CollectionMethod(2)
|
||||
List<ResponseConfigValueChange> queryResponseConfigValueChange(@ParamMapper("mainId")int mainId);
|
||||
|
||||
/**
|
||||
* <h2>执行自定义查询sql</h2>
|
||||
* @param cusSql 自定义sql
|
||||
* @param param 参数信息
|
||||
* @return 查询结果
|
||||
*/
|
||||
@Select(custom = true)
|
||||
String executeCusQuerySql(@SqlString String cusSql,@ParamMapper("whereItem") Map<String,Object> whereParam,@ParamMapper("param")Map<String,Object> param);
|
||||
|
||||
/**
|
||||
* <h2>执行自定义更新sql</h2>
|
||||
* @param cusSql 自定义sql
|
||||
* @param updateParam 更新参数信息
|
||||
* @param whereParam 条件参数信息
|
||||
* @return 查询结果
|
||||
*/
|
||||
@Update(custom = true)
|
||||
boolean executeUpdateCusSql(@SqlString String cusSql,
|
||||
@ParamMapper("updateParam")Map<String,Object> updateParam,
|
||||
@ParamMapper("whereParam")Map<String,Object> whereParam);
|
||||
|
||||
/**
|
||||
* <h2>执行自定义批量新增sql</h2>
|
||||
* @param cusSql 自定义sql
|
||||
* @param insertList 新镇参数信息
|
||||
* @return 处理结果
|
||||
*/
|
||||
@BatchInsert(custom = true)
|
||||
boolean executeInsertBatchCusSql(@SqlString String cusSql,
|
||||
@BatchSqlArgs List<Map<String,Object>> insertList);
|
||||
|
||||
/**
|
||||
* <h2>执行自定义批量更新sql</h2>
|
||||
* @param cusSql 自定义sql
|
||||
* @param updateList 更新参数信息
|
||||
* @param whereList 条件参数信息
|
||||
* @return 处理结果
|
||||
*/
|
||||
@BatchUpdate(custom = true)
|
||||
boolean executeUpdateBatchCusSql(@SqlString String cusSql,
|
||||
@BatchSqlArgs("upItem") List<Map<String,Object>> updateList,
|
||||
@BatchSqlArgs("whereItem") List<Map<String,Object>> whereList);
|
||||
|
||||
}
|
|
@ -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 <h1></h1>
|
||||
**/
|
||||
public class DataChangeProcess {
|
||||
|
||||
public static final Map<Integer, BiFunction<ResponseConfigValueChange,Map<String,Object>,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<DataChangeProcess> 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<String,Object> 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<String,Object> 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<String,Object> 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<String,Object> param){
|
||||
String cusText = responseConfigValueChange.getCusText();
|
||||
cusText = Util.dbc2sbcCase(cusText);
|
||||
if(StringUtils.isBlank(cusText)){
|
||||
throw new CustomerException("The operation full path cannot be empty !!!");
|
||||
}
|
||||
Map<String,String> 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<String,Object> param){
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* <h2></h2>
|
||||
* @param path 全路径类名
|
||||
* @param clazz 父类接口
|
||||
* @param pathParamMap 路径参数
|
||||
* @return 接口实现类
|
||||
* @param <T> 泛型
|
||||
*/
|
||||
public static <T> T getCusInterfaceObj(String path, Class<T> clazz, Map<String, String> 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);
|
||||
}
|
||||
}
|
|
@ -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 <h1></h1>
|
||||
**/
|
||||
public class TypeChangeProcess {
|
||||
|
||||
public static final Map<Integer, Function<Object,Object>> MODE_METHOD_MAP = new HashMap<>();
|
||||
|
||||
public static final Logger logger = Util.getLogger();
|
||||
|
||||
static {
|
||||
try {
|
||||
Class<TypeChangeProcess> 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));
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -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 <h1></h1>
|
||||
**/
|
||||
public class InsertOrUpdateState extends State{
|
||||
|
||||
@Override
|
||||
public void handle() {
|
||||
if(ResponseUtil.parameterIsNotNull(this.context.getTableDefinitionCallback())){
|
||||
this.context.getTableDefinitionCallback().tableHandle(this.context);
|
||||
}
|
||||
List<RowDefinition> rowDefinitionList = this.context.getRowDefinitionList();
|
||||
List<RowDefinition> updateRowList = new ArrayList<>();
|
||||
List<RowDefinition> 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<RowDefinition> 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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 <h1></h1>
|
||||
**/
|
||||
public class InsertSate extends State{
|
||||
@Override
|
||||
public void handle() {
|
||||
int tableType = this.context.getTableType();
|
||||
int mainOrDetail = this.context.getMainOrDetail();
|
||||
List<RowDefinition> rowDefinitionList = this.context.getRowDefinitionList();
|
||||
Map<String, TableDefinition> 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<Map<String, Object>> updateList = new ArrayList<>();
|
||||
List<Map<String, Object>> whereList = new ArrayList<>();
|
||||
List<Integer> 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<Map<String, Object>> insertList = rowDefinitionList.stream().map(RowDefinition::getUpdateParam).collect(Collectors.toList());
|
||||
boolean flag = this.configMapper.executeInsertBatchCusSql(insertSql, insertList);
|
||||
}
|
||||
}
|
||||
|
||||
private void detailTableDeal(RowDefinition rowDefinition,Map<String, TableDefinition> mainDetailMap){
|
||||
int mainId = rowDefinition.getDataId();
|
||||
Map<String, TableDefinition> detailTableMap = rowDefinition.getDetailTableMap();
|
||||
detailTableMap.forEach((key,value) ->{
|
||||
List<RowDefinition> 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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 <h1></h1>
|
||||
**/
|
||||
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();
|
||||
|
||||
}
|
|
@ -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 <h1></h1>
|
||||
**/
|
||||
public class StateFactory {
|
||||
|
||||
private static final Map<Class<?>,Map<Integer,State>> CLASS_STATE_MAP = new HashMap<>();
|
||||
|
||||
private static final Map<Integer,State> 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<Integer, State> 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<Integer,State> stateMap){
|
||||
CLASS_STATE_MAP.put(aclass,stateMap);
|
||||
}
|
||||
}
|
|
@ -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 <h1></h1>
|
||||
**/
|
||||
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<String, TableDefinition> detailTableMap = ResponseUtil.parameterIsNull(this.context.getDetailTableMap()) ?
|
||||
new HashMap<>() : this.context.getDetailTableMap();
|
||||
List<RowDefinition> 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<Map<String, Object>> updateList = new ArrayList<>();
|
||||
List<Map<String, Object>> 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<String, TableDefinition> mainDetailMap){
|
||||
List<RowDefinition> rowDefinitionList = this.context.getRowDefinitionList();
|
||||
rowDefinitionList.forEach(item ->{
|
||||
Map<String, TableDefinition> 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);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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 <h1></h1>
|
||||
**/
|
||||
|
||||
@Getter
|
||||
public class ResponseStore {
|
||||
|
||||
private final Logger logger = Util.getLogger();
|
||||
|
||||
private List<ResponseConfig> responseConfigList = new ArrayList<>();
|
||||
|
||||
private Map<String,List<ResponseConfig>> responseConfigMap = new HashMap<>();
|
||||
|
||||
private final ConfigMapper configMapper = Util.getMapper(ConfigMapper.class);
|
||||
|
||||
private ResponseStore(){
|
||||
this.init();
|
||||
}
|
||||
|
||||
private void init(){
|
||||
try {
|
||||
List<ResponseConfig> 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();
|
||||
}
|
||||
}
|
|
@ -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 <h1></h1>
|
||||
**/
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
|
@ -120,6 +120,18 @@ public interface BankMapper {
|
|||
" AND $t{currencyField} = #{currency}")
|
||||
List<Map<String, Object>> queryOaOtherList(Map<String, Object> param);
|
||||
|
||||
/**
|
||||
* <h2>查询托收等付款信息</h2>
|
||||
* @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<Map<String, Object>> queryOaOutOtherList(Map<String, Object> param);
|
||||
|
||||
/**
|
||||
* <h2>查询流程付款信息</h2>
|
||||
* @param param 查询参数
|
||||
|
|
|
@ -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<Map<String, Object>> 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<Map<String, Object>> 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();
|
||||
return bankMapper.queryOaOutOtherList(item).stream();
|
||||
}).collect(Collectors.toList());
|
||||
List<Map<String, Object>> oaInOtherList = inOtherParam.stream().flatMap(item -> {
|
||||
//获取其他收款信息
|
||||
List<Map<String, Object>> 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)){
|
||||
if (StringUtils.isNotBlank(detailId)) {
|
||||
String table = Util.null2String(item.get("tableName"));
|
||||
String detailTale = table + "_" + detailId;
|
||||
item.put("detailTable",detailTale);
|
||||
item.put("detailTable", detailTale);
|
||||
return bankMapper.queryOaOtherDetailList(item).stream();
|
||||
}
|
||||
return bankMapper.queryOaOtherList(item).stream();
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
//获取银企直联收款信息
|
||||
List<Map<String, Object>> oaInList = inParam.stream()
|
||||
.flatMap(item -> {
|
||||
item.put("currentBankAccount",bankAccount);
|
||||
|
|
|
@ -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 <h1>同步教研资数据定时任务</h1>
|
||||
**/
|
||||
@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<String, Object> requestParam = dealWithMapping.getRequestParam(new HashMap<>(), requestMappingConfig);
|
||||
// 发起API POST请求
|
||||
ResponeVo responeVo = httpUtils.apiPost(requestMappingConfig.getRequestUrl(), requestParam);
|
||||
if (responeVo.getCode() == 200) {
|
||||
Map<String, Object> 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");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<String, GetValueTypeEnum> LOOK_UP = new HashMap<>(8);
|
||||
|
||||
|
|
|
@ -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("不支持的取值方式");
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<String, Object> 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<RowDefinition> 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());
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ public interface ConfigMapper {
|
|||
* @param whereList 条件参数信息
|
||||
* @return 处理结果
|
||||
*/
|
||||
@BatchInsert(custom = true)
|
||||
@BatchUpdate(custom = true)
|
||||
boolean executeUpdateBatchCusSql(@SqlString String cusSql,
|
||||
@BatchSqlArgs("upItem") List<Map<String,Object>> updateList,
|
||||
@BatchSqlArgs("whereItem") List<Map<String,Object>> whereList);
|
||||
|
|
|
@ -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 <h1></h1>
|
||||
**/
|
||||
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<RowDefinition> 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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<Class<?>,Map<Integer,State>> CLASS_STATE_MAP = new HashMap<>();
|
||||
|
||||
private static final Map<Integer,State> 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<Integer, State> 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<Integer,State> stateMap){
|
||||
CLASS_STATE_MAP.put(aclass,stateMap);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue