From 5d2e6ca50091f405dfda9e287b367dd295dc6cf8 Mon Sep 17 00:00:00 2001
From: Xiajijian <1176061145@qq.com>
Date: Mon, 09 Feb 2026 17:39:17 +0800
Subject: [PATCH] 1. 航线任务增加校验,只有下发人和登陆人是一个人才可以删除修改操作。 2. 增加校验航线任务是否可以创建航线接口。

---
 ard-route/src/main/java/com/ard/route/service/impl/ArdRouteInfoServiceImpl.java |  323 +++++++++++++++++++++++++----------------------------
 1 files changed, 151 insertions(+), 172 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 97f5cd3..5ecf63c 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
@@ -1,11 +1,11 @@
 package com.ard.route.service.impl;
 
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.List;
 
 import com.ard.common.exception.ControlException;
 import com.ard.common.utils.DateUtils;
+import com.ard.common.utils.SecurityUtils;
 import com.ard.common.utils.file.FileUtils;
 import com.ard.common.utils.uuid.IdUtils;
 import com.ard.data.noflyzone.domain.ArdNoFlyZone;
@@ -21,12 +21,15 @@
 import com.ard.route.domain.djuav.UavRouteReq;
 import com.ard.route.domain.dto.ArdNoflyDto;
 import com.ard.route.domain.route.ArdRouteInfo;
+import com.ard.route.domain.route.ArdRouteMission;
 import com.ard.route.domain.vo.KmzResultVo;
 import com.ard.route.mapper.ArdRouteInfoMapper;
+import com.ard.route.mapper.ArdRouteMissionMapper;
 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;
@@ -34,12 +37,13 @@
 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.common.utils.SecurityUtils.getUserId;
 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.buildWayLineUploadDTO;
 import static com.ard.route.util.UavRouteReqUtils.fileConversionEntity;
 
 /**
@@ -59,9 +63,11 @@
     @Autowired
     private OssServiceContext ossService;
 
-
     @Autowired
     private UavRouteService routeService;
+
+    @Autowired
+    private ArdRouteMissionMapper ardRouteMissionMapper;
 
     @Resource
     private IArdNoFlyZoneService ardNoFlyZoneService;
@@ -79,24 +85,33 @@
     public ArdRouteInfo selectArdRouteInfoById(String id) {
         ArdRouteInfo ardRouteInfo = ardRouteInfoMapper.selectArdRouteInfoById(id);
         try {
-            if (ardRouteInfo.getRouteData() != null){
-                ardRouteInfo.setUavRouteReq((UavRouteReq) deserialize(ardRouteInfo.getRouteData()));
+            if (ardRouteInfo != null) {
+                if (ardRouteInfo.getRouteData() != null){
+                    ardRouteInfo.setUavRouteReq((UavRouteReq) deserialize(ardRouteInfo.getRouteData()));
+                }
             }
         } catch (IOException | ClassNotFoundException e) {
             throw new RuntimeException(e);
         }
 
-        // 主逻辑优化
-        double altitudeOffset = getDoublePoint(ardRouteInfo.getUavRouteReq().getTakeOffRefPoint(), "alt");
-
-        for (RoutePointReq routePointReq : ardRouteInfo.getUavRouteReq().getRoutePointList()) {
-            // 调整航点高度
-            adjustRoutePointHeight(routePointReq, altitudeOffset);
+        // 如果参考起飞点不为空,将每个航点高度进行加工。
+        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);
     }
@@ -125,6 +140,9 @@
      */
     @Override
     public String insertArdRouteInfo(ArdRouteInfo ardRouteInfo) {
+        validateForCreate(ardRouteInfo);
+        checkRouteMissionStatus(ardRouteInfo,"1");
+        checkRouteMissionStatus(ardRouteInfo,"2");
         ardRouteInfo.setId(IdUtils.simpleUUID());
         ardRouteInfo.setCreateTime(DateUtils.getNowDate());
         ardRouteInfo.setUpdateTime(DateUtils.getNowDate()); // 修改时间,用于排序
@@ -133,22 +151,72 @@
         }
         ardRouteInfo.getUavRouteReq().setDroneType(subStringDroneType(ardRouteInfo.getAircraft()));
         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()));
