feat: 新增 OAuth2 客户端批量删除接口
This commit is contained in:
parent
e91096e4e0
commit
33d7fdedf8
|
@ -11,12 +11,13 @@ import cn.iocoder.yudao.module.system.service.oauth2.OAuth2ClientService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
|
import jakarta.validation.Valid;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
import java.util.List;
|
||||||
import jakarta.validation.Valid;
|
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
|
|
||||||
|
@ -53,6 +54,15 @@ public class OAuth2ClientController {
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/delete-list")
|
||||||
|
@Parameter(name = "ids", description = "编号列表", required = true)
|
||||||
|
@Operation(summary = "批量删除 OAuth2 客户端")
|
||||||
|
@PreAuthorize("@ss.hasPermission('system:oauth2-client:delete')")
|
||||||
|
public CommonResult<Boolean> deleteOAuth2ClientList(@RequestParam("ids") List<Long> ids) {
|
||||||
|
oAuth2ClientService.deleteOAuth2ClientList(ids);
|
||||||
|
return success(true);
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/get")
|
@GetMapping("/get")
|
||||||
@Operation(summary = "获得 OAuth2 客户端")
|
@Operation(summary = "获得 OAuth2 客户端")
|
||||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||||
|
|
|
@ -4,9 +4,10 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientPageReqVO;
|
import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientPageReqVO;
|
||||||
import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientSaveReqVO;
|
import cn.iocoder.yudao.module.system.controller.admin.oauth2.vo.client.OAuth2ClientSaveReqVO;
|
||||||
import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ClientDO;
|
import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ClientDO;
|
||||||
|
|
||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* OAuth2.0 Client Service 接口
|
* OAuth2.0 Client Service 接口
|
||||||
|
@ -39,6 +40,13 @@ public interface OAuth2ClientService {
|
||||||
*/
|
*/
|
||||||
void deleteOAuth2Client(Long id);
|
void deleteOAuth2Client(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除 OAuth2 客户端
|
||||||
|
*
|
||||||
|
* @param ids 编号数组
|
||||||
|
*/
|
||||||
|
void deleteOAuth2ClientList(List<Long> ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得 OAuth2 客户端
|
* 获得 OAuth2 客户端
|
||||||
*
|
*
|
||||||
|
|
|
@ -14,14 +14,15 @@ import cn.iocoder.yudao.module.system.dal.dataobject.oauth2.OAuth2ClientDO;
|
||||||
import cn.iocoder.yudao.module.system.dal.mysql.oauth2.OAuth2ClientMapper;
|
import cn.iocoder.yudao.module.system.dal.mysql.oauth2.OAuth2ClientMapper;
|
||||||
import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants;
|
import cn.iocoder.yudao.module.system.dal.redis.RedisKeyConstants;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
|
import jakarta.annotation.Resource;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
|
||||||
import jakarta.annotation.Resource;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||||
|
@ -72,12 +73,32 @@ public class OAuth2ClientServiceImpl implements OAuth2ClientService {
|
||||||
oauth2ClientMapper.deleteById(id);
|
oauth2ClientMapper.deleteById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@CacheEvict(cacheNames = RedisKeyConstants.OAUTH_CLIENT,
|
||||||
|
allEntries = true) // allEntries 清空所有缓存,因为 id 不是直接的缓存 key,不好清理
|
||||||
|
public void deleteOAuth2ClientList(List<Long> ids) {
|
||||||
|
if (CollUtil.isEmpty(ids)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 校验存在
|
||||||
|
validateOAuth2ClientBatchExists(ids);
|
||||||
|
// 批量删除
|
||||||
|
oauth2ClientMapper.deleteByIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
private void validateOAuth2ClientExists(Long id) {
|
private void validateOAuth2ClientExists(Long id) {
|
||||||
if (oauth2ClientMapper.selectById(id) == null) {
|
if (oauth2ClientMapper.selectById(id) == null) {
|
||||||
throw exception(OAUTH2_CLIENT_NOT_EXISTS);
|
throw exception(OAUTH2_CLIENT_NOT_EXISTS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void validateOAuth2ClientBatchExists(List<Long> ids) {
|
||||||
|
List<OAuth2ClientDO> clients = oauth2ClientMapper.selectByIds(ids);
|
||||||
|
if (clients.size() != ids.size()) {
|
||||||
|
throw exception(OAUTH2_CLIENT_NOT_EXISTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void validateClientIdExists(Long id, String clientId) {
|
void validateClientIdExists(Long id, String clientId) {
|
||||||
OAuth2ClientDO client = oauth2ClientMapper.selectByClientId(clientId);
|
OAuth2ClientDO client = oauth2ClientMapper.selectByClientId(clientId);
|
||||||
|
|
Loading…
Reference in New Issue