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

This commit is contained in:
lyd
2022-10-28 16:04:45 +08:00
parent 321912fdba
commit 5026959e11
2 changed files with 18 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.config.RsaProperties;
import org.nl.modules.common.exception.BadRequestException; import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.PageUtil; 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.RsaUtils;
import org.nl.modules.common.utils.SecurityUtils; import org.nl.modules.common.utils.SecurityUtils;
import org.nl.modules.logging.annotation.Log; import org.nl.modules.logging.annotation.Log;
@@ -67,6 +68,7 @@ public class UserController {
private final DataService dataService; private final DataService dataService;
private final DeptService deptService; private final DeptService deptService;
private final RoleService roleService; private final RoleService roleService;
private final RedisUtils redisUtils;
@ApiOperation("导出用户数据") @ApiOperation("导出用户数据")
@GetMapping(value = "/download") @GetMapping(value = "/download")
@@ -144,6 +146,12 @@ public class UserController {
if (currentLevel > optLevel) { if (currentLevel > optLevel) {
throw new BadRequestException("角色权限不足,不能删除:" + userService.findById(id).getUsername()); 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); userService.delete(ids);
return new ResponseEntity<>(HttpStatus.OK); 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.config.RsaProperties;
import org.nl.modules.common.exception.BadRequestException; import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.PageUtil; 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.RsaUtils;
import org.nl.modules.common.utils.SecurityUtils; import org.nl.modules.common.utils.SecurityUtils;
import org.nl.modules.logging.annotation.Log; import org.nl.modules.logging.annotation.Log;
@@ -37,7 +38,9 @@ import org.nl.modules.system.service.UserService;
import org.nl.modules.system.service.dto.RoleSmallDto; import org.nl.modules.system.service.dto.RoleSmallDto;
import org.nl.modules.system.service.dto.UserDto; import org.nl.modules.system.service.dto.UserDto;
import org.nl.modules.system.service.dto.UserQueryCriteria; import org.nl.modules.system.service.dto.UserQueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@@ -67,6 +70,7 @@ public class UserController {
private final DataService dataService; private final DataService dataService;
private final DeptService deptService; private final DeptService deptService;
private final RoleService roleService; private final RoleService roleService;
private final RedisUtils redisUtils;
@ApiOperation("导出用户数据") @ApiOperation("导出用户数据")
@GetMapping(value = "/download") @GetMapping(value = "/download")
@@ -144,6 +148,12 @@ public class UserController {
if (currentLevel > optLevel) { if (currentLevel > optLevel) {
throw new BadRequestException("角色权限不足,不能删除:" + userService.findById(id).getUsername()); 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); userService.delete(ids);
return new ResponseEntity<>(HttpStatus.OK); return new ResponseEntity<>(HttpStatus.OK);