Commit 33d7fdedf8419f0f1fa37d0bc4e7010dc237fda8

Authored by puhui999
1 parent e91096e4

feat: 新增 OAuth2 客户端批量删除接口

yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/oauth2/OAuth2ClientController.java
... ... @@ -11,12 +11,13 @@ import cn.iocoder.yudao.module.system.service.oauth2.OAuth2ClientService;
11 11 import io.swagger.v3.oas.annotations.Operation;
12 12 import io.swagger.v3.oas.annotations.Parameter;
13 13 import io.swagger.v3.oas.annotations.tags.Tag;
  14 +import jakarta.annotation.Resource;
  15 +import jakarta.validation.Valid;
14 16 import org.springframework.security.access.prepost.PreAuthorize;
15 17 import org.springframework.validation.annotation.Validated;
16 18 import org.springframework.web.bind.annotation.*;
17 19  
18   -import jakarta.annotation.Resource;
19   -import jakarta.validation.Valid;
  20 +import java.util.List;
20 21  
21 22 import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
22 23  
... ... @@ -53,6 +54,15 @@ public class OAuth2ClientController {
53 54 return success(true);
54 55 }
55 56  
  57 + @DeleteMapping("/delete-list")
  58 + @Parameter(name = "ids", description = "编号列表", required = true)
  59 + @Operation(summary = "批量删除 OAuth2 客户端")
  60 + @PreAuthorize("@ss.hasPermission('system:oauth2-client:delete')")
  61 + public CommonResult<Boolean> deleteOAuth2ClientList(@RequestParam("ids") List<Long> ids) {
  62 + oAuth2ClientService.deleteOAuth2ClientList(ids);
  63 + return success(true);
  64 + }
  65 +
56 66 @GetMapping("/get")
57 67 @Operation(summary = "获得 OAuth2 客户端")
58 68 @Parameter(name = "id", description = "编号", required = true, example = "1024")
... ...
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientService.java
... ... @@ -4,9 +4,10 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 4 import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientPageReqVO;
5 5 import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientSaveReqVO;
6 6 import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ClientDO;
7   -
8 7 import jakarta.validation.Valid;
  8 +
9 9 import java.util.Collection;
  10 +import java.util.List;
10 11  
11 12 /**
12 13 * OAuth2.0 Client Service 接口
... ... @@ -40,6 +41,13 @@ public interface OAuth2ClientService {
40 41 void deleteOAuth2Client(Long id);
41 42  
42 43 /**
  44 + * 批量删除 OAuth2 客户端
  45 + *
  46 + * @param ids 编号数组
  47 + */
  48 + void deleteOAuth2ClientList(List<Long> ids);
  49 +
  50 + /**
43 51 * 获得 OAuth2 客户端
44 52 *
45 53 * @param id 编号
... ...
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/oauth2/OAuth2ClientServiceImpl.java
... ... @@ -14,14 +14,15 @@ import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ClientDO;
14 14 import cn.iocoder.yudao.module.system.dal.mysql.oauth2.OAuth2ClientMapper;
15 15 import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants;
16 16 import com.google.common.annotations.VisibleForTesting;
  17 +import jakarta.annotation.Resource;
17 18 import lombok.extern.slf4j.Slf4j;
18 19 import org.springframework.cache.annotation.CacheEvict;
19 20 import org.springframework.cache.annotation.Cacheable;
20 21 import org.springframework.stereotype.Service;
21 22 import org.springframework.validation.annotation.Validated;
22 23  
23   -import jakarta.annotation.Resource;
24 24 import java.util.Collection;
  25 +import java.util.List;
25 26  
26 27 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
27 28 import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
... ... @@ -72,12 +73,32 @@ public class OAuth2ClientServiceImpl implements OAuth2ClientService {
72 73 oauth2ClientMapper.deleteById(id);
73 74 }
74 75  
  76 + @Override
  77 + @CacheEvict(cacheNames = RedisKeyConstants.OAUTH_CLIENT,
  78 + allEntries = true) // allEntries 清空所有缓存,因为 id 不是直接的缓存 key,不好清理
  79 + public void deleteOAuth2ClientList(List<Long> ids) {
  80 + if (CollUtil.isEmpty(ids)) {
  81 + return;
  82 + }
  83 + // 校验存在
  84 + validateOAuth2ClientBatchExists(ids);
  85 + // 批量删除
  86 + oauth2ClientMapper.deleteByIds(ids);
  87 + }
  88 +
75 89 private void validateOAuth2ClientExists(Long id) {
76 90 if (oauth2ClientMapper.selectById(id) == null) {
77 91 throw exception(OAUTH2_CLIENT_NOT_EXISTS);
78 92 }
79 93 }
80 94  
  95 + private void validateOAuth2ClientBatchExists(List<Long> ids) {
  96 + List<OAuth2ClientDO> clients = oauth2ClientMapper.selectByIds(ids);
  97 + if (clients.size() != ids.size()) {
  98 + throw exception(OAUTH2_CLIENT_NOT_EXISTS);
  99 + }
  100 + }
  101 +
81 102 @VisibleForTesting
82 103 void validateClientIdExists(Long id, String clientId) {
83 104 OAuth2ClientDO client = oauth2ClientMapper.selectByClientId(clientId);
... ...