From 3ef7b8e8c75e1667347daff4d500f1c2d06ca4f0 Mon Sep 17 00:00:00 2001 From: Liuyang <2746366019@qq.com> Date: Mon, 24 Mar 2025 15:33:21 +0800 Subject: [PATCH] =?UTF-8?q?feat(llm):=20=E6=B7=BB=E5=8A=A0=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 - 新增 downloadExampleExcelFile 方法,用于下载示例 Excel 文件 - 修复了文件未找到时的异常处理 - 优化了文件下载的 HTTP 响应头设置 --- .../admin/dataset/DatasetController.java | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 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 cc32004ac..036d30f0e 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,29 +104,30 @@ public class DatasetController { BeanUtils.toBean(list, DatasetRespVO.class)); } + @GetMapping("/download-example-excel") + @Operation(summary = "下载示例文件") + public ResponseEntity downloadExampleExcelFile (@RequestParam("type") int type, HttpServletResponse response) throws IOException { + FileInfoVO fileInfo = getFileInfo(type); - // public ResponseEntity downloadExampleFile (@RequestParam("type") int type, HttpServletResponse response) throws IOException { - // FileInfoVO fileInfo = getFileInfo(type); - // - // // 从 resources/file/dataset_example 目录加载文件 - // ClassPathResource resource = new ClassPathResource("file/dataset_example/" + fileInfo.getFileName()); - // if (!resource.exists()) { - // throw new FileNotFoundException("文件未找到: " + fileInfo.getFileName()); - // } - // - // InputStream inputStream = resource.getInputStream(); - // HttpHeaders headers = new HttpHeaders(); - // headers.add("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(fileInfo.getFileName(), "UTF-8") + "\""); - // - // return ResponseEntity.ok() - // .headers(headers) - // .contentType(MediaType.APPLICATION_OCTET_STREAM) - // .body(new InputStreamResource(inputStream)); - // } + // 从 resources/file/dataset_example 目录加载文件 + ClassPathResource resource = new ClassPathResource("file/dataset_example/" + fileInfo.getFileName()); + if (!resource.exists()) { + throw new FileNotFoundException("文件未找到: " + fileInfo.getFileName()); + } + + InputStream inputStream = resource.getInputStream(); + HttpHeaders headers = new HttpHeaders(); + headers.add("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(fileInfo.getFileName(), "UTF-8") + "\""); + + return ResponseEntity.ok() + .headers(headers) + .contentType(MediaType.APPLICATION_OCTET_STREAM) + .body(new InputStreamResource(inputStream)); + } @GetMapping("/download-example") @Operation(summary = "下载示例文件") - public CommonResult downloadExampleFile(@RequestParam("type") int type) throws IOException { + 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()) { @@ -144,6 +145,7 @@ public class DatasetController { return CommonResult.success(base64); } } + private FileInfoVO getFileInfo (int type) { switch (type) { case 1: