返回信息解析
parent
6fe6171532
commit
b1e3a119bc
|
@ -67,6 +67,8 @@ public interface SourceTrackingMapper {
|
||||||
@CollectionMethod(3)
|
@CollectionMethod(3)
|
||||||
List<QuotaData> queryQuotaList(@ParamMapper("sourceTackingCode")String sourceTackingCode);
|
List<QuotaData> queryQuotaList(@ParamMapper("sourceTackingCode")String sourceTackingCode);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h2>删除报表数据</h2>
|
* <h2>删除报表数据</h2>
|
||||||
* @param ids 主键id数组
|
* @param ids 主键id数组
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class DealWithMapping extends ToolUtil {
|
||||||
|
|
||||||
private DealWithMapper mapper = null;
|
private DealWithMapper mapper = null;
|
||||||
|
|
||||||
private final Logger logger = aiyh.utils.Util.getLogger("json-util");
|
private final Logger logger = aiyh.utils.Util.getLogger("json_util");
|
||||||
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import basetest.BaseTest;
|
||||||
import bokang.xiao.entity.CourseEntity;
|
import bokang.xiao.entity.CourseEntity;
|
||||||
import bokang.xiao.entity.StudentEntity;
|
import bokang.xiao.entity.StudentEntity;
|
||||||
import bokang.xiao.entity.TeacherEntity;
|
import bokang.xiao.entity.TeacherEntity;
|
||||||
|
import bokang.xiao.response_deal.ResponseMappingDeal;
|
||||||
import bokang.xiao.util.XmlParser;
|
import bokang.xiao.util.XmlParser;
|
||||||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||||||
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
import cn.afterturn.easypoi.excel.entity.ExportParams;
|
||||||
|
@ -62,6 +63,7 @@ import weaver.interfaces.datasource.DataSource;
|
||||||
import weaver.workflow.workflow.WfForceOver;
|
import weaver.workflow.workflow.WfForceOver;
|
||||||
import weaver.workflow.workflow.WorkflowVersion;
|
import weaver.workflow.workflow.WorkflowVersion;
|
||||||
import weaver.xiao.commons.utils.DocImageFileUtil;
|
import weaver.xiao.commons.utils.DocImageFileUtil;
|
||||||
|
import youhong.ai.utiltest.resultjsonparase.ParseTest;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
|
@ -120,6 +122,15 @@ public class NormalTest extends BaseTest {
|
||||||
examineSchedule.runCode();
|
examineSchedule.runCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testResponseSync(){
|
||||||
|
ParseTest parseTest = new ParseTest();
|
||||||
|
Map<String, Object> resultData = parseTest.getResultData();
|
||||||
|
System.out.println(JSON.toJSONString(resultData));
|
||||||
|
ResponseMappingDeal responseMappingDeal = new ResponseMappingDeal();
|
||||||
|
responseMappingDeal.doResponseSync("test1",resultData);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void paramGet(){
|
public void paramGet(){
|
||||||
Map<String,Object> param = new HashMap<>();
|
Map<String,Object> param = new HashMap<>();
|
||||||
|
|
|
@ -1,19 +1,24 @@
|
||||||
package bokang.xiao.response_deal;
|
package bokang.xiao.response_deal;
|
||||||
|
|
||||||
import aiyh.utils.ScriptUtil;
|
|
||||||
import aiyh.utils.Util;
|
import aiyh.utils.Util;
|
||||||
import aiyh.utils.excention.CustomerException;
|
import aiyh.utils.function.Bi3Function;
|
||||||
import aiyh.utils.httpUtil.ResponeVo;
|
import aiyh.utils.httpUtil.ResponeVo;
|
||||||
import aiyh.utils.tool.cn.hutool.core.collection.CollectionUtil;
|
|
||||||
import aiyh.utils.tool.cn.hutool.core.util.StrUtil;
|
|
||||||
import bokang.xiao.exception.ResponseException;
|
import bokang.xiao.exception.ResponseException;
|
||||||
import bokang.xiao.response_deal.entity.ResponseConfig;
|
import bokang.xiao.response_deal.constant.ResponseConfigConstant;
|
||||||
import bokang.xiao.response_deal.entity.ResponseConfigAlias;
|
import bokang.xiao.response_deal.entity.*;
|
||||||
import bokang.xiao.response_deal.entity.ResponseConfigValueChange;
|
import bokang.xiao.response_deal.intfaces.FieldDefinitionCallback;
|
||||||
|
import bokang.xiao.response_deal.intfaces.RowDefinitionCallback;
|
||||||
|
import bokang.xiao.response_deal.intfaces.TableDefinitionCallback;
|
||||||
import bokang.xiao.response_deal.mapper.ConfigMapper;
|
import bokang.xiao.response_deal.mapper.ConfigMapper;
|
||||||
|
import bokang.xiao.response_deal.process.DataChangeProcess;
|
||||||
|
import bokang.xiao.response_deal.process.TypeChangeProcess;
|
||||||
|
import bokang.xiao.response_deal.util.ResponseUtil;
|
||||||
|
import lombok.Setter;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,68 +27,28 @@ import java.util.stream.Collectors;
|
||||||
* @Date 2023/7/4 17:42
|
* @Date 2023/7/4 17:42
|
||||||
* @Description <h1>响应信息处理类</h1>
|
* @Description <h1>响应信息处理类</h1>
|
||||||
**/
|
**/
|
||||||
|
@Setter
|
||||||
public class ResponseMappingDeal {
|
public class ResponseMappingDeal {
|
||||||
|
|
||||||
private final Logger logger = Util.getLogger("json-util");
|
private final Logger logger = Util.getLogger("json_util");
|
||||||
|
|
||||||
private final ConfigMapper configMapper = Util.getMapper(ConfigMapper.class);
|
private final ConfigMapper configMapper = Util.getMapper(ConfigMapper.class);
|
||||||
|
|
||||||
|
private TableDefinitionCallback tableCallback;
|
||||||
|
|
||||||
public void parseConfig(String uniqueCode, ResponeVo responeVo) {
|
private RowDefinitionCallback rowCallback;
|
||||||
if (responeVo.getCode() != 200) {
|
|
||||||
throw new CustomerException("你妈没成功");
|
|
||||||
}
|
|
||||||
|
|
||||||
List<ResponseConfig> responseConfigs = configMapper.queryResponseConfigByUnique(uniqueCode);
|
private FieldDefinitionCallback fieldDefinitionCallback;
|
||||||
|
|
||||||
if (CollectionUtil.isEmpty(responseConfigs)) {
|
public void doResponseSync(String uniqueCode, ResponeVo responeVo) {
|
||||||
throw new CustomerException("sb");
|
|
||||||
}
|
|
||||||
for (ResponseConfig responseConfig : responseConfigs) {
|
|
||||||
parseConfigOne(responseConfig, responeVo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void parseConfigOne(ResponseConfig responseConfig, ResponeVo responeVo) {
|
|
||||||
List<ResponseConfigAlias> responseConfigAliasList = responseConfig.getResponseConfigAliasList();
|
|
||||||
String successExp = responseConfig.getSuccessExp();
|
|
||||||
Map<String, Object> responseMap = responeVo.getResponseMap();
|
Map<String, Object> responseMap = responeVo.getResponseMap();
|
||||||
List<Map<String, Object>> resultList = new ArrayList<>();
|
ResponseUtil.parameterJudgment(responseMap,"接口返回都为空 你处理个勾");
|
||||||
if (CollectionUtil.isEmpty(responseMap)) {
|
this.doResponseSync(uniqueCode,responseMap);
|
||||||
// 他是一个list,尝试获取一下
|
|
||||||
List<Map> result = responeVo.getResult();
|
|
||||||
if (CollectionUtil.isEmpty(result)) {
|
|
||||||
throw new CustomerException("没有响应结果,你同步个J8");
|
|
||||||
} else {
|
|
||||||
for (Map map : result) {
|
|
||||||
Map<String, Object> tempMap = new HashMap<>();
|
|
||||||
for (Object entry : map.entrySet()) {
|
|
||||||
|
|
||||||
}
|
|
||||||
resultList.add(tempMap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
resultList.add(responseMap);
|
|
||||||
}
|
|
||||||
if (StrUtil.isNotBlank(successExp)) {
|
|
||||||
for (Map<String, Object> map : resultList) {
|
|
||||||
boolean flag = (boolean) ScriptUtil.invokeScript(successExp, map);
|
|
||||||
if (!flag) {
|
|
||||||
throw new CustomerException("失败了!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void doResponseSync(String uniqueCode, Map<String, Object> responseMap) {
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void getConfig(String uniqueCode, ResponeVo responeVo) {
|
|
||||||
List<ResponseConfig> responseConfigList = configMapper.queryResponseConfigByUnique(uniqueCode);
|
List<ResponseConfig> responseConfigList = configMapper.queryResponseConfigByUnique(uniqueCode);
|
||||||
if (Objects.isNull(responseConfigList) || responseConfigList.isEmpty()) {
|
ResponseUtil.parameterJudgment(responseConfigList,"response config is empty please check!!! ");
|
||||||
throw new ResponseException("response config is empty please check!!! ");
|
|
||||||
}
|
|
||||||
Map<String, ResponseConfig> tableNameConfig;
|
Map<String, ResponseConfig> tableNameConfig;
|
||||||
try {
|
try {
|
||||||
tableNameConfig = responseConfigList.stream().collect(Collectors.toMap(ResponseConfig::getModelTableName, v -> v));
|
tableNameConfig = responseConfigList.stream().collect(Collectors.toMap(ResponseConfig::getModelTableName, v -> v));
|
||||||
|
@ -91,51 +56,187 @@ public class ResponseMappingDeal {
|
||||||
logger.error("response config error please check!!! " + Util.getErrString(e));
|
logger.error("response config error please check!!! " + Util.getErrString(e));
|
||||||
throw new ResponseException("response config error please check!!! ");
|
throw new ResponseException("response config error please check!!! ");
|
||||||
}
|
}
|
||||||
tableNameConfig.entrySet().stream().forEach(item -> {
|
ResponseUtil.parameterJudgment(responseMap,"接口返回都为空 你处理个勾");
|
||||||
dealConfig(item.getValue(), responeVo);
|
tableNameConfig.forEach((key, value) -> doResponseSync(value, responseMap));
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dealConfig(ResponseConfig responseConfig, ResponeVo responeVo) {
|
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();
|
List<ResponseConfigValueChange> valueChangeList = responseConfig.getValueChangeList();
|
||||||
if (Objects.isNull(valueChangeList) || valueChangeList.isEmpty()) {
|
ResponseUtil.parameterJudgment(valueChangeList,"valueChangeList config is empty please check!!!");
|
||||||
throw new ResponseException("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)
|
||||||
|
.tableType(responseConfig.getTableType())
|
||||||
|
.assignType(ResponseConfigConstant.NO_HANDLE)
|
||||||
|
.assignTable(responseConfig.getModelTableName()).build();
|
||||||
}
|
}
|
||||||
Map<Integer, List<ResponseConfigValueChange>> tableTypeMap = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getTableType));
|
//做数据处理
|
||||||
List<ResponseConfigValueChange> mainConfig = tableTypeMap.get(0);
|
tableDefinition.setDefaultState();
|
||||||
Map<String, List<ResponseConfigValueChange>> collect = mainConfig.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getAssignTable));
|
tableDefinition.dataProcess();
|
||||||
if (collect.size() > 1) {
|
|
||||||
throw new ResponseException("The primary table cannot have details please check!!! ");
|
|
||||||
}
|
|
||||||
// Map<String, Object> responseMap = responeVo.getResponseMap();
|
|
||||||
// Map<Util.ValueOrList,List<FieldDefinition>> mainFieldMap = new HashMap<>();
|
|
||||||
// for (ResponseConfigValueChange responseConfigValueChange : mainConfig) {
|
|
||||||
// String valuePath = responseConfigValueChange.getValuePath();
|
|
||||||
// Util.ValueOrList valueOrListByKeyStr = Util.getValueOrListByKeyStr(valuePath, responseMap);
|
|
||||||
// if(valueOrListByKeyStr.isArray() && !mainFieldMap.isEmpty() && !mainFieldMap.containsKey(valueOrListByKeyStr)){
|
|
||||||
// throw new ResponseException("The primary table cannot contain multiple List data please check!!!");
|
|
||||||
// }else if(valueOrListByKeyStr.isArray() && mainFieldMap.isEmpty()){
|
|
||||||
// List<Map<String, Object>> listValue = (List<Map<String, Object>>) valueOrListByKeyStr.getValue();
|
|
||||||
// List<FieldDefinition> fieldDefinitions = listValue.stream().map(item -> FieldDefinition.builder().build()).collect(Collectors.toList());
|
|
||||||
// mainFieldMap.put(valueOrListByKeyStr,fieldDefinitions);
|
|
||||||
// }else if(valueOrListByKeyStr.isArray()){
|
|
||||||
// List<FieldDefinition> fieldDefinitions = mainFieldMap.get(valueOrListByKeyStr);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
// mainConfig.stream().map(item ->{
|
|
||||||
//
|
|
||||||
//})
|
|
||||||
List<ResponseConfigValueChange> detail = tableTypeMap.get(1);
|
|
||||||
Map<String, List<ResponseConfigValueChange>> tableValueMap = valueChangeList.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getAssignTable));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void responseToEntity(ResponseConfigValueChange responseConfigValueChange, Map<String, Object> param) {
|
public TableDefinition parsingJsonToTable(
|
||||||
String valuePath = responseConfigValueChange.getValuePath();
|
String tableName,
|
||||||
Util.ValueOrList valueOrListByKeyStr = Util.getValueOrListByKeyStr(valuePath, param);
|
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)
|
||||||
|
.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)
|
||||||
|
.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())
|
||||||
|
.fieldValue(targetValue).build();
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
package bokang.xiao.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 bokang.xiao.response_deal.entity;
|
||||||
|
|
||||||
|
import bokang.xiao.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;
|
||||||
|
|
||||||
|
}
|
|
@ -5,7 +5,6 @@ import aiyh.utils.annotation.recordset.SqlOracleDbFieldAnn;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName ResponseConfigMain
|
* @ClassName ResponseConfigMain
|
||||||
* @Author 肖博亢
|
* @Author 肖博亢
|
||||||
|
@ -17,25 +16,29 @@ import java.util.List;
|
||||||
public class ResponseConfig {
|
public class ResponseConfig {
|
||||||
|
|
||||||
/** 请求唯一标识 */
|
/** 请求唯一标识 */
|
||||||
@SqlOracleDbFieldAnn("request_unique")
|
@SqlOracleDbFieldAnn("REQUEST_UNIQUE")
|
||||||
private String requestUnique;
|
private String requestUnique;
|
||||||
|
|
||||||
/** 配置描述 */
|
/** 配置描述 */
|
||||||
@SqlOracleDbFieldAnn("config_desc")
|
@SqlOracleDbFieldAnn("CONFIG_DESC")
|
||||||
private String configDesc;
|
private String configDesc;
|
||||||
|
|
||||||
/** 表类型 */
|
/** 表类型 */
|
||||||
@SqlOracleDbFieldAnn("table_type")
|
@SqlOracleDbFieldAnn("TABLE_TYPE")
|
||||||
private String tableType;
|
private int tableType;
|
||||||
|
|
||||||
/** 模型表 */
|
/** 模型表 */
|
||||||
@SqlOracleDbFieldAnn("model_table")
|
@SqlOracleDbFieldAnn("MODEL_TABLE")
|
||||||
private String modelTable;
|
private String modelTable;
|
||||||
|
|
||||||
/** 模型表名称 */
|
/** 模型表名称 */
|
||||||
@SqlOracleDbFieldAnn("model_table_name")
|
@SqlOracleDbFieldAnn("MODEL_TABLE_NAME")
|
||||||
private String modelTableName;
|
private String modelTableName;
|
||||||
|
|
||||||
|
/** 数据根路径 */
|
||||||
|
@SqlOracleDbFieldAnn("ROOT_PATH")
|
||||||
|
private String rootPath;
|
||||||
|
|
||||||
private String successExp;
|
private String successExp;
|
||||||
|
|
||||||
private List<ResponseConfigAlias> responseConfigAliasList;
|
private List<ResponseConfigAlias> responseConfigAliasList;
|
||||||
|
|
|
@ -3,6 +3,9 @@ package bokang.xiao.response_deal.entity;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import aiyh.utils.annotation.recordset.SqlOracleDbFieldAnn;
|
import aiyh.utils.annotation.recordset.SqlOracleDbFieldAnn;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName ResponseConfigDtAlias
|
* @ClassName ResponseConfigDtAlias
|
||||||
* @Author 肖博亢
|
* @Author 肖博亢
|
||||||
|
@ -13,26 +16,49 @@ import aiyh.utils.annotation.recordset.SqlOracleDbFieldAnn;
|
||||||
public class ResponseConfigAlias {
|
public class ResponseConfigAlias {
|
||||||
|
|
||||||
/** 数据路径 */
|
/** 数据路径 */
|
||||||
@SqlOracleDbFieldAnn("data_path")
|
@SqlOracleDbFieldAnn("DATA_PATH")
|
||||||
private String dataPath;
|
private String dataPath;
|
||||||
|
|
||||||
/** 数据类型 */
|
/** 数据类型 */
|
||||||
@SqlOracleDbFieldAnn("data_type")
|
@SqlOracleDbFieldAnn("DATA_TYPE")
|
||||||
private String dataType;
|
private int dataType;
|
||||||
|
|
||||||
/** 数据别名 */
|
/** 数据别名 */
|
||||||
@SqlOracleDbFieldAnn("data_alias")
|
@SqlOracleDbFieldAnn("DATA_ALIAS")
|
||||||
private String dataAlias;
|
private String dataAlias;
|
||||||
|
|
||||||
/** 数据变更 */
|
/** 表类型 */
|
||||||
@SqlOracleDbFieldAnn("data_change")
|
@SqlOracleDbFieldAnn("TABLE_TYPE")
|
||||||
private String dataChange;
|
private int tableType;
|
||||||
|
|
||||||
/** 自定义文本 */
|
/** 明细表 */
|
||||||
@SqlOracleDbFieldAnn("cus_text")
|
@SqlOracleDbFieldAnn("DETAIL_TABLE")
|
||||||
private String cusText;
|
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<>();
|
||||||
|
|
||||||
/** 类型变更 */
|
|
||||||
@SqlOracleDbFieldAnn("type_change")
|
|
||||||
private String typeChange;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,56 +16,47 @@ import java.util.regex.Pattern;
|
||||||
public class ResponseConfigValueChange {
|
public class ResponseConfigValueChange {
|
||||||
|
|
||||||
/** 值路径 */
|
/** 值路径 */
|
||||||
@SqlOracleDbFieldAnn("value_path")
|
@SqlOracleDbFieldAnn("VALUE_PATH")
|
||||||
private String valuePath;
|
private String valuePath;
|
||||||
|
|
||||||
/** 字段类型 */
|
/** 字段类型 */
|
||||||
@SqlOracleDbFieldAnn("field_type")
|
@SqlOracleDbFieldAnn("FIELD_TYPE")
|
||||||
private int fieldType;
|
private int fieldType;
|
||||||
|
|
||||||
/** 分配字段 */
|
/** 分配字段 */
|
||||||
@SqlOracleDbFieldAnn("assign_field")
|
@SqlOracleDbFieldAnn("ASSIGN_FIELD")
|
||||||
private String assignField;
|
private String assignField;
|
||||||
|
|
||||||
/** 分配表 */
|
/** 分配表 */
|
||||||
@SqlOracleDbFieldAnn("assign_table")
|
@SqlOracleDbFieldAnn("ASSIGN_TABLE")
|
||||||
private String assignTable;
|
private String assignTable;
|
||||||
|
|
||||||
/** 表类型 */
|
/** 表类型 */
|
||||||
@SqlOracleDbFieldAnn("table_type")
|
@SqlOracleDbFieldAnn("TABLE_TYPE")
|
||||||
private int tableType;
|
private int tableType;
|
||||||
|
|
||||||
public void setTableType(int tableType){
|
|
||||||
this.tableType = tableType == -1 ? this.judgmentIsDetail(this.assignTable) : tableType;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** 分配字段名 */
|
/** 分配字段名 */
|
||||||
@SqlOracleDbFieldAnn("assign_field_name")
|
@SqlOracleDbFieldAnn("ASSIGN_FIELD_NAME")
|
||||||
private String assignFieldName;
|
private String assignFieldName;
|
||||||
|
|
||||||
/** 分配类型 */
|
/** 分配类型 */
|
||||||
@SqlOracleDbFieldAnn("assign_type")
|
@SqlOracleDbFieldAnn("ASSIGN_TYPE")
|
||||||
private int assignType;
|
private int assignType;
|
||||||
|
|
||||||
/** 数据变更 */
|
/** 数据变更 */
|
||||||
@SqlOracleDbFieldAnn("data_change")
|
@SqlOracleDbFieldAnn("DATA_CHANGE")
|
||||||
private int dataChange;
|
private int dataChange;
|
||||||
|
|
||||||
/** 类型变更 */
|
/** 类型变更 */
|
||||||
@SqlOracleDbFieldAnn("type_change")
|
@SqlOracleDbFieldAnn("TYPE_CHANGE")
|
||||||
private int typeChange;
|
private int typeChange;
|
||||||
|
|
||||||
/** 自定义文本 */
|
/** 自定义文本 */
|
||||||
@SqlOracleDbFieldAnn("cus_text")
|
@SqlOracleDbFieldAnn("CUS_TEXT")
|
||||||
private String cusText;
|
private String cusText;
|
||||||
|
|
||||||
/** 判断脚本 */
|
/** 接口响应值 */
|
||||||
@SqlOracleDbFieldAnn("judgment_script")
|
private Object jsonData;
|
||||||
private String judgmentScript;
|
|
||||||
|
|
||||||
/** 条件脚本 */
|
|
||||||
@SqlOracleDbFieldAnn("condition_script")
|
|
||||||
private String conditionScript;
|
|
||||||
|
|
||||||
public int judgmentIsDetail(String tableName){
|
public int judgmentIsDetail(String tableName){
|
||||||
Pattern compiledPattern = Pattern.compile("dt_\\d+$");
|
Pattern compiledPattern = Pattern.compile("dt_\\d+$");
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
package bokang.xiao.response_deal.entity;
|
||||||
|
|
||||||
|
import bokang.xiao.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,66 @@
|
||||||
|
package bokang.xiao.response_deal.entity;
|
||||||
|
|
||||||
|
import bokang.xiao.response_deal.intfaces.TableDefinitionCallback;
|
||||||
|
import bokang.xiao.response_deal.state.State;
|
||||||
|
import bokang.xiao.response_deal.state.StateFactory;
|
||||||
|
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;
|
||||||
|
this.state.setContext(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefaultState() {
|
||||||
|
this.state = StateFactory.createState(this.getAssignType());
|
||||||
|
this.state.setContext(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dataProcess(){
|
||||||
|
this.state.handle();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package bokang.xiao.response_deal.intfaces;
|
||||||
|
|
||||||
|
import bokang.xiao.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,14 @@
|
||||||
|
package bokang.xiao.response_deal.intfaces;
|
||||||
|
|
||||||
|
import bokang.xiao.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,16 @@
|
||||||
|
package bokang.xiao.response_deal.intfaces;
|
||||||
|
|
||||||
|
import bokang.xiao.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,15 @@
|
||||||
|
package bokang.xiao.response_deal.intfaces;
|
||||||
|
|
||||||
|
import bokang.xiao.response_deal.entity.TableDefinition;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName DataCallbackInterface
|
||||||
|
* @Author 肖博亢
|
||||||
|
* @Date 2023/7/10 13:04
|
||||||
|
* @Description <h1></h1>
|
||||||
|
**/
|
||||||
|
public interface TableDefinitionCallback {
|
||||||
|
|
||||||
|
void tableHandle(TableDefinition tableDefinition);
|
||||||
|
|
||||||
|
}
|
|
@ -6,6 +6,7 @@ import bokang.xiao.response_deal.entity.ResponseConfigAlias;
|
||||||
import bokang.xiao.response_deal.entity.ResponseConfigValueChange;
|
import bokang.xiao.response_deal.entity.ResponseConfigValueChange;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName ConfigMapper
|
* @ClassName ConfigMapper
|
||||||
|
@ -48,14 +49,56 @@ public interface ConfigMapper {
|
||||||
@CollectionMethod(1)
|
@CollectionMethod(1)
|
||||||
List<ResponseConfigAlias> queryResponseConfigAlias(@ParamMapper("mainId")int mainId);
|
List<ResponseConfigAlias> queryResponseConfigAlias(@ParamMapper("mainId")int mainId);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <h2>查询响应数据转换配置信息</h2>
|
* <h2>查询响应数据转换配置信息</h2>
|
||||||
* @param mainId 主数据id
|
* @param mainId 主数据id
|
||||||
* @return 响应数据转换配置信息列表
|
* @return 响应数据转换配置信息列表
|
||||||
*/
|
*/
|
||||||
@Select("select * from uf_response_config_dt2 where mainid = #{mainId}")
|
@Select("select * from uf_response_config_dt3 where mainid = #{mainId}")
|
||||||
@CollectionMethod(2)
|
@CollectionMethod(2)
|
||||||
List<ResponseConfigValueChange> queryResponseConfigValueChange(@ParamMapper("mainId")int mainId);
|
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 处理结果
|
||||||
|
*/
|
||||||
|
@BatchInsert(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 bokang.xiao.response_deal.process;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.annotation.MethodRuleNo;
|
||||||
|
import aiyh.utils.excention.CustomerException;
|
||||||
|
import bokang.xiao.exception.ResponseException;
|
||||||
|
import bokang.xiao.response_deal.entity.ResponseConfigValueChange;
|
||||||
|
import bokang.xiao.response_deal.intfaces.DataChangeInterface;
|
||||||
|
import bokang.xiao.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 bokang.xiao.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,68 @@
|
||||||
|
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.entity.RowDefinition;
|
||||||
|
import bokang.xiao.response_deal.entity.TableDefinition;
|
||||||
|
import bokang.xiao.response_deal.intfaces.RowDefinitionCallback;
|
||||||
|
import bokang.xiao.response_deal.util.ResponseUtil;
|
||||||
|
|
||||||
|
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(1,updateRowList);
|
||||||
|
}
|
||||||
|
if(ResponseUtil.parameterIsNotNull(insertRowList)){
|
||||||
|
this.tableProcess(0,insertRowList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void tableProcess(int assignType,List<RowDefinition> rowDefinitionList){
|
||||||
|
TableDefinition tableDefinition = new TableDefinition();
|
||||||
|
BeanUtil.copyProperties(this.context,tableDefinition);
|
||||||
|
tableDefinition.setRowDefinitionList(rowDefinitionList);
|
||||||
|
tableDefinition.setTableDefinitionCallback(null);
|
||||||
|
tableDefinition.setAssignType(assignType);
|
||||||
|
tableDefinition.setDefaultState();
|
||||||
|
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 bokang.xiao.response_deal.state;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import aiyh.utils.recordset.MapperBuilderSql;
|
||||||
|
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;
|
||||||
|
import bokang.xiao.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();
|
||||||
|
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 bokang.xiao.response_deal.state;
|
||||||
|
|
||||||
|
import aiyh.utils.Util;
|
||||||
|
import bokang.xiao.response_deal.entity.TableDefinition;
|
||||||
|
import bokang.xiao.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,22 @@
|
||||||
|
package bokang.xiao.response_deal.state;
|
||||||
|
|
||||||
|
import org.docx4j.wml.U;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ClassName StateFactory
|
||||||
|
* @Author 肖博亢
|
||||||
|
* @Date 2023/7/9 23:34
|
||||||
|
* @Description <h1></h1>
|
||||||
|
**/
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,90 @@
|
||||||
|
package bokang.xiao.response_deal.state;
|
||||||
|
|
||||||
|
import aiyh.utils.ScriptUtil;
|
||||||
|
import aiyh.utils.recordset.MapperBuilderSql;
|
||||||
|
import bokang.xiao.exception.ResponseException;
|
||||||
|
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.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();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,7 +11,7 @@ import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @ClassName VendorStore
|
* @ClassName ResponseStore
|
||||||
* @Author 肖博亢
|
* @Author 肖博亢
|
||||||
* @Date 2023/3/17 18:31
|
* @Date 2023/3/17 18:31
|
||||||
* @Description <h1></h1>
|
* @Description <h1></h1>
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
package bokang.xiao.response_deal.util;
|
||||||
|
|
||||||
|
import bokang.xiao.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue