kongzy
2023-12-08 ca5445257b1fdeceddf3fcc2dea18c442023aeb7
assess-framework/src/main/java/com/gkhy/assess/framework/shiro/service/SysLoginService.java
@@ -1,6 +1,8 @@
package com.gkhy.assess.framework.shiro.service;
import com.gkhy.assess.common.constant.CacheConstant;
import com.gkhy.assess.common.enums.ApproveStatusEnum;
import com.gkhy.assess.common.enums.UserIdentityEnum;
import com.gkhy.assess.common.enums.UserStatusEnum;
import com.gkhy.assess.common.exception.ApiException;
import com.gkhy.assess.common.utils.JwtTokenUtil;
@@ -34,13 +36,18 @@
    public void validUser(SysUser sysUser){
        if(sysUser==null) {
            throw new ApiException("用户不存在");
            throw new AuthenticationException("用户不存在");
        }
        if(UserStatusEnum.DELETED.getCode().equals(sysUser.getDelFlag())){
            throw new ApiException("用户已被删除");
            throw new AuthenticationException("用户已被删除");
        }
        if(UserStatusEnum.DISABLE.getCode().equals(sysUser.getStatus())){
            throw new ApiException("用户已被停用");
            throw new AuthenticationException("用户已被停用");
        }
        if(UserIdentityEnum.AGENCY.getCode().equals(sysUser.getIdentity())){
            if(!ApproveStatusEnum.APPROVED.getCode().equals(sysUser.getState())){
                throw new AuthenticationException("机构账户审批还未通过");
            }
        }
    }
@@ -72,15 +79,17 @@
     * @return
     */
    public boolean jwtTokenRefresh(String jwtToken,String username,String passWord){
        String key=redisUtils.generateKey(CacheConstant.SYS_USER_TOKEN+":"+JwtTokenUtil.md5Encode(jwtToken));
        String cacheToken= (String) redisUtils.get(key);
        String tokenKey=redisUtils.generateKey(CacheConstant.SYS_USER_TOKEN+":"+JwtTokenUtil.md5Encode(jwtToken));
        String userKey=redisUtils.generateKey(CacheConstant.SYS_USER_TOKEN+":"+username);
        String cacheToken= (String) redisUtils.get(tokenKey);
        if(StringUtils.isNotEmpty(cacheToken)){
            // 校验token有效性
            if(!JwtTokenUtil.verify(cacheToken,username,passWord)){
                String newToken=JwtTokenUtil.sign(username,passWord);
                // 设置超时时间
                redisUtils.set(key,newToken);
                redisUtils.expire(key,JwtTokenUtil.EXPIRATION*2/1000);
                redisUtils.set(tokenKey,newToken);
                redisUtils.expire(tokenKey,JwtTokenUtil.EXPIRATION*2/1000);
                redisUtils.expire(userKey,(JwtTokenUtil.EXPIRATION*2/1000)+2);
            }
            return true;
        }