feat(drone-dock): 接入图传与重召唤的本地模拟流程

新增 live 接口、状态展示和本地视频预览;支持同任务重新召唤、单次回查和防重,保留禁飞拦截。同步测试、模拟证据、后端接口确认文档及景区空境库范围约定。

验证:168 个相关用例最终均通过;最后复跑 38 项零失败。真实设备指令未发送。
This commit is contained in:
2026-11-02 09:49:17 +08:00
parent 2913273e35
commit c1fd2d0859
33 changed files with 3246 additions and 84 deletions
@@ -0,0 +1,68 @@
import Foundation
/// live 文档已明确的任务与设备回执;当前合同没有可用于播放的字段。
struct DroneDockLiveResponse: Decodable, Equatable, Sendable {
/// 后端回显的订单飞行任务 ID,不能用请求值补齐。
let orderFlightTaskID: Int
/// 设备明细尚未定义字段,保留原 JSON 类型。
let airport: DroneDockHomeJSONValue?
/// 无人机明细尚未定义字段,保留原 JSON 类型。
let drone: DroneDockHomeJSONValue?
/// 文档中的任务摘要,若提供身份必须与顶层任务一致。
let task: DroneDockShootingTaskIdentity?
/// 已锁定机场序列号,不用于客户端选择或重新绑定设备。
let airportSN: String?
/// 随接口返回的展示读数,不触发额外实时采集。
let metrics: [DroneDockHomeMetric]
/// 完整回执,包含尚未建模字段,不解释成播放器配置。
let dataJSON: String
/// live 文档中的已知字段映射。
private enum CodingKeys: String, CodingKey {
case orderFlightTaskID = "order_flight_task_id", airport, drone, task
case airportSN = "airport_sn", metrics
}
/// 任务 ID 必须明确提供;未知字段及 null 留在完整 JSON 中供后续合同核对。
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
orderFlightTaskID = try container.decode(Int.self, forKey: .orderFlightTaskID)
airport = try container.decodeIfPresent(DroneDockHomeJSONValue.self, forKey: .airport)
drone = try container.decodeIfPresent(DroneDockHomeJSONValue.self, forKey: .drone)
task = try container.decodeIfPresent(DroneDockShootingTaskIdentity.self, forKey: .task)
airportSN = try container.decodeIfPresent(String.self, forKey: .airportSN)
metrics = try container.decodeIfPresent([DroneDockHomeMetric].self, forKey: .metrics) ?? []
let raw = try DroneDockHomeJSONValue(from: decoder)
let encoder = JSONEncoder()
encoder.outputFormatting = [.prettyPrinted, .sortedKeys, .withoutEscapingSlashes]
dataJSON = String(decoding: try encoder.encode(DroneDockLiveJSONSnapshot(value: raw)), as: UTF8.self)
}
}
/// 只负责原样编码解码所得的 JSON,不追加猜测的流媒体参数。
private struct DroneDockLiveJSONSnapshot: Encodable {
let value: DroneDockHomeJSONValue
/// 保持字典、数组、空值、数值与字符串的原始类型。
func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
switch value {
case .object(let value): try container.encode(value.mapValues { Self(value: $0) })
case .array(let value): try container.encode(value.map { Self(value: $0) })
case .string(let value): try container.encode(value)
case .number(let value): try container.encode(value)
case .bool(let value): try container.encode(value)
case .null: try container.encodeNil()
}
}
}
/// 图传区域的明确状态;本地视频预览不代表设备连接或真实图传成功。
enum DroneDockLiveState: Equatable, Sendable {
case restricted
case idle
case loading
case unavailable(String)
case failed(String)
case localPreview(URL)
}
@@ -17,6 +17,36 @@ struct DroneDockShootResponse: Decodable, Equatable, Sendable {
}
}
/// 重新召唤回执中可核对的订单任务身份;顶层 task_id 属于实际航线任务,不作订单任务 ID 使用。
struct DroneDockResummonReceiptIdentity: Decodable, Sendable {
/// 后端明确回显的订单飞行任务 ID,缺失时由后续 shooting 核对。
let orderFlightTaskID: Int?
/// 后端已提供的订单任务摘要身份。
let orderFlightTask: TaskIdentity?
/// 已锁定任务的飞机 ID;实际提供时核对是否仍为原任务飞机。
let planeID: Int?
/// 只读取已约定的订单任务身份字段。
private enum CodingKeys: String, CodingKey {
case orderFlightTaskID = "order_flight_task_id", orderFlightTask = "order_flight_task", planeID = "plane_id"
}
/// 嵌套订单任务的可选身份字段,不读取或推断设备执行阶段。
struct TaskIdentity: Decodable, Sendable {
/// 原订单飞行任务 ID。
let id: Int?
/// 任务所属订单。
let orderNumber: String?
/// 任务所属景区。
let scenicID: Int?
/// 订单任务摘要字段映射。
private enum CodingKeys: String, CodingKey {
case id, orderNumber = "order_number", scenicID = "scenic_id"
}
}
}
/// 将现有 JSON 值解码结果格式化,完整保留 shoot 尚未约定的成功数据结构。
private struct DroneDockShootJSONSnapshot: Encodable {
let value: DroneDockHomeJSONValue