Compare commits

...

4 Commits

Author SHA1 Message Date
ic_excellent 8740a1bfa6 Merge branch 'dev' of https://gitea.yeyaguitu.cn/ecology/ebu_ecology_dev1 into dev
处理冲突
2023-07-10 20:36:19 +08:00
ic_excellent b1e3a119bc 返回信息解析 2023-07-10 20:35:59 +08:00
ic_excellent 6fe6171532 Merge branch 'dev' of https://gitea.yeyaguitu.cn/ecology/ebu_ecology_dev1 into dev
处理冲突
2023-07-06 11:15:53 +08:00
ic_excellent efaca449a1 修复新宏bug 2023-07-06 11:15:28 +08:00
27 changed files with 1265 additions and 157 deletions

View File

@ -67,12 +67,14 @@ public interface SourceTrackingMapper {
@CollectionMethod(3)
List<QuotaData> queryQuotaList(@ParamMapper("sourceTackingCode")String sourceTackingCode);
/**
* <h2></h2>
* @param sourceTrackingCode
* @return
* <h2></h2>
* @param ids id
* @return
*/
@Update("update uf_src_rfq set sfypf = 0 where xydh = #{sourceTrackingCode}")
boolean updateSourceTrackingStatus(String sourceTrackingCode);
@Delete("delete from uf_vendorMarkReport where id in ($t{ids})")
boolean deleteReport(@ParamMapper("ids")String ids);
}

View File

