From 99091a8cbb8e098575c75a7c640b568addbcc29d Mon Sep 17 00:00:00 2001 From: wzy <wzy19931122ai@163.com> Date: Sun, 09 Oct 2022 21:41:13 +0800 Subject: [PATCH] Merge branch 'score_shop' --- zq-erp/src/main/java/com/matrix/system/common/authority/DefaultAuthorityManager.java | 41 ++++++++++++++--------------------------- 1 files changed, 14 insertions(+), 27 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 db8c386..de5d17c 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,9 @@ 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.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; @@ -14,8 +13,10 @@ 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.apache.poi.ss.formula.functions.T; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -47,8 +48,6 @@ **/ public static final String USER_URL_MAPPING = "userUrlMapping"; - @Autowired - RedisClient redisClient; private DefaultAuthorityManager() { } @@ -156,26 +155,13 @@ 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)); - } + 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>>(){}); + menuFunction = JSONObject.parseObject(JSON.toJSONString( cachePowerMap.get(MENUSFUNCTION)) ,new TypeReference<List<SysFunction>>(){}); + userUrlMapping =JSONObject.parseObject(JSON.toJSONString( cachePowerMap.get(USER_URL_MAPPING)) , new TypeReference<List<String>>(){}); + } else { // 获取用户所有权限 getUserFunction(userFunction, menuFunctionMap, userUrlMapping); @@ -187,7 +173,8 @@ 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