删除用户没删除redis缓存问题

This commit is contained in:
lyd
2022-10-28 16:05:26 +08:00
parent e5b8408441
commit a296900af3
2 changed files with 16 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ import lombok.RequiredArgsConstructor;
import org.nl.modules.common.config.RsaProperties;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.PageUtil;
import org.nl.modules.common.utils.RedisUtils;
import org.nl.modules.common.utils.RsaUtils;
import org.nl.modules.common.utils.SecurityUtils;
import org.nl.modules.logging.annotation.Log;
@@ -67,6 +68,7 @@ public class UserController {
private final DataService dataService;
private final DeptService deptService;
private final RoleService roleService;
private final RedisUtils redisUtils;
@ApiOperation("导出用户数据")
@GetMapping(value = "/download")
@@ -144,6 +146,12 @@ public class UserController {
if (currentLevel > optLevel) {
throw new BadRequestException("角色权限不足,不能删除:" + userService.findById(id).getUsername());
}
// 删除缓存信息
UserDto userDto = userService.findById(id);
redisUtils.del("data::user:" + userDto.getId());
redisUtils.del("menu::user:" + userDto.getId());
redisUtils.del("role::auth:" + userDto.getId());
redisUtils.del("user::username:" + userDto.getUsername());
}
userService.delete(ids);
return new ResponseEntity<>(HttpStatus.OK);

View File

@@ -25,6 +25,7 @@ import lombok.RequiredArgsConstructor;
import org.nl.modules.common.config.RsaProperties;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.PageUtil;
import org.nl.modules.common.utils.RedisUtils;
import org.nl.modules.common.utils.RsaUtils;
import org.nl.modules.common.utils.SecurityUtils;
import org.nl.modules.logging.annotation.Log;
@@ -67,6 +68,7 @@ public class UserController {
private final DataService dataService;
private final DeptService deptService;
private final RoleService roleService;
private final RedisUtils redisUtils;
@ApiOperation("导出用户数据")
@GetMapping(value = "/download")
@@ -144,6 +146,12 @@ public class UserController {
if (currentLevel > optLevel) {
throw new BadRequestException("角色权限不足,不能删除:" + userService.findById(id).getUsername());
}
// 删除缓存信息
UserDto userDto = userService.findById(id);
redisUtils.del("data::user:" + userDto.getId());
redisUtils.del("menu::user:" + userDto.getId());
redisUtils.del("role::auth:" + userDto.getId());
redisUtils.del("user::username:" + userDto.getUsername());
}
userService.delete(ids);
return new ResponseEntity<>(HttpStatus.OK);