From 9001e055d272ad7e0a3b60e2891939aeb29dc1ad Mon Sep 17 00:00:00 2001
From: Xiajijian <1176061145@qq.com>
Date: Fri, 12 Dec 2025 15:23:07 +0800
Subject: [PATCH] 1. 禁飞区修改。

---
 ard-route/src/main/java/com/ard/route/util/RouteFileUtils.java |  179 ++++++++++++++++++++++++++++++++---------------------------
 1 files changed, 97 insertions(+), 82 deletions(-)

diff --git a/ard-route/src/main/java/com/ard/route/util/RouteFileUtils.java b/ard-route/src/main/java/com/ard/route/util/RouteFileUtils.java
index b888454..da95d7b 100644
--- a/ard-route/src/main/java/com/ard/route/util/RouteFileUtils.java
+++ b/ard-route/src/main/java/com/ard/route/util/RouteFileUtils.java
@@ -3,8 +3,8 @@
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.ObjectUtil;
-import com.ard.route.domain.*;
-import com.ard.route.domain.kml.*;
+import com.ard.route.domain.djuav.*;
+import com.ard.route.domain.djuav.kml.*;
 import com.ard.route.enums.kml.*;
 import com.ard.route.constant.FileTypeConstants;
 import com.thoughtworks.xstream.XStream;
@@ -21,21 +21,12 @@
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
 
