From 224ff363431b196dfd99913ed433bc130c089e7a Mon Sep 17 00:00:00 2001 From: Liuyang <2746366019@qq.com> Date: Mon, 24 Mar 2025 15:35:24 +0800 Subject: [PATCH] =?UTF-8?q?refactor(llm):=20=E9=87=8D=E6=9E=84=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E9=9B=86=E7=A4=BA=E4=BE=8B=E6=96=87=E4=BB=B6=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改下载示例文件接口路径,将 "/download-example-excel"改为 "/download-example" - 优化下载逻辑,使用 ResponseEntity 作为返回类型 - 删除冗余的 Base64 编码下载方法 --- .../admin/dataset/DatasetController.java | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/dataset/DatasetController.java b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/dataset/DatasetController.java index 036d30f0e..82f0f4188 100644 --- a/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/dataset/DatasetController.java +++ b/yudao-module-llm/yudao-module-llm-biz/src/main/java/cn/iocoder/yudao/module/llm/controller/admin/dataset/DatasetController.java @@ -104,9 +104,9 @@ public class DatasetController { BeanUtils.toBean(list, DatasetRespVO.class)); } - @GetMapping("/download-example-excel") + @GetMapping("/download-example") @Operation(summary = "下载示例文件") - public ResponseEntity downloadExampleExcelFile (@RequestParam("type") int type, HttpServletResponse response) throws IOException { + public ResponseEntity downloadExampleFile (@RequestParam("type") int type, HttpServletResponse response) throws IOException { FileInfoVO fileInfo = getFileInfo(type); // 从 resources/file/dataset_example 目录加载文件 @@ -125,26 +125,26 @@ public class DatasetController { .body(new InputStreamResource(inputStream)); } - @GetMapping("/download-example") - @Operation(summary = "下载示例文件") - public CommonResult downloadExampleFile (@RequestParam("type") int type) throws IOException { - FileInfoVO fileInfo = getFileInfo(type); - ClassPathResource resource = new ClassPathResource("file/dataset_example/" + fileInfo.getFileName()); - if (!resource.exists()) { - throw new FileNotFoundException("文件未找到: " + fileInfo.getFileName()); - } - - try (InputStream inputStream = resource.getInputStream(); - ByteArrayOutputStream byteStream = new ByteArrayOutputStream()) { - byte[] buffer = new byte[1024]; - int bytesRead; - while ((bytesRead = inputStream.read(buffer)) != -1) { - byteStream.write(buffer, 0, bytesRead); - } - String base64 = Base64.getEncoder().encodeToString(byteStream.toByteArray()); - return CommonResult.success(base64); - } - } +// @GetMapping("/download-example") +// @Operation(summary = "下载示例文件") +// public CommonResult downloadExampleFile (@RequestParam("type") int type) throws IOException { +// FileInfoVO fileInfo = getFileInfo(type); +// ClassPathResource resource = new ClassPathResource("file/dataset_example/" + fileInfo.getFileName()); +// if (!resource.exists()) { +// throw new FileNotFoundException("文件未找到: " + fileInfo.getFileName()); +// } +// +// try (InputStream inputStream = resource.getInputStream(); +// ByteArrayOutputStream byteStream = new ByteArrayOutputStream()) { +// byte[] buffer = new byte[1024]; +// int bytesRead; +// while ((bytesRead = inputStream.read(buffer)) != -1) { +// byteStream.write(buffer, 0, bytesRead); +// } +// String base64 = Base64.getEncoder().encodeToString(byteStream.toByteArray()); +// return CommonResult.success(base64); +// } +// } private FileInfoVO getFileInfo (int type) { switch (type) {