Xiajijian
2025-12-24 d4f279e8f286b7f331ad43ec6eb87a82ec9831ab
ard-route/src/main/java/com/ard/route/service/impl/ArdRouteInfoServiceImpl.java
@@ -25,13 +25,14 @@
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.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
@@ -87,37 +88,28 @@
            throw new RuntimeException(e);
        }
        // 主逻辑优化
        double altitudeOffset = getDoublePoint(ardRouteInfo.getUavRouteReq().getTakeOffRefPoint(), "alt");
        boolean isM350RTK = M350_RTK.getValue().equals(ardRouteInfo.getUavRouteReq().getDroneType());
        // 如果参考起飞点不为空,将每个航点高度进行加工。
        if (ardRouteInfo.getUavRouteReq().getTakeOffRefPoint() != null){
        for (RoutePointReq routePointReq : ardRouteInfo.getUavRouteReq().getRoutePointList()) {
            // 调整航点高度
            adjustRoutePointHeight(routePointReq, altitudeOffset);
            // 如果是M350_RTK无人机,处理变焦动作
//            if (isM350RTK && routePointReq.getActionGroupList() != null) {
//                for (ActionGroupReq actionGroupReq : routePointReq.getActionGroupList()) {
//                    if (actionGroupReq != null && actionGroupReq.getActions() != null) {
//                        processZoomActions(actionGroupReq);
//                    }
//                }
//            }
            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);
    }
    // 提取变焦值处理逻辑到方法中
    private void processZoomActions(ActionGroupReq actionGroupReq) {
        for (PointActionReq action : actionGroupReq.getActions()) {
            if (action != null && action.getZoom() != null) {
                action.setZoom(divided_23(action.getZoom()));
            }
        }
    }
    /**
@@ -150,16 +142,16 @@
        if (ardRouteInfo.getGroupId() == null){
            ardRouteInfo.setGroupId("0");
        }
        UavRouteReq uavRouteReq = new UavRouteReq();
        BeanUtils.copyProperties(ardRouteInfo.getUavRouteReq(), uavRouteReq);
        ardRouteInfo.getUavRouteReq().setDroneType(subStringDroneType(ardRouteInfo.getAircraft()));
        KmzResultVo kmzResult = routeService.buildKmz(uavRouteReq,ardRouteInfo.getName());
        if (M350_RTK.getValue().equals(uavRouteReq.getDroneType())) {
        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()) {
                        action.setZoom(divided_23(action.getZoom()));
                        if (action.getZoom() != null){
                            action.setZoom(divided_23(action.getZoom()));
                        }
                    }
                }
            }
@@ -253,6 +245,9 @@
     */
    @Override
    public int deleteArdRouteInfoById(String id) {
        // 删除航线(kmz)文件
        ArdRouteInfo information = ardRouteInfoMapper.selectArdRouteInfoById(id);
        delOssService(information);
        return ardRouteInfoMapper.deleteArdRouteInfoById(id);
    }
@@ -273,17 +268,6 @@
                ardRouteInfo.setType(templateTypeData(uavRouteReq));
                ardRouteInfo.setAircraft(droneTypeData(uavRouteReq));
            }
            // 判断禁飞区
            try {
                arrayWithinNoFlyZone(ardRouteInfo.getUavRouteReq().getRoutePointList());
            } catch (ControlException e) {
                // 返回包含禁飞区错误信息的特定结果
                return MinioUploadResult.builder()
                        .originalFilename("禁飞区错误.航线航点在禁飞区!")
                        .build();
            }
            String url = ossService.upload("kmz",file);
            ardRouteInfo.setName(file.getOriginalFilename());
            ardRouteInfo.setPath(url);
@@ -362,7 +346,6 @@
    /**
     * 上传航线到边缘服务器
     *
     * ardNoflyDto
     * @return 结果
     */
@@ -376,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);
@@ -397,7 +410,12 @@
     * @return 结果
     */
    @Override
    public Boolean routeBegins(String boxSn) {
    public Boolean routeBegins(String id,String boxSn) {
        ArdRouteInfo route = ardRouteInfoMapper.selectArdRouteInfoById(id);
        // 判断是否循环航线
        if ("1".equals(route.getIsLoop())) {
            deleteArdRouteInfoById(id);
        }
        WayLineBeginDTO wayLineBeginDTO = new WayLineBeginDTO(boxSn);
        tyService.wayLineBegin(wayLineBeginDTO);
        return true;