feat(drone-dock): 接通任务召唤与状态页并固定拍摄布局
接入 plane-status、tasks/create、shoot 与 shooting,保持同一任务 ID 串接、重复提交保护和只读单次刷新。拍摄任务页固定顶部参数与底部安全控制,中间状态区域适配小屏且不滚动;同步接口记录、脱敏响应及相关测试。
This commit is contained in:
@@ -0,0 +1,202 @@
|
||||
import Foundation
|
||||
|
||||
/// 朱工 shooting 的只读快照;完整 data 用于展示,不表示已召唤或已开始拍摄。
|
||||
struct DroneDockShootingResponse: Decodable, Equatable, Sendable {
|
||||
/// 后端若明确提供订单号则保留,不由请求上下文伪造响应身份。
|
||||
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 ui: DroneDockShootingUI?
|
||||
/// 完整 data 的格式化 JSON,保留未知字段、空值及原 JSON 类型。
|
||||
let dataJSON: String
|
||||
|
||||
/// 只映射已知展示字段,不假设响应中的任务 ID 位置。
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
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 metrics, planeStatus = "plane_status"
|
||||
}
|
||||
|
||||
/// 可选字段缺失或为 null 时保持未知;不把缺失执行门禁推断为允许。
|
||||
init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
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)
|
||||
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?
|
||||
/// 后端原始任务状态,不与订单状态混用。
|
||||
let status: Int?
|
||||
/// 服务端任务状态文案。
|
||||
let statusLabel: String?
|
||||
/// 实测航线任务状态,与订单飞行任务状态分别保留。
|
||||
let waylineStatus: Int?
|
||||
/// 服务端航线状态文案;执行失败优先于笼统的订单任务执行中。
|
||||
let waylineStatusLabel: 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"
|
||||
}
|
||||
}
|
||||
|
||||
/// 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?
|
||||
/// 服务端工作状态文案。
|
||||
let workStatusLabel: String?
|
||||
/// 服务端完整状态文案。
|
||||
let statusText: String?
|
||||
|
||||
/// 当前设备字段映射。
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case id, snNumber = "sn_number", workStatusLabel = "work_status_label", statusText = "status_text"
|
||||
}
|
||||
}
|
||||
|
||||
/// shooting 执行门禁的原始结果;false 与未知分别保留。
|
||||
struct DroneDockShootingExecuteGate: Decodable, Equatable, Sendable {
|
||||
/// 服务端明确的执行许可,不从文案或 action 推导。
|
||||
let canExecute: Bool?
|
||||
/// 服务端门禁原因码。
|
||||
let code: String?
|
||||
/// 服务端门禁说明。
|
||||
let message: String?
|
||||
/// 服务端建议动作,本阶段仅展示。
|
||||
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?
|
||||
}
|
||||
|
||||
/// 将现有 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user