Commit 837c432c authored by 李健华's avatar 李健华

销户和冻结时删除token的缓存

parent bee82863
...@@ -3,9 +3,11 @@ package cn.quantgroup.xyqb.controller.middleoffice.user; ...@@ -3,9 +3,11 @@ package cn.quantgroup.xyqb.controller.middleoffice.user;
import cn.quantgroup.xyqb.entity.User; import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.event.DisableActiveEvent; import cn.quantgroup.xyqb.event.DisableActiveEvent;
import cn.quantgroup.xyqb.model.JsonResult; import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.service.session.ISessionService;
import cn.quantgroup.xyqb.service.user.IUserService; import cn.quantgroup.xyqb.service.user.IUserService;
import cn.quantgroup.xyqb.util.TenantUtil; import cn.quantgroup.xyqb.util.TenantUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -27,6 +29,10 @@ public class UserController { ...@@ -27,6 +29,10 @@ public class UserController {
@Resource @Resource
private ApplicationEventPublisher applicationEventPublisher; private ApplicationEventPublisher applicationEventPublisher;
@Autowired
private ISessionService sessionService;
@PutMapping("/enable/{userId}") @PutMapping("/enable/{userId}")
public JsonResult enable(@PathVariable Long userId) { public JsonResult enable(@PathVariable Long userId) {
User user = userService.findById(userId); User user = userService.findById(userId);
...@@ -51,6 +57,9 @@ public class UserController { ...@@ -51,6 +57,9 @@ public class UserController {
user.setEnable(false); user.setEnable(false);
//清理缓存 //清理缓存
userService.saveUser(user); userService.saveUser(user);
// 清除token缓存
/* 清空session */
sessionService.deleteByUserId(user.getId());
//通知消息中心 //通知消息中心
applicationEventPublisher.publishEvent(new DisableActiveEvent(this, user)); applicationEventPublisher.publishEvent(new DisableActiveEvent(this, user));
......
...@@ -230,6 +230,8 @@ public class SessionServiceImpl implements ISessionService { ...@@ -230,6 +230,8 @@ public class SessionServiceImpl implements ISessionService {
if (!CollectionUtils.isEmpty(useIdKeys)) { if (!CollectionUtils.isEmpty(useIdKeys)) {
useIdKeys.forEach(key -> { useIdKeys.forEach(key -> {
log.info("删除用户userId={}的缓存信息", userId); log.info("删除用户userId={}的缓存信息", userId);
String token = stringRedisTemplate.opsForValue().get(String.valueOf(key));
stringRedisTemplate.delete(getUserTokenKey(token));
stringRedisTemplate.delete(String.valueOf(key)); stringRedisTemplate.delete(String.valueOf(key));
}); });
//2.删除session缓存健 //2.删除session缓存健
...@@ -237,6 +239,10 @@ public class SessionServiceImpl implements ISessionService { ...@@ -237,6 +239,10 @@ public class SessionServiceImpl implements ISessionService {
} }
} }
private String getUserTokenKey(String token) {
return Constants.Session.USER_SESSION_CACHE + token;
}
/** /**
* 删除注销后缓存查询结果 * 删除注销后缓存查询结果
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment