Files
suixinkan_uikit/suixinkan/Features/DroneDock/Models/DroneDockShootModels.swift
T
lujiuyin c1fd2d0859 feat(drone-dock): 接入图传与重召唤的本地模拟流程
新增 live 接口、状态展示和本地视频预览;支持同任务重新召唤、单次回查和防重,保留禁飞拦截。同步测试、模拟证据、后端接口确认文档及景区空境库范围约定。

验证:168 个相关用例最终均通过;最后复跑 38 项零失败。真实设备指令未发送。
2026-11-02 09:49:17 +08:00

67 lines
3.0 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Foundation
/// shoot 业务成功后的原始 data 回执,不假设或构造飞机、任务及飞行阶段字段。
struct DroneDockShootResponse: Decodable, Equatable, Sendable {
/// 完整 data JSON;nil 表示统一客户端未提供 data,不补造 null 或空对象。
let dataJSON: String?
/// 保留已格式化回执;业务成功但 data 缺失或为 null 时使用 nil。
init(dataJSON: String?) { self.dataJSON = dataJSON }
/// 支持任意真实 JSON 值,保留未知结构、空数组、布尔值及原始字段类型。
init(from decoder: Decoder) throws {
let raw = try DroneDockHomeJSONValue(from: decoder)
let encoder = JSONEncoder()
encoder.outputFormatting = [.prettyPrinted, .sortedKeys, .withoutEscapingSlashes]
dataJSON = String(decoding: try encoder.encode(DroneDockShootJSONSnapshot(value: raw)), as: UTF8.self)
}
}
/// 重新召唤回执中可核对的订单任务身份;顶层 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
/// 按真实 JSON 类型编码,不推导任务身份或追加外层业务字段。
func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
switch value {
case .object(let object): try container.encode(object.mapValues { DroneDockShootJSONSnapshot(value: $0) })
case .array(let array): try container.encode(array.map { DroneDockShootJSONSnapshot(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()
}
}
}