From 7970a2456bb9836a9cdb8e1ec0310821aacbb792 Mon Sep 17 00:00:00 2001 From: wangxuanran <3055088966@qq.com> Date: Thu, 20 Jul 2023 13:17:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../state/InsertOrUpdateState.java | 11 ++++++++++- .../utils/response_deal/state/InsertSate.java | 17 +++++++++++++++-- .../utils/response_deal/state/UpdateState.java | 12 +++++++++++- .../controller/CommonDataAsyncController.java | 6 ++++++ .../XkHospitalCommonDataAsyncServiceImpl.java | 2 +- 5 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/main/java/aiyh/utils/response_deal/state/InsertOrUpdateState.java b/src/main/java/aiyh/utils/response_deal/state/InsertOrUpdateState.java index 1ec7952..cd59460 100644 --- a/src/main/java/aiyh/utils/response_deal/state/InsertOrUpdateState.java +++ b/src/main/java/aiyh/utils/response_deal/state/InsertOrUpdateState.java @@ -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)); } diff --git a/src/main/java/aiyh/utils/response_deal/state/InsertSate.java b/src/main/java/aiyh/utils/response_deal/state/InsertSate.java index 31cf7b7..7567239 100644 --- a/src/main/java/aiyh/utils/response_deal/state/InsertSate.java +++ b/src/main/java/aiyh/utils/response_deal/state/InsertSate.java @@ -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)->{ diff --git a/src/main/java/aiyh/utils/response_deal/state/UpdateState.java b/src/main/java/aiyh/utils/response_deal/state/UpdateState.java index b7c4ebe..446c194 100644 --- a/src/main/java/aiyh/utils/response_deal/state/UpdateState.java +++ b/src/main/java/aiyh/utils/response_deal/state/UpdateState.java @@ -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); diff --git a/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/controller/CommonDataAsyncController.java b/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/controller/CommonDataAsyncController.java index 024f20d..4f07883 100644 --- a/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/controller/CommonDataAsyncController.java +++ b/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/controller/CommonDataAsyncController.java @@ -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 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){ diff --git a/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/service/impl/XkHospitalCommonDataAsyncServiceImpl.java b/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/service/impl/XkHospitalCommonDataAsyncServiceImpl.java index d8e16cc..6dbebf9 100644 --- a/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/service/impl/XkHospitalCommonDataAsyncServiceImpl.java +++ b/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/service/impl/XkHospitalCommonDataAsyncServiceImpl.java @@ -13,7 +13,7 @@ import java.util.HashMap; import java.util.Map; /** - *

+ *

数据同步

* * @author xuanran.wang * @date 2023/7/18 11:15