ludc
2024-09-27 7ccbd7f6fc245ee6a8704140ae7ad09e2509e6c4
redis服务移动到base下,实现超时过期用户减去一个在线用户数
已修改10个文件
已重命名3个文件
135 ■■■■ 文件已修改
Source/plt-web/plt-web-parent/plt-web-api/src/main/java/com/vci/pagemodel/PLTabButtonVO.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/plt-web/plt-web-parent/plt-web-base/pom.xml 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/constant/VConstant.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/interceptor/VciLogAfterInterceptor.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/interceptor/VciSecurityInterceptor.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/redis/FastJson2JsonRedisSerializer.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/redis/RedisConfig.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/redis/RedisService.java 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/plt-web/plt-web-parent/plt-web/pom.xml 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/impl/SmHMSysModConfigServiceImpl.java 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/impl/SmSessionForLoginImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/LoginServiceImpl.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/UIManagerServiceImpl.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
Source/plt-web/plt-web-parent/plt-web-api/src/main/java/com/vci/pagemodel/PLTabButtonVO.java
@@ -76,7 +76,7 @@
    private List<PLTabButtonVO> children;
    /**
     * æ˜¯å¦æ˜¾ç¤º
     * æ˜¾ç¤ºæ–¹å¼
     */
    private String displayMode;
@@ -91,7 +91,7 @@
    private String authorization;
    /**
     * æ˜¾ç¤ºæ–¹å¼
     * æ˜¯å¦æ˜¾ç¤º
     */
    private String show;
Source/plt-web/plt-web-parent/plt-web-base/pom.xml
@@ -73,6 +73,23 @@
            <artifactId>icegridgui</artifactId>
            <version>1.0.RELEASE</version>
        </dependency>
        <!--redis start-->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-redis</artifactId>
            <version>2.1.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.9.0</version>
        </dependency>
        <!--redis end-->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.13.3</version>
        </dependency>
    </dependencies>
</project>
Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/constant/VConstant.java
@@ -82,6 +82,11 @@
    public static final String SYS_ENUM_KEY = "sys_enum:";
    /**
     * å½“前登录的用户总数cache key
     */
    public static final String CURRENT_LOGGED_USERS_KEY = "current_logged_users";
    /**
     * èµ„源映射路径 å‰ç¼€
     */
    public static final String RESOURCE_PREFIX = "/profile";
Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/interceptor/VciLogAfterInterceptor.java
@@ -1,8 +1,6 @@
package com.vci.starter.web.interceptor;
import com.vci.starter.web.constant.TokenKeyConstant;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.starter.web.util.WebThreadLocalUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/interceptor/VciSecurityInterceptor.java
@@ -4,9 +4,11 @@
import com.vci.starter.web.annotation.controller.VciUnCheckRight;
import com.vci.starter.web.autoconfigure.SpringMVCConfig;
import com.vci.starter.web.constant.TokenKeyConstant;
import com.vci.starter.web.constant.VConstant;
import com.vci.starter.web.enumpck.ResultCodeEnum;
import com.vci.starter.web.pagemodel.BaseResult;
import com.vci.starter.web.pagemodel.SessionInfo;
import com.vci.starter.web.redis.RedisService;
import com.vci.starter.web.util.ApplicationContextProvider;
import com.vci.starter.web.util.LangBaseUtil;
import com.vci.starter.web.util.VciBaseUtil;
@@ -15,15 +17,11 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@@ -56,6 +54,9 @@
    @Autowired
    private VciSessionForLoginI vciSessionForLoginI;
    @Autowired
    private RedisService redisService;
    /**
     * æ‰§è¡Œæ‹¦æˆª
     * @param request è¯·æ±‚对象
@@ -76,7 +77,7 @@
        if(StringUtils.isBlank(userToken)){
            userToken = request.getParameter(TokenKeyConstant.USER_TOKEN_KEY);
        }
        if(!(handler instanceof  HandlerMethod)){
        if(!(handler instanceof HandlerMethod)){
            return true;
        }
@@ -127,6 +128,11 @@
                if(logger.isErrorEnabled()) {
                    logger.error("token值非法,或过期,或者用户已经被踢下线," + userToken);
                }
                //删除缓存中统计的用户信息
                if(redisService == null){
                    redisService = ApplicationContextProvider.getBean(RedisService.class);
                }
                redisService.decreOnlineUser(VConstant.CURRENT_LOGGED_USERS_KEY);
                sendErrorMsg(response,"token值非法,或过期,或者用户已经被踢下线," + userToken,1);
                return false;
            }else{
Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/redis/FastJson2JsonRedisSerializer.java
ÎļþÃû´Ó Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/redis/FastJson2JsonRedisSerializer.java ÐÞ¸Ä
@@ -1,4 +1,4 @@
package com.vci.web.redis;
package com.vci.starter.web.redis;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/redis/RedisConfig.java
ÎļþÃû´Ó Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/redis/RedisConfig.java ÐÞ¸Ä
@@ -1,4 +1,4 @@
package com.vci.web.redis;
package com.vci.starter.web.redis;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cache.annotation.CachingConfigurerSupport;
Source/plt-web/plt-web-parent/plt-web-base/src/main/java/com/vci/starter/web/redis/RedisService.java
ÎļþÃû´Ó Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/redis/RedisService.java ÐÞ¸Ä
@@ -1,4 +1,4 @@
package com.vci.web.redis;
package com.vci.starter.web.redis;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -11,6 +11,7 @@
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.*;
@@ -21,10 +22,9 @@
 * @author dangsn
 **/
