From ffc176faeea3b9bd1a7cd69d020a0730b1a58356 Mon Sep 17 00:00:00 2001
From: zhaowenyu <35589726@qq.com>
Date: Wed, 26 Nov 2025 14:02:25 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev

---
 ard-work/src/main/java/com/ard/work/aspect/UavControlAspect.java |   84 +++++++++++++++++++++++++++--------------
 1 files changed, 55 insertions(+), 29 deletions(-)

diff --git a/ard-work/src/main/java/com/ard/work/aspect/UavControlAspect.java b/ard-work/src/main/java/com/ard/work/aspect/UavControlAspect.java
index 06ee04a..f03b555 100644
--- a/ard-work/src/main/java/com/ard/work/aspect/UavControlAspect.java
+++ b/ard-work/src/main/java/com/ard/work/aspect/UavControlAspect.java
@@ -10,21 +10,19 @@
 import com.ard.data.noflyzone.domain.Vertex;
 import com.ard.data.noflyzone.service.IArdNoFlyZoneService;
 import com.ard.data.noflyzone.utils.NoFlyZoneUtils;
+import com.ard.work.aspect.annotation.CheckControlRight;
 import com.ard.work.aspect.annotation.CheckDroneStatus;
 import com.ard.work.aspect.annotation.CheckNoFlyZone;
 import com.ard.work.aspect.annotation.CheckTakeoffAltitude;
-import com.ard.work.aspect.annotation.CheckControlRight;
 import com.ard.work.domain.cache.UavTelemetryDataCache;
 import com.ard.work.domain.dto.telemetry.TelemetryData;
-import com.ard.work.domain.entity.ArdDroneInfo;
-import com.ard.work.service.IArdDroneInfoService;
-import com.ard.work.service.control.UavControlService;
 import com.ard.work.domain.message.UavControlType;
+import com.ard.work.domain.receiver.BoxInfoReceiver;
+import com.ard.work.service.control.UavControlService;
 import org.aspectj.lang.JoinPoint;
 import org.aspectj.lang.annotation.Aspect;
 import org.aspectj.lang.annotation.Before;
 import org.springframework.stereotype.Component;
-
 import javax.annotation.Resource;
 import java.util.List;
 
@@ -77,8 +75,8 @@
             }
 
             // 3️⃣ 检查在线状态
-            Boolean online = redisCache.getCacheObject(CacheConstants.UAV_ONLINE_KEY + boxSn);
-            if (online == null || !online) {
+            BoxInfoReceiver obj = redisCache.getCacheObject(CacheConstants.UAV_ONLINE_KEY + boxSn);
+            if (obj == null || !obj.getOnLine().equals(1)) {
                 throw new ControlException("无人机离线,无法执行操作!boxSn: " + boxSn);
             }
 
@@ -89,7 +87,7 @@
      * 高度检查
      */
     @Before("@annotation(checkTakeoffAltitude)")
-    public void takeoffAltitudeCheck(JoinPoint joinPoint, CheckTakeoffAltitude checkTakeoffAltitude) {
+    public void takeoffAltitudeCheck(JoinPoint joinPoint, CheckTakeoffAltitude checkTakeoffAltitude){
         // 获取最小高度
         double minAltitude = checkTakeoffAltitude.minAltitude();
         // 获取方法参数
@@ -127,8 +125,9 @@
             }
             // 检查在线状态
             if (checkDroneStatus.checkOnline()) {
-                Boolean online = redisCache.getCacheObject(CacheConstants.UAV_ONLINE_KEY + boxSn);
-                if (online == null || !online) {
+                // 3️⃣ 检查在线状态
+                BoxInfoReceiver obj = redisCache.getCacheObject(CacheConstants.UAV_ONLINE_KEY + boxSn);
+                if (obj == null || !obj.getOnLine().equals(1)) {
                     throw new ControlException("无人机离线,无法执行操作!boxSn: " + boxSn);
                 }
             }
@@ -145,34 +144,61 @@
             return;
         }
 
-        Double longitude = null;
-        Double latitude = null;
+        // ① 提取 boxSn(无人机编号)和目标点坐标
+        String boxSn = null;
+        Double targetLon = null, targetLat = null;
 
         for (Object arg : args) {
-            if (arg == null) {
-                continue;
+            if (arg == null) continue;
+
+            if (boxSn == null) {
+                String sn = ReflectUtils.getFieldValue(arg, "boxSn");
+                if (sn != null) boxSn = sn;
             }
-            Double lon = ReflectUtils.getFieldValue(arg, "longitude");
-            Double lat = ReflectUtils.getFieldValue(arg, "latitude");
-            if (lon != null && lat != null) {
-                longitude = lon;
-                latitude = lat;
-                break;
+
+            if (targetLon == null || targetLat == null) {
+                Double lon = ReflectUtils.getFieldValue(arg, "longitude");
+                Double lat = ReflectUtils.getFieldValue(arg, "latitude");
+                if (lon != null && lat != null) {
+                    targetLon = lon;
+                    targetLat = lat;
+                }
             }
         }
 
-        if (longitude == null || latitude == null) {
-            throw new ControlException("方法参数中未找到有效经纬度字段,无法判断禁飞区!");
+        if (targetLon == null || targetLat == null) {
+            throw new ControlException("方法参数中未找到有效目标经纬度字段,无法判断禁飞区!");
         }
 
-        List<ArdNoFlyZone> ardNoFlyZones = ardNoFlyZoneService.selectArdNoFlyZoneList(new ArdNoFlyZone());
-        if (!ardNoFlyZones.isEmpty()) {
-            Vertex vertex = new Vertex(longitude, latitude);
-            boolean inNoFlyZones = NoFlyZoneUtils.isInNoFlyZones(vertex, ardNoFlyZones);
-            if (inNoFlyZones) {
-                throw new ControlException("目标点在禁飞区内,无法执行操作!");
+        // ② 获取无人机当前位置(从缓存)
+        Vertex current = null;
+        if (boxSn != null) {
+            TelemetryData telemetry = UavTelemetryDataCache.get(boxSn);
+            if (telemetry != null) {
+                current = new Vertex(telemetry.getLng(), telemetry.getLat());
+                //current = new Vertex(125.03, 46.58);
+            }
+        }
+
+        Vertex target = new Vertex(targetLon, targetLat);
+
+        // ③ 查询禁飞区
+        List<ArdNoFlyZone> zones = ardNoFlyZoneService.selectArdNoFlyZoneList(new ArdNoFlyZone());
+        if (zones.isEmpty()) return;
+
+        for (ArdNoFlyZone zone : zones) {
+            List<Vertex> polygon = zone.getVertices();
+            if (polygon == null || polygon.size() < 3) continue;
+
+            // 检查目标点是否在禁飞区
+            if (NoFlyZoneUtils.isPointInPolygon(target, polygon)) {
+                throw new ControlException("目标点在禁飞区【" + zone.getName() + "】内,无法执行操作!");
+            }
+
+            // 检查路径是否穿越禁飞区
+            if (current != null && NoFlyZoneUtils.isLineIntersectPolygon(current, target, polygon)) {
+                throw new ControlException("路径穿越禁飞区【" + zone.getName() + "】,无法执行操作!");
             }
         }
     }
-
 }

--
Gitblit v1.9.3