获取下一个人员/部门方法优化
parent
1dff070cc1
commit
f042d058f0
|
@ -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,7 +4135,7 @@ 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);
|
||||
|
@ -4140,5 +4143,35 @@ public class Util extends weaver.general.Util {
|
|||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>获取当前线程rs对象</h1>
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* <h1>通过名字获取rs池中rs对象</h1>
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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 {
|
|||
* <h2>部门缓存</h2>
|
||||
**/
|
||||
protected static final DepartmentComInfo DEPARTMENT_COM_INFO = new DepartmentComInfo();
|
||||
/**
|
||||
* <h2>人员缓存</h2>
|
||||
**/
|
||||
protected static ResourceComInfo RESOURCE_COM_INFO = null;
|
||||
|
||||
/**
|
||||
* <h2>系统主题接口</h2>
|
||||
**/
|
||||
protected static final ThemeServiceImpl THEME_SERVICE = new ThemeServiceImpl();
|
||||
/**
|
||||
* <h2>人员缓存</h2>
|
||||
**/
|
||||
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<Integer> 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<Map<String, Integer>> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<Map<String, Integer>> 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Integer> 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<Map<String, Integer>> selectHrmSubByHrmIdList(@ParamMapper("idList") List<Integer> idList);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue