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

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

@ -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<FormdataDto> list) {
String fileName = file.getOriginalFilename();
String subFixFile = StringUtils.substringAfterLast(fileName, SPLIT_FILE_SYMBOL);
List<WavDTO> 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<WavDTO> zipUtil(MultipartFile file) {
List<WavDTO> 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);

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

@ -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;

Loading…
Cancel
Save