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: