From 7af72fa3484e88caaf8ae94124179489af64f587 Mon Sep 17 00:00:00 2001
From: Xiajijian <1176061145@qq.com>
Date: Sat, 01 Nov 2025 17:12:43 +0800
Subject: [PATCH] 1.优化编辑kmz文件业务逻辑。 2.增加根据文件名称查询航线信息接口。

---
 ard-route/src/main/java/com/ard/route/service/impl/UavRouteServiceImpl.java |   87 +++++++++++++++++++++++++++++++++++--------
 1 files changed, 71 insertions(+), 16 deletions(-)

diff --git a/ard-route/src/main/java/com/ard/route/service/impl/UavRouteServiceImpl.java b/ard-route/src/main/java/com/ard/route/service/impl/UavRouteServiceImpl.java
index a8aeee0..678afaf 100644
--- a/ard-route/src/main/java/com/ard/route/service/impl/UavRouteServiceImpl.java
+++ b/ard-route/src/main/java/com/ard/route/service/impl/UavRouteServiceImpl.java
@@ -12,8 +12,10 @@
 import com.ard.route.domain.WaypointTurnReq;
 import com.ard.route.domain.kml.*;
 import com.ard.route.domain.route.ArdRouteInformation;
+import com.ard.route.domain.vo.KmzInfoVO;
 import com.ard.route.enums.kml.ExitOnRCLostEnums;
 import com.ard.route.service.IArdRouteInformationService;
+import com.ard.route.util.FileUtils;
 import com.ard.route.util.RouteFileUtils;
 import com.ard.route.service.UavRouteService;
 import com.thoughtworks.xstream.XStream;
@@ -29,16 +31,14 @@
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
+import java.io.*;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
 import java.util.zip.ZipOutputStream;
 
 import static com.ard.route.util.RouteFileUtils.*;
+import static com.ard.route.util.ToolUtils.extractFilePath;
 import static com.ard.route.util.ToolUtils.getFileNameWithoutExtension;
 
 /**
@@ -48,14 +48,11 @@
 @Service
 public class UavRouteServiceImpl implements UavRouteService {
 
-    @Value("${isLocal}")
-    private Boolean isLocal;
+    private Boolean isLocal = false;
 
-    @Value("${kmz.path}")
-    private String localFilePath;
+    private String localFilePath = "KmzFile/kmz/";
 
-    @Value("${MinioKmz.path}")
-    private String kmzPath;
+    private String kmzPath = "kmz";
 
     @Resource
     private OssServiceContext ossService;
@@ -68,11 +65,20 @@
      */
     private static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
 
+    /**
+     * 编辑kmz文件
+     */
     @Override
-    public String updateKmz(UavRouteReq uavRouteReq) {
-        // TODO 替换本地文件路径!!!
-        File file = FileUtil.file("/Users/songjian/Project/IdeaProjects/dj-uav/file/kmz/航线kmz文件.kmz");
-        try (ArchiveInputStream archiveInputStream = new ZipArchiveInputStream(FileUtil.getInputStream(file))) {
+    public String updateKmz(UavRouteReq uavRouteReq,String fileName){
+        // 校验修改的文件是否存在
+        ArdRouteInformation routeInformation = ardRouteInformationService.selectArdRouteInformationByName(fileName);
+        if ( routeInformation == null ){
+            return "修改航线文件失败,请检查文件是否存在";
+        }
+        // 获取文件
+        String minioUrl = routeInformation.getMinioUpPath();
+        try (InputStream inputStream = ossService.getObject(kmzPath,minioUrl);
+             ArchiveInputStream archiveInputStream = new ZipArchiveInputStream(inputStream)){
             ArchiveEntry entry;
             KmlInfo kmlInfo = new KmlInfo();
             KmlInfo wpmlInfo = new KmlInfo();
@@ -88,9 +94,12 @@
                     this.handleRouteUpdate(wpmlInfo, uavRouteReq, FileTypeConstants.WPML, kmlParams);
                 }
             }
-            return RouteFileUtils.buildKmz("更新航线kmz文件", kmlInfo, wpmlInfo, kmzPath);
+            // 删除minio的文件
+
+            // 插入修改好的minio文件
+
+            return RouteFileUtils.buildKmz("更新航线kmz文件111111", kmlInfo, wpmlInfo, kmzPath);
         } catch (Exception e) {
-            e.printStackTrace();
             return "更新航线kmz文件失败";
         }
     }
@@ -136,6 +145,9 @@
         }
     }
 
+    /**
+     * 生成kmz文件(带航点)
+     */
     @Override
     public String buildKmz(UavRouteReq uavRouteReq, String fileName) {
         KmlParams kmlParams = new KmlParams();
@@ -214,6 +226,7 @@
                 ArdRouteInformation ardRouteInformation = new ArdRouteInformation();
                 ardRouteInformation.setFileName(fileName);
                 ardRouteInformation.setFileNameNew(getFileNameWithoutExtension(kmzFilePath));
+                ardRouteInformation.setMinioUpPath(extractFilePath(kmzFilePath));
                 ardRouteInformation.setUpPath(kmzFilePath);
                 ardRouteInformation.setUpFileSize(fileSize);
                 ardRouteInformation.setCreateBy(SecurityUtils.getUsername());
@@ -224,4 +237,46 @@
             }
         }
     }
+
+    /**
+     * 解析kmz文件
+     */
+    @Override
+    public KmzInfoVO parseKmz(String fileUrl) throws IOException {
+        KmzInfoVO kmzInfoVO = new KmzInfoVO();
+        try (InputStream inputStream = ossService.getObject(kmzPath,fileUrl);
+             ArchiveInputStream archiveInputStream = new ZipArchiveInputStream(inputStream)){
+            ArchiveEntry entry;
+            while (!Objects.isNull(entry = archiveInputStream.getNextEntry())) {
+                String name = entry.getName();
+                if (name.toLowerCase().endsWith(".kml")) {
+                    kmzInfoVO.setKmlInfo(RouteFileUtils.parseKml(archiveInputStream));
+                } else if (name.toLowerCase().endsWith(".wpml")) {
+                    kmzInfoVO.setWpmlInfo(RouteFileUtils.parseKml(archiveInputStream));
+                }
+            }
+            return kmzInfoVO;
+        }catch (Exception e) {
+            e.printStackTrace();
+        }
+        return null;
+
+
+//        File file = FileUtils.downloadUrlToTempFile(fileUrl);
+//        try (ArchiveInputStream archiveInputStream = new ZipArchiveInputStream(FileUtil.getInputStream(file))) {
+//            ArchiveEntry entry;
+//            while (!Objects.isNull(entry = archiveInputStream.getNextEntry())) {
+//                String name = entry.getName();
+//                if (name.toLowerCase().endsWith(".kml")) {
+//                    kmzInfoVO.setKmlInfo(RouteFileUtils.parseKml(archiveInputStream));
+//                } else if (name.toLowerCase().endsWith(".wpml")) {
+//                    kmzInfoVO.setWpmlInfo(RouteFileUtils.parseKml(archiveInputStream));
+//                }
+//            }
+//            return kmzInfoVO;
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
+//        return null;
+    }
 }

--
Gitblit v1.9.3