lyhzzz před 3 měsíci
rodič
revize
b513991d94

+ 1 - 2
src/main/java/com/fdkankan/manage_jp/interceptor/UcenterInterceptor.java

@@ -40,8 +40,7 @@ public class UcenterInterceptor implements HandlerInterceptor {
 			return false;
 			return false;
 		}
 		}
 		try {
 		try {
-			String username = JwtUtil.getUsername(token);
-			String redisKey = String.format(RedisKeyUtil.LOGIN_USER,username,token);
+			String redisKey = String.format(RedisKey.TOKEN_V3,token);
 			if(redisUtil.hasKey(redisKey)){
 			if(redisUtil.hasKey(redisKey)){
 				redisUtil.expire(redisKey,2 * 60 * 60);
 				redisUtil.expire(redisKey,2 * 60 * 60);
 				return true;
 				return true;

+ 1 - 1
src/main/java/com/fdkankan/manage_jp/service/IUserService.java

@@ -50,5 +50,5 @@ public interface IUserService extends IService<User> {
 
 
     void export(UserParam param, HttpServletRequest req, HttpServletResponse resp);
     void export(UserParam param, HttpServletRequest req, HttpServletResponse resp);
 
 
-    void del(Integer id);
+    void del(Long id);
 }
 }

+ 23 - 10
src/main/java/com/fdkankan/manage_jp/service/impl/UserServiceImpl.java

@@ -29,6 +29,7 @@ import com.fdkankan.manage_jp.vo.response.UserExcelVo;
 import com.fdkankan.manage_jp.vo.response.UserVo;
 import com.fdkankan.manage_jp.vo.response.UserVo;
 import com.fdkankan.redis.constant.RedisKey;
 import com.fdkankan.redis.constant.RedisKey;
 import com.fdkankan.redis.util.RedisUtil;
 import com.fdkankan.redis.util.RedisUtil;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -51,6 +52,7 @@ import java.util.stream.Collectors;
  * @since 2022-12-23
  * @since 2022-12-23
  */
  */
 @Service
 @Service
+@Slf4j
 public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements IUserService {
 public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements IUserService {
 
 
     @Autowired
     @Autowired
@@ -138,7 +140,7 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
 
 
     public String redisLogin(String userName,String value,String loginType){
     public String redisLogin(String userName,String value,String loginType){
         String token = JwtUtil.createJWT(-1,userName,loginType);
         String token = JwtUtil.createJWT(-1,userName,loginType);
-        String redisKey = String.format(RedisKeyUtil.LOGIN_USER,userName,token);
+        String redisKey = String.format(RedisKey.TOKEN_V3,token);
         redisUtil.set(redisKey, value,2 * 60 * 60);
         redisUtil.set(redisKey, value,2 * 60 * 60);
         return token;
         return token;
     }
     }
@@ -224,8 +226,7 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
 
 
     @Override
     @Override
     public void logout(String token) {
     public void logout(String token) {
-        String username = JwtUtil.getUsername(token);
-        redisUtil.del(String.format(RedisKeyUtil.LOGIN_USER,username,token));
+        redisUtil.del(String.format(RedisKey.TOKEN_V3,token));
     }
     }
 
 
     @Override
     @Override
@@ -261,16 +262,14 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
         this.update(wrapper);
         this.update(wrapper);
 
 
         if(param.getStatus() == 0 ){
         if(param.getStatus() == 0 ){
-            String redisKey = String.format(RedisKeyUtil.LOGIN_USER,user.getUserName(),"*");
-            Set<String> keys = redisUtil.keys(redisKey);
-            keys.forEach(e -> redisUtil.del(e));
+            logout(param.getId());
         }
         }
 
 
 
 
     }
     }
 
 
     @Override
     @Override
-    public void del(Integer id) {
+    public void del(Long id) {
         if(id == null ){
         if(id == null ){
             throw new BusinessException(ResultCode.PARAM_ERROR);
             throw new BusinessException(ResultCode.PARAM_ERROR);
         }
         }
@@ -279,9 +278,23 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
             throw new BusinessException(ResultCode.USER_NOT_EXIST);
             throw new BusinessException(ResultCode.USER_NOT_EXIST);
         }
         }
         this.removeById(id);
         this.removeById(id);
-        String redisKey = String.format(RedisKeyUtil.LOGIN_USER,user.getUserName(),"*");
-        Set<String> keys = redisUtil.keys(redisKey);
-        keys.forEach(e -> redisUtil.del(e));
+        logout(id);
+    }
+
+    private void logout(Long userId){
+        try {
+            String redisKey = String.format(RedisKey.TOKEN_V3,"*");
+            Set<String> keys = redisUtil.keys(redisKey);
+            for (String key : keys) {
+                String s = redisUtil.get(key);
+                UserVo userVo = JSONObject.parseObject(s, UserVo.class);
+                if(userId.equals(userVo.getId())){
+                    redisUtil.del(key);
+                }
+            }
+        }catch (Exception e){
+            log.info("退出登录失败:{}",userId);
+        }
     }
     }
 
 
     @Override
     @Override

+ 1 - 1
src/main/java/com/fdkankan/manage_jp/vo/request/UserParam.java

@@ -7,7 +7,7 @@ import java.util.List;
 
 
 @Data
 @Data
 public class UserParam {
 public class UserParam {
-    private Integer id;
+    private Long id;
     private String newPassword;
     private String newPassword;
     private String password;
     private String password;
     private Integer status;
     private Integer status;