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 5876922..a4a57f8 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 @@ -211,7 +211,7 @@ public class FormdataServiceImpl implements FormdataService { os.close(); inputStream.close(); } catch (IOException e) { - log.error("ERROR FormdataServiceImpl|parseMediaFileToLocal ",e); + log.error("ERROR FormdataServiceImpl|parseMediaFileToLocal ", e); } } return path; @@ -226,14 +226,12 @@ public class FormdataServiceImpl implements FormdataService { @Override public void uploadOOS(MultipartFile file, List list) { - String fileName = file.getOriginalFilename(); - String subFixFile = StringUtils.substringAfterLast(fileName, SPLIT_FILE_SYMBOL); List wavList = zipUtil(file); for (WavDTO wavDTO : wavList) { for (FormdataDto info : list) { if (wavDTO.getName().equals(info.getPhone())) { //上传路径 - String newFileName = buildPathUtils.buildFileOosPath(subFixFile); + String newFileName = buildPathUtils.buildFileOosPath(wavDTO.getSubFixFile()); OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); ossClient.putObject(bucketName, newFileName, wavDTO.getLine()); ossClient.shutdown(); @@ -248,9 +246,10 @@ public class FormdataServiceImpl implements FormdataService { private List zipUtil(MultipartFile file) { List wavDTOS = new ArrayList<>(); + String zipFileName = null; try { - ZipInputStream zipInputStream = new ZipInputStream(file.getInputStream(), Charset.defaultCharset()); + ZipInputStream zipInputStream = new ZipInputStream(file.getInputStream(), Charset.forName("GBK")); BufferedInputStream bs = new BufferedInputStream(zipInputStream); ZipEntry zipEntry; byte[] bytes = null; @@ -258,6 +257,8 @@ public class FormdataServiceImpl implements FormdataService { WavDTO wavDTO = new WavDTO(); zipFileName = zipEntry.getName(); wavDTO.setName(zipFileName.substring(0, zipFileName.lastIndexOf("."))); + + wavDTO.setSubFixFile(StringUtils.substringAfterLast(zipFileName, SPLIT_FILE_SYMBOL)); bytes = new byte[(int) zipEntry.getSize()]; bs.read(bytes, 0, (int) zipEntry.getSize()); InputStream byteArrayInputStream = new ByteArrayInputStream(bytes); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/dto/WavDTO.java b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/dto/WavDTO.java index 4f17d14..fcdef2c 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/dto/WavDTO.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/uploadnew/service/dto/WavDTO.java @@ -12,5 +12,6 @@ import java.io.InputStream; @Data public class WavDTO { private String name; + private String subFixFile; private InputStream line; } 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 bfb1c41..774f2eb 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,13 +1,17 @@ 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; import me.zhengjie.utils.FileUtil; +import me.zhengjie.utils.StringUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.io.File; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; /** * @author wjt @@ -69,21 +73,28 @@ public class BuildPathUtils { * 构建文件上传保存路径 */ public String buildFileOosPath(String subFixFile) { + // 加一个音频格式不存在的格式通配 + if (StringUtils.isBlank(subFixFile)){ + subFixFile = "wav"; + } + OsInfo osInfo = SystemUtil.getOsInfo(); - String timeFormate = DateUtil.now() + "" + (Math.random() * 9 + 1) * 10000 + "." + subFixFile; + DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); + String timeFormate = LocalDateTime.now().format(dtf) + RandomUtil.randomString(10) + "." + subFixFile; + String dirPath; if (osInfo.isWindows()) { - dirPath = fileBasePathWindows + timeFormate; + dirPath = timeFormate; FileUtil.mkdir(new File(dirPath)); // 构建存储文件 return dirPath; } else if (osInfo.isLinux()) { - dirPath = fileBasePathLinux + timeFormate; + dirPath = timeFormate; FileUtil.mkdir(new File(dirPath)); // 构建存储文件 return dirPath; } else if (osInfo.isMac()) { - dirPath = fileBasePathMac + timeFormate; + dirPath = timeFormate; FileUtil.mkdir(new File(dirPath)); // 构建存储文件 return dirPath;