From bbe0a2fd03063316e50cf141986bda984599bbda Mon Sep 17 00:00:00 2001 From: 935090232@qq.com <ak473600000> Date: Tue, 22 Feb 2022 23:41:42 +0800 Subject: [PATCH] Merge branch 'developer' --- zq-erp/src/main/java/com/matrix/system/common/authority/DefaultAuthorityManager.java | 78 +++++++++++++++++++------------------- 1 files changed, 39 insertions(+), 39 deletions(-) diff --git a/zq-erp/src/main/java/com/matrix/system/common/authority/DefaultAuthorityManager.java b/zq-erp/src/main/java/com/matrix/system/common/authority/DefaultAuthorityManager.java index 4329524..381b643 100644 --- a/zq-erp/src/main/java/com/matrix/system/common/authority/DefaultAuthorityManager.java +++ b/zq-erp/src/main/java/com/matrix/system/common/authority/DefaultAuthorityManager.java @@ -1,10 +1,6 @@ package com.matrix.system.common.authority; import cn.hutool.crypto.SecureUtil; -import cn.hutool.json.JSONArray; -import cn.hutool.json.JSONObject; -import cn.hutool.json.JSONUtil; -import com.matrix.component.redis.RedisClient; import com.matrix.core.constance.MatrixConstance; import com.matrix.core.pojo.AjaxResult; import com.matrix.core.tools.StringUtils; @@ -14,6 +10,7 @@ import com.matrix.system.common.bean.SysFunction; import com.matrix.system.common.bean.SysUsers; import com.matrix.system.common.constance.AppConstance; +import com.matrix.system.common.init.LocalCache; import com.matrix.system.common.service.SysFunctionService; import org.apache.commons.collections.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -47,8 +44,6 @@ **/ public static final String USER_URL_MAPPING = "userUrlMapping"; - @Autowired - RedisClient redisClient; private DefaultAuthorityManager() { } @@ -79,24 +74,33 @@ SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); Map<String, SysFunction> userFunction = WebUtil.getSessionAttribute(USERFUNCTION); + + // 企业管理员不校验按钮权限 if (AppConstance.USER_TYPE_DEVELOPER.equals(user.getSuUserType()) || AppConstance.USER_TYPE_SUPER.equals(user.getSuUserType()) || AppConstance.USER_TYPE_ADMIN.equals(user.getSuUserType())) { return true; } - String[] strs = matchStr.split("-"); - if (strs.length != DEFAULT_2) { - throw new IllegalArgumentException("权限matchStr格式错误,需要fnCode:btnValue"); - } - SysFunction fn = userFunction.get(strs[0].trim()); - // 功能是否存在 - if (fn == null) { + if (userFunction == null) { return false; } else { - return StringUtils.isContentSet(strs[1].trim(), fn.getRpfBns()); + + String[] strs = matchStr.split("-"); + if (strs.length != DEFAULT_2) { + throw new IllegalArgumentException("权限matchStr格式错误,需要fnCode:btnValue"); + } + + SysFunction fn = userFunction.get(strs[0].trim()); + // 功能是否存在 + if (fn == null) { + return false; + } else { + return StringUtils.isContentSet(strs[1].trim(), fn.getRpfBns()); + } } + } /** @@ -113,8 +117,13 @@ return true; } Map<String, SysFunction> userFunction = WebUtil.getSessionAttribute(USERFUNCTION); - SysFunction fn = userFunction.get(fnCode); - return fn == null ? false : true; + if (userFunction == null) { + return false; + } else { + SysFunction fn = userFunction.get(fnCode); + return fn == null ? false : true; + } + } /** @@ -141,27 +150,17 @@ SysUsers sysUser = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY); - String redisKey = USER_POWER_REDISKEY_PC + SecureUtil.md5(sysUser.getSuId()+""); - String cachedValue = redisClient.getCachedValue(redisKey); - if (StringUtils.isNotBlank(cachedValue)) { - //从缓存中获取用户权限 - JSONObject powerMap = JSONUtil.parseObj(cachedValue); - String userFunctionMapStr = powerMap.get(USERFUNCTION).toString(); - JSONObject userFunctionMap = JSONUtil.parseObj(userFunctionMapStr); - Set<String> userFunctionMapKeys = userFunctionMap.keySet(); - userFunctionMapKeys.forEach(key -> { - userFunction.put(key, userFunctionMap.get(key, SysFunction.class)); - }); - String menusFunctionListStr = powerMap.get(MENUSFUNCTION).toString(); - JSONArray menusFunctionArray = JSONUtil.parseArray(menusFunctionListStr); - for (int i = 0; i < menusFunctionArray.size(); i++) { - menuFunction.add(menusFunctionArray.get(i, SysFunction.class)); - } - String userUrlMappingListStr = powerMap.get(USER_URL_MAPPING).toString(); - JSONArray userUrlMappingArray = JSONUtil.parseArray(userUrlMappingListStr); - for (int i = 0; i < userUrlMappingArray.size(); i++) { - userUrlMapping.add(userUrlMappingArray.get(i, String.class)); - } + String redisKey = USER_POWER_REDISKEY_PC + SecureUtil.md5(sysUser.getSuId() + ""); + Map<String, Object> cachePowerMap = LocalCache.get(redisKey); + + if (Objects.nonNull(cachePowerMap)) { + + userFunction = (Map<String, SysFunction>) cachePowerMap.get(USERFUNCTION); + + menuFunction = (List<SysFunction>) cachePowerMap.get(MENUSFUNCTION); + + userUrlMapping = (List<String>) cachePowerMap.get(USER_URL_MAPPING); + } else { // 获取用户所有权限 getUserFunction(userFunction, menuFunctionMap, userUrlMapping); @@ -169,11 +168,12 @@ // 组装菜单 assembleMenu(menuFunction, menuFunctionMap); - Map<String ,Object> powerMap=new HashMap<>(); + Map<String, Object> powerMap = new HashMap<>(); powerMap.put(USERFUNCTION, userFunction); powerMap.put(MENUSFUNCTION, menuFunction); powerMap.put(USER_URL_MAPPING, userUrlMapping); - redisClient.saveValue(redisKey,JSONUtil.parseObj(powerMap,true)); + //权限信息加入缓存中 + LocalCache.save(redisKey,powerMap); } -- Gitblit v1.9.1