姜友瑶
2022-05-04 9fc4177dd26683f5dc6d8ebb62ab5b230ac21def
Merge branch 'developer' into alpha
7 files modified
28 ■■■■■ changed files
zq-erp/src/main/java/com/matrix/system/app/action/ApiCommonAction.java 5 ●●●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/system/app/authority/AppAuthorityManager.java 2 ●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/system/common/authority/DefaultAuthorityManager.java 2 ●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/system/common/init/LocalCache.java 4 ●●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/system/common/init/UserCacheManager.java 6 ●●●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/system/common/interceptor/ApiUserLoginInterceptor.java 3 ●●●● patch | view | raw | blame | history
zq-erp/src/test/java/com/matrix/LocalCacheTest.java 6 ●●●●● patch | view | raw | blame | history
zq-erp/src/main/java/com/matrix/system/app/action/ApiCommonAction.java
@@ -2,6 +2,7 @@
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.TypeReference;
import com.matrix.component.tools.HttpCurlUtil;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.tools.*;
@@ -194,7 +195,7 @@
            return AjaxResult.buildFailInstance("该手机号不存在");
        }
        String codeExist = LocalCache.get(smsCodeDto.getTelphone());
        String codeExist = LocalCache.get(smsCodeDto.getTelphone(),new TypeReference<String>(){});
        if (StringUtils.isNotBlank(codeExist)) {
            return AjaxResult.buildFailInstance("请勿重复发送验证码");
        }
@@ -215,7 +216,7 @@
            return AjaxResult.buildFailInstance("该手机号不存在");
        }
        String code = LocalCache.get(pwdResetDto.getTelphone());
        String code = LocalCache.get(pwdResetDto.getTelphone(),new TypeReference<String>(){});
        if (StringUtils.isBlank(code)) {
            return AjaxResult.buildFailInstance("验证码已失效,请重新发送");
        }
zq-erp/src/main/java/com/matrix/system/app/authority/AppAuthorityManager.java
@@ -101,7 +101,7 @@
        String redisKey = USER_POWER_REDISKEY_APP + SecureUtil.md5(user.getSuId()+"");
        Map<String, Object> cachePowerMap = LocalCache.get(redisKey);
        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>>(){});
zq-erp/src/main/java/com/matrix/system/common/authority/DefaultAuthorityManager.java
@@ -155,7 +155,7 @@
        SysUsers sysUser = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
        String redisKey = USER_POWER_REDISKEY_PC + SecureUtil.md5(sysUser.getSuId() + "");
        Map<String, Object> cachePowerMap = LocalCache.get(redisKey);
        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>>(){});
zq-erp/src/main/java/com/matrix/system/common/init/LocalCache.java
@@ -81,7 +81,7 @@
     * @param key
     * @param <T>
     * @return
     */
     *//*
    public static <T> T get(String key) {
        CacheValue value = localCache.get(key);
        if (Objects.nonNull(value)) {
@@ -89,7 +89,7 @@
        }
        return null;
    }
*/
    /**
     * 获取本地缓存,如果需要转换为List,Map类型的具体泛型使用本方法
     * @param key
zq-erp/src/main/java/com/matrix/system/common/init/UserCacheManager.java
@@ -7,11 +7,13 @@
 */
package com.matrix.system.common.init;
import com.alibaba.fastjson.TypeReference;
import com.matrix.core.constance.SystemErrorCode;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.tools.StringUtils;
import com.matrix.core.tools.UUIDUtil;
import com.matrix.core.tools.WebUtil;
import com.matrix.system.common.bean.SysUsers;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@@ -44,7 +46,7 @@
    public boolean isUserLogin() {
        String token = getUserToken();
        if (StringUtils.isNotBlank(token)) {
            return LocalCache.get(token) != null;
            return LocalCache.get(token,new TypeReference<String>(){}) != null;
        } else {
            return false;
        }
@@ -92,7 +94,7 @@
    public <T> T getLoginUser() {
        String userToken = getUserToken();
        if (userToken != null) {
            T user = LocalCache.get(userToken);
            T user = LocalCache.get(userToken,new TypeReference<SysUsers>(){});
            if (Objects.nonNull(user)) {
                //重新设置key过期时间
                LocalCache.resetExpire(userToken);
zq-erp/src/main/java/com/matrix/system/common/interceptor/ApiUserLoginInterceptor.java
@@ -1,6 +1,7 @@
package com.matrix.system.common.interceptor;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.pojo.AjaxResult;
@@ -61,7 +62,7 @@
            return false;
        }
        SysUsers sysUsers = LocalCache.get(token);
        SysUsers sysUsers = LocalCache.get(token,new TypeReference<SysUsers>(){});
        if (Objects.isNull(sysUsers)) {
            ajaxResult.setInfo("login time out");
            response.getWriter().write(new ObjectMapper().writeValueAsString(ajaxResult));
zq-erp/src/test/java/com/matrix/LocalCacheTest.java
@@ -7,6 +7,8 @@
 */
package com.matrix;
import com.alibaba.fastjson.TypeReference;
import com.matrix.system.common.bean.SysUsers;
import com.matrix.system.common.init.LocalCache;
import org.junit.Assert;
import org.junit.Test;
@@ -27,9 +29,9 @@
    public void testNoticeTask() throws IOException, InterruptedException {
        LocalCache.save("name","jyy",1000*3);
        System.out.println("放入对象");
        Assert.assertNotNull(LocalCache.get("name"));
        Assert.assertNotNull(LocalCache.get("name",new TypeReference<SysUsers>(){}));
        Thread.sleep(1000*5);
        Assert.assertNull(LocalCache.get("name"));
        Assert.assertNull(LocalCache.get("name",new TypeReference<SysUsers>(){}));
    }
}