From 33542df0eb4b4d6367a618045edc671fd7a1c75e Mon Sep 17 00:00:00 2001 From: XaoLi717 <144221124+XaoLi717@users.noreply.github.com> Date: Wed, 13 Nov 2024 09:58:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8E=9F=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infra/controller/admin/file/FileController.java | 10 ++++++++-- .../file/core/client/local/LocalFileClient.java | 12 ++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java index 58994c4..d38051a 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/controller/admin/file/FileController.java @@ -67,12 +67,13 @@ public class FileController { return success(true); } - @GetMapping("/{configId}/get/**") + @GetMapping("/{configId}/get/{fileDate}/**") @PermitAll @Operation(summary = "下载文件") @Parameter(name = "configId", description = "配置编号", required = true) public void getFileContent(HttpServletRequest request, HttpServletResponse response, + @PathVariable("fileDate") String fileDate,//获取时间信息 @PathVariable("configId") Long configId) throws Exception { // 获取请求的路径 String path = StrUtil.subAfter(request.getRequestURI(), "/get/", false); @@ -82,8 +83,13 @@ public class FileController { // 解码,解决中文路径的问题 https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/807/ path = URLUtil.decode(path); + String[] parts = path.split("/"); + if (parts.length > 1) { path = parts[1]; }//分离原路径和时间信息 + + String filePath = fileDate+"\\"+path; //拼接原路径和时间信息 + // 读取内容 - byte[] content = fileService.getFileContent(configId, path); + byte[] content = fileService.getFileContent(configId, filePath); if (content == null) { log.warn("[getFileContent][configId({}) path({}) 文件不存在]", configId, path); response.setStatus(HttpStatus.NOT_FOUND.value()); diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/client/local/LocalFileClient.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/client/local/LocalFileClient.java index a919690..167a7fa 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/client/local/LocalFileClient.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/framework/file/core/client/local/LocalFileClient.java @@ -4,6 +4,8 @@ import cn.hutool.core.io.FileUtil; import cn.iocoder.yudao.module.infra.framework.file.core.client.AbstractFileClient; import java.io.File; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; /** * 本地文件客户端 @@ -26,11 +28,17 @@ public class LocalFileClient extends AbstractFileClient { @Override public String upload(byte[] content, String path, String type) { + //获取当前时间 + LocalDateTime now = LocalDateTime.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + String date = now.format(formatter);//当前时间获取 + String filesPath = date+"\\"+path; + String urlPath = date+"/"+path; // 执行写入 - String filePath = getFilePath(path); + String filePath = getFilePath(filesPath); FileUtil.writeBytes(content, filePath); // 拼接返回路径 - return super.formatFileUrl(config.getDomain(), path); + return super.formatFileUrl(config.getDomain(), urlPath); } @Override