fix:支付宝支付退款以及消息通知
This commit is contained in:
+27
@@ -8,6 +8,8 @@ import com.central.order.model.dto.AgeDeviceLocationDTO;
|
||||
import com.central.order.model.dto.BoatRealtimePositionDTO;
|
||||
import com.central.order.model.dto.DroneLatestTrackPointDTO;
|
||||
import com.central.order.mission.VO.TakeoffRequestVO;
|
||||
import com.central.order.mission.VO.FlyToPointRequestVO;
|
||||
import com.central.order.mission.VO.FlyToPointUpdateRequestVO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -39,6 +41,10 @@ public interface DeviceCenterService {
|
||||
@PostMapping("/device/command/takeoff")
|
||||
Result<String> takeoff(@RequestBody TakeoffRequestVO request);
|
||||
|
||||
@Operation(summary = "无人机返航")
|
||||
@PostMapping("/device/command/return")
|
||||
Result<String> returnHome(@RequestParam("deviceSn") String deviceSn);
|
||||
|
||||
/**
|
||||
* 执行航线任务
|
||||
*
|
||||
@@ -133,4 +139,25 @@ public interface DeviceCenterService {
|
||||
@Operation(summary = "获取无人机最新轨迹点")
|
||||
@GetMapping("/api/device/drone/track/latest/{deviceSn}")
|
||||
Result<DroneLatestTrackPointDTO> getDroneLatestTrackPoint(@PathVariable("deviceSn") String deviceSn);
|
||||
|
||||
/**
|
||||
* 指点飞行 - 首次飞向目标点
|
||||
*/
|
||||
@Operation(summary = "无人机指点飞行 - 飞向目标")
|
||||
@PostMapping("/device/command/flyToPoint")
|
||||
Result<String> flyToPoint(@RequestBody FlyToPointRequestVO request);
|
||||
|
||||
/**
|
||||
* 指点飞行 - 更新目标点(连续指点)
|
||||
*/
|
||||
@Operation(summary = "无人机指点飞行 - 更新目标点")
|
||||
@PostMapping("/device/command/flyToPointUpdate")
|
||||
Result<String> flyToPointUpdate(@RequestBody FlyToPointUpdateRequestVO request);
|
||||
|
||||
/**
|
||||
* 指点飞行 - 停止指点飞行
|
||||
*/
|
||||
@Operation(summary = "无人机指点飞行 - 停止")
|
||||
@PostMapping("/device/command/flyToPointStop")
|
||||
Result<String> flyToPointStop(@RequestParam("deviceSn") String deviceSn);
|
||||
}
|
||||
|
||||
+26
@@ -7,6 +7,8 @@ import com.central.order.model.dto.AgeDeviceLocationDTO;
|
||||
import com.central.order.model.dto.BoatRealtimePositionDTO;
|
||||
import com.central.order.model.dto.DroneLatestTrackPointDTO;
|
||||
import com.central.order.mission.VO.TakeoffRequestVO;
|
||||
import com.central.order.mission.VO.FlyToPointRequestVO;
|
||||
import com.central.order.mission.VO.FlyToPointUpdateRequestVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -43,6 +45,12 @@ public class DeviceCenterServiceFallbackFactory implements FallbackFactory<Devic
|
||||
return Result.failed("设备中心服务调用失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> returnHome(String deviceSn) {
|
||||
log.error("调用设备中心returnHome失败: deviceSn={}, error={}", deviceSn, cause.getMessage());
|
||||
return Result.failed("设备中心服务调用失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> executeWayline(String deviceSn, String waylineId, String missionCode) {
|
||||
log.error("调用设备中心executeWayline失败: deviceSn={}, waylineId={}, missionCode={}, error={}",
|
||||
@@ -98,6 +106,24 @@ public class DeviceCenterServiceFallbackFactory implements FallbackFactory<Devic
|
||||
log.error("调用设备中心getDroneLatestTrackPoint失败: deviceSn={}, error={}", deviceSn, cause.getMessage());
|
||||
return Result.failed("设备中心服务调用失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> flyToPoint(FlyToPointRequestVO request) {
|
||||
log.error("调用设备中心flyToPoint失败: deviceSn={}, error={}", request.getDeviceSn(), cause.getMessage());
|
||||
return Result.failed("设备中心服务调用失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> flyToPointUpdate(FlyToPointUpdateRequestVO request) {
|
||||
log.error("调用设备中心flyToPointUpdate失败: deviceSn={}, error={}", request.getDeviceSn(), cause.getMessage());
|
||||
return Result.failed("设备中心服务调用失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<String> flyToPointStop(String deviceSn) {
|
||||
log.error("调用设备中心flyToPointStop失败: deviceSn={}, error={}", deviceSn, cause.getMessage());
|
||||
return Result.failed("设备中心服务调用失败");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package com.central.order.mission.VO;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 指点飞行(首次飞向目标)Feign 请求 VO
|
||||
*
|
||||
* @author dzc
|
||||
* @date 2026-01-23
|
||||
*/
|
||||
@Data
|
||||
public class FlyToPointRequestVO {
|
||||
/** 设备SN */
|
||||
private String deviceSn;
|
||||
/** 飞行会话ID(= missionCode) */
|
||||
private String flyToId;
|
||||
/** 目标纬度 */
|
||||
private Double latitude;
|
||||
/** 目标经度 */
|
||||
private Double longitude;
|
||||
/** 目标椭球高 */
|
||||
private Float height;
|
||||
/** 最大飞行速度(m/s),默认 12 */
|
||||
private Float maxSpeed;
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.central.order.mission.VO;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 指点飞行更新目标(连续指点)Feign 请求 VO
|
||||
* 注意:设备协议不含 fly_to_id,仅传 max_speed + points
|
||||
*
|
||||
* @author dzc
|
||||
* @date 2026-01-23
|
||||
*/
|
||||
@Data
|
||||
public class FlyToPointUpdateRequestVO {
|
||||
/** 设备SN */
|
||||
private String deviceSn;
|
||||
/** 目标纬度 */
|
||||
private Double latitude;
|
||||
/** 目标经度 */
|
||||
private Double longitude;
|
||||
/** 目标椭球高 */
|
||||
private Float height;
|
||||
/** 最大飞行速度(m/s),默认 12 */
|
||||
private Float maxSpeed;
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package com.central.order.mission.command;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 指点飞行目标下发参数。
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
public class FlyToPointTargetCommand {
|
||||
|
||||
private Double latitude;
|
||||
private Double longitude;
|
||||
private Float height;
|
||||
private Float maxSpeed;
|
||||
private String clearanceStatus;
|
||||
private Float clearanceMeters;
|
||||
private Float candidateSurfaceHeight;
|
||||
private boolean riskAcknowledged;
|
||||
private String riskReason;
|
||||
private Long riskAcknowledgedUserId;
|
||||
private String riskAcknowledgedUsername;
|
||||
|
||||
public void validateRiskAcknowledgement() {
|
||||
if (!"VERIFIED".equals(clearanceStatus) && !riskAcknowledged) {
|
||||
throw new IllegalArgumentException("路径净空未验证,请确认风险后再发送目标");
|
||||
}
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.central.order.mission.command;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 指点飞行目标更新接口请求。
|
||||
*/
|
||||
@Data
|
||||
public class FlyToPointUpdateRequest {
|
||||
private String missionCode;
|
||||
private Double latitude;
|
||||
private Double longitude;
|
||||
private Float height;
|
||||
private Float maxSpeed;
|
||||
private String clearanceStatus;
|
||||
private Float clearanceMeters;
|
||||
private Float candidateSurfaceHeight;
|
||||
private Boolean riskAcknowledged;
|
||||
private String riskReason;
|
||||
|
||||
public FlyToPointTargetCommand toCommand() {
|
||||
return FlyToPointTargetCommand.builder()
|
||||
.latitude(latitude)
|
||||
.longitude(longitude)
|
||||
.height(height)
|
||||
.maxSpeed(maxSpeed == null ? 12f : maxSpeed)
|
||||
.clearanceStatus(clearanceStatus == null ? "UNVERIFIED" : clearanceStatus)
|
||||
.clearanceMeters(clearanceMeters)
|
||||
.candidateSurfaceHeight(candidateSurfaceHeight)
|
||||
.riskAcknowledged(Boolean.TRUE.equals(riskAcknowledged))
|
||||
.riskReason(riskReason)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
+111
@@ -8,6 +8,8 @@ import com.central.common.model.Result;
|
||||
import com.central.order.feign.FileCenterService;
|
||||
import com.central.order.mission.enums.MissionStatus;
|
||||
import com.central.order.mission.enums.MissionType;
|
||||
import com.central.order.mission.command.FlyToPointTargetCommand;
|
||||
import com.central.order.mission.command.FlyToPointUpdateRequest;
|
||||
import com.central.order.mission.model.Mission;
|
||||
import com.central.order.mission.model.MissionImage;
|
||||
import com.central.order.mission.service.IMissionImageService;
|
||||
@@ -279,6 +281,115 @@ public class MissionController {
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 指点飞行编排接口 ====================
|
||||
|
||||
/**
|
||||
* 开始指点飞行
|
||||
*/
|
||||
@Operation(summary = "开始指点飞行")
|
||||
@PostMapping("/startFlyToPoint")
|
||||
public Result<Map<String, Object>> startFlyToPoint(@RequestBody Map<String, Object> params) {
|
||||
try {
|
||||
TenantContextHolder.setTenant("webApp");
|
||||
|
||||
String deviceSn = (String) params.get("deviceSn");
|
||||
if (!StringUtils.hasText(deviceSn)) {
|
||||
return Result.failed("设备SN不能为空");
|
||||
}
|
||||
|
||||
Double dockLatitude = params.get("dockLatitude") != null ?
|
||||
Double.parseDouble(params.get("dockLatitude").toString()) : null;
|
||||
Double dockLongitude = params.get("dockLongitude") != null ?
|
||||
Double.parseDouble(params.get("dockLongitude").toString()) : null;
|
||||
Float dockHeight = params.get("dockHeight") != null ?
|
||||
Float.parseFloat(params.get("dockHeight").toString()) : null;
|
||||
Boolean isAirborne = params.get("isAirborne") != null ?
|
||||
(Boolean) params.get("isAirborne") : false;
|
||||
|
||||
String missionCode = missionService.startFlyToPoint(deviceSn, dockLatitude, dockLongitude, dockHeight, isAirborne);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("missionCode", missionCode);
|
||||
return Result.succeed(result, "指点飞行任务已开始");
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("开始指点飞行异常", e);
|
||||
return Result.failed("开始指点飞行失败: " + e.getMessage());
|
||||
} finally {
|
||||
TenantContextHolder.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新指点飞行目标点
|
||||
*/
|
||||
@Operation(summary = "更新指点飞行目标点")
|
||||
@PostMapping("/flyToPointUpdate")
|
||||
public Result<String> flyToPointUpdate(@RequestBody FlyToPointUpdateRequest request) {
|
||||
try {
|
||||
TenantContextHolder.setTenant("webApp");
|
||||
|
||||
String missionCode = request.getMissionCode();
|
||||
if (!StringUtils.hasText(missionCode)) {
|
||||
return Result.failed("任务编码不能为空");
|
||||
}
|
||||
|
||||
FlyToPointTargetCommand command = request.toCommand();
|
||||
// 第一版没有服务端路径净空验证能力,不能信任客户端声明“已验证”。
|
||||
command.setClearanceStatus("UNVERIFIED");
|
||||
|
||||
if (command.getLatitude() == null || command.getLongitude() == null || command.getHeight() == null) {
|
||||
return Result.failed("目标经纬度和高度不能为空");
|
||||
}
|
||||
if (command.getLatitude() < -90 || command.getLatitude() > 90
|
||||
|| command.getLongitude() < -180 || command.getLongitude() > 180) {
|
||||
return Result.failed("目标经纬度不合法");
|
||||
}
|
||||
|
||||
LoginAppUser user = LoginUserContextHolder.getUser();
|
||||
if (user == null) {
|
||||
return Result.failed("用户未登录,无法确认飞行风险");
|
||||
}
|
||||
command.setRiskAcknowledgedUserId(user.getId());
|
||||
command.setRiskAcknowledgedUsername(user.getUsername());
|
||||
command.validateRiskAcknowledgement();
|
||||
|
||||
missionService.flyToPointUpdate(missionCode, command);
|
||||
return Result.succeed("目标点已更新");
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("更新指点飞行目标点异常", e);
|
||||
return Result.failed("更新目标点失败: " + e.getMessage());
|
||||
} finally {
|
||||
TenantContextHolder.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束指点飞行
|
||||
*/
|
||||
@Operation(summary = "结束指点飞行")
|
||||
@PostMapping("/endFlyToPoint")
|
||||
public Result<String> endFlyToPoint(@RequestBody Map<String, Object> params) {
|
||||
try {
|
||||
TenantContextHolder.setTenant("webApp");
|
||||
|
||||
String missionCode = (String) params.get("missionCode");
|
||||
if (!StringUtils.hasText(missionCode)) {
|
||||
return Result.failed("任务编码不能为空");
|
||||
}
|
||||
|
||||
missionService.endFlyToPoint(missionCode);
|
||||
return Result.succeed("指点飞行已结束,返航中");
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("结束指点飞行异常", e);
|
||||
return Result.failed("结束指点飞行失败: " + e.getMessage());
|
||||
} finally {
|
||||
TenantContextHolder.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录人的任务及图片列表
|
||||
*/
|
||||
|
||||
+9
-1
@@ -13,7 +13,8 @@ import lombok.Getter;
|
||||
public enum MissionType implements ZltEnum {
|
||||
WAYLINE(1, "航线任务"),
|
||||
TAKEOFF(2, "一键起飞任务"),
|
||||
BOAT_ROUTE(3, "无人船航线任务");
|
||||
BOAT_ROUTE(3, "无人船航线任务"),
|
||||
FLY_TO_POINT(4, "指点飞行任务");
|
||||
|
||||
MissionType(Integer id, String content) {
|
||||
this.id = id;
|
||||
@@ -58,4 +59,11 @@ public enum MissionType implements ZltEnum {
|
||||
public static boolean isBoatRouteTask(Integer type) {
|
||||
return type != null && type.equals(BOAT_ROUTE.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为指点飞行任务
|
||||
*/
|
||||
public static boolean isFlyToPointTask(Integer type) {
|
||||
return type != null && type.equals(FLY_TO_POINT.getId());
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.central.order.mission.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.central.order.mission.model.MissionFlyToPoint;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface MissionFlyToPointMapper extends BaseMapper<MissionFlyToPoint> {
|
||||
}
|
||||
+5
@@ -34,6 +34,11 @@ public interface MissionMapper extends BaseMapper<Mission> {
|
||||
*/
|
||||
Mission getByMissionCode(@Param("missionCode") String missionCode);
|
||||
|
||||
/**
|
||||
* 锁定任务行,串行化同一指点飞行会话的目标更新。
|
||||
*/
|
||||
Mission getByMissionCodeForUpdate(@Param("missionCode") String missionCode);
|
||||
|
||||
/**
|
||||
* 更新任务状态
|
||||
*
|
||||
|
||||
@@ -108,4 +108,7 @@ public class Mission extends SuperEntity {
|
||||
@Schema(description = "任务状态描述")
|
||||
@TableField(exist = false)
|
||||
private transient String missionStatusDesc;
|
||||
|
||||
@Schema(description = "会话阶段:ACTIVE / RETURNING")
|
||||
private String phase;
|
||||
}
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package com.central.order.mission.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.central.common.model.SuperEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 指点飞行每次下发目标及风险确认审计记录。
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("mission_fly_to_point")
|
||||
public class MissionFlyToPoint extends SuperEntity {
|
||||
private String missionCode;
|
||||
private String flyToId;
|
||||
private String commandId;
|
||||
private Integer seq;
|
||||
private String commandType;
|
||||
private Double latitude;
|
||||
private Double longitude;
|
||||
private Float height;
|
||||
private Float maxSpeed;
|
||||
private String status;
|
||||
private String clearanceStatus;
|
||||
private Float clearanceMeters;
|
||||
private Float candidateSurfaceHeight;
|
||||
private Integer riskAcknowledged;
|
||||
private String riskReason;
|
||||
private Long riskAcknowledgedUserId;
|
||||
private String riskAcknowledgedUsername;
|
||||
}
|
||||
+33
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.mission.model.Mission;
|
||||
import com.central.order.mission.command.FlyToPointTargetCommand;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -96,4 +97,36 @@ public interface IMissionService extends IService<Mission> {
|
||||
* @return 下发成功返回true
|
||||
*/
|
||||
boolean dispatchMissionToDevice(Mission mission);
|
||||
|
||||
// ==================== 指点飞行编排接口 ====================
|
||||
|
||||
/**
|
||||
* 开始指点飞行
|
||||
*
|
||||
* @param deviceSn 设备SN
|
||||
* @param dockLatitude 机库纬度
|
||||
* @param dockLongitude 机库经度
|
||||
* @param dockHeight 机库高度
|
||||
* @param isAirborne 是否已升空(前端 SSE 判断)
|
||||
* @return 任务编码
|
||||
*/
|
||||
String startFlyToPoint(String deviceSn, Double dockLatitude, Double dockLongitude, Float dockHeight, boolean isAirborne);
|
||||
|
||||
/**
|
||||
* 更新指点飞行目标点
|
||||
*
|
||||
* @param missionCode 任务编码
|
||||
* @param latitude 目标纬度
|
||||
* @param longitude 目标经度
|
||||
* @param height 目标椭球高
|
||||
* @param maxSpeed 最大速度
|
||||
*/
|
||||
void flyToPointUpdate(String missionCode, FlyToPointTargetCommand command);
|
||||
|
||||
/**
|
||||
* 结束指点飞行
|
||||
*
|
||||
* @param missionCode 任务编码
|
||||
*/
|
||||
void endFlyToPoint(String missionCode);
|
||||
}
|
||||
|
||||
+225
@@ -6,10 +6,14 @@ import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.feign.DeviceCenterService;
|
||||
import com.central.order.mission.VO.TakeoffRequestVO;
|
||||
import com.central.order.mission.VO.FlyToPointRequestVO;
|
||||
import com.central.order.mission.command.FlyToPointTargetCommand;
|
||||
import com.central.order.mission.enums.MissionStatus;
|
||||
import com.central.order.mission.enums.MissionType;
|
||||
import com.central.order.mission.mapper.MissionMapper;
|
||||
import com.central.order.mission.mapper.MissionFlyToPointMapper;
|
||||
import com.central.order.mission.model.Mission;
|
||||
import com.central.order.mission.model.MissionFlyToPoint;
|
||||
import com.central.order.mission.service.IMissionService;
|
||||
import com.central.order.weather.model.WeatherCheckResult;
|
||||
import com.central.order.weather.service.IWeatherRuleValidator;
|
||||
@@ -38,6 +42,9 @@ public class MissionServiceImpl extends ServiceImpl<MissionMapper, Mission> impl
|
||||
@Resource
|
||||
DeviceCenterService deviceCenterService;
|
||||
|
||||
@Resource
|
||||
MissionFlyToPointMapper missionFlyToPointMapper;
|
||||
|
||||
@Autowired
|
||||
private IWeatherRuleValidator weatherRuleValidator;
|
||||
|
||||
@@ -249,6 +256,13 @@ public class MissionServiceImpl extends ServiceImpl<MissionMapper, Mission> impl
|
||||
|
||||
@Override
|
||||
public boolean dispatchMissionToDevice(Mission mission) {
|
||||
return dispatchMissionToDevice(mission, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下发任务到设备(带升空状态)
|
||||
*/
|
||||
public boolean dispatchMissionToDevice(Mission mission, boolean isAirborne) {
|
||||
try {
|
||||
Integer missionType = mission.getMissionType();
|
||||
|
||||
@@ -311,6 +325,33 @@ public class MissionServiceImpl extends ServiceImpl<MissionMapper, Mission> impl
|
||||
log.error("无人船航线任务下发失败: missionCode={}, error={}", mission.getMissionCode(), errorMsg);
|
||||
return false;
|
||||
}
|
||||
} else if (MissionType.isFlyToPointTask(missionType)) {
|
||||
// 指点飞行任务:前端 SSE 判断是否已升空
|
||||
log.info("下发指点飞行任务到设备: missionCode={}, deviceSn={}, isAirborne={}",
|
||||
mission.getMissionCode(), mission.getDeviceSn(), isAirborne);
|
||||
|
||||
if (!isAirborne) {
|
||||
// 未升空 → 先起飞
|
||||
TakeoffRequestVO takeoffRequestVO = new TakeoffRequestVO();
|
||||
takeoffRequestVO.setTargetHeight(mission.getTargetHeight() != null ? mission.getTargetHeight().floatValue() : 20f);
|
||||
takeoffRequestVO.setDeviceSn(mission.getDeviceSn());
|
||||
takeoffRequestVO.setFlightId(mission.getMissionCode());
|
||||
takeoffRequestVO.setTargetLatitude(mission.getTargetLatitude() != null ? mission.getTargetLatitude().doubleValue() : 0d);
|
||||
takeoffRequestVO.setTargetLongitude(mission.getTargetLongitude() != null ? mission.getTargetLongitude().doubleValue() : 0d);
|
||||
Result<String> takeoffResult = deviceCenterService.takeoff(takeoffRequestVO);
|
||||
if (takeoffResult == null || takeoffResult.getResp_code() != 0) {
|
||||
log.error("指点飞行起飞命令失败: missionCode={}", mission.getMissionCode());
|
||||
return false;
|
||||
}
|
||||
log.info("指点飞行起飞命令已发送: missionCode={}", mission.getMissionCode());
|
||||
} else {
|
||||
log.info("无人机已升空,跳过起飞步骤: missionCode={}", mission.getMissionCode());
|
||||
}
|
||||
|
||||
// 命令入队成功 → 任务状态为 DOING
|
||||
updateMissionStatus(mission.getMissionCode(), MissionStatus.DOING.getId());
|
||||
return true;
|
||||
|
||||
} else {
|
||||
log.error("未知的任务类型: {}", missionType);
|
||||
return false;
|
||||
@@ -321,4 +362,188 @@ public class MissionServiceImpl extends ServiceImpl<MissionMapper, Mission> impl
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 指点飞行编排方法 ====================
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public String startFlyToPoint(String deviceSn, Double dockLatitude, Double dockLongitude, Float dockHeight, boolean isAirborne) {
|
||||
log.info("开始指点飞行: deviceSn={}, dock=({}, {}, {})", deviceSn, dockLatitude, dockLongitude, dockHeight);
|
||||
|
||||
// 1. 创建 FLY_TO_POINT 任务
|
||||
Mission mission = new Mission();
|
||||
mission.setDeviceSn(deviceSn);
|
||||
mission.setMissionType(MissionType.FLY_TO_POINT.getId());
|
||||
mission.setMissionName("指点飞行任务");
|
||||
mission.setMissionStatus(MissionStatus.PENDING.getId());
|
||||
mission.setTargetLatitude(dockLatitude != null ? java.math.BigDecimal.valueOf(dockLatitude) : null);
|
||||
mission.setTargetLongitude(dockLongitude != null ? java.math.BigDecimal.valueOf(dockLongitude) : null);
|
||||
mission.setTargetHeight(java.math.BigDecimal.valueOf(20));
|
||||
mission.setPhase("ACTIVE");
|
||||
|
||||
String missionCode = generateMissionCode();
|
||||
mission.setMissionCode(missionCode);
|
||||
|
||||
save(mission);
|
||||
log.info("指点飞行任务已创建: missionCode={}", missionCode);
|
||||
|
||||
// 2. 执行任务(dispatchMissionToDevice 会处理起飞逻辑)
|
||||
boolean dispatched = dispatchMissionToDevice(mission, isAirborne);
|
||||
if (!dispatched) {
|
||||
log.error("指点飞行任务下发失败: missionCode={}", missionCode);
|
||||
throw new RuntimeException("任务下发失败");
|
||||
}
|
||||
|
||||
return missionCode;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void flyToPointUpdate(String missionCode, FlyToPointTargetCommand command) {
|
||||
command.validateRiskAcknowledgement();
|
||||
Double latitude = command.getLatitude();
|
||||
Double longitude = command.getLongitude();
|
||||
Float height = command.getHeight();
|
||||
Float maxSpeed = command.getMaxSpeed();
|
||||
log.info("更新指点飞行目标: missionCode={}, target=({}, {}, {})", missionCode, latitude, longitude, height);
|
||||
|
||||
Mission mission = baseMapper.getByMissionCodeForUpdate(missionCode);
|
||||
if (mission == null) {
|
||||
throw new RuntimeException("任务不存在: " + missionCode);
|
||||
}
|
||||
|
||||
// 校验状态
|
||||
if (!MissionStatus.DOING.getId().equals(mission.getMissionStatus())) {
|
||||
throw new RuntimeException("任务状态不允许更新目标: " + mission.getMissionStatus());
|
||||
}
|
||||
if (!"ACTIVE".equals(mission.getPhase())) {
|
||||
throw new RuntimeException("飞行已结束,无法更新目标");
|
||||
}
|
||||
|
||||
String deviceSn = mission.getDeviceSn();
|
||||
|
||||
// 判断是否首次指点:查询 mission_fly_to_point 子表
|
||||
boolean isFirstTarget = !hasSentFirstFlyToPoint(missionCode);
|
||||
|
||||
Result<String> result;
|
||||
String commandType;
|
||||
if (isFirstTarget) {
|
||||
FlyToPointRequestVO requestVO = new FlyToPointRequestVO();
|
||||
requestVO.setDeviceSn(deviceSn);
|
||||
requestVO.setFlyToId(missionCode);
|
||||
requestVO.setLatitude(latitude);
|
||||
requestVO.setLongitude(longitude);
|
||||
requestVO.setHeight(height);
|
||||
requestVO.setMaxSpeed(maxSpeed != null ? maxSpeed : 12f);
|
||||
|
||||
result = deviceCenterService.flyToPoint(requestVO);
|
||||
if (result == null || result.getResp_code() != 0) {
|
||||
throw new RuntimeException("指点飞行命令失败: " + (result != null ? result.getResp_msg() : "无响应"));
|
||||
}
|
||||
commandType = "fly_to_point";
|
||||
log.info("首次指点飞行命令已发送: missionCode={}, commandId={}", missionCode, result.getData());
|
||||
} else {
|
||||
// 设备端不支持 fly_to_point_update,连续改飞复用 fly_to_point 并沿用同一会话标识。
|
||||
FlyToPointRequestVO requestVO = new FlyToPointRequestVO();
|
||||
requestVO.setDeviceSn(deviceSn);
|
||||
requestVO.setFlyToId(missionCode);
|
||||
requestVO.setLatitude(latitude);
|
||||
requestVO.setLongitude(longitude);
|
||||
requestVO.setHeight(height);
|
||||
requestVO.setMaxSpeed(maxSpeed != null ? maxSpeed : 12f);
|
||||
|
||||
result = deviceCenterService.flyToPoint(requestVO);
|
||||
if (result == null || result.getResp_code() != 0) {
|
||||
throw new RuntimeException("目标更新命令失败: " + (result != null ? result.getResp_msg() : "无响应"));
|
||||
}
|
||||
commandType = "fly_to_point";
|
||||
log.info("目标更新命令已发送: missionCode={}, commandId={}", missionCode, result.getData());
|
||||
}
|
||||
|
||||
MissionFlyToPoint record = new MissionFlyToPoint();
|
||||
record.setMissionCode(missionCode);
|
||||
record.setFlyToId(missionCode);
|
||||
record.setCommandId(result.getData());
|
||||
record.setSeq(nextTargetSequence(missionCode));
|
||||
record.setCommandType(commandType);
|
||||
record.setLatitude(latitude);
|
||||
record.setLongitude(longitude);
|
||||
record.setHeight(height);
|
||||
record.setMaxSpeed(maxSpeed != null ? maxSpeed : 12f);
|
||||
record.setStatus("SENT");
|
||||
record.setClearanceStatus(command.getClearanceStatus());
|
||||
record.setClearanceMeters(command.getClearanceMeters());
|
||||
record.setCandidateSurfaceHeight(command.getCandidateSurfaceHeight());
|
||||
record.setRiskAcknowledged(command.isRiskAcknowledged() ? 1 : 0);
|
||||
record.setRiskReason(command.getRiskReason());
|
||||
record.setRiskAcknowledgedUserId(command.getRiskAcknowledgedUserId());
|
||||
record.setRiskAcknowledgedUsername(command.getRiskAcknowledgedUsername());
|
||||
missionFlyToPointMapper.insert(record);
|
||||
|
||||
mission.setTargetLatitude(java.math.BigDecimal.valueOf(latitude));
|
||||
mission.setTargetLongitude(java.math.BigDecimal.valueOf(longitude));
|
||||
mission.setTargetHeight(java.math.BigDecimal.valueOf(height));
|
||||
updateById(mission);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void endFlyToPoint(String missionCode) {
|
||||
log.info("结束指点飞行: missionCode={}", missionCode);
|
||||
|
||||
Mission mission = baseMapper.getByMissionCodeForUpdate(missionCode);
|
||||
if (mission == null) {
|
||||
throw new RuntimeException("任务不存在: " + missionCode);
|
||||
}
|
||||
|
||||
// 校验状态
|
||||
if (!MissionStatus.DOING.getId().equals(mission.getMissionStatus())) {
|
||||
throw new RuntimeException("任务状态不允许结束: " + mission.getMissionStatus());
|
||||
}
|
||||
if (!"ACTIVE".equals(mission.getPhase())) {
|
||||
log.warn("任务已处于返航状态,忽略重复结束请求: missionCode={}", missionCode);
|
||||
return;
|
||||
}
|
||||
|
||||
String deviceSn = mission.getDeviceSn();
|
||||
|
||||
// 1. 原子更新 phase = RETURNING(防止并发更新目标)
|
||||
mission.setPhase("RETURNING");
|
||||
updateById(mission);
|
||||
|
||||
// 2. 设备端不支持 fly_to_point_stop,直接发送一键返航命令。
|
||||
Result<String> returnResult = deviceCenterService.returnHome(deviceSn);
|
||||
// 返航命令失败不会阻塞流程(phase 保持 RETURNING)
|
||||
if (returnResult == null || returnResult.getResp_code() != 0) {
|
||||
log.error("返航命令失败,任务保持 RETURNING: missionCode={}", missionCode);
|
||||
throw new RuntimeException("返航命令失败,任务未结束: " + (returnResult != null ? returnResult.getResp_msg() : "无响应"));
|
||||
}
|
||||
|
||||
log.info("指点飞行结束流程完成,等待降落: missionCode={}", missionCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否已发送过首次 fly_to_point 指令
|
||||
*/
|
||||
private boolean hasSentFirstFlyToPoint(String missionCode) {
|
||||
return missionFlyToPointMapper.selectCount(
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<MissionFlyToPoint>()
|
||||
.eq(MissionFlyToPoint::getMissionCode, missionCode)
|
||||
.eq(MissionFlyToPoint::getCommandType, "fly_to_point")) > 0;
|
||||
}
|
||||
|
||||
private int nextTargetSequence(String missionCode) {
|
||||
Long count = missionFlyToPointMapper.selectCount(
|
||||
new com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<MissionFlyToPoint>()
|
||||
.eq(MissionFlyToPoint::getMissionCode, missionCode));
|
||||
return count.intValue() + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成任务编码
|
||||
*/
|
||||
private String generateMissionCode() {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
return "FP" + sdf.format(new Date());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
-- 指点飞行安全审计字段;适用于已执行初始迁移的数据库。
|
||||
ALTER TABLE mission_fly_to_point
|
||||
ADD COLUMN clearance_status VARCHAR(20) NOT NULL DEFAULT 'UNVERIFIED' COMMENT '净空状态:VERIFIED / UNVERIFIED',
|
||||
ADD COLUMN clearance_meters FLOAT DEFAULT NULL COMMENT '计算得到的最小净空(米)',
|
||||
ADD COLUMN candidate_surface_height FLOAT DEFAULT NULL COMMENT '点击命中的模型或地形表面椭球高,仅审计使用',
|
||||
ADD COLUMN risk_acknowledged TINYINT NOT NULL DEFAULT 0 COMMENT '是否已确认未验证净空风险',
|
||||
ADD COLUMN risk_reason VARCHAR(512) DEFAULT NULL COMMENT '风险原因',
|
||||
ADD COLUMN risk_acknowledged_user_id BIGINT DEFAULT NULL COMMENT '确认风险的账户ID',
|
||||
ADD COLUMN risk_acknowledged_username VARCHAR(64) DEFAULT NULL COMMENT '确认风险的账户名';
|
||||
|
||||
ALTER TABLE mission_fly_to_point
|
||||
ADD UNIQUE KEY uk_mission_fly_to_point_seq (mission_code, seq);
|
||||
@@ -0,0 +1,25 @@
|
||||
-- =====================================================
|
||||
-- 指点飞行功能 - 数据库迁移脚本
|
||||
-- =====================================================
|
||||
|
||||
-- 1. missions 表新增 phase 字段
|
||||
ALTER TABLE missions ADD COLUMN phase VARCHAR(20) DEFAULT 'ACTIVE' COMMENT '会话阶段:ACTIVE / RETURNING';
|
||||
|
||||
-- 2. 创建 mission_fly_to_point 子表(记录每次目标更新)
|
||||
CREATE TABLE IF NOT EXISTS mission_fly_to_point (
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY COMMENT '主键',
|
||||
mission_code VARCHAR(64) NOT NULL COMMENT '关联任务编码',
|
||||
fly_to_id VARCHAR(64) NOT NULL COMMENT '飞行会话ID(= missionCode)',
|
||||
command_id VARCHAR(64) DEFAULT NULL COMMENT '设备命令ID',
|
||||
seq INT DEFAULT 1 COMMENT '目标序号(1, 2, 3...)',
|
||||
command_type VARCHAR(32) NOT NULL COMMENT '指令类型:fly_to_point / fly_to_point_update',
|
||||
latitude DOUBLE COMMENT '目标纬度',
|
||||
longitude DOUBLE COMMENT '目标经度',
|
||||
height FLOAT COMMENT '目标椭球高',
|
||||
max_speed FLOAT DEFAULT 12 COMMENT '最大速度',
|
||||
status VARCHAR(20) DEFAULT 'SENT' COMMENT '状态:SENT / REACHED / FAILED',
|
||||
create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
INDEX idx_mission_code (mission_code),
|
||||
INDEX idx_fly_to_id (fly_to_id)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='指点飞行目标点记录表';
|
||||
@@ -28,6 +28,7 @@
|
||||
<result column="is_del" property="isDel"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="phase" property="phase"/>
|
||||
<!-- 临时字段 -->
|
||||
<result column="tourism_name" property="tourismName"/>
|
||||
<result column="image_count" property="imageCount"/>
|
||||
@@ -40,7 +41,7 @@
|
||||
m.workspace_id, m.tourism_id, m.mission_status,
|
||||
m.target_latitude, m.target_longitude, m.target_height,
|
||||
m.start_time, m.end_time, m.creator_id, m.creator_name, m.remark,
|
||||
m.tenant_id, m.is_del, m.create_time, m.update_time
|
||||
m.tenant_id, m.is_del, m.create_time, m.update_time, m.phase
|
||||
</sql>
|
||||
|
||||
<!-- 分页查询任务列表 -->
|
||||
@@ -99,6 +100,15 @@
|
||||
AND m.is_del = 0
|
||||
</select>
|
||||
|
||||
<select id="getByMissionCodeForUpdate" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM missions m
|
||||
WHERE m.mission_code = #{missionCode}
|
||||
AND m.is_del = 0
|
||||
FOR UPDATE
|
||||
</select>
|
||||
|
||||
<!-- 更新任务状态 -->
|
||||
<update id="updateMissionStatus">
|
||||
UPDATE missions
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package com.central.order.mission.command;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
class FlyToPointTargetCommandTest {
|
||||
|
||||
@Test
|
||||
void 未验证路径且未确认风险时拒绝发送() {
|
||||
FlyToPointTargetCommand command = FlyToPointTargetCommand.builder()
|
||||
.clearanceStatus("UNVERIFIED")
|
||||
.riskAcknowledged(false)
|
||||
.build();
|
||||
|
||||
assertThrows(IllegalArgumentException.class, command::validateRiskAcknowledgement);
|
||||
}
|
||||
|
||||
@Test
|
||||
void 已验证路径无需风险确认即可发送() {
|
||||
FlyToPointTargetCommand command = FlyToPointTargetCommand.builder()
|
||||
.clearanceStatus("VERIFIED")
|
||||
.riskAcknowledged(false)
|
||||
.build();
|
||||
|
||||
assertDoesNotThrow(command::validateRiskAcknowledgement);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user