[Bug修复](master): 修复了一些问题

修复了一些问题
master
土豆兄弟 3 years ago
parent 49d0248a10
commit 8de7d8bc0a

@ -211,7 +211,7 @@ public class FormdataServiceImpl implements FormdataService {
os.close(); os.close();
inputStream.close(); inputStream.close();
} catch (IOException e) { } catch (IOException e) {
log.error("ERROR FormdataServiceImpl|parseMediaFileToLocal ",e); log.error("ERROR FormdataServiceImpl|parseMediaFileToLocal ", e);
} }
} }
return path; return path;
@ -226,14 +226,12 @@ public class FormdataServiceImpl implements FormdataService {
@Override @Override
public void uploadOOS(MultipartFile file, List<FormdataDto> list) { public void uploadOOS(MultipartFile file, List<FormdataDto> list) {
String fileName = file.getOriginalFilename();
String subFixFile = StringUtils.substringAfterLast(fileName, SPLIT_FILE_SYMBOL);
List<WavDTO> wavList = zipUtil(file); List<WavDTO> wavList = zipUtil(file);
for (WavDTO wavDTO : wavList) { for (WavDTO wavDTO : wavList) {
for (FormdataDto info : list) { for (FormdataDto info : list) {
if (wavDTO.getName().equals(info.getPhone())) { 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); OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
ossClient.putObject(bucketName, newFileName, wavDTO.getLine()); ossClient.putObject(bucketName, newFileName, wavDTO.getLine());
ossClient.shutdown(); ossClient.shutdown();
@ -248,9 +246,10 @@ public class FormdataServiceImpl implements FormdataService {
private List<WavDTO> zipUtil(MultipartFile file) { private List<WavDTO> zipUtil(MultipartFile file) {
List<WavDTO> wavDTOS = new ArrayList<>(); List<WavDTO> wavDTOS = new ArrayList<>();
String zipFileName = null; String zipFileName = null;
try { try {
ZipInputStream zipInputStream = new ZipInputStream(file.getInputStream(), Charset.defaultCharset()); ZipInputStream zipInputStream = new ZipInputStream(file.getInputStream(), Charset.forName("GBK"));
BufferedInputStream bs = new BufferedInputStream(zipInputStream); BufferedInputStream bs = new BufferedInputStream(zipInputStream);
ZipEntry zipEntry; ZipEntry zipEntry;
byte[] bytes = null; byte[] bytes = null;
@ -258,6 +257,8 @@ public class FormdataServiceImpl implements FormdataService {
WavDTO wavDTO = new WavDTO(); WavDTO wavDTO = new WavDTO();
zipFileName = zipEntry.getName(); zipFileName = zipEntry.getName();
wavDTO.setName(zipFileName.substring(0, zipFileName.lastIndexOf("."))); wavDTO.setName(zipFileName.substring(0, zipFileName.lastIndexOf(".")));
wavDTO.setSubFixFile(StringUtils.substringAfterLast(zipFileName, SPLIT_FILE_SYMBOL));
bytes = new byte[(int) zipEntry.getSize()]; bytes = new byte[(int) zipEntry.getSize()];
bs.read(bytes, 0, (int) zipEntry.getSize()); bs.read(bytes, 0, (int) zipEntry.getSize());
InputStream byteArrayInputStream = new ByteArrayInputStream(bytes); InputStream byteArrayInputStream = new ByteArrayInputStream(bytes);

@ -12,5 +12,6 @@ import java.io.InputStream;
@Data @Data
public class WavDTO { public class WavDTO {
private String name; private String name;
private String subFixFile;
private InputStream line; private InputStream line;
} }

@ -1,13 +1,17 @@
package me.zhengjie.modules.uploadnew.service.impl; package me.zhengjie.modules.uploadnew.service.impl;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.system.OsInfo; import cn.hutool.system.OsInfo;
import cn.hutool.system.SystemUtil; import cn.hutool.system.SystemUtil;
import me.zhengjie.utils.FileUtil; import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.StringUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.File; import java.io.File;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
/** /**
* @author wjt * @author wjt
@ -69,21 +73,28 @@ public class BuildPathUtils {
* *
*/ */
public String buildFileOosPath(String subFixFile) { public String buildFileOosPath(String subFixFile) {
// 加一个音频格式不存在的格式通配
if (StringUtils.isBlank(subFixFile)){
subFixFile = "wav";
}
OsInfo osInfo = SystemUtil.getOsInfo(); 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; String dirPath;
if (osInfo.isWindows()) { if (osInfo.isWindows()) {
dirPath = fileBasePathWindows + timeFormate; dirPath = timeFormate;
FileUtil.mkdir(new File(dirPath)); FileUtil.mkdir(new File(dirPath));
// 构建存储文件 // 构建存储文件
return dirPath; return dirPath;
} else if (osInfo.isLinux()) { } else if (osInfo.isLinux()) {
dirPath = fileBasePathLinux + timeFormate; dirPath = timeFormate;
FileUtil.mkdir(new File(dirPath)); FileUtil.mkdir(new File(dirPath));
// 构建存储文件 // 构建存储文件
return dirPath; return dirPath;
} else if (osInfo.isMac()) { } else if (osInfo.isMac()) {
dirPath = fileBasePathMac + timeFormate; dirPath = timeFormate;
FileUtil.mkdir(new File(dirPath)); FileUtil.mkdir(new File(dirPath));
// 构建存储文件 // 构建存储文件
return dirPath; return dirPath;

Loading…
Cancel
Save