Files
lujiuyin 34ee60b8b2 完善机巢任务实时同步并开放双构建真实操作
订阅明确无缓存时使用新发起的有效 HTTP 全量响应衔接首包,保留任务、批次和版本校验。
移除 Debug/Release 的设备指令、图传和 RTC 构建拦截,保留后端权限、身份、防重复提交及结果未知保护。
更新开发约定并补充隔离传输、飞控状态和页面回归测试。

验证:iPhone 真机 500 项相关测试通过;iOS Release 无签名编译通过。
2026-11-05 10:59:26 +08:00

282 lines
14 KiB
Swift

import Foundation
/// 朱工 shooting 的只读快照;完整 data 用于展示,不表示已召唤或已开始拍摄。
struct DroneDockShootingResponse: Decodable, Equatable, Sendable {
/// HTTP/推送共用的顶层任务身份。
let orderFlightTaskID: Int?
/// 同一执行批次下递增的完整快照版本。
let stateVersion: Int64?
/// 当前航线执行批次,先比较批次再比较版本,防止重召唤后的旧数据回退。
let executionBatch: Int64?
/// 第一版只接收 full 完整推送。
let snapshotKind: String?
/// 后端状态写入时间,不能作为设备读数采集时间。
let stateUpdatedAt: String?
/// 设备读数采集时间,用于显示来源和核对缓存。
let metricsUpdatedAt: String?
/// 设备缓存过期时保留数值,但标为非实时读数。
let metricsStale: Bool?
/// 后端确认本批次正常拍完并开始返航;缺失表示旧合同,不能从工作态忙闲推断。
let shootCompleteReturning: Bool?
/// 后端若明确提供订单号则保留,不由请求上下文伪造响应身份。
let orderNumber: String?
/// 实测返回的订单飞行任务身份;存在时必须与请求上下文核对。
let orderFlightTask: DroneDockShootingTaskIdentity?
/// 实测返回的任务摘要,不以其状态推导控制动作。
let task: DroneDockShootingTaskIdentity?
/// 拍摄任务关联的景区信息。
let scenic: DroneDockShootingPlace?
/// 拍摄任务关联的点位信息。
let scenicSpot: DroneDockShootingPlace?
/// 拍摄任务关联的航线信息。
let airLine: DroneDockShootingAirLine?
/// 服务端给出的页面标题、游客及套餐文案。
let header: DroneDockShootingHeader?
/// 服务端给出的当前设备,不由准备页推荐设备替代。
let currentPlane: DroneDockShootingPlane?
/// 六项读数使用后端格式化文案,保留未知值与真实零值。
let metrics: [DroneDockHomeMetric]
/// 景区设备连接与轮询建议,不在客户端改选推荐飞机。
let planeStatus: DroneDockShootingPlaneStatus?
/// 执行门禁参与展示和开拍校验,缺失许可时不开放操作。
let executeGate: DroneDockShootingExecuteGate?
/// 重召唤许可独立于开拍门禁,缺失不视为允许。
let restartGate: DroneDockShootingRestartGate?
/// 当前批次设备执行状态与逐项权限,不依赖服务端显示文案。
let flightControl: DroneDockFlightControl?
/// 服务端拍摄阶段和页面提示。
let ui: DroneDockShootingUI?
/// 完整 data 的格式化 JSON,保留未知字段、空值及原 JSON 类型。
let dataJSON: String
/// 只映射已知展示字段,不假设响应中的任务 ID 位置。
private enum CodingKeys: String, CodingKey {
case orderFlightTaskID = "order_flight_task_id", stateVersion = "state_version"
case executionBatch = "execution_batch", snapshotKind = "snapshot_kind"
case stateUpdatedAt = "state_updated_at", metricsUpdatedAt = "metrics_updated_at", metricsStale = "metrics_stale"
case shootCompleteReturning = "shoot_complete_returning"
case orderNumber = "order_number", orderFlightTask = "order_flight_task", task
case scenic, scenicSpot = "scenic_spot", airLine = "air_line"
case header, currentPlane = "current_plane", executeGate = "execute_gate", ui
case restartGate = "restart_gate", flightControl = "flight_control"
case metrics, planeStatus = "plane_status"
}
/// 可选字段缺失或为 null 时保持未知;不把缺失执行门禁推断为允许。
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
orderFlightTaskID = try container.decodeIfPresent(Int.self, forKey: .orderFlightTaskID)
stateVersion = try container.decodeIfPresent(Int64.self, forKey: .stateVersion)
executionBatch = try container.decodeIfPresent(Int64.self, forKey: .executionBatch)
snapshotKind = try container.decodeIfPresent(String.self, forKey: .snapshotKind)
stateUpdatedAt = try container.decodeIfPresent(String.self, forKey: .stateUpdatedAt)
metricsUpdatedAt = try container.decodeIfPresent(String.self, forKey: .metricsUpdatedAt)
metricsStale = try container.decodeIfPresent(Bool.self, forKey: .metricsStale)
shootCompleteReturning = try container.decodeIfPresent(Bool.self, forKey: .shootCompleteReturning)
orderNumber = try container.decodeIfPresent(String.self, forKey: .orderNumber)
orderFlightTask = try container.decodeIfPresent(DroneDockShootingTaskIdentity.self, forKey: .orderFlightTask)
task = try container.decodeIfPresent(DroneDockShootingTaskIdentity.self, forKey: .task)
scenic = try container.decodeIfPresent(DroneDockShootingPlace.self, forKey: .scenic)
scenicSpot = try container.decodeIfPresent(DroneDockShootingPlace.self, forKey: .scenicSpot)
airLine = try container.decodeIfPresent(DroneDockShootingAirLine.self, forKey: .airLine)
header = try container.decodeIfPresent(DroneDockShootingHeader.self, forKey: .header)
currentPlane = try container.decodeIfPresent(DroneDockShootingPlane.self, forKey: .currentPlane)
metrics = try container.decodeIfPresent([DroneDockHomeMetric].self, forKey: .metrics) ?? []
planeStatus = try container.decodeIfPresent(DroneDockShootingPlaneStatus.self, forKey: .planeStatus)
executeGate = try container.decodeIfPresent(DroneDockShootingExecuteGate.self, forKey: .executeGate)
restartGate = try container.decodeIfPresent(DroneDockShootingRestartGate.self, forKey: .restartGate)
flightControl = try container.decodeIfPresent(DroneDockFlightControl.self, forKey: .flightControl)
ui = try container.decodeIfPresent(DroneDockShootingUI.self, forKey: .ui)
let raw = try DroneDockHomeJSONValue(from: decoder)
let encoder = JSONEncoder()
encoder.outputFormatting = [.prettyPrinted, .sortedKeys, .withoutEscapingSlashes]
dataJSON = String(decoding: try encoder.encode(DroneDockShootingJSONSnapshot(value: raw)), as: UTF8.self)
}
}
/// shooting 实测返回的已有任务身份和状态摘要,各身份仅在实际提供时参与核对。
struct DroneDockShootingTaskIdentity: Decodable, Equatable, Sendable {
/// 订单飞行任务 ID。
let id: Int?
/// 任务所属订单号。
let orderNumber: String?
/// 任务所属景区。
let scenicID: Int?
/// 订单飞行任务状态:10 待执行、20 执行中、25 素材上传中、30 成功、40 失败、50 取消、60 待确认。
let status: Int?
/// 服务端任务状态文案。
let statusLabel: String?
/// 航线状态独立保留:29/39/49/91 失败,90 取消,24/30/40 为录制后的素材处理。
let waylineStatus: Int?
/// 服务端航线状态文案;执行失败优先于笼统的订单任务执行中。
let waylineStatusLabel: String?
/// 服务端实际记录的任务结果原因,空值不视为具体失败说明。
let resultMessage: String?
/// 任务结果原因码;return_home 表示手动返航中断,不能展示正常拍完提示。
let resultCode: String?
/// 已确认嵌套任务字段映射。
private enum CodingKeys: String, CodingKey {
case id, orderNumber = "order_number", scenicID = "scenic_id", status, statusLabel = "status_label"
case waylineStatus = "wayline_status", waylineStatusLabel = "wayline_status_label"
case resultMessage = "result_message"
case resultCode = "result_code"
}
}
/// shooting 的设备轮询提示与连接结果;缺失布尔保持未知。
struct DroneDockShootingPlaneStatus: Decodable, Equatable, Sendable {
/// 后端实际提供的设备列表所属景区。
let scenicID: Int?
/// 后端景区连接状态。
let connected: Bool?
/// 后端建议轮询间隔,任务页校验并限制频率后使用。
let pollHintMS: Int?
/// 设备快照字段映射,其余字段仍保留在完整 dataJSON 中。
private enum CodingKeys: String, CodingKey {
case scenicID = "scenic_id", connected, pollHintMS = "poll_hint_ms"
}
}
/// shooting 返回的景区或点位信息,缺失身份不由客户端补齐。
struct DroneDockShootingPlace: Decodable, Equatable, Sendable {
/// 服务端场景身份,未知时为 nil。
let id: Int?
/// 服务端显示名称。
let name: String?
}
/// shooting 返回的航线及其所属点位。
struct DroneDockShootingAirLine: Decodable, Equatable, Sendable {
/// 服务端航线身份。
let id: Int?
/// 服务端航线名称。
let name: String?
/// 航线所属点位,不用于推导当前任务 ID。
let scenicSpotID: Int?
/// 航线字段映射。
private enum CodingKeys: String, CodingKey { case id, name, scenicSpotID = "scenic_spot_id" }
}
/// shooting 拍摄页的服务端摘要文案。
struct DroneDockShootingHeader: Decodable, Equatable, Sendable {
/// 实测摘要返回的订单身份,不能忽略其与请求订单的一致性。
let orderNumber: String?
/// 页面主标题。
let title: String?
/// 服务端提供的游客显示文案。
let touristLabel: String?
/// 订单套餐显示文案。
let packageName: String?
/// 页面摘要字段映射。
private enum CodingKeys: String, CodingKey {
case orderNumber = "order_number", title, touristLabel = "tourist_label", packageName = "package_name"
}
}
/// shooting 当前设备的展示信息,不代表调用方已发送飞行指令。
struct DroneDockShootingPlane: Decodable, Equatable, Sendable {
/// 当前设备身份。
let id: Int?
/// 当前设备序列号。
let snNumber: String?
/// 飞机表在线标记:1 在线,0/2 等非 1 为离线;不覆盖明确的机巢工作态。
let onlineStatus: Int?
/// 文档工作状态:0 离线、1 空闲、2 拍摄中;不据此推断返航完成。
let workStatus: Int?
/// 服务端工作状态文案。
let workStatusLabel: String?
/// 服务端完整状态文案。
let statusText: String?
/// 当前设备字段映射。
private enum CodingKeys: String, CodingKey {
case id, snNumber = "sn_number", workStatusLabel = "work_status_label", statusText = "status_text"
case onlineStatus = "online_status", workStatus = "work_status"
}
}
/// shooting 执行门禁的原始结果;false 与未知分别保留。
struct DroneDockShootingExecuteGate: Decodable, Equatable, Sendable {
/// 服务端明确的执行许可,不从文案或 action 推导。
let canExecute: Bool?
/// 服务端门禁原因码。
let code: String?
/// 服务端门禁说明。
let message: String?
/// 服务端建议动作;本地模拟开拍要求明确为 start_shoot。
let primaryAction: String?
/// 服务端建议动作名称。
let primaryActionLabel: String?
/// 门禁字段映射。
private enum CodingKeys: String, CodingKey {
case canExecute = "can_execute", code, message
case primaryAction = "primary_action", primaryActionLabel = "primary_action_label"
}
}
/// shooting 返回的拍摄阶段显示信息。
struct DroneDockShootingUI: Decodable, Equatable, Sendable {
/// 原始阶段标识,未知值原样保留。
let phase: String?
/// 服务端页面提示。
let title: String?
/// 服务端阶段说明,不由 GET 请求成功拼造飞行进度。
let message: String?
/// 拍摄环节子阶段,shoot_done_returning 表示正常拍完后开始返航。
let waylineStage: String?
/// 页面层的正常拍完返航标记,和顶层字段共同保留。
let shootCompleteReturning: Bool?
/// 服务端实际提供的安全指令;缺失时保持未知,不据阶段文案自行补齐。
let commands: [DroneDockShootingCommand]?
/// 保留既有展示构造方式,新增动作列表默认为未知。
init(phase: String?, title: String?, message: String?, commands: [DroneDockShootingCommand]? = nil,
waylineStage: String? = nil, shootCompleteReturning: Bool? = nil) {
self.phase = phase
self.title = title
self.message = message
self.commands = commands
self.waylineStage = waylineStage
self.shootCompleteReturning = shootCompleteReturning
}
/// 保留现有页面字段,并映射新增返航标记的原始命名。
private enum CodingKeys: String, CodingKey {
case phase, title, message, commands
case waylineStage = "wayline_stage", shootCompleteReturning = "shoot_complete_returning"
}
}
/// shooting 或 start-shoot 的指令展示项;原始字符串保留,执行时另作白名单校验。
struct DroneDockShootingCommand: Decodable, Equatable, Sendable {
/// 服务端指令码,未知值不应开放动作。
let command: String?
/// 服务端按钮标题。
let label: String?
/// 服务端按钮副标题。
let sub: String?
}
/// 将现有 JSON 值解码结果重新格式化,完整保留 shooting 的未建模字段。
private struct DroneDockShootingJSONSnapshot: Encodable {
let value: DroneDockHomeJSONValue
/// 保留字符串、数字、布尔、null 及嵌套结构,不添加外层业务包裹。
func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
switch value {
case .object(let object): try container.encode(object.mapValues { DroneDockShootingJSONSnapshot(value: $0) })
case .array(let array): try container.encode(array.map { DroneDockShootingJSONSnapshot(value: $0) })
case .string(let text): try container.encode(text)
case .number(let number): try container.encode(number)
case .bool(let flag): try container.encode(flag)
case .null: try container.encodeNil()
}
}
}