From cd6e5f5da8225a0a2b663ff86f858c9affef5cd9 Mon Sep 17 00:00:00 2001 From: wujingtao Date: Mon, 9 Aug 2021 16:52:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9C=AC=E5=9C=B0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BF=9D=E5=AD=98=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/FormdataServiceImpl.java | 3 ++- .../service/impl/BuildPathUtils.java | 22 +++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/formdata/service/impl/FormdataServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/formdata/service/impl/FormdataServiceImpl.java index a4a57f8..bcbdeb4 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/formdata/service/impl/FormdataServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/formdata/service/impl/FormdataServiceImpl.java @@ -180,8 +180,9 @@ public class FormdataServiceImpl implements FormdataService { // 存储音频压缩文件到指定目录下 每次上传以 2021-8-5 为 文件名进行记录 每次记录一天的 并保存记录 //文件名 String fileName = file.getOriginalFilename(); + //文件保存地址 - String path = buildPathUtils.buildFilePath(fileName); + String path = buildPathUtils.buildFilePath(); OutputStream os = null; InputStream inputStream = null; try { diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/impl/BuildPathUtils.java b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/impl/BuildPathUtils.java index 774f2eb..9d2b3ff 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/impl/BuildPathUtils.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/impl/BuildPathUtils.java @@ -1,6 +1,5 @@ package me.zhengjie.modules.uploadnew.service.impl; -import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.RandomUtil; import cn.hutool.system.OsInfo; import cn.hutool.system.SystemUtil; @@ -13,6 +12,7 @@ import java.io.File; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; + /** * @author wjt * @date 2021/8/6 @@ -41,26 +41,26 @@ public class BuildPathUtils { /** * 构建文件上传保存路径 */ - public String buildFilePath(String fileName) { + public String buildFilePath() { // 获取环境配置信息 OsInfo osInfo = SystemUtil.getOsInfo(); // 定义的时间格式 - String timeFormate = DateUtil.today(); - + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMdd"); + String timeForMate = LocalDateTime.now().format(dtf) + RandomUtil.randomString(4); String dirPath; if (osInfo.isWindows()) { - dirPath = fileBasePathWindows + timeFormate + File.separator + fileName; + dirPath = fileBasePathWindows + timeForMate; FileUtil.mkdir(new File(dirPath)); // 构建存储文件 return dirPath; } else if (osInfo.isLinux()) { - dirPath = fileBasePathLinux + timeFormate + File.separator + fileName; + dirPath = fileBasePathLinux + timeForMate; FileUtil.mkdir(new File(dirPath)); // 构建存储文件 return dirPath; } else if (osInfo.isMac()) { - dirPath = fileBasePathMac + timeFormate + File.separator + fileName; + dirPath = fileBasePathMac + timeForMate; FileUtil.mkdir(new File(dirPath)); // 构建存储文件 return dirPath; @@ -74,13 +74,13 @@ public class BuildPathUtils { */ public String buildFileOosPath(String subFixFile) { // 加一个音频格式不存在的格式通配 - if (StringUtils.isBlank(subFixFile)){ + if (StringUtils.isBlank(subFixFile)) { subFixFile = "wav"; } OsInfo osInfo = SystemUtil.getOsInfo(); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); - String timeFormate = LocalDateTime.now().format(dtf) + RandomUtil.randomString(10) + "." + subFixFile; + String timeFormate = LocalDateTime.now().format(dtf) + RandomUtil.randomString(10) + "." + subFixFile; String dirPath; if (osInfo.isWindows()) { @@ -89,12 +89,12 @@ public class BuildPathUtils { // 构建存储文件 return dirPath; } else if (osInfo.isLinux()) { - dirPath = timeFormate; + dirPath = timeFormate; FileUtil.mkdir(new File(dirPath)); // 构建存储文件 return dirPath; } else if (osInfo.isMac()) { - dirPath = timeFormate; + dirPath = timeFormate; FileUtil.mkdir(new File(dirPath)); // 构建存储文件 return dirPath;