Commit 18fcc8fbc557cf6fadd29884272eaaf67902e19e

Authored by puhui999
1 parent 287b2eab

feat: 新增用户批量删除接口

yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/user/UserController.java
... ... @@ -71,6 +71,15 @@ public class UserController {
71 71 return success(true);
72 72 }
73 73  
  74 + @DeleteMapping("/delete-list")
  75 + @Parameter(name = "ids", description = "编号列表", required = true)
  76 + @Operation(summary = "批量删除用户")
  77 + @PreAuthorize("@ss.hasPermission('system:user:delete')")
  78 + public CommonResult<Boolean> deleteUserList(@RequestParam("ids") List<Long> ids) {
  79 + userService.deleteUserList(ids);
  80 + return success(true);
  81 + }
  82 +
74 83 @PutMapping("/update-password")
75 84 @Operation(summary = "重置用户密码")
76 85 @PreAuthorize("@ss.hasPermission('system:user:update-password')")
... ...
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserService.java
... ... @@ -96,6 +96,13 @@ public interface AdminUserService {
96 96 void deleteUser(Long id);
97 97  
98 98 /**
  99 + * 批量删除用户
  100 + *
  101 + * @param ids 用户编号数组
  102 + */
  103 + void deleteUserList(List<Long> ids);
  104 +
  105 + /**
99 106 * 通过用户名查询用户
100 107 *
101 108 * @param username 用户名
... ...
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/user/AdminUserServiceImpl.java
... ... @@ -249,6 +249,28 @@ public class AdminUserServiceImpl implements AdminUserService {
249 249 }
250 250  
251 251 @Override
  252 + @Transactional(rollbackFor = Exception.class)
  253 + public void deleteUserList(List<Long> ids) {
  254 + if (CollUtil.isEmpty(ids)) {
  255 + return;
  256 + }
  257 + // 1. 校验用户存在
  258 + List<AdminUserDO> users = userMapper.selectByIds(ids);
  259 + if (CollUtil.isEmpty(users)) {
  260 + return;
  261 + }
  262 +
  263 + // 2. 批量删除用户
  264 + userMapper.deleteByIds(ids);
  265 +
  266 + // 3. 批量删除用户关联数据
  267 + ids.forEach(id -> {
  268 + permissionService.processUserDeleted(id);
  269 + userPostMapper.deleteByUserId(id);
  270 + });
  271 + }
  272 +
  273 + @Override
252 274 public AdminUserDO getUserByUsername(String username) {
253 275 return userMapper.selectByUsername(username);
254 276 }
... ...