From 0b1e9e70818f0e3eb32dd6c029d42d93236ecdc6 Mon Sep 17 00:00:00 2001
From: zrj <646384940@qq.com>
Date: Wed, 03 Jul 2024 12:07:01 +0800
Subject: [PATCH] 数据同步新增连接池配置
---
src/main/java/org/springblade/common/cache/SysCache.java | 67 ++++++++++++++++++++++-----------
1 files changed, 45 insertions(+), 22 deletions(-)
diff --git a/src/main/java/org/springblade/common/cache/SysCache.java b/src/main/java/org/springblade/common/cache/SysCache.java
index c98fa56..190da4b 100644
--- a/src/main/java/org/springblade/common/cache/SysCache.java
+++ b/src/main/java/org/springblade/common/cache/SysCache.java
@@ -25,6 +25,7 @@
import org.springblade.modules.system.service.*;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@@ -155,25 +156,33 @@
/**
* 获取子部门ID集合
*
- * @param deptId 主键
+ * @param deptIds 主键
* @return 子部门ID
*/
- public static List<Long> getDeptChildIds(Long deptId) {
- if (deptId == null) {
+ public static List<Long> getDeptChildIds(String deptIds) {
+ if (Strings.isBlank(deptIds)) {
return null;
}
- List<Long> deptIdList = CacheUtil.get(SYS_CACHE, DEPT_CHILDIDS_ID, deptId, List.class);
- if (deptIdList == null) {
- deptIdList = new ArrayList<>();
- List<Dept> deptChild = getDeptChild(deptId);
- if (deptChild != null) {
- List<Long> collect = deptChild.stream().map(Dept::getId).collect(Collectors.toList());
- deptIdList.addAll(collect);
+ List<Long> list = new ArrayList<>();
+ List<String> deptIdList = new ArrayList<>(Arrays.asList(deptIds.split(",")));
+ for (String deptId : deptIdList) {
+ List<Long> deptIdLists = CacheUtil.get(SYS_CACHE, DEPT_CHILDIDS_ID, deptId, List.class);
+ if (deptIdLists == null) {
+ deptIdLists = new ArrayList<>();
+ List<Dept> deptChild = getDeptChild(Long.parseLong(deptId));
+ if (deptChild != null) {
+ List<Long> collect = deptChild.stream().map(Dept::getId).collect(Collectors.toList());
+ deptIdLists.addAll(collect);
+ }
+ deptIdLists.add(Long.parseLong(deptId));
+ CacheUtil.put(SYS_CACHE, DEPT_CHILDIDS_ID, deptId, deptIdLists);
}
- deptIdList.add(deptId);
- CacheUtil.put(SYS_CACHE, DEPT_CHILDIDS_ID, deptId, deptIdList);
+ list.addAll(deptIdLists);
}
- return deptIdList;
+ // 去重
+ List<Long> collect = list.stream().distinct().collect(Collectors.toList());
+ // 返回
+ return collect;
}
/**
@@ -326,13 +335,27 @@
* @return regionCode
*/
public static List<String> getRegionChildCodesByDeptId(String deptId) {
- List<String> list = new ArrayList<>();
- // 查询对应的区域编号code
- Dept dept = deptService.getById(deptId);
- if (null!=dept && !Strings.isBlank(dept.getRegionCode()) && !AuthUtil.isAdministrator()){
- list = getRegionChildCodes(dept.getRegionCode());
- }
- return list;
+ //多个部门按逗号分割
+ List<String> deptIdList = Arrays.asList(deptId.split(","));
+
+ //所有行政区划code
+ List<String> allRegionList = new ArrayList<>();
+ deptIdList.forEach(id->{
+ List<String> list = new ArrayList<>();
+ // 查询对应的区域编号code
+ Dept dept = deptService.getById(id);
+ if (null!=dept && !Strings.isBlank(dept.getRegionCode()) && !AuthUtil.isAdministrator()){
+ list = getRegionChildCodes(dept.getRegionCode());
+ //行政区划不为空添加进集合
+ if (list.size()>0){
+ allRegionList.addAll(list);
+ }
+ }
+ });
+
+ // 去重
+ List<String> collect = allRegionList.stream().distinct().collect(Collectors.toList());
+ return collect;
}
/**
@@ -345,14 +368,14 @@
return null;
}
List<String> regionCodeList = CacheUtil.get(SYS_CACHE, REGION_CHILDCODES_CODE, regionCode, List.class);
- if (regionCodeList == null) {
+ if (regionCodeList == null || regionCodeList.size()==0) {
regionCodeList = new ArrayList<>();
List<Region> deptChild = getRegionChild(regionCode);
if (deptChild != null) {
List<String> collect = deptChild.stream().map(Region::getCode).collect(Collectors.toList());
regionCodeList.addAll(collect);
}
-// regionCodeList.add(regionCode);
+ regionCodeList.add(regionCode);
CacheUtil.put(SYS_CACHE, REGION_CHILDCODES_CODE, regionCode, regionCodeList);
}
return regionCodeList;
--
Gitblit v1.9.3