From f042d058f0655a2dbe1026c94d4054288fce0e17 Mon Sep 17 00:00:00 2001 From: wangxuanran <3055088966@qq.com> Date: Wed, 19 Jul 2023 15:35:30 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=B8=8B=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E5=91=98/=E9=83=A8=E9=97=A8=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/aiyh/utils/Util.java | 45 ++++++++++++++--- .../XkHospitalCommonDefinition.java | 50 +++---------------- .../row/HrmDepartmentRowDefinition.java | 10 +++- .../table/HrmDepartmentTableDefinition.java | 35 ++++++++++--- .../mapper/XkHospitalDataAsyncMapper.java | 4 +- .../wang/xk_hospital/test/XkHospitalTest.java | 36 +++++++++++++ 6 files changed, 119 insertions(+), 61 deletions(-) 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/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..efbbedf 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 @@ -45,8 +45,14 @@ public class HrmDepartmentRowDefinition extends XkHospitalCommonDefinition imple throw new CustomerException("从 " + table + " 获取下一个id失败!"); } rowDefinition.setDataId(nextId); - rowDefinition.getWhereParam().put("id", nextId); - rowDefinition.setConditionScript(" id = #{whereItem.id}"); + 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}"); + } } 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..bc637bf 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 @@ -9,6 +9,7 @@ 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; @@ -38,16 +39,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/test/java/xuanran/wang/xk_hospital/test/XkHospitalTest.java b/src/test/java/xuanran/wang/xk_hospital/test/XkHospitalTest.java index 4f0f792..99171ed 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,39 @@ 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\":\"TEST1\",\n" + + "\t\"EmplName\":\"测试人员1\",\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); + } }