@SuppressWarnings(value = { "unchecked", "rawtypes" })
@Component
@Service
@Slf4j
public class RedisService
{
public class RedisService {
    @Autowired(required = false)
    public RedisTemplate redisTemplate;
@@ -393,19 +393,33 @@
    /**
     * ç”¨æˆ·ç™»å½•
     * @param currentLoggedUserKey
     * @param username
     */
    public void userLogin(String currentLoggedUserKey,String username) {
        redisTemplate.opsForSet().add(currentLoggedUserKey, username);
    public void increOnlineUser(String currentLoggedUserKey) {
        // æ£€æŸ¥é”®æ˜¯å¦å­˜åœ¨
        if (!redisTemplate.hasKey(currentLoggedUserKey)) {
            // å¦‚果键不存在,初始化为0
            redisTemplate.opsForValue().set(currentLoggedUserKey, 0);
        }
        // è‡ªå¢žåœ¨çº¿ç”¨æˆ·æ•°
        redisTemplate.opsForValue().increment(currentLoggedUserKey);
    }
    /**
     * ç”¨æˆ·ç™»å‡º
     * @param currentLoggedUserKey
     * @param username
     */
    public void userLogout(String currentLoggedUserKey,String username) {
        redisTemplate.opsForSet().remove(currentLoggedUserKey, username);
    public void decreOnlineUser(String currentLoggedUserKey) {
        // æ£€æŸ¥å½“前在线用户数
        String currentLoggedUser = (String)redisTemplate.opsForValue().get(currentLoggedUserKey);
        if (currentLoggedUser != null) {
            Long currentCount = Long.parseLong((String)redisTemplate.opsForValue().get(currentLoggedUserKey));
            if(currentCount > 0){
            }
            // è‡ªå‡åœ¨çº¿ç”¨æˆ·æ•°
            redisTemplate.opsForValue().decrement(currentLoggedUserKey);
        }
    }
    /**
@@ -413,8 +427,8 @@
     * @param currentLoggedUserKey
     * @return
     */
    public long getCurrentLoggedUserCount(String currentLoggedUserKey) {
        return redisTemplate.opsForSet().size(currentLoggedUserKey);
    public long getCurrentOnlineUserCount(String currentLoggedUserKey) {
        return Long.parseLong(redisTemplate.opsForValue().get(currentLoggedUserKey).toString());
    }
    /**
Source/plt-web/plt-web-parent/plt-web/pom.xml
@@ -106,23 +106,6 @@
            <version>0.9.11</version>
        </dependency>
        <!--redis start-->
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-redis</artifactId>
            <version>2.1.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.9.0</version>
        </dependency>
        <!--redis end-->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>2.13.3</version>
        </dependency>
    </dependencies>
    <build>
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/impl/SmHMSysModConfigServiceImpl.java
@@ -12,13 +12,14 @@
import com.vci.starter.poi.bo.WriteExcelData;
import com.vci.starter.poi.bo.WriteExcelOption;
import com.vci.starter.poi.util.ExcelUtil;
import com.vci.starter.web.constant.VConstant;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.pagemodel.BaseResult;
import com.vci.starter.web.pagemodel.SessionInfo;
import com.vci.starter.web.util.LocalFileUtil;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.starter.web.util.WebThreadLocalUtil;
import com.vci.web.redis.RedisService;
import com.vci.starter.web.redis.RedisService;
import com.vci.web.util.Func;
import com.vci.web.util.PlatformClientUtil;
import org.slf4j.Logger;
@@ -62,11 +63,6 @@
    @Autowired
    private RedisService redisService;
    /**
     * å½“前登录的用户总数key
     */
    private static final String CURRENT_LOGGED_USERS_KEY = "current_logged_users";
    /**
     * æ—¥å¿—
@@ -609,8 +605,6 @@
        return res;
    }
    /**
     * æ£€æŸ¥æ˜¯å¦å­˜åœ¨å¼•用关系
     * @param ids
@@ -795,7 +789,7 @@
     */
    @Override
    public long getOnlineUsersNum() {
        long currentLoggedUserCount = redisService.getCurrentLoggedUserCount(CURRENT_LOGGED_USERS_KEY);
        long currentLoggedUserCount = redisService.getCurrentOnlineUserCount(VConstant.CURRENT_LOGGED_USERS_KEY);
        return currentLoggedUserCount;
    }
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/frameworkcore/compatibility/impl/SmSessionForLoginImpl.java
@@ -13,7 +13,7 @@
import com.vci.starter.web.util.*;
import com.vci.constant.CacheNameConstant;
import com.vci.web.properties.WebProperties;
import com.vci.web.redis.RedisService;
import com.vci.starter.web.redis.RedisService;
import com.vci.web.service.WebBoServiceI;
import com.vci.web.util.PlatformClientUtil;
import com.vci.web.util.WebUtil;
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/LoginServiceImpl.java
@@ -19,6 +19,7 @@
import com.vci.starter.web.annotation.bus.VciLoginAfter;
import com.vci.starter.web.annotation.bus.VciLogoutBefore;
import com.vci.starter.web.annotation.bus.VciLogoutPlugin;
import com.vci.starter.web.constant.VConstant;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.interceptor.VciSessionForLoginI;
import com.vci.starter.web.pagemodel.RequestClientInfo;
@@ -30,7 +31,7 @@
import com.vci.constant.CacheNameConstant;
import com.vci.dto.LoginUserDTO;
import com.vci.web.properties.WebProperties;
import com.vci.web.redis.RedisService;
import com.vci.starter.web.redis.RedisService;
import com.vci.web.service.LoginServiceI;
import com.vci.web.util.Func;
import com.vci.web.util.PlatformClientUtil;
@@ -128,11 +129,6 @@
    private PlatformClientUtil platformClientUtil;
    /**
     * å½“前登录的用户总数key
     */
    private static final String CURRENT_LOGGED_USERS_KEY = "current_logged_users";
    /**
     * æ‰§è¡Œç™»å½•
     * @param userDTO ç™»å½•信息
     * @param clientInfo è¯·æ±‚的客户端的信息
@@ -151,7 +147,7 @@
     * @return æ‰§è¡Œç»“æžœ
     * @throws VciBaseException å‚数错误,用户不能登录等会抛出异常
     */
    private LoginResultBO login(LoginUserDTO userDTO, RequestClientInfo clientInfo, boolean checkPassword/*单点登录不需要校验密码*/) throws VciBaseException, PLException {
    private LoginResultBO login(LoginUserDTO userDTO, RequestClientInfo clientInfo, boolean checkPassword/*单点登录不需要校验密码*/) throws VciBaseException {
        LoginResultBO loginResult = new LoginResultBO();
        loginResult.setSuccess(false);
@@ -172,7 +168,7 @@
            String tokenKey = redisService.getCacheObject(userIdTokenKey);
            redisService.deleteObject(tokenKey);
            redisService.deleteObject(userIdTokenKey);
            redisService.userLogout(CURRENT_LOGGED_USERS_KEY,userDTO.getUserId());
            redisService.decreOnlineUser(VConstant.CURRENT_LOGGED_USERS_KEY);
        }
        //3.获取用户的对象(对象中包含角色部门还有密码策略信息(当前用户没设置密码策略就是取的默认密码策略))
@@ -249,7 +245,7 @@
        //初始化平台的token
        sessionForLogin.initInvocationInfo(sessionInfo);
        //记录当前登录人数的总数
        redisService.userLogin(CURRENT_LOGGED_USERS_KEY,userDTO.getUserId());
        redisService.increOnlineUser(VConstant.CURRENT_LOGGED_USERS_KEY);
        //拷贝用户到新的session会话中
        copyUser2SessionInfo(user, sessionInfo, userDTO.getLangCode());
        //拷贝请求信息到session会话中
@@ -567,7 +563,7 @@
            });
        }
        //清除存当前登录的用户(总数-1)
        redisService.userLogout(CURRENT_LOGGED_USERS_KEY,WebThreadLocalUtil.getCurrentUserSessionInfoInThread().getUserId());
        redisService.decreOnlineUser(VConstant.CURRENT_LOGGED_USERS_KEY);
        sessionForLogin.logout(userToken);
        if(!CollectionUtils.isEmpty(logoutpluginBeanMap)){
            logoutpluginBeanMap.forEach((k,v) -> {
Source/plt-web/plt-web-parent/plt-web/src/main/java/com/vci/web/service/impl/UIManagerServiceImpl.java
@@ -21,7 +21,7 @@
import com.vci.starter.web.pagemodel.DataGrid;
import com.vci.starter.web.pagemodel.SessionInfo;
import com.vci.starter.web.util.*;
import com.vci.web.redis.RedisService;
import com.vci.starter.web.redis.RedisService;
import com.vci.web.service.OsBtmServiceI;
import com.vci.web.service.UIManagerServiceI;
import com.vci.web.util.*;