@ -39,6 +39,14 @@ public interface VendorReportMapper {
"values(#{item.project},#{item.desc},#{item.weight},#{item.score},#{item.detailDesc},#{mainId})")
boolean insertReportDt(@BatchSqlArgs List<VendorMarkReportDt> vendorMarkReportDtList,@ParamMapper("mainId") int mainId);
/**
* <h2></h2>
* @param sourceTrackingCode
* @return
*/
@Update("update uf_src_rfq set sfypf = 0 where xydh = #{sourceTrackingCode}")
boolean updateSourceTrackingStatus(String sourceTrackingCode);
/**
* <h2></h2>
* @param ids id

View File

@ -92,14 +92,15 @@ public class GenerateReportSchedule extends CusBaseCronJob {
vendorReportMapper.updateReport(vendorMarkReport);
vendorReportMapper.insertReportDt(vendorMarkReport.getVendorMarkReportDtList(),dataId);
}
sourceTrackingMapper.updateSourceTrackingStatus(sourceTrackingData.getSourceTrackingCode());
vendorReportMapper.updateSourceTrackingStatus(sourceTrackingData.getSourceTrackingCode());
Util.rebuildModeDataShareByAsyncList(1,Util.getIntValue(reportModelId),reportIdList);
Util.commitTransMapper(VendorReportMapper.class);
}catch (Exception e){
log.info("GenerateReportSchedule execute error!!! "+Util.getErrString(e));
Util.rollbackTransMapper(VendorReportMapper.class);
if(!reportIdList.isEmpty()) {
String ids = reportIdList.stream().map(Util::null2String).collect(Collectors.joining(","));
vendorReportMapper.deleteReport(ids);
sourceTrackingMapper.deleteReport(ids);
}
}
}

View File

@ -68,7 +68,7 @@ public class DealWithMapping extends ToolUtil {
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 {

View File

@ -9,6 +9,7 @@ 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;
@ -62,6 +63,7 @@ import weaver.interfaces.datasource.DataSource;
import weaver.workflow.workflow.WfForceOver;
import weaver.workflow.workflow.WorkflowVersion;
import weaver.xiao.commons.utils.DocImageFileUtil;
import youhong.ai.utiltest.resultjsonparase.ParseTest;
import java.io.*;
import java.lang.reflect.Constructor;
@ -120,6 +122,15 @@ public class NormalTest extends BaseTest {
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
public void paramGet(){
Map<String,Object> param = new HashMap<>();

View File

@ -1,19 +1,24 @@
package bokang.xiao.response_deal;
import aiyh.utils.ScriptUtil;
import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
import aiyh.utils.function.Bi3Function;
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.response_deal.entity.ResponseConfig;
import bokang.xiao.response_deal.entity.ResponseConfigAlias;
import bokang.xiao.response_deal.entity.ResponseConfigValueChange;
import bokang.xiao.response_deal.constant.ResponseConfigConstant;
import bokang.xiao.response_deal.entity.*;
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.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 java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
@ -22,68 +27,28 @@ import java.util.stream.Collectors;
* @Date 2023/7/4 17:42
* @Description <h1></h1>
**/
@Setter
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 TableDefinitionCallback tableCallback;
public void parseConfig(String uniqueCode, ResponeVo responeVo) {
if (responeVo.getCode() != 200) {
throw new CustomerException("你妈没成功");
}
private RowDefinitionCallback rowCallback;
List<ResponseConfig> responseConfigs = configMapper.queryResponseConfigByUnique(uniqueCode);
private FieldDefinitionCallback fieldDefinitionCallback;
if (CollectionUtil.isEmpty(responseConfigs)) {
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();
public void doResponseSync(String uniqueCode, ResponeVo responeVo) {
Map<String, Object> responseMap = responeVo.getResponseMap();
List<Map<String, Object>> resultList = new ArrayList<>();
if (CollectionUtil.isEmpty(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("失败了!");
}
}
}
ResponseUtil.parameterJudgment(responseMap,"接口返回都为空 你处理个勾");
this.doResponseSync(uniqueCode,responseMap);
}
public void getConfig(String uniqueCode, ResponeVo responeVo) {
public void doResponseSync(String uniqueCode, Map<String, Object> responseMap) {
List<ResponseConfig> responseConfigList = configMapper.queryResponseConfigByUnique(uniqueCode);
if (Objects.isNull(responseConfigList) || responseConfigList.isEmpty()) {
throw new ResponseException("response config is empty please check!!! ");
}
ResponseUtil.parameterJudgment(responseConfigList,"response config is empty please check!!! ");
Map<String, ResponseConfig> tableNameConfig;
try {
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));
throw new ResponseException("response config error please check!!! ");
}
tableNameConfig.entrySet().stream().forEach(item -> {
dealConfig(item.getValue(), responeVo);
});
ResponseUtil.parameterJudgment(responseMap,"接口返回都为空 你处理个勾");
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();
if (Objects.isNull(valueChangeList) || valueChangeList.isEmpty()) {
throw new ResponseException("valueChangeList config is empty please check!!!");
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)
.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);
Map<String, List<ResponseConfigValueChange>> collect = mainConfig.stream().collect(Collectors.groupingBy(ResponseConfigValueChange::getAssignTable));
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));
//做数据处理
tableDefinition.setDefaultState();
tableDefinition.dataProcess();
}
public void responseToEntity(ResponseConfigValueChange responseConfigValueChange, Map<String, Object> param) {
String valuePath = responseConfigValueChange.getValuePath();
Util.ValueOrList valueOrListByKeyStr = Util.getValueOrListByKeyStr(valuePath, param);
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)
.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());
}
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -5,7 +5,6 @@ import aiyh.utils.annotation.recordset.SqlOracleDbFieldAnn;
import java.util.List;
/**
* @ClassName ResponseConfigMain
* @Author
@ -17,26 +16,30 @@ import java.util.List;
public class ResponseConfig {
/** 请求唯一标识 */
@SqlOracleDbFieldAnn("request_unique")
@SqlOracleDbFieldAnn("REQUEST_UNIQUE")
private String requestUnique;
/** 配置描述 */
@SqlOracleDbFieldAnn("config_desc")
@SqlOracleDbFieldAnn("CONFIG_DESC")
private String configDesc;
/** 表类型 */
@SqlOracleDbFieldAnn("table_type")
private String tableType;
@SqlOracleDbFieldAnn("TABLE_TYPE")
private int tableType;
/** 模型表 */
@SqlOracleDbFieldAnn("model_table")
@SqlOracleDbFieldAnn("MODEL_TABLE")
private String modelTable;
/** 模型表名称 */
@SqlOracleDbFieldAnn("model_table_name")
@SqlOracleDbFieldAnn("MODEL_TABLE_NAME")
private String modelTableName;
private String successExp;
/** 数据根路径 */
@SqlOracleDbFieldAnn("ROOT_PATH")
private String rootPath;
private String successExp;
private List<ResponseConfigAlias> responseConfigAliasList;

View File

