diff --git a/epdc-cloud-commons-yushan b/epdc-cloud-commons-yushan index 476ef80..14ba011 160000 --- a/epdc-cloud-commons-yushan +++ b/epdc-cloud-commons-yushan @@ -1 +1 @@ -Subproject commit 476ef8053346b3f90873fcf90716c05bceaec011 +Subproject commit 14ba01162799b397ec4cae757f29790fc88df9cb diff --git a/epdc-cloud-optimize-yushan/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/constant/OptimizeRedisKeys.java b/epdc-cloud-optimize-yushan/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/constant/OptimizeRedisKeys.java index 1024d9c..097e3d7 100644 --- a/epdc-cloud-optimize-yushan/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/constant/OptimizeRedisKeys.java +++ b/epdc-cloud-optimize-yushan/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/constant/OptimizeRedisKeys.java @@ -1,6 +1,7 @@ package com.elink.esua.epdc.optimize.constant; import com.elink.esua.epdc.commons.tools.constant.StrConstant; +import com.elink.esua.epdc.commons.tools.redis.RedisKeys; /** * 优化功能所用到的redis key @@ -10,8 +11,6 @@ import com.elink.esua.epdc.commons.tools.constant.StrConstant; */ public class OptimizeRedisKeys { - private static final String PREFIX = "epdc:optimize:"; - /** * 用于存放用户部门层级关系 * @@ -22,7 +21,24 @@ public class OptimizeRedisKeys { * @date 2020/5/25 15:05 */ public static String getUserDeptLevelOptionKey(Long userId, String keyStr) { - return PREFIX.concat("deptlevel:").concat(String.valueOf(userId)).concat(StrConstant.COLON).concat(keyStr); + return RedisKeys.getAdminUserDeptOptionKey(userId).concat(StrConstant.COLON).concat(keyStr); + } + + /** + * 用于存放用户部门数据权限 + * + * @param userId 用户id + * @param keyStr 关键字 + * @return java.lang.String + * @author work@yujt.net.cn + * @date 2020/5/29 15:07 + */ + public static String getUserDeptScopeKey(Long userId, String keyStr) { + return RedisKeys.getAdminUserDeptOptionKey(userId) + .concat(StrConstant.COLON) + .concat("scope") + .concat(StrConstant.COLON) + .concat(keyStr); } } diff --git a/epdc-cloud-optimize-yushan/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/deptlevel/controller/OptDeptLevelController.java b/epdc-cloud-optimize-yushan/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/deptlevel/controller/OptDeptLevelController.java index 61df862..f755c8b 100644 --- a/epdc-cloud-optimize-yushan/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/deptlevel/controller/OptDeptLevelController.java +++ b/epdc-cloud-optimize-yushan/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/deptlevel/controller/OptDeptLevelController.java @@ -4,10 +4,7 @@ import com.elink.esua.epdc.commons.tools.utils.Result; import com.elink.esua.epdc.dto.DeptLevelAndLeaderDTO; import com.elink.esua.epdc.optimize.modules.deptlevel.service.OptSysDeptService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -18,7 +15,7 @@ import java.util.List; * @date 2020/5/21 09:58 */ @RestController -@RequestMapping("optimize/deptlevel") +@RequestMapping("optimize") public class OptDeptLevelController { @@ -35,9 +32,24 @@ public class OptDeptLevelController { * @author work@yujt.net.cn * @date 2020/5/22 09:13 */ - @GetMapping("listByParent/{typeKey}/{deptId}") + @GetMapping("deptlevel/listByParent/{typeKey}/{deptId}") public Result> listChildDeptLevelById(@PathVariable("typeKey") String typeKey, @PathVariable("deptId") Long deptId) { List childDeptLevelList = optSysDeptService.listChildDeptLevelById(typeKey, deptId); return new Result().ok(childDeptLevelList); } + + /** + * 根据部门类别,过滤部门权限 + * + * @param userId 用户id + * @param typeKeys 部门类别关键字{@link com.elink.esua.epdc.commons.tools.constant.OrganizationTypeConstant} + * @return com.elink.esua.epdc.commons.tools.utils.Result> + * @author work@yujt.net.cn + * @date 2020/5/29 15:42 + */ + @PostMapping("deptScope/listByTypeKey/{userId}") + public Result> getUserDeptScope(@PathVariable("userId") Long userId, @RequestBody String[] typeKeys) { + List userDeptScope = optSysDeptService.getUserDeptScope(userId, typeKeys); + return new Result().ok(userDeptScope); + } } diff --git a/epdc-cloud-optimize-yushan/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/deptlevel/service/OptSysDeptService.java b/epdc-cloud-optimize-yushan/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/deptlevel/service/OptSysDeptService.java index ba3ef7d..37585c8 100644 --- a/epdc-cloud-optimize-yushan/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/deptlevel/service/OptSysDeptService.java +++ b/epdc-cloud-optimize-yushan/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/deptlevel/service/OptSysDeptService.java @@ -37,7 +37,6 @@ public interface OptSysDeptService extends BaseService { */ DeptLevelAndLeaderDTO getDeptLevelById(Long deptId); - /** * 根据数据权限获取用户部门层级关系 * @@ -49,4 +48,15 @@ public interface OptSysDeptService extends BaseService { * @date 2020/5/25 15:17 */ DeptOption getDeptOption(Long userId, List dataScopeDeptIdList, String... typeKeys); + + /** + * 按部门类别二次过滤用户部门数据权限 + * + * @param userId 用户主键 + * @param typeKeys 需要部门类别的关键字 {@link com.elink.esua.epdc.commons.tools.constant.OrganizationTypeConstant} + * @return java.util.List + * @author work@yujt.net.cn + * @date 2020/5/29 15:16 + */ + List getUserDeptScope(Long userId, String... typeKeys); } diff --git a/epdc-cloud-optimize-yushan/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/deptlevel/service/impl/OptSysDeptServiceImpl.java b/epdc-cloud-optimize-yushan/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/deptlevel/service/impl/OptSysDeptServiceImpl.java index 36d477e..d70c8f5 100644 --- a/epdc-cloud-optimize-yushan/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/deptlevel/service/impl/OptSysDeptServiceImpl.java +++ b/epdc-cloud-optimize-yushan/epdc-optimize-department/src/main/java/com/elink/esua/epdc/optimize/modules/deptlevel/service/impl/OptSysDeptServiceImpl.java @@ -10,6 +10,8 @@ import com.elink.esua.epdc.commons.tools.constant.OrganizationTypeConstant; import com.elink.esua.epdc.commons.tools.constant.StrConstant; import com.elink.esua.epdc.commons.tools.exception.RenException; import com.elink.esua.epdc.commons.tools.redis.RedisUtils; +import com.elink.esua.epdc.commons.tools.redis.UserDetailRedis; +import com.elink.esua.epdc.commons.tools.security.user.UserDetail; import com.elink.esua.epdc.dto.DeptLevelAndLeaderDTO; import com.elink.esua.epdc.dto.DeptOption; import com.elink.esua.epdc.optimize.constant.OptimizeConstant; @@ -40,6 +42,9 @@ public class OptSysDeptServiceImpl extends BaseServiceImpl listChildDeptLevelById(String typeKey, Long deptId) { OptSysDeptEntity parentDept = baseDao.selectById(deptId); @@ -108,6 +113,41 @@ public class OptSysDeptServiceImpl extends BaseServiceImpl getUserDeptScope(Long userId, String... typeKeys) { + + UserDetail userDetail = userDetailRedis.get(userId); + if (null == userDetail) { + return Lists.newArrayList(); + } + List deptScope = userDetail.getDeptIdList(); + if (null == userDetail.getId() || CollUtil.isEmpty(deptScope)) { + return Lists.newArrayList(); + } + // 是否需要对数据权限部门进行二次筛选 + boolean filterDataScope = false; + if (ArrayUtil.isEmpty(typeKeys)) { + typeKeys = new String[]{OptimizeConstant.COMPLETE_DEPT_LEVEL_KEY}; + } else { + filterDataScope = true; + } + // 先从redis获取,减少重复查询 + String redisKey = OptimizeRedisKeys.getUserDeptScopeKey(userId, StringUtils.join(escapeDeptTypeKey(typeKeys), StrConstant.HYPHEN)); + Object obj = redisUtils.get(redisKey); + if (null != obj) { + return (List) obj; + } + // 根据部门类型,二次筛选数据权限部门 + if (filterDataScope) { + deptScope = baseDao.selectListDeptIdByTypeKeyAndScope(deptScope, typeKeys); + } + // 存入redis,超时时长设置为一小时 + redisUtils.set(redisKey, deptScope, RedisUtils.HOUR_ONE_EXPIRE); + + return deptScope; + } + + /** * 根据部门数据权限组装部门层级结构 *