diff --git a/src/main/java/aiyh/utils/Util.java b/src/main/java/aiyh/utils/Util.java index 136bd19..f0dd810 100644 --- a/src/main/java/aiyh/utils/Util.java +++ b/src/main/java/aiyh/utils/Util.java @@ -12,6 +12,7 @@ import aiyh.utils.mapUtil.UtilHashMap; import aiyh.utils.mapUtil.UtilLinkedHashMap; import aiyh.utils.mapper.UtilMapper; import aiyh.utils.recordset.RecordsetUtil; +import aiyh.utils.recordset.RsThreadLocalManager; import aiyh.utils.service.UtilService; import aiyh.utils.sqlUtil.builderSql.impl.BuilderSqlImpl; import aiyh.utils.sqlUtil.whereUtil.Where; @@ -106,6 +107,7 @@ public class Util extends weaver.general.Util { static ToolUtil toolUtil = new ToolUtil(); private static RecordSet rs; private static volatile Logger log = null; + private static final RsThreadLocalManager LOCAL_MANAGER = new RsThreadLocalManager(); static { try { @@ -4111,14 +4113,15 @@ public class Util extends weaver.general.Util { * @return 部门id **/ public static int getNextDepartmentId(int subId){ - RecordSet insertRs = new RecordSet(); char separator = weaver.general.Util.getSeparator(); String uuid = UUID.randomUUID().toString(); + String empty = ""; String para = uuid + separator +uuid + separator + - "" + separator + "" + separator + subId + separator + 1 + separator + ""; - insertRs.executeProc("HrmDepartment_Insert", para); - if(insertRs.next()){ - return insertRs.getInt(1); + empty + separator + empty + separator + subId + separator + 1 + separator + empty; + RecordSet procRs = getThreadRecord(); + procRs.executeProc("HrmDepartment_Insert", para); + if(procRs.next()){ + return procRs.getInt(1); } return -1; } @@ -4132,13 +4135,43 @@ public class Util extends weaver.general.Util { * @return 人员id **/ public static int getNextHrmId(){ - RecordSet procRs = new RecordSet(); + RecordSet procRs = getThreadRecord(); procRs.executeProc("HrmResourceMaxId_Get", ""); if (procRs.next()) { return procRs.getInt(1); } return -1; } + + /** + *

获取当前线程rs对象

+ * @author xuanran.wang + * @dateTime 2023/7/19 15:28 + * @return recordSet对象 + **/ + public static RecordSet getThreadRecord(){ + String name = Thread.currentThread().getId() + "_" + Thread.currentThread().getName(); + return getRecordFromRsManger(name); + } + + /** + *

通过名字获取rs池中rs对象

+ * @author xuanran.wang + * @dateTime 2023/7/19 15:29 + * @param name rs池中的key + * @return recordSet对象 + **/ + public static RecordSet getRecordFromRsManger(String name){ + RecordSet rs = LOCAL_MANAGER.getRs(name); + if(null == rs){ + LOCAL_MANAGER.setRecordSet(name); + rs = LOCAL_MANAGER.getRs(name); + if(null == rs){ + rs = new RecordSet(); + } + } + return rs; + } } diff --git a/src/main/java/aiyh/utils/response_deal/ResponseMappingDeal.java b/src/main/java/aiyh/utils/response_deal/ResponseMappingDeal.java index 81f6d36..4d8fd4d 100644 --- a/src/main/java/aiyh/utils/response_deal/ResponseMappingDeal.java +++ b/src/main/java/aiyh/utils/response_deal/ResponseMappingDeal.java @@ -68,6 +68,16 @@ public class ResponseMappingDeal { logger.info(String.format("%s 相关响应配置信息==> %s", uniqueCode, JSON.toJSONString(responseConfigList))); // 自定义校验 ResponseUtil.parameterJudgment(responseConfigList, "response config is empty please check!!! "); + // 将所有跟sql有关的字段全部全角转半角 + responseConfigList.forEach(item-> { + item.getResponseConfigAliasList().forEach(responseConfigAlias -> { + responseConfigAlias.setConditionScript(Util.sbc2dbcCase(responseConfigAlias.getConditionScript())); + responseConfigAlias.setJudgmentScript(Util.sbc2dbcCase(responseConfigAlias.getJudgmentScript())); + }); + item.getValueChangeList().forEach(responseConfigValueChange -> { + responseConfigValueChange.setCusText(Util.sbc2dbcCase(responseConfigValueChange.getCusText())); + }); + }); Map tableNameConfig; try { // 对查询到的多个配置进行整合,以同步表表名作为key 配置作为value @@ -117,6 +127,7 @@ public class ResponseMappingDeal { .tableDefinitionCallback(this.tableCallback) .tableType(responseConfig.getTableType()) .assignType(ResponseConfigConstant.NO_HANDLE) + .tableDefinitionCallback(tableCallback) .assignTable(responseConfig.getModelTableName()).build(); } // 做数据处理 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 549969d..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,5 +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; @@ -7,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; @@ -22,9 +26,6 @@ public class InsertOrUpdateState extends State{ @Override public void handle() { - if(ResponseUtil.parameterIsNotNull(this.context.getTableDefinitionCallback())){ - this.context.getTableDefinitionCallback().tableHandle(this.context); - } List rowDefinitionList = this.context.getRowDefinitionList(); List updateRowList = new ArrayList<>(); List insertRowList = new ArrayList<>(); @@ -55,16 +56,24 @@ public class InsertOrUpdateState extends State{ BeanUtil.copyProperties(this.context,tableDefinition); tableDefinition.setState(null); tableDefinition.setRowDefinitionList(rowDefinitionList); - tableDefinition.setTableDefinitionCallback(null); tableDefinition.setAssignType(assignType); tableDefinition.setDefaultState(null); tableDefinition.dataProcess(); } private boolean judgmentRepetition(RowDefinition rowDefinition){ - String conditionScript = rowDefinition.getConditionScript(); + String 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)); + } return StrUtil.isNotBlank(dataId); } 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 e0965cc..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,19 +65,35 @@ 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); - if(ResponseUtil.parameterIsNotNull(detailTableMap) && flag){ - detailTableMap.forEach((key,value)->{ - value.setDefaultState(null); - value.dataProcess(); - }); - } }else { String insertSql = MapperBuilderSql.builderInsertSql(assignTable, tempRowDefinition.getUpdateParam(),"item"); - List> insertList = rowDefinitionList.stream().map(RowDefinition::getUpdateParam).collect(Collectors.toList()); - flag = this.configMapper.executeInsertBatchCusSql(insertSql, insertList); + List> insertList = new ArrayList<>(); + rowDefinitionList.forEach(item ->{ + if(mainOrDetail == ResponseConfigConstant.MAIN_TABLE){ + detailTableDeal(item,detailTableMap); + } + insertList.add(item.getUpdateParam()); + }); + 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)->{ + value.setDefaultState(null); + value.dataProcess(); + }); } if(ResponseUtil.parameterIsNotNull(this.context.getTableDefinitionCallback())){ this.context.getTableDefinitionCallback().afterHandle(this.context,flag); @@ -91,6 +110,7 @@ public class InsertSate extends State{ } rowDefinitionList.forEach(item ->{ item.getUpdateParam().put("mainid",mainId); + item.getWhereParam().put("mainid",mainId); }); if(mainDetailMap.containsKey(key)){ TableDefinition tableDefinition = mainDetailMap.get(key); diff --git a/src/main/java/aiyh/utils/response_deal/state/NoHandleState.java b/src/main/java/aiyh/utils/response_deal/state/NoHandleState.java new file mode 100644 index 0000000..537b4fd --- /dev/null +++ b/src/main/java/aiyh/utils/response_deal/state/NoHandleState.java @@ -0,0 +1,30 @@ +package aiyh.utils.response_deal.state; + +import aiyh.utils.response_deal.constant.ResponseConfigConstant; +import aiyh.utils.response_deal.entity.TableDefinition; +import aiyh.utils.response_deal.util.ResponseUtil; + +import java.util.HashMap; +import java.util.Map; + +/** + * @ClassName NoHandleState + * @Author 肖博亢 + * @Date 2023/7/19 16:51 + * @Description

+ **/ +public class NoHandleState extends State{ + + @Override + public void handle() { + if(this.context.getMainOrDetail() == ResponseConfigConstant.MAIN_TABLE) { + Map detailTableMap = this.context.getDetailTableMap(); + if (ResponseUtil.parameterIsNotNull(detailTableMap)) { + detailTableMap.forEach((key, value) -> { + value.setDefaultState(null); + value.dataProcess(); + }); + } + } + } +} diff --git a/src/main/java/aiyh/utils/response_deal/state/State.java b/src/main/java/aiyh/utils/response_deal/state/State.java index 6bea1b3..29a0a3b 100644 --- a/src/main/java/aiyh/utils/response_deal/state/State.java +++ b/src/main/java/aiyh/utils/response_deal/state/State.java @@ -16,7 +16,7 @@ public abstract class State { protected final ConfigMapper configMapper = Util.getMapper(ConfigMapper.class); /** 日志对象 */ - protected final Logger logger = Util.getLogger(); + protected final Logger logger = Util.getLogger("json_util"); /** 上下文对象 */ protected TableDefinition context; 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 2a64808..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); @@ -83,6 +93,12 @@ public class UpdateState extends State { return; } detailTableMap.forEach((key,value) ->{ + if(item.getDataId() > 0){ + for (RowDefinition rowDefinition : value.getRowDefinitionList()) { + rowDefinition.getUpdateParam().put("mainid", item.getDataId()); + rowDefinition.getWhereParam().put("mainid", item.getDataId()); + } + } if(mainDetailMap.containsKey(key)){ mainDetailMap.get(key).getRowDefinitionList().addAll(value.getRowDefinitionList()); }else { diff --git a/src/main/java/com/api/bokang/xiao/sh_bigdata/mapper/ReportMapper.java b/src/main/java/com/api/bokang/xiao/sh_bigdata/mapper/ReportMapper.java index 6ff3959..4cdc5df 100644 --- a/src/main/java/com/api/bokang/xiao/sh_bigdata/mapper/ReportMapper.java +++ b/src/main/java/com/api/bokang/xiao/sh_bigdata/mapper/ReportMapper.java @@ -37,12 +37,15 @@ public interface ReportMapper { @CaseConversion(value = false) List> queryReportData2(@ParamMapper("param") Map param,@ParamMapper("uid") int uid); - @Select("select id,hbwb,ysclwb,gzrywb,gzclwb,ldrwb,sfsjyc,ddsjyc,dlsk,yslx,hbcc,sfsj,ddsj,sfd,ddd,wdwcl,dwcljsy,wdwclqt,xcap,lxr," + - " lxrdh,bz,gzcl,gzry,zs,dyjbr,djr,ldr,lddw,rwzt,ykdh,gbs, " + - " (select LISTAGG(concat(wb, ',', dw), '-') WITHIN GROUP (ORDER BY wb) from uf_zwfwdjjmb_dt1 where mainid = main.id) ysdx, " + - " dyjbr, (select lastname from hrmresource where id = dyjbr) dyjbr_span," + - " djr, (select lastname from hrmresource where id = djr) djr_span " + - " from uf_zwfwdjjmb main $t{param.whereSql} order by dlsk1 ") + @Select("select main.*," + + " (select lastname from hrmresource where id = dyjbr) dyjbr_span," + + " (select lastname from hrmresource where id = djr) djr_span," + + " (select LISTAGG(concat(wb, ',', dw), '-') WITHIN GROUP (ORDER BY wb) from uf_zwfwdjjmb_dt1 where mainid = main.id) ysdx," + + " (select LISTAGG(concat(dwclwb,'(', dwcljsywb,')'), ',') WITHIN GROUP (ORDER BY dwclwb) from uf_zwfwdjjmb_dt3 where mainid = main.id) car_people," + + " (select LISTAGG(concat(gzclwb,'(', gzcljsywb,')'), ',') WITHIN GROUP (ORDER BY gzclwb) from uf_zwfwdjjmb_dt4 where mainid = main.id) work_people," + + " (select LISTAGG(concat(fjhwb,'(', ysdxwb,')'), ',') WITHIN GROUP (ORDER BY fjhwb) from uf_zwfwdjjmb_dt2 where mainid = main.id) put_up " + + "from uf_zwfwdjjmb main $t{param.whereSql} " + + "order by dlsk1 ") @CaseConversion(value = false) List> queryReportData3(@ParamMapper("param") Map param,@ParamMapper("uid") int uid); @@ -60,7 +63,7 @@ public interface ReportMapper { * @param param 查询参数 * @return 当日值班人员 */ - @Select("select hrm.lastname today_welcome,ry.zbry,hrm1.lastname organ_watch,ry.zbry1,hrm2.lastname head_watch,ry.zbry2 " + + @Select("select hrm.lastname head_watch,ry.zbry,hrm1.lastname organ_watch,ry.zbry1,hrm2.lastname today_welcome,ry.zbry2 " + " from uf_ryzbjlbzjb_dt1 ry " + " inner join hrmresource hrm on ry.zbry = hrm.id " + " inner join hrmresource hrm1 on ry.zbry1 = hrm1.id " + diff --git a/src/main/java/com/api/bokang/xiao/sh_bigdata/service/ReportService.java b/src/main/java/com/api/bokang/xiao/sh_bigdata/service/ReportService.java index e83907c..ceffa97 100644 --- a/src/main/java/com/api/bokang/xiao/sh_bigdata/service/ReportService.java +++ b/src/main/java/com/api/bokang/xiao/sh_bigdata/service/ReportService.java @@ -41,12 +41,12 @@ public class ReportService { //开始日期 String beginDate = Util.null2String(param.get("beginDate")); //结束日期 - String endData = Util.null2String(param.get("endData")); + String endDate = Util.null2String(param.get("endDate")); //航班车次 String flightAndTrain = Util.null2String(param.get("flightAndTrain")); String whereSql = ""; - if(!"".equals(beginDate) && !"".equals(endData)){ - whereSql += " and (dlsk1 between #{param.beginDate} and #{param.endData} )"; + if(!"".equals(beginDate) && !"".equals(endDate)){ + whereSql += " and (dlsk1 between #{param.beginDate} and #{param.endDate} )"; }else { param.put("today", TimeUtil.getCurrentDateString()); whereSql += " and dlsk1 >= #{param.today} "; @@ -55,10 +55,11 @@ public class ReportService { whereSql += " and dyjbr = #{param.registrationPeople} "; } if(!"".equals(flightAndTrain)){ - whereSql += " and hbwb = #{param.flightAndTrain} "; + whereSql += " and hbcc = #{param.flightAndTrain} "; } if(!"".equals(project)){ - whereSql += " and exits (select 1 from uf_zwfwdjjmb_dt1 where mainid = main.id and ysdx = #{param.project}) "; + //whereSql += " and exits (select 1 from uf_zwfwdjjmb_dt1 where mainid = main.id and ysdx = #{param.project}) "; + whereSql += " and exits (select 1 from uf_zwfwdjjmb_dt1 where mainid = main.id and wb like '%$t{param.project}%') "; } whereSql = whereSql.replaceFirst(" and "," where "); return whereSql; 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/definitions/XkHospitalCommonDefinition.java b/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/definitions/XkHospitalCommonDefinition.java index 477ed90..e447d77 100644 --- a/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/definitions/XkHospitalCommonDefinition.java +++ b/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/definitions/XkHospitalCommonDefinition.java @@ -8,10 +8,6 @@ import com.engine.common.service.impl.ThemeServiceImpl; import org.apache.log4j.Logger; import weaver.hrm.company.DepartmentComInfo; import weaver.hrm.resource.ResourceComInfo; -import weaver.matrix.MatrixUtil; - -import java.util.List; -import java.util.Map; import java.util.concurrent.ExecutorService; /** @@ -49,14 +45,16 @@ public class XkHospitalCommonDefinition { *

部门缓存

**/ protected static final DepartmentComInfo DEPARTMENT_COM_INFO = new DepartmentComInfo(); - /** - *

人员缓存

- **/ - protected static ResourceComInfo RESOURCE_COM_INFO = null; + /** *

系统主题接口

**/ protected static final ThemeServiceImpl THEME_SERVICE = new ThemeServiceImpl(); + /** + *

人员缓存

+ **/ + protected static ResourceComInfo RESOURCE_COM_INFO = null; + static { try { RESOURCE_COM_INFO = new ResourceComInfo(); @@ -66,40 +64,4 @@ public class XkHospitalCommonDefinition { } } - /** - * 同步系统缓存 - * @param table 表名 - * @param idList 数据id集合 - */ - protected void synCache(String table, List idList){ - if (DEPARTMENT.equals(table)) { - threadPoolInstance.execute(()->{ - try { - DEPARTMENT_COM_INFO.removeCache(); - MatrixUtil.sysDepartmentData(); - }catch (Exception e){ - log.error("同步系统部门缓存error : " + e.getMessage()); - Util.logErrorStr(e); - } - }); - }else if(HRM_RESOURCE.equals(table)){ - try { - List> hrmSubList = dataAsyncMapper.selectHrmSubByHrmIdList(idList); - hrmSubList.forEach(map->{ - THEME_SERVICE.createSubCompanyMenu(map.get("id"), map.get("sub")); - }); - RESOURCE_COM_INFO.removeCache(); - }catch (Exception e){ - log.error("同步系统人员缓存error : " + e.getMessage()); - Util.logErrorStr(e); - } - } - } - - - - - - - } diff --git a/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/definitions/row/HrmDepartmentRowDefinition.java b/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/definitions/row/HrmDepartmentRowDefinition.java index fa1c7c8..50ac6fe 100644 --- a/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/definitions/row/HrmDepartmentRowDefinition.java +++ b/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/definitions/row/HrmDepartmentRowDefinition.java @@ -2,6 +2,7 @@ package com.api.xuanran.wang.xk_hospital.data_async.definitions.row; import aiyh.utils.Util; import aiyh.utils.excention.CustomerException; +import aiyh.utils.response_deal.constant.ResponseConfigConstant; import aiyh.utils.response_deal.entity.RowDefinition; import aiyh.utils.response_deal.intfaces.RowDefinitionCallback; import aiyh.utils.response_deal.mapper.ConfigMapper; @@ -9,6 +10,7 @@ import aiyh.utils.tool.cn.hutool.core.util.StrUtil; import com.api.xuanran.wang.xk_hospital.data_async.definitions.XkHospitalCommonDefinition; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; +import org.apache.commons.lang3.StringUtils; import weaver.conn.RecordSet; import java.util.HashMap; @@ -31,22 +33,33 @@ public class HrmDepartmentRowDefinition extends XkHospitalCommonDefinition imple @Override public boolean judgmentRepetition(RowDefinition rowDefinition) { - String conditionScript = rowDefinition.getConditionScript(); + int orDetail = rowDefinition.getMainOrDetail(); + String conditionScript = Util.sbc2dbcCase(rowDefinition.getConditionScript()); String cusQuerySql = "select id from " + rowDefinition.getAssignTable() + " where " + conditionScript; String dataId = configMapper.executeCusQuerySql(cusQuerySql, rowDefinition.getWhereParam(),new HashMap<>()); - if(StrUtil.isBlank(dataId)){ - int nextId = -1; - if(HRM_RESOURCE.equals(table)){ - nextId = Util.getNextHrmId(); - }else if(DEPARTMENT.equals(table)){ - nextId = Util.getNextDepartmentId(); + if(ResponseConfigConstant.MAIN_TABLE == orDetail){ + if(StrUtil.isBlank(dataId)){ + int nextId = -1; + if(HRM_RESOURCE.equals(table)){ + nextId = Util.getNextHrmId(); + }else if(DEPARTMENT.equals(table)){ + nextId = Util.getNextDepartmentId(); + } + if(nextId < 0){ + throw new CustomerException("从 " + table + " 获取下一个id失败!"); + } + rowDefinition.setDataId(nextId); + if(HRM_RESOURCE.equals(table)){ + rowDefinition.getUpdateParam().put("id", nextId); + rowDefinition.setConditionScript(""); + return false; + }else { + rowDefinition.getWhereParam().put("id", nextId); + rowDefinition.setConditionScript(" id = #{whereItem.id}"); + } } - if(nextId < 0){ - throw new CustomerException("从 " + table + " 获取下一个id失败!"); - } - rowDefinition.setDataId(nextId); - rowDefinition.getWhereParam().put("id", nextId); - rowDefinition.setConditionScript(" id = #{whereItem.id}"); + }else { + return StringUtils.isNotBlank(dataId); } return true; } diff --git a/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/definitions/table/HrmDepartmentTableDefinition.java b/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/definitions/table/HrmDepartmentTableDefinition.java index e36e021..8d7aac7 100644 --- a/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/definitions/table/HrmDepartmentTableDefinition.java +++ b/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/definitions/table/HrmDepartmentTableDefinition.java @@ -2,6 +2,7 @@ package com.api.xuanran.wang.xk_hospital.data_async.definitions.table; import aiyh.utils.Util; import aiyh.utils.excention.CustomerException; +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.TableDefinitionCallback; @@ -9,9 +10,11 @@ import com.api.xuanran.wang.xk_hospital.data_async.definitions.XkHospitalCommonD import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; import org.apache.commons.collections.CollectionUtils; +import weaver.matrix.MatrixUtil; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.stream.Collectors; /** @@ -28,7 +31,18 @@ public class HrmDepartmentTableDefinition extends XkHospitalCommonDefinition imp @Override public void tableHandle(TableDefinition tableDefinition) { - + if(ResponseConfigConstant.DETAIL_TABLE == tableDefinition.getMainOrDetail()){ + List list = tableDefinition.getRowDefinitionList(); + if(CollectionUtils.isEmpty(list)){ + return; + } + for (RowDefinition rowDefinition : list) { + Object mainId = rowDefinition.getUpdateParam().remove("mainid"); + if(!Objects.isNull(mainId)){ + rowDefinition.getUpdateParam().put("id", mainId); + } + } + } } @Override @@ -38,16 +52,36 @@ public class HrmDepartmentTableDefinition extends XkHospitalCommonDefinition imp .map(RowDefinition::getDataId) .filter(dataId -> dataId > 0) .collect(Collectors.toList()); - if(CollectionUtils.isEmpty(idList)){ - return; - } - if(!flag){ - if (!this.dataAsyncMapper.deleteHrmDepart(idList)) { + if (!flag) { + if (CollectionUtils.isNotEmpty(idList) && !this.dataAsyncMapper.deleteHrmDepart(idList)) { log.error("删除 " + table + " 表数据失败!"); } throw new CustomerException("同步 " + table + " 表数据失败!"); - }else { - synCache(table, idList); + } else { + if (HRM_RESOURCE.equals(table)) { + try { + if(CollectionUtils.isNotEmpty(idList)) { + List> hrmSubList = dataAsyncMapper.selectHrmSubByHrmIdList(idList); + hrmSubList.forEach(map -> { + THEME_SERVICE.createSubCompanyMenu(map.get("id"), map.get("sub")); + }); + } + RESOURCE_COM_INFO.removeCache(); + } catch (Exception e) { + log.error("同步系统人员缓存error : " + e.getMessage()); + Util.logErrorStr(e); + } + } else if (DEPARTMENT.equals(table)) { + threadPoolInstance.execute(() -> { + try { + DEPARTMENT_COM_INFO.removeCache(); + MatrixUtil.sysDepartmentData(); + } catch (Exception e) { + log.error("同步系统部门缓存error : " + e.getMessage()); + Util.logErrorStr(e); + } + }); + } } } } diff --git a/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/mapper/XkHospitalDataAsyncMapper.java b/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/mapper/XkHospitalDataAsyncMapper.java index 4b59630..0efd014 100644 --- a/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/mapper/XkHospitalDataAsyncMapper.java +++ b/src/main/java/com/api/xuanran/wang/xk_hospital/data_async/mapper/XkHospitalDataAsyncMapper.java @@ -14,10 +14,10 @@ import java.util.Map; @SqlMapper public interface XkHospitalDataAsyncMapper { - @Delete("delete from hrmdepartment where id in $t{idList}") + @Delete("delete from hrmdepartment where id in ($t{idList})") boolean deleteHrmDepart(@ParamMapper("idList") List idList); - @Select("select id, subcompanyid1 as sub from hrmresource where id in $t{idList}") + @Select("select id, subcompanyid1 as sub from hrmresource where id in ($t{idList})") @ToLowerCase List> selectHrmSubByHrmIdList(@ParamMapper("idList") List idList); 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 diff --git a/src/test/java/xuanran/wang/xk_hospital/test/XkHospitalTest.java b/src/test/java/xuanran/wang/xk_hospital/test/XkHospitalTest.java index 4f0f792..1afaa31 100644 --- a/src/test/java/xuanran/wang/xk_hospital/test/XkHospitalTest.java +++ b/src/test/java/xuanran/wang/xk_hospital/test/XkHospitalTest.java @@ -1,6 +1,7 @@ package xuanran.wang.xk_hospital.test; +import aiyh.utils.Util; import basetest.BaseTest; import com.alibaba.fastjson.JSONObject; import com.api.xuanran.wang.xk_hospital.data_async.service.XkHospitalCommonDataAsyncService; @@ -34,4 +35,83 @@ public class XkHospitalTest extends BaseTest { Map map = JSONObject.parseObject(json, Map.class); service.async("4bce0693734a","dept",map); } + + @Test + public void testB(){ + // String json2 = "{\n" + + // "\t\"ID\":\"1\",\n" + + // "\t\"DeptCode\":\"test3\",\n" + + // "\t\"DeptName\":\"科室测试名称3\",\n" + + // "\t\"DeptLevel\": null, \n" + + // "\t\"ParentDeptCode\": \"test2\",\n" + + // "\t\"IsDelete\": false, \n" + + // "\t\"Remark\":\"备注\"\n" + + // "}\n"; + // + // Map map2 = JSONObject.parseObject(json2, Map.class); + // service.async("4bce0693734a","dept",map2); + + String json = "{\n" + + "\t\"ID\":\"1\",\n" + + "\t\"EmplCode\":\"TEST10\",\n" + + "\t\"EmplName\":\"测试人员10\",\n" + + "\t\"EmplType\":\"人员类型代码\",\n" + + "\t\"EmplTypeCaption\":\"人员类型名称\",\n" + + "\t\"Gender\":\"男\",\n" + + "\t\"DeptCode\":\"test3\",\n" + + "\t\"DeptName\":\"科室名称\",\n" + + "\t\"EmplTitle\":\"职称代码\",\n" + + "\t\"EmplTitleCaption\":\"职称名称\",\n" + + "\t\"EmplPosition\":\"职务代码\",\n" + + "\t\"EmplPositionCaption\":\"职务名称\",\n" + + "\t\"Remark\":\"备注\"\n" + + "}\n"; + Map map = JSONObject.parseObject(json, Map.class); + Util.null2DefaultStr(null,""); + service.async("4bce0693734c","hrm",map); + } + + @Test + public void testC(){ + String json = "{\n" + + "\t\"ID\":\"主键\",\n" + + "\t\"GroupID\":\"test_yl_01\",\n" + + "\t\"GroupCode\":\"test_yl_dm_03\",\n" + + "\t\"GroupName\":\"医疗组名称1\",\n" + + "\t\"DeptCode\":\"test03\",\n" + + "\t\"DeptName\":\"测试科室03\",\n" + + "\t\"WardCode\":\"病区代码\",\n" + + "\t\"WardName\":\"病区名称\",\n" + + "\t\"Ward_BedNumber\":\"病区床位数,int类型\",\n" + + "\t\"IsDelete\":\"是否停用,bool类型\",\n" + + "\t\"Remark\":\"备注\",\n" + + "\t\"Wards\":[\t\n" + + "\t\t{\t\t\t\n" + + "\t\t\t\"ID\":\"1\",\n" + + "\t\t\t\"WardCode\":\"bq_01\",\n" + + "\t\t\t\"WardName\":\"病区名称01_2_3\"\n" + + "\t\t},{\t\t\t\n" + + "\t\t\t\"ID\":\"2\",\n" + + "\t\t\t\"WardCode\":\"bq_03\",\n" + + "\t\t\t\"WardName\":\"病区名称02_1_3\"\n" + + "\t\t}\n" + + "\t],\n" + + "\t\"WardHeads\":[\n" + + "\t\t{\n" + + "\t\t\t\"ID\":\"1\",\n" + + "\t\t\t\"EmplCode\":\"TEST10\",\n" + + "\t\t\t\"EmplName\":\"傻逼01\",\n" + + "\t\t\t\"Category\":\"人员分组,当人员为主治和住院医师时使用\"\n" + + "\t\t},{\n" + + "\t\t\t\"ID\":\"2\",\n" + + "\t\t\t\"EmplCode\":\"TEST10\",\n" + + "\t\t\t\"EmplName\":\"傻逼02\",\n" + + "\t\t\t\"Category\":\"人员分组,当人员为主治和住院医师时使用\"\n" + + "\t\t}\n" + + "\t]\n" + + "}\n"; + Map map = JSONObject.parseObject(json, Map.class); + Util.null2DefaultStr(null,""); + service.async("4bce0693734d","common", map); + } }