Commit e713977a authored by yanzg's avatar yanzg

表结构修改

parent 82dc5851
......@@ -22,13 +22,13 @@ import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/**
* 文件上传服务实现
......@@ -71,7 +71,7 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
* 压缩文件
*
* @param req 文件上传请求参数
* @return
* @return 上传文件对象
*/
@Override
public YzgFileUploadResVo upload(YzgFileUploadReqVo req) {
......@@ -80,9 +80,13 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
throw YzgError.getRuntimeException("062");
}
String folder = checkFolder(req.getFolder());
for (MultipartFile uploadFile : req.getFile()) {
// 获取上传源文件名和扩展名
String originalFilename = uploadFile.getOriginalFilename();
if (StringHelper.isEmpty(originalFilename)) {
throw YzgError.getRuntimeException("062");
}
String ext = originalFilename.substring(originalFilename.lastIndexOf("."));
// 保存的文件名
String saveFileName = StringHelper.getNewID() + ext;
......@@ -132,7 +136,7 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
/**
* 立即删除临时路径
*
* @param tempFolder
* @param tempFolder 删除的临时目录
*/
@Override
public void removeTempFolder(String tempFolder) {
......@@ -151,7 +155,7 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
// 父文件夹不存在子文件时则删除
File file = new File(toFolder);
File parentFile = file.getParentFile();
if (parentFile.listFiles() == null || parentFile.listFiles().length == 0) {
if (parentFile.listFiles() == null || Objects.requireNonNull(parentFile.listFiles()).length == 0) {
removeTempFolder(parentFile.getAbsolutePath());
}
} finally {
......@@ -164,8 +168,8 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
/**
* 下载文件
*
* @param fromUrl
* @param response
* @param fromUrl 下载文件路径
* @param response 输出流
*/
@Override
public void down(String fromUrl, HttpServletResponse response) throws IOException {
......@@ -185,7 +189,7 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
/**
* 移动文件或文件夹
*
* @param req
* @param req 请求参数
*/
@Override
public void moveFile(YzgFileMoveReqVo req) {
......@@ -228,6 +232,9 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
}
private void move(YzgFileMoveItemReqVo item) {
checkFolder(item.getFrom());
checkFolder(item.getTo());
String fullFrom = fileConfig.getServerFullPath(item.getFrom());
String fullTo = fileConfig.getServerFullPath(item.getTo());
// 路径相等,不移动
......@@ -260,11 +267,13 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
/**
* 获取文件信息
*
* @param fromUrl
* @return
* @param fromUrl 文件路径
* @return 文件信息
*/
@Override
public YzgFileVideoImageInfoVo getInfo(String fromUrl) {
checkFolder(fromUrl);
YzgFileVideoImageInfoVo info = new YzgFileVideoImageInfoVo();
fileConfig.init(info, fromUrl);
......@@ -284,7 +293,7 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
break;
}
case FileHelper.FILE_TYPE_IMAGE: {
BufferedImage sourceImg = ImageIO.read(new FileInputStream(serverFullPath));
BufferedImage sourceImg = ImageIO.read(Files.newInputStream(Paths.get(serverFullPath)));
info.setWidth(sourceImg.getWidth());
info.setHeight(sourceImg.getHeight());
break;
......@@ -307,19 +316,18 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
*/
@Override
public void convertImage(YzgFileVideoImageReqVo req) {
this.convert(req, FileHelper.FILE_TYPE_IMAGE, "图片", new YzgConvert() {
@Override
public void run(YzgFileVideoImageItemReqVo item, String from, String toFileTemp) throws IOException {
checkFolder(req.getFrom());
checkFolder(req.getTo());
this.convert(req, FileHelper.FILE_TYPE_IMAGE, "图片", (item, from, toFileTemp) -> {
// 压缩视频到临时文件
MediaHelper.compressPic(from, toFileTemp, item.getQuote(), item.getSize());
}
});
}
/**
* 转换视频第一帧
*
* @param req
* @param req 请求参数
*/
@Override
public void convertVideoFirst(YzgFileConvertVideoFirstReqVo req) {
......@@ -351,13 +359,14 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
/**
* 移动文件或文件夹
*
* @param req
* @param req 转换
*/
@Override
public void convertVideo(YzgFileVideoImageReqVo req) {
this.convert(req, FileHelper.FILE_TYPE_VIDEO, "视频", new YzgConvert() {
@Override
public void run(YzgFileVideoImageItemReqVo item, String from, String toFileTemp) throws IOException {
checkFolder(req.getFrom());
checkFolder(req.getTo());
this.convert(req, FileHelper.FILE_TYPE_VIDEO, "视频", (item, from, toFileTemp) -> {
// 压缩视频的参数
MediaParameter parameter = new MediaParameter(item.getSize(), item.getQuote());
// 设置最小宽度,指的是宽度和高度中的大值,宽度>高度
......@@ -366,22 +375,23 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
parameter.setMinVideoHeight(StringHelper.getFirst(item.getHeight(), parameter.getMinVideoHeight()));
// 设置视频最小比特率
parameter.setMinVideoBitRate(StringHelper.getFirst(item.getBitrate(), parameter.getMinVideoBitRate()));
// 压缩视频到临时文件
MediaHelper.zipVideoMp4(from, toFileTemp, parameter);
}
});
}
/**
* 转换文件函数
*
* @param req
* @param type
* @param tag
* @param run
* @param req 请求参数
* @param type 类型
* @param tag 标记
* @param run 执行数据
*/
private void convert(YzgFileVideoImageReqVo req, int type, String tag, YzgConvert run) {
checkFolder(req.getFrom());
checkFolder(req.getTo());
List<YzgFileVideoImageItemReqVo> toFiles = req.getList();
if (toFiles == null || toFiles.isEmpty()) {
return;
......@@ -431,6 +441,8 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
}
private void convertBase(YzgFileVideoImageReqVo req) {
checkFolder(req.getFrom());
checkFolder(req.getTo());
// 先循环检测参数
checkFolder(req.getFrom());
for (YzgFileVideoImageItemReqVo item : req.getList()) {
......@@ -455,6 +467,5 @@ public class YzgFileServiceImpl implements YzgFileService, ApplicationContextAwa
throw YzgError.getRuntimeException("076");
}
return folder;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment