无人机大图压缩包上传
This commit is contained in:
@ -140,10 +140,9 @@ public interface IDroDroneBigPictureService extends IService<DroDroneBigPicture>
|
||||
/**
|
||||
* 解压zip文件
|
||||
*
|
||||
* @param file zip文件
|
||||
* @param zipName zip文件名
|
||||
* @param zipFile zip文件
|
||||
* @param tempDir 临时目录
|
||||
* @return 解压后的文件的对象存储Ids
|
||||
*/
|
||||
CompletableFuture<List<Long>> unzipAsync(MultipartFile file, String zipName, File tempDir);
|
||||
CompletableFuture<List<Long>> unzipAsync(File zipFile, File tempDir);
|
||||
}
|
||||
|
||||
@ -630,8 +630,15 @@ public class DroDroneBigPictureServiceImpl extends ServiceImpl<DroDroneBigPictur
|
||||
throw new RuntimeException("创建临时目录失败");
|
||||
}
|
||||
}
|
||||
// 主线程保存 ZIP 文件(必须提前保存!)
|
||||
File zipFile = new File(tempDir, zipName);
|
||||
try {
|
||||
file.transferTo(zipFile);
|
||||
} catch (IOException e) {
|
||||
throw new ServiceException("ZIP 文件保存失败");
|
||||
}
|
||||
// 异步解压
|
||||
self.unzipAsync(file, zipName, tempDir)
|
||||
self.unzipAsync(zipFile, tempDir)
|
||||
.thenAccept(result -> {
|
||||
String fileStr = result.stream()
|
||||
.map(String::valueOf)
|
||||
@ -659,22 +666,17 @@ public class DroDroneBigPictureServiceImpl extends ServiceImpl<DroDroneBigPictur
|
||||
/**
|
||||
* 解压zip文件
|
||||
*
|
||||
* @param file zip文件
|
||||
* @param zipName zip文件名
|
||||
* @param zipFile zip文件
|
||||
* @param tempDir 临时目录
|
||||
* @return 解压后的文件的对象存储Ids
|
||||
*/
|
||||
@Async("unzipExecutor")
|
||||
@Override
|
||||
public CompletableFuture<List<Long>> unzipAsync(MultipartFile file, String zipName, File tempDir) {
|
||||
// 保存 ZIP
|
||||
File zipFile = new File(tempDir, zipName);
|
||||
public CompletableFuture<List<Long>> unzipAsync(File zipFile, File tempDir) {
|
||||
File unzipDir;
|
||||
try {
|
||||
file.transferTo(zipFile);
|
||||
// 解压操作非常耗时
|
||||
unzipDir = ZipUtil.unzip(zipFile);
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
// 记录错误日志
|
||||
log.error("解压失败:{}", zipFile.getAbsolutePath(), e);
|
||||
// 抛出异常到上层 thenCompose,便于处理
|
||||
|
||||
Reference in New Issue
Block a user