From 7545fd839a3171fe2f55f13b1083caf666d3cf05 Mon Sep 17 00:00:00 2001
From: Xiajijian <1176061145@qq.com>
Date: Sat, 27 Dec 2025 15:40:46 +0800
Subject: [PATCH] 1. 判断是否循环航线业务优化。

---
 ard-route/src/main/java/com/ard/route/service/impl/ArdRouteInfoServiceImpl.java |  130 +++++++++++++++++++++++++++++++++++++------
 1 files changed, 111 insertions(+), 19 deletions(-)

diff --git a/ard-route/src/main/java/com/ard/route/service/impl/ArdRouteInfoServiceImpl.java b/ard-route/src/main/java/com/ard/route/service/impl/ArdRouteInfoServiceImpl.java
index eb3795a..f40d867 100644
--- a/ard-route/src/main/java/com/ard/route/service/impl/ArdRouteInfoServiceImpl.java
+++ b/ard-route/src/main/java/com/ard/route/service/impl/ArdRouteInfoServiceImpl.java
@@ -12,9 +12,9 @@
 import com.ard.data.noflyzone.domain.Vertex;
 import com.ard.data.noflyzone.service.IArdNoFlyZoneService;
 import com.ard.data.noflyzone.utils.NoFlyZoneUtils;
+import com.ard.framework.web.service.TokenService;
 import com.ard.oss.model.MinioUploadResult;
 import com.ard.oss.service.impl.OssServiceContext;
-import com.ard.ossdock.service.impl.OssDockServiceContext;
 import com.ard.route.domain.djuav.ActionGroupReq;
 import com.ard.route.domain.djuav.PointActionReq;
 import com.ard.route.domain.djuav.RoutePointReq;
@@ -25,16 +25,22 @@
 import com.ard.route.mapper.ArdRouteInfoMapper;
 import com.ard.route.service.IArdRouteInfoService;
 import com.ard.route.service.UavRouteService;
+import com.ard.work.domain.cache.UavTelemetryDataCache;
 import com.ard.work.domain.cache.UavWaylineCache;
 import com.ard.work.domain.dto.state.PointData;
+import com.ard.work.domain.dto.telemetry.TelemetryData;
 import com.ard.work.domain.dto.wayline.*;
 import com.ard.work.service.ITyService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 
+import static com.ard.route.enums.kml.DroneEnumValueEnums.M350_RTK;
+import static com.ard.route.util.InitializationUtils.divided_23;
 import static com.ard.route.util.ToolUtils.*;
 import static com.ard.route.util.UavRouteReqUtils.fileConversionEntity;
 
@@ -47,14 +53,14 @@
 @Service
 public class ArdRouteInfoServiceImpl implements IArdRouteInfoService {
 
+    private static final Logger log = LoggerFactory.getLogger(TokenService.class);
+
     @Autowired
     private ArdRouteInfoMapper ardRouteInfoMapper;
 
     @Autowired
     private OssServiceContext ossService;
 
-    @Autowired
-    private OssDockServiceContext ossDockService;
 
     @Autowired
     private UavRouteService routeService;
@@ -81,7 +87,29 @@
         } catch (IOException | ClassNotFoundException e) {
             throw new RuntimeException(e);
         }
+
+        // 如果参考起飞点不为空,将每个航点高度进行加工。
+        if (ardRouteInfo.getUavRouteReq().getTakeOffRefPoint() != null){
+
+            double altitudeOffset = getDoublePoint(ardRouteInfo.getUavRouteReq().getTakeOffRefPoint(), "alt");
+
+            for (RoutePointReq routePointReq : ardRouteInfo.getUavRouteReq().getRoutePointList()) {
+                // 调整每个航点高度
+                adjustRoutePointHeight(routePointReq, altitudeOffset);
+            }
+        }else {
+            // 如果没有设置参考起飞点,将第一个航点设置为参考起飞点。
+            ardRouteInfo.getUavRouteReq().setTakeOffRefPoint(
+                    ardRouteInfo.getUavRouteReq().getRoutePointList().get(0).getLatitude().toString() +"," +
+                    ardRouteInfo.getUavRouteReq().getRoutePointList().get(0).getLongitude().toString()+","+
+                    ardRouteInfo.getUavRouteReq().getRoutePointList().get(0).getHeight().toString());
+        }
+
         return ardRouteInfo;
