From 75e6eea8cd3fac9cc888e2ffc9cdb126fab8429d Mon Sep 17 00:00:00 2001
From: rain <167982779@qq.com>
Date: Wed, 14 Aug 2024 15:45:55 +0800
Subject: [PATCH] 任务下发、更新、取消,优化图斑逻辑

---
 src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java |  125 ++++++++++++++++++++---------------------
 1 files changed, 60 insertions(+), 65 deletions(-)

diff --git a/src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java b/src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java
index 358e53d..c406384 100644
--- a/src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java
+++ b/src/main/java/com/dji/sample/media/service/impl/FileServiceImpl.java
@@ -117,84 +117,79 @@
     }
 
     @Override
-    public Integer saveFile(String workspaceId, FileUploadDTO file) {
+    public Integer saveFile(String workspaceId, FileUploadDTO file) throws ImageProcessingException, IOException {
         MediaFileEntity fileEntity = this.fileUploadConvertToEntity(file);
         fileEntity.setWorkspaceId(workspaceId);
+        fileEntity.setIsadd(0);
         fileEntity.setFileId(UUID.randomUUID().toString());
+        String url = pojo.getEndpoint() + "/" + pojo.getBucket() + file.getObjectKey();
+        File downloadedFile = TbFjServiceImpl.downloadFile(url);
+        Object data = ImgUtil.getInfo(downloadedFile);
+        fileEntity.setDroneData(data);
         return mapper.insert(fileEntity);
     }
     public void saveFiles(String workspaceId, FileUploadDTO file) {
         // 更新文件状态
         updateStatue(file.getName());
 
-        // 使用 CompletableFuture 异步执行
-        CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
-            try {
-                // 下载文件
-                boolean endsWithMp4 = file.getObjectKey().endsWith(".mp4");
-
-                if (endsWithMp4) {
-                    // 处理视频文件
-                    MediaFileZipEntity zipEntity = this.fileUploadConvertToZipEntity(file);
-                    zipEntity.setWorkspaceId(workspaceId);
-                    zipEntity.setFileId(UUID.randomUUID().toString());
-                    zipMapper.insert(zipEntity);
-
-                    // 处理视频文件的其他逻辑(如果有)
-                } else {
-                    // 处理图片文件
-                    String url = pojo.getEndpoint() + "/" + pojo.getBucket() + file.getObjectKey();
-                    File downloadedFile = TbFjServiceImpl.downloadFile(url);
-                    File nailFile = new File(ImgZipUtil.compressImage(downloadedFile, 50).toURI());
-                    MediaFileNailEntity nailEntity = this.fileUploadConvertToNailEntity(file);
-                    Object data = ImgUtil.getInfo(downloadedFile);
-                    nailEntity.setIsadd(0);
-                    nailEntity.setIsOriginal(false);
-                    nailEntity.setDronedata(data);
-                    nailEntity.setWorkspaceId(workspaceId);
-                    nailEntity.setFileName("nail" + file.getName());
-                    nailEntity.setObjectKey("/nail" + file.getPath() + "/" + file.getName());
-                    nailEntity.setFilePath("nail" + file.getPath());
-                    String nailName = nailEntity.getObjectKey();
-                    nailEntity.setFileId(UUID.randomUUID().toString());
-
-                    // 上传图片文件
-//                    uploadFile("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket", file.getObjectKey(), downloadedFile, "image/jpeg");
-                    uploadFile(pojo.getEndpoint(), pojo.getAccessKey(), pojo.getSecretKey(), pojo.getBucket(), nailName, nailFile, "image/jpeg");
-//                    uploadFile("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket", nailName, nailFile, "image/jpeg");
-                    nailMapper.insert(nailEntity);
-
-                    // 处理压缩后的图片文件(如果有)
-                    File zipFile = new File(ImgZipUtil.compressImageAndGetFile(downloadedFile, 0.5f).toURI());
-                    MediaFileZipEntity zipEntity = this.fileUploadConvertToZipEntity(file);
-                    zipEntity.setIsOriginal(false);
-                    zipEntity.setWorkspaceId(workspaceId);
-                    zipEntity.setFileName("zip" + file.getName());
-                    zipEntity.setObjectKey("/zip" + file.getPath() + "/" + file.getName());
-                    zipEntity.setFilePath("zip" + file.getPath());
-                    String zipName = zipEntity.getObjectKey();
-                    zipEntity.setFileId(UUID.randomUUID().toString());
-
-                    // 上传压缩文件
-                    uploadFile(pojo.getEndpoint(), pojo.getAccessKey(), pojo.getSecretKey(), pojo.getBucket(), zipName, zipFile, "image/jpeg");
-//                    uploadFile("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket", zipName, zipFile, "image/jpeg");
-                    zipMapper.insert(zipEntity);
-                }
-            } catch (IOException | ImageProcessingException e) {
-                // 处理异常
-                e.printStackTrace();
-            }
-        });
-
-        // 等待异步任务完成
         try {
-            future.get();
-        } catch (InterruptedException | ExecutionException e) {
-            Thread.currentThread().interrupt();
-            // 处理异步任务的中断和异常
+            // 下载文件
+            boolean endsWithMp4 = file.getObjectKey().endsWith(".mp4");
+
+            if (endsWithMp4) {
+                // 处理视频文件
+//            MediaFileZipEntity zipEntity = this.fileUploadConvertToZipEntity(file);
+//            zipEntity.setWorkspaceId(workspaceId);
+//            zipEntity.setFileId(UUID.randomUUID().toString());
+//            zipMapper.insert(zipEntity);
+
+                // 处理视频文件的其他逻辑(如果有)
+            } else {
+                // 处理图片文件
+                String url = pojo.getEndpoint() + "/" + pojo.getBucket() + file.getObjectKey();
+                File downloadedFile = TbFjServiceImpl.downloadFile(url);
+                File nailFile = new File(ImgZipUtil.compressImage(downloadedFile, 50).toURI());
+                MediaFileNailEntity nailEntity = this.fileUploadConvertToNailEntity(file);
+                Object data = ImgUtil.getInfo(downloadedFile);
+                nailEntity.setIsadd(0);
+                nailEntity.setIsOriginal(false);
+                nailEntity.setDronedata(data);
+                nailEntity.setWorkspaceId(workspaceId);
+                nailEntity.setFileName("nail" + file.getName());
+                nailEntity.setObjectKey("/nail" + file.getPath() + "/" + file.getName());
+                nailEntity.setFilePath("nail" + file.getPath());
+                String nailName = nailEntity.getObjectKey();
+                nailEntity.setFileId(UUID.randomUUID().toString());
+
+                // 上传图片文件
+//            uploadFile("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket", file.getObjectKey(), downloadedFile, "image/jpeg");
+                uploadFile(pojo.getEndpoint(), pojo.getAccessKey(), pojo.getSecretKey(), pojo.getBucket(), nailName, nailFile, "image/jpeg");
+//            uploadFile("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket", nailName, nailFile, "image/jpeg");
+                nailMapper.insert(nailEntity);
+
+                // 处理压缩后的图片文件(如果有)
+//            File zipFile = new File(ImgZipUtil.compressImageAndGetFile(downloadedFile, 0.5f).toURI());
+//            MediaFileZipEntity zipEntity = this.fileUploadConvertToZipEntity(file);
+//            zipEntity.setIsOriginal(false);
+//            zipEntity.setWorkspaceId(workspaceId);
+//            zipEntity.setFileName("zip" + file.getName());
+//            zipEntity.setObjectKey("/zip" + file.getPath() + "/" + file.getName());
+//            zipEntity.setFilePath("zip" + file.getPath());
+//            String zipName = zipEntity.getObjectKey();
+//            zipEntity.setFileId(UUID.randomUUID().toString());
+
+                // 上传压缩文件
+//            uploadFile(pojo.getEndpoint(), pojo.getAccessKey(), pojo.getSecretKey(), pojo.getBucket(), zipName, zipFile, "image/jpeg");
+//            uploadFile("http://139.196.74.78:9000", "sxkj", "sxkj2024", "cloud-bucket", zipName, zipFile, "image/jpeg");
+//            zipMapper.insert(zipEntity);
+            }
+        } catch (IOException | ImageProcessingException e) {
+            // 处理异常
+            e.printStackTrace();
         }
     }
 
+
     public void updateStatue(String filename) {
         if (filename.contains("~")) {
             String name = TimerUtil.getDkbh(filename);

--
Gitblit v1.9.3