From 81e00cd2e26e387d8ab2077ccd982072d6eb865b Mon Sep 17 00:00:00 2001 From: 姜友瑶 <935090232@qq.com> Date: Tue, 17 May 2022 15:40:31 +0800 Subject: [PATCH] Merge branch 'developer' into alpha --- zq-erp/src/main/java/com/matrix/system/app/authority/AppAuthorityManager.java | 33 +++++++++------------------------ 1 files changed, 9 insertions(+), 24 deletions(-) diff --git a/zq-erp/src/main/java/com/matrix/system/app/authority/AppAuthorityManager.java b/zq-erp/src/main/java/com/matrix/system/app/authority/AppAuthorityManager.java index c481134..153a47d 100644 --- a/zq-erp/src/main/java/com/matrix/system/app/authority/AppAuthorityManager.java +++ b/zq-erp/src/main/java/com/matrix/system/app/authority/AppAuthorityManager.java @@ -1,10 +1,9 @@ package com.matrix.system.app.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.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; import com.matrix.core.constance.MatrixConstance; import com.matrix.core.pojo.AjaxResult; import com.matrix.core.tools.StringUtils; @@ -15,6 +14,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; @@ -36,8 +36,6 @@ private static final int DEFAULT_2 = 2; - @Autowired - RedisClient redisClient; @Autowired SysFunctionService sysFunctionService; @@ -103,22 +101,11 @@ String redisKey = USER_POWER_REDISKEY_APP + SecureUtil.md5(user.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)); - }); + Map<String, Object> cachePowerMap = LocalCache.get(redisKey,new TypeReference<Map<String,Object>>(){}); + if (Objects.nonNull(cachePowerMap)) { + userFunction = JSONObject.parseObject(JSON.toJSONString( cachePowerMap.get(USERFUNCTION)), new TypeReference<Map<String, SysFunction>>(){}); + userUrlMapping =JSONObject.parseObject(JSON.toJSONString( cachePowerMap.get(USER_URL_MAPPING)) , new TypeReference<List<String>>(){}); - 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)); - } } else { // 获取用户所有权限 getUserFunction(user,userFunction, userUrlMapping); @@ -126,11 +113,9 @@ Map<String ,Object> powerMap=new HashMap<>(); powerMap.put(USERFUNCTION, userFunction); powerMap.put(USER_URL_MAPPING, userUrlMapping); - redisClient.saveValue(redisKey,JSONUtil.parseObj(powerMap,true)); + LocalCache.save(redisKey,powerMap); } - - // TODO 这里的用户权限应该放到redis缓存中,在拦截器中做权限拦截 WebUtil.setSessionAttribute(USERFUNCTION, userFunction); WebUtil.setSessionAttribute(USER_URL_MAPPING, userUrlMapping); result.putInMap(USERFUNCTION, userFunction); -- Gitblit v1.9.1