Commit e713977a authored by yanzg's avatar yanzg

表结构修改

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