linwei
2024-01-31 b3b566ebdfed4005aaa513da3d5d2fd3924903cc
src/main/java/org/springblade/common/cache/SysCache.java
@@ -16,7 +16,9 @@
 */
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.*;
@@ -42,6 +44,8 @@
   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:";
@@ -61,6 +65,7 @@
   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;
@@ -69,6 +74,7 @@
      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);
   }
@@ -314,4 +320,50 @@
      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> list = new ArrayList<>();
      // 查询对应的区域编号code
      Dept dept = deptService.getById(deptId);
      if (null!=dept && !Strings.isBlank(dept.getRegionCode()) && !AuthUtil.isAdministrator()){
         list = getRegionChildCodes(dept.getRegionCode());
      }
      return list;
   }
   /**
    * 获取下级所有区域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));
   }
}