-                        }
-                    }
-                }
-            }
-        }
+        zoomProcessing(ardRouteInfo);
         ardRouteInfo.setPath(kmzResult.getPath());
         ardRouteInfo.setReadOnly("0");
         ardRouteInfoMapper.insertArdRouteInfo(dataProcessing(ardRouteInfo));
         return kmzResult.getPath();
+    }
+
+    /**
+     * 航线任务数据加工校验
+     * 1.新建航线时,判断航线任务是否已完成
+     * 2.新建航线时,对航线任务数据进行加工
+     * 3.执行航线的时,修改航线任务表执行状态
+     */
+    private void checkRouteMissionStatus(ArdRouteInfo ardRouteInfo,String type){
+        ArdRouteMission mission = ardRouteMissionMapper.selectArdRouteMissionById(ardRouteInfo.getMissionId());
+        if (mission != null){
+            switch(type){
+                case "1":
+                    validateForCreate(mission);
+                    break;
+                case "2":
+                    bindRoute(mission,ardRouteInfo);
+                    break;
+                case "3":
+                    executeMission(mission,ardRouteInfo);
+                    break;
+                default:
+                    throw new RuntimeException("不支持的操作类型!!!");
+            }
+        }
+    }
+
+    // 验证,只有当前用户是下发人才能创建航线
+    private void validateForCreate(ArdRouteInfo ardRouteInfo) {
+        ArdRouteMission mission = ardRouteMissionMapper.selectArdRouteMissionById(ardRouteInfo.getMissionId());
+        if (mission != null){
+            if (!mission.getIssuerId().equals(getUserId())){
+                throw new RuntimeException("创建航线,只能创建下发自己的航线任务信息【" + mission.getMissionName() + "】,无法执行操作!");
+                //return "创建航线,只能创建下发自己的航线任务信息【" + mission.getMissionName() + "】,无法执行操作!";
+            }
+        }
+    }
+
+    private void validateForCreate(ArdRouteMission mission) {
+        if ("1".equals(mission.getExecuteStatus())){
+            throw new RuntimeException("航线任务已完成,无法创建航线!!!");
+        }
+    }
+
+    private void bindRoute(ArdRouteMission mission, ArdRouteInfo routeInfo) {
+        if (mission.getRouteId() != null) {
+            throw new RuntimeException("航线任务下已绑定航线,不可创建新航线信息!!!");
+        }
+        mission.setRouteId(routeInfo.getId());
+        ardRouteMissionMapper.updateArdRouteMission(mission);
+    }
+
+    private void executeMission(ArdRouteMission mission,ArdRouteInfo ardRouteInfo) {
+        if ("0".equals(mission.getExecuteStatus())) {
+            mission.setRouteId(ardRouteInfo.getId());
+            mission.setExecuteStatus("1");
+            mission.setExecuteName(SecurityUtils.getUsername());
+            mission.setExecuteTime(DateUtils.getNowDate());
+            mission.setUpdateTime(DateUtils.getNowDate());
+            ardRouteMissionMapper.updateArdRouteMission(mission);
+        }
     }
 
     /**
@@ -168,6 +236,8 @@
             // 先删除航线
             delOssService(route);
             // 再生成航线
+            ardRouteInfo.getUavRouteReq().setDroneType(subStringDroneType(ardRouteInfo.getAircraft()));
+            zoomProcessing(ardRouteInfo);
             kmzResult = routeService.buildKmz(ardRouteInfo.getUavRouteReq(), ardRouteInfo.getName());
             if ("更新航线kmz文件失败".equals(kmzResult.getData())) {
                 return 0;
@@ -175,6 +245,22 @@
             ardRouteInfo.setPath(kmzResult.getPath());
         }
         return ardRouteInfoMapper.updateArdRouteInfo(dataProcessing(ardRouteInfo));
+    }
+
+    // 变倍加工方法
+    private void zoomProcessing(ArdRouteInfo ardRouteInfo) {
+        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()));
+                        }
+                    }
+                }
+            }
+        }
     }
 
     // 新增信息加工
@@ -234,6 +320,9 @@
      */
     @Override
     public int deleteArdRouteInfoById(String id) {
+        // 删除航线(kmz)文件
+        ArdRouteInfo information = ardRouteInfoMapper.selectArdRouteInfoById(id);
+        delOssService(information);
         return ardRouteInfoMapper.deleteArdRouteInfoById(id);
     }
 