+import static com.ard.route.util.ToolUtils.XML_HEADER;
+
 /**
  * 航线文件操作工具类
  */
 public class RouteFileUtils {
-
-    /**
-     * XML 头部
-     */
-    private static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
-
-    /**
-     * 生成的本地 kmz 文件存储路径
-     */
-    private static final String LOCAL_KMZ_FILE_PATH = "file" + File.separator + "kmz" + File.separator;
-
 
     /**
      * kml文件解析
@@ -45,12 +36,19 @@
      */
     public static KmlInfo parseKml(InputStream inputStream) {
         XStream xStream = new XStream();
-        xStream.allowTypes(new Class[]{KmlInfo.class, KmlAction.class, KmlWayLineCoordinateSysParam.class, KmlPoint.class});
+        xStream.allowTypes(new Class[]{
+                KmlInfo.class,
+                KmlAction.class,
+                KmlWayLineCoordinateSysParam.class,
+                KmlPoint.class,
+                KmlActionGroup.class
+        });
         xStream.alias("kml", KmlInfo.class);
         xStream.processAnnotations(KmlInfo.class);
         xStream.autodetectAnnotations(true);
         xStream.ignoreUnknownElements();
         xStream.addImplicitCollection(KmlActionGroup.class, "action");
+        xStream.addImplicitCollection(KmlPlacemark.class, "actionGroup");
         return (KmlInfo) xStream.fromXML(inputStream);
     }
 
@@ -62,10 +60,11 @@
      * @param wpmlInfo wpml 文件信息
      * @return 本地文件路径
      */
-    public static String buildKmz(String fileName, KmlInfo kmlInfo, KmlInfo wpmlInfo, String kmzFilePath) {
+    public static String buildKmzA(String fileName, KmlInfo kmlInfo, KmlInfo wpmlInfo, String kmzFilePath) {
         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);
@@ -175,13 +174,18 @@
         kmlFolder.setAutoFlightSpeed(String.valueOf(kmlParams.getAutoFlightSpeed()));
         if (StringUtils.equals(fileType, FileTypeConstants.KML)) {
             kmlFolder.setTemplateType(kmlParams.getTemplateType());
-            kmlFolder.setWaylineCoordinateSysParam(buildKmlWayLineCoordinateSysParam(TemplateTypeEnums.WAYPOINT.getValue()));
+            kmlFolder.setWaylineCoordinateSysParam(buildKmlWayLineCoordinateSysParam(kmlParams.getTemplateType(), HeightModeEnums.RELATIVE_TO_START_POINT.getValue(),
+                    String.valueOf(kmlParams.getGlobalHeight())));
             kmlFolder.setPayloadParam(buildKmlPayloadParam(kmlParams));
         }
         if (StringUtils.equals(fileType, FileTypeConstants.WPML)) {
             kmlFolder.setWaylineId("0");
             kmlFolder.setExecuteHeightMode(ExecuteHeightModeEnums.RELATIVE_TO_START_POINT.getValue());
-            // TODO 航线初始动作
+            if (CollectionUtil.isNotEmpty(kmlParams.getStartActionList())) {
+                KmlActionGroup kmlActionGroup = new KmlActionGroup();
+                kmlActionGroup.setAction(getKmlActionList(kmlParams.getStartActionList(), kmlParams));
+                kmlFolder.setStartActionGroup(kmlActionGroup);
+            }
         }
         // 航点类型模板航线配置
         if (StringUtils.equals(kmlFolder.getTemplateType(), TemplateTypeEnums.WAYPOINT.getValue())) {
@@ -222,12 +226,6 @@
                 if (CollectionUtil.isNotEmpty(routePointList)) {
                     List<KmlPlacemark> kmlPlacemarkList = new ArrayList<>();
                     for (RoutePointInfo routePointInfo : routePointList) {
-//                        ActionTriggerReq actionTriggerReq = new ActionTriggerReq();
-//                        actionTriggerReq.setActionTriggerType(StringUtils.equals(kmlParams.getMappingTypeReq().getShootType(), ShootTypeEnums.TIME.getValue()) ?
-//                                ActionTriggerTypeEnums.MULTIPLE_TIMING.getValue() :
-//                                ActionTriggerTypeEnums.MULTIPLE_DISTANCE.getValue());
-//                        actionTriggerReq.setActionTriggerParam(2.0);
-//                        RoutePointInfo.setActionTriggerReq(actionTriggerReq);
                         kmlPlacemarkList.add(buildKmlPlacemark(routePointInfo, kmlParams, fileType));
                     }
                     kmlFolder.setPlacemarkList(kmlPlacemarkList);
@@ -237,17 +235,56 @@
         return kmlFolder;
     }
 
-    public static KmlWayLineCoordinateSysParam buildKmlWayLineCoordinateSysParam(String templateType) {
+    /**
+     * 构建航点动作
+     *
+     * @param actionList 航点动作列表
+     * @param kmlParams
+     * @return
+     */
+    private static List<KmlAction> getKmlActionList(List<PointActionReq> actionList, KmlParams kmlParams) {
+        List<KmlAction> kmlActionList = new ArrayList<>();
+        for (PointActionReq pointActionReq : actionList) {
+            if (ObjectUtil.isNotNull(pointActionReq.getHoverTime())) {
+                kmlActionList.add(buildKmlAction(String.valueOf(pointActionReq.getActionIndex()), ActionActuatorFuncEnums.HOVER.getValue(), pointActionReq, kmlParams));
+            } else if (ObjectUtil.isNotNull(pointActionReq.getAircraftHeading())) {
+                kmlActionList.add(buildKmlAction(String.valueOf(pointActionReq.getActionIndex()), ActionActuatorFuncEnums.ROTATE_YAW.getValue(), pointActionReq, kmlParams));
+            } else if (ObjectUtil.isNotNull(pointActionReq.getTakePhotoType()) && ObjectUtil.equals(pointActionReq.getTakePhotoType(), 0)) {
+                kmlActionList.add(buildKmlAction(String.valueOf(pointActionReq.getActionIndex()), ActionActuatorFuncEnums.TAKE_PHOTO.getValue(), pointActionReq, kmlParams));
+            } else if ((ObjectUtil.isNotNull(pointActionReq.getGimbalYawRotateAngle())) || (ObjectUtil.isNotNull(pointActionReq.getGimbalPitchRotateAngle()))) {
+                kmlActionList.add(buildKmlAction(String.valueOf(pointActionReq.getActionIndex()), ActionActuatorFuncEnums.GIMBAL_ROTATE.getValue(), pointActionReq, kmlParams));
+            } else if (ObjectUtil.isNotNull(pointActionReq.getZoom())) {
+                kmlActionList.add(buildKmlAction(String.valueOf(pointActionReq.getActionIndex()), ActionActuatorFuncEnums.ZOOM.getValue(), pointActionReq, kmlParams));
+            } else if (ObjectUtil.isNotNull(pointActionReq.getTakePhotoType()) && ObjectUtil.equals(pointActionReq.getTakePhotoType(), 1)) {
+                kmlActionList.add(buildKmlAction(String.valueOf(pointActionReq.getActionIndex()), ActionActuatorFuncEnums.PANO_SHOT.getValue(), pointActionReq, kmlParams));
+            } else if (ObjectUtil.isNotNull(pointActionReq.getStartRecord()) && pointActionReq.getStartRecord()) {
+                kmlActionList.add(buildKmlAction(String.valueOf(pointActionReq.getActionIndex()), ActionActuatorFuncEnums.START_RECORD.getValue(), pointActionReq, kmlParams));
+            } else if (ObjectUtil.isNotNull(pointActionReq.getStopRecord()) && pointActionReq.getStopRecord()) {
+                kmlActionList.add(buildKmlAction(String.valueOf(pointActionReq.getActionIndex()), ActionActuatorFuncEnums.STOP_RECORD.getValue(), pointActionReq, kmlParams));
+            }
+        }
+        return kmlActionList;
+    }
+
+    /**
+     * 构造坐标系参数信息
+     *
+     * @param templateType 航线模板类型
+     * @param heightMode   高度模式
+     * @param height       高度
+     * @return 坐标系参数信息
+     */
+    public static KmlWayLineCoordinateSysParam buildKmlWayLineCoordinateSysParam(String templateType, String heightMode, String height) {
         KmlWayLineCoordinateSysParam kmlWayLineCoordinateSysParam = new KmlWayLineCoordinateSysParam();
         kmlWayLineCoordinateSysParam.setCoordinateMode("WGS84");
-        kmlWayLineCoordinateSysParam.setHeightMode(HeightModeEnums.RELATIVE_TO_START_POINT.getValue());
+        kmlWayLineCoordinateSysParam.setHeightMode(heightMode);
         kmlWayLineCoordinateSysParam.setPositioningType(PositioningTypeEnums.GPS.getValue());
         if (StringUtils.equals(templateType, TemplateTypeEnums.MAPPING2D.getValue()) ||
                 StringUtils.equals(templateType, TemplateTypeEnums.MAPPING3D.getValue()) ||
                 StringUtils.equals(templateType, TemplateTypeEnums.MAPPING_STRIP.getValue())) {
-            kmlWayLineCoordinateSysParam.setGlobalShootHeight("50");
+            kmlWayLineCoordinateSysParam.setGlobalShootHeight(height);
             kmlWayLineCoordinateSysParam.setSurfaceFollowModeEnable("1");
-            kmlWayLineCoordinateSysParam.setSurfaceRelativeHeight("100");
+            kmlWayLineCoordinateSysParam.setSurfaceRelativeHeight(height);
         }
         return kmlWayLineCoordinateSysParam;
     }
@@ -287,6 +324,7 @@
         kmlPlacemark.setIsRisky("0");
         kmlPlacemark.setKmlPoint(buildKmlPoint(String.valueOf(routePointInfo.getLongitude()), String.valueOf(routePointInfo.getLatitude())));
         kmlPlacemark.setIndex(String.valueOf(routePointInfo.getRoutePointIndex()));
+
         handleHeight(routePointInfo, kmlParams, fileType, kmlPlacemark);
         handleSpeed(routePointInfo, kmlParams, fileType, kmlPlacemark);
         handleWaypointHeadingParam(routePointInfo, kmlParams, fileType, kmlPlacemark);
@@ -296,8 +334,12 @@
                 kmlPlacemark.setGimbalPitchAngle(String.valueOf(routePointInfo.getGimbalPitchAngle()));
             }
         }
-        if (CollectionUtil.isNotEmpty(routePointInfo.getActions())) {
-            kmlPlacemark.setActionGroup(buildKmlActionGroup(routePointInfo, kmlParams));
+        if (CollectionUtil.isNotEmpty(routePointInfo.getActionGroupList())) {
+            List<KmlActionGroup> kmlActionGroupList = new ArrayList<>();
+            for (ActionGroupReq actionGroupReq : routePointInfo.getActionGroupList()) {
+                kmlActionGroupList.add(buildKmlActionGroup(actionGroupReq, kmlParams));
+            }
+            kmlPlacemark.setActionGroup(kmlActionGroupList);
         }
         return kmlPlacemark;
     }
@@ -321,22 +363,16 @@
 
     private static KmlOverlap buildKmlOverlap(String collectionMethod, String lensType, Integer overlapH, Integer overlapW) {
         KmlOverlap overlap = new KmlOverlap();
-        if (StringUtils.equals(collectionMethod, CollectionMethodEnums.ORTHO.getValue())) {
-            if (StringUtils.equals(lensType, LensTypeEnums.LIDAR.getValue())) {
-                overlap.setOrthoLidarOverlapH(String.valueOf(overlapH));
-                overlap.setOrthoLidarOverlapW(String.valueOf(overlapW));
-            } else {
-                overlap.setOrthoCameraOverlapH(String.valueOf(overlapH));
-                overlap.setOrthoCameraOverlapW(String.valueOf(overlapW));
-            }
+        if (StringUtils.equals(collectionMethod, LensTypeEnums.CAMERA.getValue())) {
+            overlap.setOrthoCameraOverlapH(String.valueOf(overlapH));
+            overlap.setOrthoCameraOverlapW(String.valueOf(overlapW));
+            overlap.setInclinedCameraOverlapW(String.valueOf(overlapW));
+            overlap.setInclinedCameraOverlapH(String.valueOf(overlapH));
         } else {
-            if (StringUtils.equals(lensType, LensTypeEnums.LIDAR.getValue())) {
-                overlap.setInclinedLidarOverlapH(String.valueOf(overlapH));
-                overlap.setInclinedCameraOverlapW(String.valueOf(overlapW));
-            } else {
-                overlap.setInclinedCameraOverlapH(String.valueOf(overlapH));
-                overlap.setInclinedCameraOverlapW(String.valueOf(overlapW));
-            }
+            overlap.setOrthoLidarOverlapH(String.valueOf(overlapH));
+            overlap.setOrthoLidarOverlapW(String.valueOf(overlapW));
+            overlap.setInclinedLidarOverlapH(String.valueOf(overlapH));
+            overlap.setInclinedLidarOverlapW(String.valueOf(overlapW));
         }
         return overlap;
     }
@@ -462,44 +498,15 @@
         return kmlWaypointTurnParam;
     }
 
-    public static KmlActionGroup buildKmlActionGroup(RoutePointInfo routePointInfo, KmlParams kmlParams) {
+    public static KmlActionGroup buildKmlActionGroup(ActionGroupReq actionGroupReq, KmlParams kmlParams) {
         KmlActionGroup kmlActionGroup = new KmlActionGroup();
-        kmlActionGroup.setActionGroupId(String.valueOf(routePointInfo.getRoutePointIndex()));
-        kmlActionGroup.setActionGroupStartIndex(String.valueOf(routePointInfo.getRoutePointIndex()));
-        kmlActionGroup.setActionGroupEndIndex(String.valueOf(ObjectUtil.isNotNull(routePointInfo.getEndIntervalRouteIndex()) ?
-                routePointInfo.getEndIntervalRouteIndex() : routePointInfo.getRoutePointIndex()));
+        kmlActionGroup.setActionGroupId(String.valueOf(actionGroupReq.getActionGroupId()));
+        kmlActionGroup.setActionGroupStartIndex(String.valueOf(actionGroupReq.getActionGroupStartIndex()));
+        kmlActionGroup.setActionGroupEndIndex(String.valueOf(actionGroupReq.getActionGroupEndIndex()));
         kmlActionGroup.setActionGroupMode(ActionGroupModeEnums.SEQUENCE.getValue());
-        String actionTriggerType = ActionTriggerTypeEnums.REACH_POINT.getValue();
-        Double actionTriggerParam = 0.0;
-        if (ObjectUtil.isNotNull(routePointInfo.getTimeInterval())) {
-            actionTriggerType = ActionTriggerTypeEnums.MULTIPLE_TIMING.getValue();
-            actionTriggerParam = routePointInfo.getTimeInterval();
-        } else if (ObjectUtil.isNotNull(routePointInfo.getDistanceInterval())) {
-            actionTriggerType = ActionTriggerTypeEnums.MULTIPLE_DISTANCE.getValue();
-            actionTriggerParam = routePointInfo.getDistanceInterval();
-        }
-        kmlActionGroup.setActionTrigger(buildKmlActionTrigger(actionTriggerType, actionTriggerParam));
-        List<KmlAction> kmlActionList = new ArrayList<>();
-        for (PointActionReq pointActionReq : routePointInfo.getActions()) {
-            if (ObjectUtil.isNotNull(pointActionReq.getHoverTime())) {
-                kmlActionList.add(buildKmlAction(String.valueOf(pointActionReq.getActionIndex()), ActionActuatorFuncEnums.HOVER.getValue(), pointActionReq, kmlParams));
-            } else if (ObjectUtil.isNotNull(pointActionReq.getAircraftHeading())) {
-                kmlActionList.add(buildKmlAction(String.valueOf(pointActionReq.getActionIndex()), ActionActuatorFuncEnums.ROTATE_YAW.getValue(), pointActionReq, kmlParams));
-            } else if (ObjectUtil.isNotNull(pointActionReq.getTakePhotoType()) && ObjectUtil.equals(pointActionReq.getTakePhotoType(), 0)) {
-                kmlActionList.add(buildKmlAction(String.valueOf(pointActionReq.getActionIndex()), ActionActuatorFuncEnums.TAKE_PHOTO.getValue(), pointActionReq, kmlParams));
-            } else if ((ObjectUtil.isNotNull(pointActionReq.getGimbalYawRotateAngle())) || (ObjectUtil.isNotNull(pointActionReq.getGimbalPitchRotateAngle()))) {
-                kmlActionList.add(buildKmlAction(String.valueOf(pointActionReq.getActionIndex()), ActionActuatorFuncEnums.GIMBAL_ROTATE.getValue(), pointActionReq, kmlParams));
-            } else if (ObjectUtil.isNotNull(pointActionReq.getZoom())) {
-                kmlActionList.add(buildKmlAction(String.valueOf(pointActionReq.getActionIndex()), ActionActuatorFuncEnums.ZOOM.getValue(), pointActionReq, kmlParams));
-            } else if (ObjectUtil.isNotNull(pointActionReq.getTakePhotoType()) && ObjectUtil.equals(pointActionReq.getTakePhotoType(), 1)) {
-                kmlActionList.add(buildKmlAction(String.valueOf(pointActionReq.getActionIndex()), ActionActuatorFuncEnums.PANO_SHOT.getValue(), pointActionReq, kmlParams));
-            } else if (ObjectUtil.isNotNull(pointActionReq.getStartRecord()) && pointActionReq.getStartRecord()) {
-                kmlActionList.add(buildKmlAction(String.valueOf(pointActionReq.getActionIndex()), ActionActuatorFuncEnums.START_RECORD.getValue(), pointActionReq, kmlParams));
-            } else if (ObjectUtil.isNotNull(pointActionReq.getStopRecord()) && pointActionReq.getStopRecord()) {
-                kmlActionList.add(buildKmlAction(String.valueOf(pointActionReq.getActionIndex()), ActionActuatorFuncEnums.STOP_RECORD.getValue(), pointActionReq, kmlParams));
-            }
-        }
-        kmlActionGroup.setAction(kmlActionList);
+
+        kmlActionGroup.setActionTrigger(buildKmlActionTrigger(actionGroupReq.getActionTriggerType(), actionGroupReq.getActionTriggerParam()));
+        kmlActionGroup.setAction(getKmlActionList(actionGroupReq.getActions(), kmlParams));
         return kmlActionGroup;
     }
 
@@ -526,7 +533,11 @@
         if (StringUtils.equals(actionActuatorFunc, ActionActuatorFuncEnums.TAKE_PHOTO.getValue()) ||
                 StringUtils.equals(actionActuatorFunc, ActionActuatorFuncEnums.START_RECORD.getValue())) {
             kmlActionActuatorFuncParam.setPayloadPositionIndex(String.valueOf(kmlParams.getPayloadPosition()));
-            kmlActionActuatorFuncParam.setFileSuffix("");
+            if (pointActionReq.getFileSuffix() != null){
+                kmlActionActuatorFuncParam.setFileSuffix(pointActionReq.getFileSuffix());
+            }else {
+                kmlActionActuatorFuncParam.setFileSuffix("panoramicPhoto_360");
+            }
             kmlActionActuatorFuncParam.setUseGlobalPayloadLensIndex(String.valueOf(pointActionReq.getUseGlobalImageFormat()));
             if (ObjectUtil.equals(pointActionReq.getUseGlobalImageFormat(), 0)) {
                 kmlActionActuatorFuncParam.setPayloadLensIndex(pointActionReq.getImageFormat());
@@ -568,7 +579,11 @@
         } else if (StringUtils.equals(actionActuatorFunc, ActionActuatorFuncEnums.PANO_SHOT.getValue())) {
             kmlActionActuatorFuncParam.setPayloadPositionIndex(String.valueOf(kmlParams.getPayloadPosition()));
             kmlActionActuatorFuncParam.setUseGlobalPayloadLensIndex(String.valueOf(pointActionReq.getUseGlobalImageFormat()));
-            kmlActionActuatorFuncParam.setPanoShotSubMode("panoShot_360");
+            if (pointActionReq.getFileSuffix()!=null){
+                kmlActionActuatorFuncParam.setPanoShotSubMode(pointActionReq.getPanoShotSubMode());
+            }else {
+                kmlActionActuatorFuncParam.setPanoShotSubMode("panoShot_360");
+            }
             if (ObjectUtil.equals(pointActionReq.getUseGlobalImageFormat(), 0)) {
                 kmlActionActuatorFuncParam.setPayloadLensIndex(pointActionReq.getImageFormat());
             } else {

--
Gitblit v1.9.3