From 9d81f6179a527eeef8ba9b567ed06e01b70ed062 Mon Sep 17 00:00:00 2001
From: Xiajijian <1176061145@qq.com>
Date: Thu, 27 Nov 2025 10:03:27 +0800
Subject: [PATCH] 1.哈尔滨增加,另一个Minio配置。
---
ard-route/src/main/java/com/ard/route/service/impl/UavRouteServiceImpl.java | 201 ++++++++++++++++++++++++++++---------------------
1 files changed, 114 insertions(+), 87 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 2db7981..1a8b76e 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
@@ -2,20 +2,19 @@
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
-import cn.hutool.core.io.FileUtil;
-import com.ard.common.utils.SecurityUtils;
import com.ard.oss.service.impl.OssServiceContext;
import com.ard.route.constant.FileTypeConstants;
-import com.ard.route.domain.RoutePointReq;
-import com.ard.route.domain.UavRouteReq;
-import com.ard.route.domain.WaypointHeadingReq;
-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.domain.djuav.RoutePointReq;
+import com.ard.route.domain.djuav.UavRouteReq;
+import com.ard.route.domain.djuav.WaypointHeadingReq;
+import com.ard.route.domain.djuav.WaypointTurnReq;
+import com.ard.route.domain.djuav.kml.*;
+import com.ard.route.domain.route.ArdRouteInfo;
+import com.ard.route.domain.vo.KmzInfoVo;
+import com.ard.route.domain.vo.KmzResultVo;
import com.ard.route.enums.kml.ExitOnRCLostEnums;
-import com.ard.route.service.IArdRouteInformationService;
-import com.ard.route.util.FileUtils;
+import com.ard.route.service.IArdRouteInfoService;
+import com.ard.route.util.InitializationUtils;
import com.ard.route.util.RouteFileUtils;
import com.ard.route.service.UavRouteService;
import com.thoughtworks.xstream.XStream;
@@ -25,7 +24,6 @@
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
@@ -38,37 +36,40 @@
import java.util.zip.ZipOutputStream;
import static com.ard.route.util.RouteFileUtils.*;
-import static com.ard.route.util.ToolUtils.getFileNameWithoutExtension;
+import static com.ard.route.util.ToolUtils.*;
/**
- * Author:songjian
+ * Author:xia
* Date: 2024/12/22 10:36
**/
@Service
public class UavRouteServiceImpl implements UavRouteService {
- private Boolean isLocal = false;
-
- private String localFilePath = "KmzFile/kmz/";
-
- private String kmzPath = "kmz";
-
@Resource
private OssServiceContext ossService;
@Resource
- private IArdRouteInformationService ardRouteInformationService;
+ private IArdRouteInfoService ardRouteInformationService;
+
+ InitializationUtils init = new InitializationUtils();
/**
- * XML 头部
+ * 编辑kmz文件
*/
- private static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
-
@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 KmzResultVo updateKmz(UavRouteReq uavRouteReq,String fileName){
+ KmzResultVo result = new KmzResultVo();
+ // 校验修改的文件是否存在
+ ArdRouteInfo routeInformation = ardRouteInformationService.selectArdRouteInfoByName(fileName);
+ if ( routeInformation == null ){
+ result.setData("修改航线文件失败,请检查文件是否存在");
+ return result;
+ }
+
+ // 获取文件
+ String minioUrlName = subStringMinioUrlName(routeInformation.getPath());
+ try (InputStream inputStream = ossService.getObject(kmzPath,minioUrlName);
+ ArchiveInputStream archiveInputStream = new ZipArchiveInputStream(inputStream)){
ArchiveEntry entry;
KmlInfo kmlInfo = new KmlInfo();
KmlInfo wpmlInfo = new KmlInfo();
@@ -84,10 +85,13 @@
this.handleRouteUpdate(wpmlInfo, uavRouteReq, FileTypeConstants.WPML, kmlParams);
}
}
- return RouteFileUtils.buildKmz("更新航线kmz文件", kmlInfo, wpmlInfo, kmzPath);
+ // 删除文件
+ ossService.deleteObject(kmzPath, minioUrlName);
+ return buildKmzMethod(routeInformation.getName(), kmlInfo, wpmlInfo);
} catch (Exception e) {
e.printStackTrace();
- return "更新航线kmz文件失败";
+ result.setData("更新航线kmz文件失败");
+ return result;
}
}
@@ -132,12 +136,17 @@
}
}
+ /**
+ * 生成kmz文件(带航点)
+ */
@Override
- public String buildKmz(UavRouteReq uavRouteReq, String fileName) {
+ public KmzResultVo buildKmz(UavRouteReq uavRouteReq, String kmzName) {
+ // 赋值默认参数
+ init.initialization(uavRouteReq);
KmlParams kmlParams = new KmlParams();
BeanUtils.copyProperties(uavRouteReq, kmlParams);
kmlParams.setRoutePointList(BeanUtil.copyToList(uavRouteReq.getRoutePointList(), RoutePointInfo.class));
- return buildKmz(fileName, kmlParams);
+ return buildKmz(kmzName, kmlParams);
}
/**
@@ -147,10 +156,10 @@
* @param kmlParams 参数对象
* @return 本地文件路径
*/
- public String buildKmz(String fileName, KmlParams kmlParams) {
+ public KmzResultVo buildKmz(String fileName, KmlParams kmlParams) {
KmlInfo kmlInfo = buildKml(kmlParams);
KmlInfo wpmlInfo = buildWpml(kmlParams);
- return buildKmz(fileName, kmlInfo, wpmlInfo);
+ return buildKmzMethod(fileName, kmlInfo, wpmlInfo);
}
/**
@@ -161,71 +170,50 @@
* @param wpmlInfo wpml 文件信息
* @return 本地文件路径
*/
- public String buildKmz(String fileName, KmlInfo kmlInfo, KmlInfo wpmlInfo) {
+ public KmzResultVo buildKmzMethod(String fileName, KmlInfo kmlInfo, KmlInfo wpmlInfo) {
XStream xStream = new XStream(new DomDriver());
xStream.processAnnotations(KmlInfo.class);
xStream.addImplicitCollection(KmlActionGroup.class, "action");
+ xStream.addImplicitCollection(KmlPlacemark.class, "actionGroup");
String kml = XML_HEADER + xStream.toXML(kmlInfo);
String wpml = XML_HEADER + xStream.toXML(wpmlInfo);
+ KmzResultVo result = new KmzResultVo();
+ try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ZipOutputStream zipOutputStream = new ZipOutputStream(baos)) {
+ zipOutputStream.setLevel(0);
- // 判断本地生成kmz文件
- if (isLocal) {
- try (FileOutputStream fileOutputStream = new FileOutputStream(localFilePath + fileName + ".kmz");
- ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream)) {
- zipOutputStream.setLevel(0); // 0 表示不压缩,存储方式
+ // 创建 wpmz 目录中的 template.kml 文件条目
+ buildZipFile("wpmz/template.kml", zipOutputStream, kml);
+ // 创建 wpmz 目录中的 waylines.wpml 文件条目
+ buildZipFile("wpmz/waylines.wpml", zipOutputStream, wpml);
- // 创建KMZ文件内容
- buildZipFile("wpmz/template.kml", zipOutputStream, kml);
- buildZipFile("wpmz/waylines.wpml", zipOutputStream, wpml);
+ zipOutputStream.finish();
+ zipOutputStream.flush();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- return localFilePath + fileName + ".kmz";
- }else {
- try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ZipOutputStream zipOutputStream = new ZipOutputStream(baos)) {
- zipOutputStream.setLevel(0);
-
- // 创建KMZ文件内容
- buildZipFile("wpmz/template.kml", zipOutputStream, kml);
- buildZipFile("wpmz/waylines.wpml", zipOutputStream, wpml);
-
- zipOutputStream.finish();
- zipOutputStream.flush();
-
- // 获取文件大小
- Double fileSize = (double) baos.size(); // 字节数
-
- // 创建MultipartFile对象
- MultipartFile multipartFile = new MockMultipartFile(
- fileName + ".kmz",
- fileName + ".kmz",
- "application/vnd.google-earth.kmz",
- new ByteArrayInputStream(baos.toByteArray())
- );
- String kmzFilePath = ossService.upload(kmzPath,multipartFile);
- // KMZ信息管理
- ArdRouteInformation ardRouteInformation = new ArdRouteInformation();
- ardRouteInformation.setFileName(fileName);
- ardRouteInformation.setFileNameNew(getFileNameWithoutExtension(kmzFilePath));
- ardRouteInformation.setUpPath(kmzFilePath);
- ardRouteInformation.setUpFileSize(fileSize);
- ardRouteInformation.setCreateBy(SecurityUtils.getUsername());
- ardRouteInformationService.insertArdRouteInformation(ardRouteInformation);
- return kmzFilePath;
- } catch (Exception e) {
- throw new RuntimeException("KMZ文件生成或上传失败", e);
- }
+ // 创建MultipartFile对象
+ MultipartFile multipartFile = new MockMultipartFile(
+ fileName + ".kmz",
+ fileName + ".kmz",
+ "application/vnd.google-earth.kmz",
+ new ByteArrayInputStream(baos.toByteArray())
+ );
+ String kmzFilePath = ossService.upload(kmzPath,multipartFile);
+ result.setPath(kmzFilePath);
+ return result;
+ } catch (Exception e) {
+ throw new RuntimeException("KMZ文件生成或上传失败", e);
}
}
+ /**
+ * 解析kmz文件
+ */
@Override
- public KmzInfoVO parseKmz(String fileUrl) throws IOException {
- KmzInfoVO kmzInfoVO = new KmzInfoVO();
- File file = FileUtils.downloadUrlToTempFile(fileUrl);
- try (ArchiveInputStream archiveInputStream = new ZipArchiveInputStream(FileUtil.getInputStream(file))) {
+ public KmzInfoVo parseKmz(String fileUrl){
+ 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();
@@ -236,9 +224,48 @@
}
}
return kmzInfoVO;
- } catch (Exception e) {
+ }catch (Exception e) {
e.printStackTrace();
}
return null;
}
+
+ @Override
+ public KmzResultVo updateKmzNew(UavRouteReq uavRouteReq, String oldFile, String newFile) {
+ KmzResultVo result = new KmzResultVo();
+ // 校验修改的文件是否存在
+ ArdRouteInfo routeInformation = ardRouteInformationService.selectArdRouteInfoByName(oldFile);
+ if ( routeInformation == null ){
+ result.setData("修改航线文件失败,请检查文件是否存在");
+ return result;
+ }
+
+ // 获取文件
+ String minioUrl = subStringMinioUrlName(routeInformation.getPath());
+ try (InputStream inputStream = ossService.getObject(kmzPath,minioUrl);
+ ArchiveInputStream archiveInputStream = new ZipArchiveInputStream(inputStream)){
+ ArchiveEntry entry;
+ KmlInfo kmlInfo = new KmlInfo();
+ KmlInfo wpmlInfo = new KmlInfo();
+ KmlParams kmlParams = new KmlParams();
+ while (!Objects.isNull(entry = archiveInputStream.getNextEntry())) {
+ String name = entry.getName();
+ if (name.toLowerCase().endsWith(".kml")) {
+ kmlInfo = RouteFileUtils.parseKml(archiveInputStream);
+ buildKmlParams(kmlParams, kmlInfo);
+ this.handleRouteUpdate(kmlInfo, uavRouteReq, FileTypeConstants.KML, kmlParams);
+ } else if (name.toLowerCase().endsWith(".wpml")) {
+ wpmlInfo = RouteFileUtils.parseKml(archiveInputStream);
+ this.handleRouteUpdate(wpmlInfo, uavRouteReq, FileTypeConstants.WPML, kmlParams);
+ }
+ }
+ // 删除文件
+ ossService.deleteObject(kmzPath, minioUrl);
+ return buildKmzMethod(newFile, kmlInfo, wpmlInfo);
+ } catch (Exception e) {
+ result.setData("更新航线kmz文件失败");
+ return result;
+ }
+ }
+
}
--
Gitblit v1.9.3