无人机大图压缩包上传

This commit is contained in:
lcj
2025-11-25 14:05:27 +08:00
parent 209e624fc2
commit aac6efc568
2 changed files with 13 additions and 12 deletions

View File

@ -140,10 +140,9 @@ public interface IDroDroneBigPictureService extends IService<DroDroneBigPicture>
/** /**
* 解压zip文件 * 解压zip文件
* *
* @param file zip文件 * @param zipFile zip文件
* @param zipName zip文件名
* @param tempDir 临时目录 * @param tempDir 临时目录
* @return 解压后的文件的对象存储Ids * @return 解压后的文件的对象存储Ids
*/ */
CompletableFuture<List<Long>> unzipAsync(MultipartFile file, String zipName, File tempDir); CompletableFuture<List<Long>> unzipAsync(File zipFile, File tempDir);
} }

View File

@ -630,8 +630,15 @@ public class DroDroneBigPictureServiceImpl extends ServiceImpl<DroDroneBigPictur
throw new RuntimeException("创建临时目录失败"); 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 -> { .thenAccept(result -> {
String fileStr = result.stream() String fileStr = result.stream()
.map(String::valueOf) .map(String::valueOf)
@ -659,22 +666,17 @@ public class DroDroneBigPictureServiceImpl extends ServiceImpl<DroDroneBigPictur
/** /**
* 解压zip文件 * 解压zip文件
* *
* @param file zip文件 * @param zipFile zip文件
* @param zipName zip文件名
* @param tempDir 临时目录 * @param tempDir 临时目录
* @return 解压后的文件的对象存储Ids * @return 解压后的文件的对象存储Ids
*/ */
@Async("unzipExecutor") @Async("unzipExecutor")
@Override @Override
public CompletableFuture<List<Long>> unzipAsync(MultipartFile file, String zipName, File tempDir) { public CompletableFuture<List<Long>> unzipAsync(File zipFile, File tempDir) {
// 保存 ZIP
File zipFile = new File(tempDir, zipName);
File unzipDir; File unzipDir;
try { try {
file.transferTo(zipFile);
// 解压操作非常耗时
unzipDir = ZipUtil.unzip(zipFile); unzipDir = ZipUtil.unzip(zipFile);
} catch (IOException e) { } catch (Exception e) {
// 记录错误日志 // 记录错误日志
log.error("解压失败:{}", zipFile.getAbsolutePath(), e); log.error("解压失败:{}", zipFile.getAbsolutePath(), e);
// 抛出异常到上层 thenCompose便于处理 // 抛出异常到上层 thenCompose便于处理