| | |
| | | */ |
| | | package org.springblade.common.cache; |
| | | |
| | | import org.apache.logging.log4j.util.Strings; |
| | | import org.springblade.core.cache.utils.CacheUtil; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.utils.SpringUtil; |
| | | import org.springblade.core.tool.utils.StringPool; |
| | | import org.springblade.modules.system.entity.*; |
| | | import org.springblade.modules.system.service.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | private static final String DEPT_NAMES_ID = "deptNames:id:"; |
| | | private static final String DEPT_CHILD_ID = "deptChild:id:"; |
| | | private static final String DEPT_CHILDIDS_ID = "deptChildIds:id:"; |
| | | private static final String REGION_CHILD_CODE = "regionChild:code:"; |
| | | private static final String REGION_CHILDCODES_CODE = "regionChildCodes:code:"; |
| | | private static final String POST_ID = "post:id:"; |
| | | private static final String POST_NAME = "post:name:"; |
| | | private static final String POST_NAME_FUZZY = "post:nameFuzzy:"; |
| | |
| | | private static final IDeptService deptService; |
| | | private static final IPostService postService; |
| | | private static final IRoleService roleService; |
| | | private static final IRegionService regionService; |
| | | private static final ITenantService tenantService; |
| | | private static final ITenantPackageService tenantPackageService; |
| | | |
| | |
| | | deptService = SpringUtil.getBean(IDeptService.class); |
| | | postService = SpringUtil.getBean(IPostService.class); |
| | | roleService = SpringUtil.getBean(IRoleService.class); |
| | | regionService = SpringUtil.getBean(IRegionService.class); |
| | | tenantService = SpringUtil.getBean(ITenantService.class); |
| | | tenantPackageService = SpringUtil.getBean(ITenantPackageService.class); |
| | | } |
| | |
| | | /** |
| | | * 获取子部门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; |
| | | } |
| | | |
| | | /** |
| | |
| | | return CacheUtil.get(SYS_CACHE, TENANT_PACKAGE_ID, tenantId, () -> tenantPackageService.getById(tenant.getPackageId()), Boolean.FALSE); |
| | | } |
| | | |
| | | /** |
| | | * 获取下级所有区域code |
| | | * |
| | | * @return regionCode |
| | | */ |
| | | public static List<String> getRegionChildCodesByDeptId(String deptId) { |
| | | //多个部门按逗号分割 |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * 获取下级所有区域code |
| | | * |
| | | * @return regionCode |
| | | */ |
| | | public static List<String> getRegionChildCodes(String regionCode) { |
| | | if (regionCode == null) { |
| | | return null; |
| | | } |
| | | List<String> regionCodeList = CacheUtil.get(SYS_CACHE, REGION_CHILDCODES_CODE, regionCode, List.class); |
| | | 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); |
| | | CacheUtil.put(SYS_CACHE, REGION_CHILDCODES_CODE, regionCode, regionCodeList); |
| | | } |
| | | return regionCodeList; |
| | | } |
| | | |
| | | /** |
| | | * 获取下级区域 |
| | | * @param regionCode |
| | | * @return |
| | | */ |
| | | private static List<Region> getRegionChild(String regionCode) { |
| | | return CacheUtil.get(SYS_CACHE, REGION_CHILD_CODE, regionCode, () -> regionService.getRegionChild(regionCode)); |
| | | } |
| | | } |