@ -3,6 +3,9 @@ package bokang.xiao.response_deal.entity;
import lombok.Data;
import aiyh.utils.annotation.recordset.SqlOracleDbFieldAnn;
import java.util.HashMap;
import java.util.Map;
/**
* @ClassName ResponseConfigDtAlias
* @Author
@ -13,26 +16,49 @@ import aiyh.utils.annotation.recordset.SqlOracleDbFieldAnn;
public class ResponseConfigAlias {
/** 数据路径 */
@SqlOracleDbFieldAnn("data_path")
@SqlOracleDbFieldAnn("DATA_PATH")
private String dataPath;
/** 数据类型 */
@SqlOracleDbFieldAnn("data_type")
private String dataType;
@SqlOracleDbFieldAnn("DATA_TYPE")
private int dataType;
/** 数据别名 */
@SqlOracleDbFieldAnn("data_alias")
@SqlOracleDbFieldAnn("DATA_ALIAS")
private String dataAlias;
/** 数据变更 */
@SqlOracleDbFieldAnn("data_change")
private String dataChange;
/** 表类型 */
@SqlOracleDbFieldAnn("TABLE_TYPE")
private int tableType;
/** 自定义文本 */
@SqlOracleDbFieldAnn("cus_text")
private String cusText;
/** 明细表 */
@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<>();
/** 类型变更 */
@SqlOracleDbFieldAnn("type_change")
private String typeChange;
}

View File

@ -16,56 +16,47 @@ import java.util.regex.Pattern;
public class ResponseConfigValueChange {
/** 值路径 */
@SqlOracleDbFieldAnn("value_path")
@SqlOracleDbFieldAnn("VALUE_PATH")
private String valuePath;
/** 字段类型 */
@SqlOracleDbFieldAnn("field_type")
@SqlOracleDbFieldAnn("FIELD_TYPE")
private int fieldType;
/** 分配字段 */
@SqlOracleDbFieldAnn("assign_field")
@SqlOracleDbFieldAnn("ASSIGN_FIELD")
private String assignField;
/** 分配表 */
@SqlOracleDbFieldAnn("assign_table")
@SqlOracleDbFieldAnn("ASSIGN_TABLE")
private String assignTable;
/** 表类型 */
@SqlOracleDbFieldAnn("table_type")
@SqlOracleDbFieldAnn("TABLE_TYPE")
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;
/** 分配类型 */
@SqlOracleDbFieldAnn("assign_type")
@SqlOracleDbFieldAnn("ASSIGN_TYPE")
private int assignType;
/** 数据变更 */
@SqlOracleDbFieldAnn("data_change")
@SqlOracleDbFieldAnn("DATA_CHANGE")
private int dataChange;
/** 类型变更 */
@SqlOracleDbFieldAnn("type_change")
@SqlOracleDbFieldAnn("TYPE_CHANGE")
private int typeChange;
/** 自定义文本 */
@SqlOracleDbFieldAnn("cus_text")
@SqlOracleDbFieldAnn("CUS_TEXT")
private String cusText;
/** 判断脚本 */
@SqlOracleDbFieldAnn("judgment_script")
private String judgmentScript;
/** 条件脚本 */
@SqlOracleDbFieldAnn("condition_script")
private String conditionScript;
/** 接口响应值 */
private Object jsonData;
public int judgmentIsDetail(String tableName){
Pattern compiledPattern = Pattern.compile("dt_\\d+$");

View File

@ -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;
}

View File

@ -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();
}
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -6,6 +6,7 @@ import bokang.xiao.response_deal.entity.ResponseConfigAlias;
import bokang.xiao.response_deal.entity.ResponseConfigValueChange;
import java.util.List;
import java.util.Map;
/**
* @ClassName ConfigMapper
@ -48,14 +49,56 @@ public interface ConfigMapper {
@CollectionMethod(1)
List<ResponseConfigAlias> queryResponseConfigAlias(@ParamMapper("mainId")int mainId);
/**
* <h2></h2>
* @param mainId id
* @return
*/
@Select("select * from uf_response_config_dt2 where mainid = #{mainId}")
@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
*/
@BatchInsert(custom = true)
boolean executeUpdateBatchCusSql(@SqlString String cusSql,
@BatchSqlArgs("upItem") List<Map<String,Object>> updateList,
@BatchSqlArgs("whereItem") List<Map<String,Object>> whereList);
}

View File

@ -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);
}
}

View File

@ -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));
}
}

View File

@ -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);
}
}

View File

@ -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);
}
});
}
}

View File

@ -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();
}

View File

@ -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();
}
}
}

View File

@ -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);
}
});
});
}
}

View File

@ -11,7 +11,7 @@ import java.util.*;
import java.util.stream.Collectors;
/**
* @ClassName VendorStore
* @ClassName ResponseStore
* @Author
* @Date 2023/3/17 18:31
* @Description <h1></h1>

View File

@ -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);
}
}