Files
suixinkan_uikit/suixinkan/Features/ScenicMaterials/Models/ScenicMaterialsAPIModels.swift
T
lujiuyin b95b251de1 feat: 完善机巢模拟调试与素材交付交互
增加禁飞期间的设备指令拦截及本地模拟拍摄流程;适配订单素材库和景区空境库,完善素材筛选、预览与下载;订单交付入口改为方式选择弹窗并复用云端上传。补充单元测试、接口记录和模拟器截图。
2026-10-30 09:59:11 +08:00

114 lines
5.4 KiB
Swift

import Foundation
/// 场次接口中已由部署响应确认的分页和保留策略;子项保留原始字段供合同映射使用。
struct ScenicMaterialsSessionsResponse: Decodable, Equatable, Sendable {
/// 当前页场次原始对象,不能把未确认的子项结构当成空列表。
let list: [[String: ScenicMaterialsJSONValue]]
/// 服务端航线分组原始对象。
let groups: [[String: ScenicMaterialsJSONValue]]
/// 当前筛选场次总数。
let total: Int
/// 服务端实际返回的页码。
let page: Int
/// 服务端实际返回的每页数量。
let pageSize: Int
/// 本次查询的素材保留窗口。
let retentionDays: Int
/// 服务端提供的保留期提示。
let retentionTips: String
/// 服务端实际应用的筛选。
let filter: ScenicMaterialsFilter
/// 当前景区可用的航线筛选对象。
let airLines: [[String: ScenicMaterialsJSONValue]]
/// 部署接口的根字段。
private enum CodingKeys: String, CodingKey {
case list, groups, total, page, pageSize = "page_size", retentionDays = "retention_days"
case retentionTips = "retention_tips", filter, filterOptions = "filter_options"
}
/// 只接受真实容器和有效分页,避免缺字段响应被误显示成空态。
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
list = try container.decode([[String: ScenicMaterialsJSONValue]].self, forKey: .list)
groups = try container.decode([[String: ScenicMaterialsJSONValue]].self, forKey: .groups)
total = try container.decode(Int.self, forKey: .total)
page = try container.decode(Int.self, forKey: .page)
pageSize = try container.decode(Int.self, forKey: .pageSize)
retentionDays = try container.decode(Int.self, forKey: .retentionDays)
retentionTips = try container.decode(String.self, forKey: .retentionTips)
filter = try container.decode(ScenicMaterialsFilter.self, forKey: .filter)
airLines = try container.decode(ScenicMaterialsFilterOptions.self, forKey: .filterOptions).airLines
guard total >= 0, page > 0, (1...100).contains(pageSize), (1...365).contains(retentionDays),
list.count <= pageSize, list.count <= total else {
throw DecodingError.dataCorruptedError(forKey: .list, in: container, debugDescription: "空境库场次分页或保留期无效")
}
}
}
/// 后端实际应用的筛选,全部航线为 0、全部日期为空字符串。
struct ScenicMaterialsFilter: Decodable, Equatable, Sendable {
/// 当前航线筛选值。
let airLineID: Int
/// 当前起始日期筛选值。
let dateFrom: String
/// 当前结束日期筛选值。
let dateTo: String
/// 部署响应中的筛选字段。
private enum CodingKeys: String, CodingKey {
case airLineID = "air_line_id", dateFrom = "date_from", dateTo = "date_to"
}
}
/// filter_options 下独立返回当前景区的航线集合。
private struct ScenicMaterialsFilterOptions: Decodable {
let airLines: [[String: ScenicMaterialsJSONValue]]
/// 部署响应中的航线容器。
private enum CodingKeys: String, CodingKey { case airLines = "air_lines" }
}
/// 场次详情的已确认素材数组及完整场次信息,不借用订单素材 ID 模型。
struct ScenicMaterialsSessionDetailResponse: Decodable, Equatable, Sendable {
/// 文档明确返回的全部素材项,保留服务端所有字段。
let materials: [[String: ScenicMaterialsJSONValue]]
/// 场次详情完整对象,供依据实际合同解码归属与展示信息。
let fields: [String: ScenicMaterialsJSONValue]
/// 缺少 materials 或容器错误时报错,不伪装成没有素材。
init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
fields = try container.decode([String: ScenicMaterialsJSONValue].self)
guard case let .array(values)? = fields["materials"] else {
throw DecodingError.dataCorruptedError(in: container, debugDescription: "空境场次详情缺少 materials 数组")
}
materials = try values.map { value in
guard case let .object(fields) = value else {
throw DecodingError.dataCorruptedError(in: container, debugDescription: "空境素材必须为对象")
}
return fields
}
}
}
/// 保留空境库尚未完整描述的子项 JSON,不猜测字段类型或单位。
indirect enum ScenicMaterialsJSONValue: Decodable, Equatable, Sendable {
case object([String: ScenicMaterialsJSONValue])
case array([ScenicMaterialsJSONValue])
case string(String)
case number(Decimal)
case bool(Bool)
case null
/// 按真实 JSON 类型读取,未知字段不会静默丢失。
init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
if container.decodeNil() { self = .null }
else if let value = try? container.decode(Bool.self) { self = .bool(value) }
else if let value = try? container.decode(String.self) { self = .string(value) }
else if let value = try? container.decode(Decimal.self) { self = .number(value) }
else if let value = try? container.decode([String: ScenicMaterialsJSONValue].self) { self = .object(value) }
else { self = .array(try container.decode([ScenicMaterialsJSONValue].self)) }
}
}