+    }
+
+    private void adjustRoutePointHeight(RoutePointReq routePointReq, double altitudeOffset) {
+        routePointReq.setHeight(routePointReq.getHeight() + altitudeOffset);
     }
 
     /**
@@ -115,7 +143,19 @@
             ardRouteInfo.setGroupId("0");
         }
         ardRouteInfo.getUavRouteReq().setDroneType(subStringDroneType(ardRouteInfo.getAircraft()));
-        KmzResultVo kmzResult = routeService.buildKmz(ardRouteInfo.getUavRouteReq(), ardRouteInfo.getName());
+        KmzResultVo kmzResult = routeService.buildKmz(ardRouteInfo.getUavRouteReq(),ardRouteInfo.getName());
+        if (M350_RTK.getValue().equals(ardRouteInfo.getUavRouteReq().getDroneType())) {
+            // 变焦数值加工
+            for (RoutePointReq routePointReq : ardRouteInfo.getUavRouteReq().getRoutePointList()) {
+                for (ActionGroupReq actionGroupReq : routePointReq.getActionGroupList()) {
+                    for (PointActionReq action : actionGroupReq.getActions()) {
+                        if (action.getZoom() != null){
+                            action.setZoom(divided_23(action.getZoom()));
+                        }
+                    }
+                }
+            }
+        }
         ardRouteInfo.setPath(kmzResult.getPath());
         ardRouteInfo.setReadOnly("0");
         ardRouteInfoMapper.insertArdRouteInfo(dataProcessing(ardRouteInfo));
@@ -145,7 +185,6 @@
             }
             ardRouteInfo.setPath(kmzResult.getPath());
         }
-        ardRouteInfo.setReadOnly("0");
         return ardRouteInfoMapper.updateArdRouteInfo(dataProcessing(ardRouteInfo));
     }
 
@@ -196,9 +235,6 @@
         if (information.getPath() != null){
             ossService.deleteObject("kmz", subStringMinioUrlName(information.getPath()));
         }
-        if (information.getPath1() != null){
-            ossDockService.deleteObject("kmz", subStringMinioUrlName(information.getPath1()));
-        }
     }
 
     /**
@@ -209,6 +245,9 @@
      */
     @Override
     public int deleteArdRouteInfoById(String id) {
+        // 删除航线(kmz)文件
+        ArdRouteInfo information = ardRouteInfoMapper.selectArdRouteInfoById(id);
+        delOssService(information);
         return ardRouteInfoMapper.deleteArdRouteInfoById(id);
     }
 
@@ -229,18 +268,9 @@
                 ardRouteInfo.setType(templateTypeData(uavRouteReq));
                 ardRouteInfo.setAircraft(droneTypeData(uavRouteReq));
             }
-            // 判断禁飞区
-            List<RoutePointReq> routePointList = ardRouteInfo.getUavRouteReq().getRoutePointList();
-            for (RoutePointReq routePointReq : routePointList) {
-                ArdNoflyDto ardNoflyDto = new ArdNoflyDto();
-                ardNoflyDto.setCurrent(new Vertex(routePointReq.getLongitude(), routePointReq.getLatitude()));
-                verifyNoFlyZone(ardNoflyDto);
-            }
             String url = ossService.upload("kmz",file);
-            String urlDock = ossDockService.upload("kmz",file);
             ardRouteInfo.setName(file.getOriginalFilename());
             ardRouteInfo.setPath(url);
-            ardRouteInfo.setPath1(urlDock);
             ardRouteInfo.setGroupId("0");     // 默认分组
             ardRouteInfo.setReadOnly("1");   // 默认只读
             insertRouteInfomation(ardRouteInfo);
