同步优化

dev
wangxuanran 2023-07-20 13:17:45 +08:00
parent 0de7a593e9
commit 7970a2456b
5 changed files with 43 additions and 5 deletions

View File

@ -1,6 +1,8 @@
package aiyh.utils.response_deal.state;
import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
import aiyh.utils.excention.ParseSqlException;
import aiyh.utils.response_deal.constant.ResponseConfigConstant;
import aiyh.utils.response_deal.entity.RowDefinition;
import aiyh.utils.response_deal.entity.TableDefinition;
@ -8,6 +10,7 @@ import aiyh.utils.response_deal.intfaces.RowDefinitionCallback;
import aiyh.utils.response_deal.util.ResponseUtil;
import aiyh.utils.tool.cn.hutool.core.bean.BeanUtil;
import aiyh.utils.tool.cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
@ -61,7 +64,13 @@ public class InsertOrUpdateState extends State{
private boolean judgmentRepetition(RowDefinition rowDefinition){
String conditionScript = Util.sbc2dbcCase(rowDefinition.getConditionScript());
String cusQuerySql = "select id from " + rowDefinition.getAssignTable() + " where " + conditionScript;
String dataId = this.configMapper.executeCusQuerySql(cusQuerySql, rowDefinition.getWhereParam(),new HashMap<>());
String dataId;
try {
dataId = this.configMapper.executeCusQuerySql(cusQuerySql, rowDefinition.getWhereParam(),new HashMap<>());
}catch (ParseSqlException e){
logger.error(Util.logStr("parse sql error, current sql : [{}], whereParam : [{}]", cusQuerySql, JSONObject.toJSONString(rowDefinition.getWhereParam())));
throw new CustomerException(e);
}
if(StrUtil.isNotBlank(dataId)){
rowDefinition.setDataId(Util.getIntValue(dataId, -1));
}

View File

@ -1,12 +1,15 @@
package aiyh.utils.response_deal.state;
import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
import aiyh.utils.excention.ParseSqlException;
import aiyh.utils.recordset.MapperBuilderSql;
import aiyh.utils.response_deal.constant.ResponseConfigConstant;
import aiyh.utils.response_deal.entity.RowDefinition;
import aiyh.utils.response_deal.entity.TableDefinition;
import aiyh.utils.response_deal.intfaces.RowDefinitionCallback;
import aiyh.utils.response_deal.util.ResponseUtil;
import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
@ -62,7 +65,12 @@ public class InsertSate extends State{
}
String updateSql = MapperBuilderSql.builderUpdateSql(assignTable, tempRowDefinition.getUpdateParam(),"upItem");
updateSql = updateSql + " where id = #{whereItem.id}";
flag = this.configMapper.executeUpdateBatchCusSql(updateSql, updateList, whereList);
try {
flag = this.configMapper.executeUpdateBatchCusSql(updateSql, updateList, whereList);
}catch (ParseSqlException e){
logger.error(Util.logStr("parse sql error, current sql : [{}], updateList : [{}], whereList : [{}]", updateSql, JSONObject.toJSONString(updateList), JSONObject.toJSONString(whereList)));
throw new CustomerException(e);
}
String modeId = Util.getModeIdByTableName(assignTable);
Util.rebuildModeDataShareByAsyncList(1,modeId,dataIdList);
}else {
@ -74,7 +82,12 @@ public class InsertSate extends State{
}
insertList.add(item.getUpdateParam());
});
flag = this.configMapper.executeInsertBatchCusSql(insertSql, insertList);
try {
flag = this.configMapper.executeInsertBatchCusSql(insertSql, insertList);
}catch (ParseSqlException e){
logger.error(Util.logStr("parse sql error, current sql : [{}], insertList : [{}]", insertSql, JSONObject.toJSONString(insertList)));
throw new CustomerException(e);
}
}
if(ResponseUtil.parameterIsNotNull(detailTableMap) && flag){
detailTableMap.forEach((key,value)->{

View File

@ -1,12 +1,16 @@
package aiyh.utils.response_deal.state;
import aiyh.utils.ScriptUtil;
import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
import aiyh.utils.excention.ParseSqlException;
import aiyh.utils.recordset.MapperBuilderSql;
import aiyh.utils.response_deal.constant.ResponseConfigConstant;
import aiyh.utils.response_deal.entity.RowDefinition;
import aiyh.utils.response_deal.entity.TableDefinition;
import aiyh.utils.response_deal.exception.ResponseException;
import aiyh.utils.response_deal.util.ResponseUtil;
import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
@ -58,7 +62,13 @@ public class UpdateState extends State {
String tempConditionScript = rowDefinition.getConditionScript();
String updateSql = MapperBuilderSql.builderUpdateSql(assignTable, rowDefinition.getUpdateParam(),"upItem");
updateSql = updateSql + " where " + tempConditionScript;
boolean flag = this.configMapper.executeUpdateBatchCusSql(updateSql, updateList, whereList);
boolean flag;
try {
flag = this.configMapper.executeUpdateBatchCusSql(updateSql, updateList, whereList);
}catch (ParseSqlException e){
logger.error(Util.logStr("parse sql error, current sql : [{}], updateList : [{}], whereList : [{}]", updateSql, JSONObject.toJSONString(updateList), JSONObject.toJSONString(whereList)));
throw new CustomerException(e);
}
logger.info("批量更新处理结果 ==>"+flag);
if(ResponseUtil.parameterIsNotNull(this.context.getTableDefinitionCallback())){
this.context.getTableDefinitionCallback().afterHandle(this.context,flag);

View File

@ -2,6 +2,8 @@ package com.api.xuanran.wang.xk_hospital.data_async.controller;
import aiyh.utils.ApiResult;
import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
import aiyh.utils.tool.cn.hutool.core.util.StrUtil;
import com.api.xuanran.wang.xk_hospital.data_async.service.XkHospitalCommonDataAsyncService;
import com.api.xuanran.wang.xk_hospital.data_async.service.impl.XkHospitalCommonDataAsyncServiceImpl;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
@ -37,6 +39,10 @@ public class CommonDataAsyncController {
@PathParam("type") String type,
@RequestBody Map<String, Object> params){
try {
if(StrUtil.isBlank(configId) || StrUtil.isBlank(type)){
throw new CustomerException("configId or type can not be empty!");
}
logger.info(Util.logStr("configId : {}, type : {}, params : {}", configId, type, params));
service.async(configId, type, params);
return ApiResult.successNoData();
}catch (Exception e){

View File

@ -13,7 +13,7 @@ import java.util.HashMap;
import java.util.Map;
/**
* <h1></h1>
* <h1></h1>
*
* @author xuanran.wang
* @date 2023/7/18 11:15