| | |
| | | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.apikey.AiApiKeyPageReqVO; |
| | | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.apikey.AiApiKeyRespVO; |
| | | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.apikey.AiApiKeySaveReqVO; |
| | | import cn.iocoder.yudao.module.ai.controller.admin.model.vo.model.AiModelRespVO; |
| | | import cn.iocoder.yudao.module.ai.dal.dataobject.model.AiApiKeyDO; |
| | | import cn.iocoder.yudao.module.ai.service.model.AiApiKeyService; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | 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.validation.annotation.Validated; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.List; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | | import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; |
| | | |
| | | @Tag(name = "管理后台 - AI API 密钥") |
| | | @RestController |
| | | @RequestMapping("/ai/api-key") |
| | | @Validated |
| | | public class AiApiKeyController { |
| | | |
| | | @Resource |
| | |
| | | |
| | | @DeleteMapping("/delete") |
| | | @Operation(summary = "删除 API 密钥") |
| | | @Parameter(name = "id", description = "编号", required = true) |
| | | @PreAuthorize("@ss.hasPermission('ai:api-key:delete')") |
| | | public CommonResult<Boolean> deleteApiKey(@RequestParam("id") Long id) { |
| | | apiKeyService.deleteApiKey(id); |
| | |
| | | } |
| | | |
| | | @GetMapping("/get") |
| | | @Operation(summary = "获得 API 密钥") |
| | | @Parameter(name = "id", description = "编号", required = true, example = "1024") |
| | | @Operation(summary = "获取 API 密钥") |
| | | @PreAuthorize("@ss.hasPermission('ai:api-key:query')") |
| | | public CommonResult<AiApiKeyRespVO> getApiKey(@RequestParam("id") Long id) { |
| | | AiApiKeyDO apiKey = apiKeyService.getApiKey(id); |
| | | return success(BeanUtils.toBean(apiKey, AiApiKeyRespVO.class)); |
| | | return success(BeanUtils.toBean(apiKeyService.getApiKey(id), AiApiKeyRespVO.class)); |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | | @Operation(summary = "获得 API 密钥分页") |
| | | @Operation(summary = "获取 API 密钥分页") |
| | | @PreAuthorize("@ss.hasPermission('ai:api-key:query')") |
| | | public CommonResult<PageResult<AiApiKeyRespVO>> getApiKeyPage(@Valid AiApiKeyPageReqVO pageReqVO) { |
| | | PageResult<AiApiKeyDO> pageResult = apiKeyService.getApiKeyPage(pageReqVO); |
| | | return success(BeanUtils.toBean(pageResult, AiApiKeyRespVO.class)); |
| | | } |
| | | |
| | | @GetMapping("/simple-list") |
| | | @Operation(summary = "获得 API 密钥分页列表") |
| | | public CommonResult<List<AiModelRespVO>> getApiKeySimpleList() { |
| | | List<AiApiKeyDO> list = apiKeyService.getApiKeyList(); |
| | | return success(convertList(list, key -> new AiModelRespVO().setId(key.getId()).setName(key.getName()))); |
| | | } |
| | | |
| | | } |
| | | } |