feat(drone-dock): 展示首页真实拍摄订单
This commit is contained in:
@@ -6,8 +6,8 @@ struct DroneDockHomeResponse: Decodable, Equatable, Sendable {
|
||||
let scenicID: Int
|
||||
/// 当前景区的机巢设备,按真实非空响应的字段读取。
|
||||
let airports: [DroneDockHomeAirport]
|
||||
/// 订单原始记录;不将未知字段猜测成演示订单。
|
||||
let orders: [DroneDockHomeRecord]
|
||||
/// 按真实响应字段读取的拍摄订单,保持后端返回顺序。
|
||||
let orders: [DroneDockHomeOrder]
|
||||
/// 今日数据缺失时保留未知,不生成零值统计。
|
||||
let today: DroneDockHomeToday?
|
||||
|
||||
@@ -28,7 +28,10 @@ struct DroneDockHomeResponse: Decodable, Equatable, Sendable {
|
||||
guard Set(airports.map(\.id)).count == airports.count else {
|
||||
throw DecodingError.dataCorruptedError(forKey: .airports, in: container, debugDescription: "设备 ID 重复,无法确定设备身份")
|
||||
}
|
||||
orders = try container.decode([DroneDockHomeRecord].self, forKey: .orders)
|
||||
orders = try container.decode([DroneDockHomeOrder].self, forKey: .orders)
|
||||
guard Set(orders.map(\.orderID)).count == orders.count else {
|
||||
throw DecodingError.dataCorruptedError(forKey: .orders, in: container, debugDescription: "订单 ID 重复,无法确定订单身份")
|
||||
}
|
||||
today = try container.decodeIfPresent(DroneDockHomeToday.self, forKey: .today)
|
||||
}
|
||||
}
|
||||
@@ -153,14 +156,123 @@ struct DroneDockHomeToday: Decodable, Equatable, Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
/// 尚未取得真实样本的订单行,保留对象字段供后续精确接入和诊断。
|
||||
struct DroneDockHomeRecord: Decodable, Equatable, Sendable {
|
||||
/// 原始对象键值,不猜测订单状态或拍摄次数的字段别名。
|
||||
let fields: [String: DroneDockHomeJSONValue]
|
||||
/// 首页拍摄订单的展示数据;状态及动作仅用于呈现,不代表飞行执行许可。
|
||||
struct DroneDockHomeOrder: Decodable, Equatable, Sendable {
|
||||
/// 后端订单稳定 ID,用于 Diffable 项身份。
|
||||
let orderID: Int
|
||||
/// 后端订单编号,保留字符串形式与前导零。
|
||||
let orderNumber: String?
|
||||
/// 后端游客展示名称。
|
||||
let touristLabel: String?
|
||||
/// 后端已脱敏的游客手机号。
|
||||
let touristPhoneMask: String?
|
||||
/// 后端套餐名称,不据此推断套餐类型或项目 ID。
|
||||
let packageName: String?
|
||||
/// 后端订单状态展示文案。
|
||||
let statusLabel: String?
|
||||
/// 后端拍摄总次数,未知时不默认成零。
|
||||
let shotTotal: Int?
|
||||
/// 后端已拍摄次数,不在客户端根据任务状态重新计算。
|
||||
let shotUsed: Int?
|
||||
/// 后端剩余拍摄次数,不用总次数减已拍摄次数推断。
|
||||
let shotRemain: Int?
|
||||
/// 后端格式化的拍摄进度文案。
|
||||
let progressText: String?
|
||||
/// 后端素材状态原始值,保留尚未验证的值。
|
||||
let mediaStatus: String?
|
||||
/// 后端素材状态展示文案;空文案不生成新的业务状态。
|
||||
let mediaStatusLabel: String?
|
||||
/// 后端主动作标识,仅用于展示入口,不作为执行权限。
|
||||
let primaryAction: String?
|
||||
/// 后端主动作按钮文案。
|
||||
let primaryActionLabel: String?
|
||||
/// 后端游客用户 ID。
|
||||
let userID: Int?
|
||||
|
||||
/// 只接受 JSON 对象作为列表记录,拒绝 null、标量和嵌套数组。
|
||||
/// 已实测的首页订单字段名。
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case orderID = "order_id"
|
||||
case orderNumber = "order_number"
|
||||
case touristLabel = "tourist_label"
|
||||
case touristPhoneMask = "tourist_phone_mask"
|
||||
case packageName = "package_name"
|
||||
case statusLabel = "status_label"
|
||||
case shotTotal = "shot_total"
|
||||
case shotUsed = "shot_used"
|
||||
case shotRemain = "shot_remain"
|
||||
case progressText = "progress_text"
|
||||
case mediaStatus = "media_status"
|
||||
case mediaStatusLabel = "media_status_label"
|
||||
case primaryAction = "primary_action"
|
||||
case primaryActionLabel = "primary_action_label"
|
||||
case userID = "user_id"
|
||||
}
|
||||
|
||||
/// 严格校验列表身份和计数;缺失展示字段保留未知。
|
||||
init(from decoder: Decoder) throws {
|
||||
fields = try decoder.singleValueContainer().decode([String: DroneDockHomeJSONValue].self)
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
orderID = try container.decode(DroneDockHomeInteger.self, forKey: .orderID).value
|
||||
guard orderID > 0 else {
|
||||
throw DecodingError.dataCorruptedError(forKey: .orderID, in: container, debugDescription: "订单 ID 必须为正整数")
|
||||
}
|
||||
orderNumber = try container.decodeIfPresent(String.self, forKey: .orderNumber)
|
||||
touristLabel = try container.decodeIfPresent(String.self, forKey: .touristLabel)
|
||||
touristPhoneMask = try container.decodeIfPresent(String.self, forKey: .touristPhoneMask)
|
||||
packageName = try container.decodeIfPresent(String.self, forKey: .packageName)
|
||||
statusLabel = try container.decodeIfPresent(String.self, forKey: .statusLabel)
|
||||
shotTotal = try container.decodeIfPresent(DroneDockHomeInteger.self, forKey: .shotTotal)?.value
|
||||
shotUsed = try container.decodeIfPresent(DroneDockHomeInteger.self, forKey: .shotUsed)?.value
|
||||
shotRemain = try container.decodeIfPresent(DroneDockHomeInteger.self, forKey: .shotRemain)?.value
|
||||
for (key, value) in [(CodingKeys.shotTotal, shotTotal), (.shotUsed, shotUsed), (.shotRemain, shotRemain)] {
|
||||
if let value, value < 0 {
|
||||
throw DecodingError.dataCorruptedError(forKey: key, in: container, debugDescription: "拍摄次数不能为负数")
|
||||
}
|
||||
}
|
||||
progressText = try container.decodeIfPresent(String.self, forKey: .progressText)
|
||||
mediaStatus = try container.decodeIfPresent(String.self, forKey: .mediaStatus)
|
||||
mediaStatusLabel = try container.decodeIfPresent(String.self, forKey: .mediaStatusLabel)
|
||||
primaryAction = try container.decodeIfPresent(String.self, forKey: .primaryAction)
|
||||
primaryActionLabel = try container.decodeIfPresent(String.self, forKey: .primaryActionLabel)
|
||||
userID = try container.decodeIfPresent(DroneDockHomeInteger.self, forKey: .userID)?.value
|
||||
}
|
||||
|
||||
/// 页面稳定身份,与后端订单 ID 一致。
|
||||
var id: Int { orderID }
|
||||
|
||||
/// 展示后端订单编号;缺失时不以内部 ID 冒充订单编号。
|
||||
var orderNumberText: String { DroneDockHomeMetric.usableText(orderNumber) ?? "—" }
|
||||
|
||||
/// 优先展示服务端游客文案,其次使用已脱敏手机号。
|
||||
var touristTitle: String {
|
||||
if let label = DroneDockHomeMetric.usableText(touristLabel) { return label }
|
||||
if let phone = DroneDockHomeMetric.usableText(touristPhoneMask) { return "游客 \(phone)" }
|
||||
return "游客信息待确认"
|
||||
}
|
||||
|
||||
/// 展示后端套餐名称,缺失时不生成套餐或次数。
|
||||
var packageTitle: String { DroneDockHomeMetric.usableText(packageName) ?? "套餐信息待确认" }
|
||||
|
||||
/// 展示后端状态,缺失时不默认成待拍摄。
|
||||
var statusTitle: String { DroneDockHomeMetric.usableText(statusLabel) ?? "状态待确认" }
|
||||
|
||||
/// 优先展示后端进度文案;没有文案时逐项展示真实计数与未知占位。
|
||||
var progressTitle: String {
|
||||
if let text = DroneDockHomeMetric.usableText(progressText) { return text }
|
||||
let used = shotUsed.map(String.init) ?? "—"
|
||||
let total = shotTotal.map(String.init) ?? "—"
|
||||
let remain = shotRemain.map(String.init) ?? "—"
|
||||
return "已拍摄 \(used)/\(total) 次,剩余 \(remain) 次"
|
||||
}
|
||||
|
||||
/// 只有后端同时提供动作标识和文案时才显示按钮,不猜测缺失动作。
|
||||
var actionTitle: String? {
|
||||
guard DroneDockHomeMetric.usableText(primaryAction) != nil else { return nil }
|
||||
return DroneDockHomeMetric.usableText(primaryActionLabel)
|
||||
}
|
||||
|
||||
/// 仅展示有效的后端素材状态文案,不将空值转成未上传等新状态。
|
||||
var mediaStatusTitle: String? {
|
||||
DroneDockHomeMetric.usableText(mediaStatusLabel)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user