@@ -332,7 +421,6 @@
 
     /**
      * 上传航线到边缘服务器
-     *
      * ardNoflyDto
      * @return 结果
      */
@@ -346,6 +434,34 @@
         } 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获取航线信息
@@ -369,7 +485,15 @@
      * @return 结果
      */
     @Override
-    public Boolean routeBegins(String boxSn) {
+    public Boolean routeBegins(String id,String boxSn) {
+        ArdRouteInfo route = ardRouteInfoMapper.selectArdRouteInfoById(id);
+        if (null != route){
+            // 判断是否循环航线
+            if ("0".equals(route.getIsLoop())){
+                deleteArdRouteInfoById(id);
+            }
+            checkRouteMissionStatus(route,"3");
+        }
         WayLineBeginDTO wayLineBeginDTO = new WayLineBeginDTO(boxSn);
         tyService.wayLineBegin(wayLineBeginDTO);
         return true;
@@ -412,151 +536,6 @@
         WayLineEndDTO wayLineEndDTO = new WayLineEndDTO(boxSn);
         tyService.wayLineEnd(wayLineEndDTO);
         return true;
-    }
-
-    /**
-     * ArdRouteInfo实体转换,WayLineUploadDTO
-     */
-    private WayLineUploadDTO buildWayLineUploadDTO(ArdRouteInfo ardRouteInfo){
-        WayLineUploadDTO wayLineUploadDTO = new WayLineUploadDTO();
-        String finishAction = ardRouteInfo.getUavRouteReq().getFinishAction(); //1
-        Double autoFlightSpeed = ardRouteInfo.getUavRouteReq().getAutoFlightSpeed(); //15
-        Double globalTransitionalSpeed = ardRouteInfo.getUavRouteReq().getGlobalTransitionalSpeed(); //8
-        String exitOnRcLostAction = ardRouteInfo.getUavRouteReq().getExitOnRcLostAction();  //0
-
-        PlanLineData planLineData = new PlanLineData();
-        if (finishAction != null){
-            planLineData.setLoseAction(0);
-        }
-        if (autoFlightSpeed != null){
-            planLineData.setAutoSpeed(8);
-        }
-        planLineData.setMaxSpeed(15);
-//        if (globalTransitionalSpeed != null){
-//            planLineData.setMaxSpeed(15);
-//        }
-        if (exitOnRcLostAction != null){
-            planLineData.setFinishedAction(1);
-        }
-        planLineData.setHomeHeight(50);
-        planLineData.setInterests(new ArrayList<>());
-        planLineData.setIsSaveEnergyMode(0);
-        planLineData.setPoints(buildPointDataList(ardRouteInfo.getUavRouteReq()));
-
-        wayLineUploadDTO.setWayLineData(planLineData);
-        return wayLineUploadDTO;
-    }
-
-    private List<PointData> buildPointDataList(UavRouteReq uavRouteReq){
-        List<PointData> pointDataList = new ArrayList<>();
-        for (RoutePointReq routePointReq : uavRouteReq.getRoutePointList()) {
-            PointData pointData = new PointData();
-
-            Integer routePointIndex = routePointReq.getRoutePointIndex();
-            if (routePointIndex != null){
-                pointData.setGroupIndex(routePointIndex);
-            }
-            Double height = routePointReq.getHeight();
-            if (height != null){
-                pointData.setHeight(height.floatValue());
-            }
-            Double longitude = routePointReq.getLongitude();
-            if (longitude != null){
-                pointData.setLng(longitude.floatValue());
-            }
-            Double latitude = routePointReq.getLatitude();
-            if (latitude != null){
-                pointData.setLat(latitude.floatValue());
-            }
-            Double speed = routePointReq.getSpeed();
-            if (speed != null){
-                pointData.setSpeed(speed.floatValue());
-            }
-            pointData.setDampingDistance(0);
-            pointData.setFlightPathMode(1);
-            pointData.setHeading(0);
-            pointData.setHeadingMode(0);
-            pointData.setInterestIndex(-1);
-            pointData.setSafeGohomeFlag(0);
-            pointData.setActions(buildPointActionList(routePointReq.getActionGroupList()));
-            pointDataList.add(pointData);
-
-        }
-        return pointDataList;
-    }
-
-    private List<PointAction> buildPointActionList(List<ActionGroupReq> actionGroupList){
-        List<PointAction> pointActionList = new ArrayList<>();
-        for (ActionGroupReq actionGroupReq : actionGroupList) {
-            for (PointActionReq action : actionGroupReq.getActions()) {
-                PointAction pointAction = typeProcessing(action);
-                pointActionList.add(pointAction);
-            }
-        }
-        return pointActionList;
-    }
-
-    private PointAction typeProcessing(PointActionReq pointActionReq){
-        PointAction pointAction = new PointAction();
-
-        if (pointActionReq.getZoom() != null){
-            pointAction.setType(1);
-            pointAction.setParam(pointActionReq.getZoom().floatValue());
-            pointAction.setSpeakInfo("");
-            pointAction.setWaitTime(2);
-        }
-
-        if (pointActionReq.getTakePhotoType() != null){
-            pointAction.setType(2);
-            pointAction.setParam(1);
-            pointAction.setSpeakInfo("");
-            pointAction.setWaitTime(2);
-        }
-
-        if (pointActionReq.getStartRecord() != null){
-            pointAction.setType(3);
-            pointAction.setParam(1);
-            pointAction.setSpeakInfo("");
-            pointAction.setWaitTime(2);
-        }
-
-        if (pointActionReq.getStopRecord() != null){
-            pointAction.setType(4);
-            pointAction.setParam(1);
-            pointAction.setSpeakInfo("");
-            pointAction.setWaitTime(2);
-        }
-
-        if (pointActionReq.getAircraftHeading() != null){
-            pointAction.setType(5);
-            pointAction.setParam(pointActionReq.getAircraftHeading().floatValue());
-            pointAction.setSpeakInfo("");
-            pointAction.setWaitTime(2);
-        }
-
-        if (pointActionReq.getGimbalPitchRotateAngle() != null){
-            pointAction.setType(6);
-            pointAction.setParam(pointActionReq.getGimbalPitchRotateAngle().floatValue());
-            pointAction.setSpeakInfo("");
-            pointAction.setWaitTime(2);
-        }
-
-        if (pointActionReq.getGimbalYawRotateAngle() != null){
-            pointAction.setType(7);
-            pointAction.setParam(pointActionReq.getGimbalYawRotateAngle().floatValue());
-            pointAction.setSpeakInfo("");
-            pointAction.setWaitTime(2);
-        }
-
-        if (pointActionReq.getHoverTime() != null){
-            pointAction.setType(9);
-            pointAction.setParam(pointActionReq.getHoverTime().floatValue());
-            pointAction.setSpeakInfo("");
-            pointAction.setWaitTime(2);
-        }
-
-        return pointAction;
-
     }
 
     /**

--
Gitblit v1.9.3