|
|
@@ -29,6 +29,7 @@ import com.fdkankan.manage_jp.vo.response.UserExcelVo;
|
|
|
import com.fdkankan.manage_jp.vo.response.UserVo;
|
|
|
import com.fdkankan.redis.constant.RedisKey;
|
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -51,6 +52,7 @@ import java.util.stream.Collectors;
|
|
|
* @since 2022-12-23
|
|
|
*/
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements IUserService {
|
|
|
|
|
|
@Autowired
|
|
|
@@ -138,7 +140,7 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
|
|
|
|
|
|
public String redisLogin(String userName,String value,String 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);
|
|
|
return token;
|
|
|
}
|
|
|
@@ -224,8 +226,7 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
|
|
|
|
|
|
@Override
|
|
|
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
|
|
|
@@ -261,16 +262,14 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
|
|
|
this.update(wrapper);
|
|
|
|
|
|
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
|
|
|
- public void del(Integer id) {
|
|
|
+ public void del(Long id) {
|
|
|
if(id == null ){
|
|
|
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);
|
|
|
}
|
|
|
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
|