@@ -250,7 +280,35 @@
                     .originalFilename(file.getOriginalFilename())
                     .build();
         }catch (Exception e){
+            log.error("上传航线文件失败", e);
             return null;
+        }
+    }
+
+    /**
+     * 判断一组数组,是否包含禁飞区
+     */
+    private void arrayWithinNoFlyZone(List<RoutePointReq> routePointList) {
+        if (routePointList == null || routePointList.isEmpty()) {
+            return;
+        }
+        // 检查第一个航点
+        ArdNoflyDto firstDto = new ArdNoflyDto();
+        firstDto.setTarget(new Vertex(
+                routePointList.get(0).getLongitude(),
+                routePointList.get(0).getLatitude()));
+        verifyNoFlyZone(firstDto);
+
+        // 检查后续航点及与前一个航点的线段
+        for (int i = 1; i < routePointList.size(); i++) {
+            ArdNoflyDto dto = new ArdNoflyDto();
+            dto.setCurrent(new Vertex(
+                    routePointList.get(i - 1).getLongitude(),
+                    routePointList.get(i - 1).getLatitude()));
+            dto.setTarget(new Vertex(
+                    routePointList.get(i).getLongitude(),
+                    routePointList.get(i).getLatitude()));
+            verifyNoFlyZone(dto);
         }
     }
 
@@ -288,7 +346,6 @@
 
     /**
      * 上传航线到边缘服务器
-     *
      * ardNoflyDto
      * @return 结果
      */
@@ -302,6 +359,36 @@
         } catch (IOException | ClassNotFoundException e) {
             throw new RuntimeException(e);
         }
+
+        // 获取第一个点
+        double firstPointLng = route.getUavRouteReq().getRoutePointList().get(0).getLongitude();
+        double firstPointLat = route.getUavRouteReq().getRoutePointList().get(0).getLatitude();
+
+        // 获取最后一个点
+        double lastPointLng = route.getUavRouteReq().getRoutePointList().get(route.getUavRouteReq().getRoutePointList().size()-1).getLongitude();
+        double lastPointLat = route.getUavRouteReq().getRoutePointList().get(route.getUavRouteReq().getRoutePointList().size()-1).getLatitude();
+
+        // 无人机遥测数据,用于校验真实起飞点和第一个点是否在禁飞区
+        TelemetryData telemetryData = UavTelemetryDataCache.get(boxSn);
+        double telemetryDataLng = 0;
+        double telemetryDataLat = 0;
+        if (telemetryData != null){
+            telemetryDataLng = telemetryData.getLng();
+            telemetryDataLat = telemetryData.getLat();
+        }
+
+        ArdNoflyDto dto1 = new ArdNoflyDto();
+        dto1.setCurrent(new Vertex(telemetryDataLng,telemetryDataLat));
+        dto1.setTarget(new Vertex(firstPointLng,firstPointLat));
+        verifyNoFlyZone(dto1);
+
+        ArdNoflyDto dto2 = new ArdNoflyDto();
+        dto2.setCurrent(new Vertex(lastPointLng,lastPointLat));
+        dto2.setTarget(new Vertex(telemetryDataLng,telemetryDataLat));
+        verifyNoFlyZone(dto2);
+
+        // 判断禁飞区
+        arrayWithinNoFlyZone(route.getUavRouteReq().getRoutePointList());
         // 1.2通过minio获取航线信息
         // 2.将航线信息转换成对应实体类
         WayLineUploadDTO wayLineUploadDTO = buildWayLineUploadDTO(route);
@@ -323,7 +410,12 @@
      * @return 结果
      */
     @Override
-    public Boolean routeBegins(String boxSn) {
+    public Boolean routeBegins(String id,String boxSn) {
+        ArdRouteInfo route = ardRouteInfoMapper.selectArdRouteInfoById(id);
+        // 判断是否循环航线
+        if ("0".equals(route.getIsLoop())) {
+            deleteArdRouteInfoById(id);
+        }
         WayLineBeginDTO wayLineBeginDTO = new WayLineBeginDTO(boxSn);
         tyService.wayLineBegin(wayLineBeginDTO);
         return true;

--
Gitblit v1.9.3