适配上传中订单并完善机巢操作与订阅兜底
支持订单状态 25 和持续拍摄、交付确认;安全指令点击后直接提交;鉴权超时保留 HTTP 兜底并退避换票重连。补充对应隔离回归测试。
This commit is contained in:
@@ -185,6 +185,13 @@ struct DroneDockHomeToday: Decodable, Equatable, Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
/// 整单履约阶段,与订单飞行任务、航线任务的数字状态分别解析。
|
||||
enum DroneDockOrderStatus: Int, Sendable {
|
||||
case executing = 20
|
||||
case uploading = 25
|
||||
case completed = 30
|
||||
}
|
||||
|
||||
/// 张工类型 25 订单摘要;操作入口取后端 can_* 权限,进入准备页仍需校验设备条件。
|
||||
struct DroneDockHomeOrder: Decodable, Equatable, Sendable {
|
||||
/// 订单号同时作为 Diffable 稳定身份,不虚构接口未提供的整数 ID。
|
||||
@@ -207,7 +214,7 @@ struct DroneDockHomeOrder: Decodable, Equatable, Sendable {
|
||||
let shotRemain: Int?
|
||||
/// 拍摄列表状态 pending、processing、completed;未知值保留。
|
||||
let shootStatus: String?
|
||||
/// 订单支付和交付状态,与飞行任务状态分开。
|
||||
/// 整单履约状态:20 执行中、25 素材上传中、30 已完成;保留未知原值。
|
||||
let orderStatus: Int?
|
||||
/// 整单原素材汇总状态。
|
||||
let materialStatus: Int?
|
||||
@@ -295,8 +302,20 @@ struct DroneDockHomeOrder: Decodable, Equatable, Sendable {
|
||||
/// 缺失项目名称时保留未知。
|
||||
var packageTitle: String { DroneDockHomeMetric.usableText(packageName) ?? "套餐信息待确认" }
|
||||
|
||||
/// 仅映射文档定义的拍摄列表状态,不根据次数推导完成。
|
||||
/// 已知整单状态;未知值仍保留在原始 orderStatus 中。
|
||||
var knownOrderStatus: DroneDockOrderStatus? { orderStatus.flatMap(DroneDockOrderStatus.init(rawValue:)) }
|
||||
|
||||
/// 执行和素材上传均为未完成订单,具体操作仍由各自后端许可决定。
|
||||
var isActiveOrderStatus: Bool { knownOrderStatus == .executing || knownOrderStatus == .uploading }
|
||||
|
||||
/// 上传、完成优先使用整单状态;执行中的未拍订单保留明确的待拍摄提示。
|
||||
var statusTitle: String {
|
||||
switch knownOrderStatus {
|
||||
case .uploading: return "素材上传中"
|
||||
case .completed: return "已完成"
|
||||
case .executing: return shootStatus == "pending" ? "待拍摄" : "执行中"
|
||||
case nil: break
|
||||
}
|
||||
switch shootStatus {
|
||||
case "pending": return "待拍摄"
|
||||
case "processing": return "进行中"
|
||||
@@ -305,6 +324,22 @@ struct DroneDockHomeOrder: Decodable, Equatable, Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
/// 卡片使用统一语义色,不把素材上传中显示为任务失败或订单已完成。
|
||||
var statusTone: DroneDockStatusTone {
|
||||
switch knownOrderStatus {
|
||||
case .uploading: return .blue
|
||||
case .completed: return .green
|
||||
case .executing: return shootStatus == "pending" ? .blue : .orange
|
||||
case nil:
|
||||
switch shootStatus {
|
||||
case "pending": return .blue
|
||||
case "processing": return .orange
|
||||
case "completed": return .green
|
||||
default: return .gray
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 逐项展示真实计数和未知占位,不把任务数当作已使用次数。
|
||||
var progressTitle: String {
|
||||
let used = shotUsed.map(String.init) ?? "—"
|
||||
@@ -326,7 +361,7 @@ struct DroneDockHomeOrder: Decodable, Equatable, Sendable {
|
||||
var canDeliverFilm: Bool {
|
||||
switch orderStatus {
|
||||
case 30: true
|
||||
case 20, nil: canUploadFilm == true
|
||||
case 20, 25, nil: canUploadFilm == true
|
||||
default: false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ enum DroneDockShootingSocketMessage {
|
||||
case subscribed(taskID: Int)
|
||||
case subscriptionMetadata(taskID: Int, hasSnapshot: Bool, executionBatch: Int?)
|
||||
case snapshot(DroneDockShootingResponse)
|
||||
case subscriptionTimedOut(message: String)
|
||||
case subscriptionRejected(code: Int, message: String)
|
||||
case rejected(code: Int, message: String)
|
||||
case unrelated
|
||||
@@ -32,10 +33,19 @@ enum DroneDockShootingSocketMessage {
|
||||
if json as? String == "Opened" { return .opened }
|
||||
guard let root = json as? [String: Any],
|
||||
let code = root["code"] as? Int else { throw APIError.invalidResponse }
|
||||
// 鉴权硬超时是服务暂不可用。合同以正式失败回执的 hint 标识,未约定专用错误码;
|
||||
// 即使返回 100099,也不能按无权限永久关闭 HTTP 和 Socket 读取。
|
||||
if let body = root["data"] as? [String: Any],
|
||||
body["type"] as? Int == 310, body["ack"] as? String == "subscribe",
|
||||
boolean(body["subscribed"]) == false,
|
||||
let hint = body["hint"] as? String, hint.contains("鉴权超时") {
|
||||
return .subscriptionTimedOut(message: hint.trimmingCharacters(in: .whitespacesAndNewlines))
|
||||
}
|
||||
if code != 100000 {
|
||||
let message = root["msg"] as? String ?? "任务订阅失败"
|
||||
if let body = root["data"] as? [String: Any],
|
||||
body["type"] as? Int == 310, boolean(body["subscribed"]) == false {
|
||||
body["type"] as? Int == 310, body["ack"] as? String == "subscribe",
|
||||
boolean(body["subscribed"]) == false {
|
||||
return .subscriptionRejected(code: code, message: message)
|
||||
}
|
||||
return .rejected(code: code, message: message)
|
||||
|
||||
@@ -201,6 +201,9 @@ final class DroneDockShootingRealtimeSession {
|
||||
log("websocket.snapshot_ignored", fields: ["reason": "old_version"])
|
||||
case .invalid: throw APIError.decodeFailed("任务快照身份或结构不一致")
|
||||
}
|
||||
case .subscriptionTimedOut(let message):
|
||||
// 收到服务端三秒鉴权超时便结束本轮等待,保留 HTTP,并退避取新票重连。
|
||||
fail(message)
|
||||
case .subscriptionRejected(let code, let message):
|
||||
// 310 明确拒绝可按错误码处理,不依赖服务端说明的语言或措辞。
|
||||
if code == 100099 { deny(message) }
|
||||
|
||||
@@ -29,7 +29,7 @@ final class DroneDockConfirmationViewModel {
|
||||
var isCompleted: Bool { detail?.order.orderStatus == 30 }
|
||||
/// 最新订单仍待游客确认;本次出码成功后,无需等详情中的确认状态更新。
|
||||
var isAwaitingConfirmation: Bool {
|
||||
detail?.order.orderStatus == 20 && (order.confirmStatus == 1 || code != nil)
|
||||
detail?.order.isActiveOrderStatus == true && (order.confirmStatus == 1 || code != nil)
|
||||
}
|
||||
/// 允许无云端成片的订单生成码,权限由服务端 can_confirm 决定。
|
||||
var canGenerate: Bool {
|
||||
@@ -178,7 +178,7 @@ final class DroneDockConfirmationViewModel {
|
||||
func validateContext() -> Bool { accepts(generation) }
|
||||
|
||||
private var permitsInvitation: Bool {
|
||||
detail?.order.orderStatus == 20 && detail?.order.canConfirm == true
|
||||
detail?.order.isActiveOrderStatus == true && detail?.order.canConfirm == true
|
||||
}
|
||||
|
||||
@MainActor
|
||||
|
||||
@@ -53,7 +53,7 @@ final class DroneDockCompactOrderCell: UICollectionViewCell {
|
||||
customerLabel.text = order.touristTitle
|
||||
orderNumberLabel.isHidden = false
|
||||
orderNumberLabel.text = "订单号 \(order.orderNumberText)"
|
||||
statusLabel.apply(title: order.statusTitle, tone: order.statusTitle == "待拍摄" ? .blue : .gray)
|
||||
statusLabel.apply(title: order.statusTitle, tone: order.statusTone)
|
||||
packageLabel.text = order.packageTitle
|
||||
packageLabel.numberOfLines = 0
|
||||
countsLabel.numberOfLines = 0
|
||||
|
||||
@@ -39,13 +39,7 @@ final class DroneDockMaterialOrderCell: UICollectionViewCell {
|
||||
/// 不根据任务数量或素材上传状态推导订单拍摄履约状态。
|
||||
func apply(order: DroneDockHomeOrder) {
|
||||
customerLabel.text = order.touristTitle
|
||||
let tone: DroneDockStatusTone = switch order.shootStatus {
|
||||
case "completed": .green
|
||||
case "processing": .blue
|
||||
case "pending": .orange
|
||||
default: .gray
|
||||
}
|
||||
statusLabel.apply(title: order.statusTitle, tone: tone)
|
||||
statusLabel.apply(title: order.statusTitle, tone: order.statusTone)
|
||||
numberLabel.text = order.orderNumberText
|
||||
let total = order.shotTotal.map(String.init) ?? "—"
|
||||
let used = order.shotUsed.map(String.init) ?? "—"
|
||||
|
||||
@@ -670,7 +670,7 @@ final class DroneDockShootingTaskViewController: GlobalLoadingPageViewController
|
||||
feedPlaceholder.apply(liveViewModel)
|
||||
}
|
||||
|
||||
/// 返航会中断任务,先明确展示其含义再提交一次。
|
||||
/// 安全动作点击后直接提交,沿用当前任务的权限与防重校验。
|
||||
private func safetyCommandTriggered(_ command: DroneDockSafetyCommand) {
|
||||
logEvent("action.safety", fields: ["command": command.rawValue, "enabled": viewModel.canSendCommand(command)])
|
||||
guard isPageVisible, isApplicationActive,
|
||||
@@ -679,24 +679,7 @@ final class DroneDockShootingTaskViewController: GlobalLoadingPageViewController
|
||||
logSafetyRejection(command, stage: "tap")
|
||||
return
|
||||
}
|
||||
if command == .returnHome {
|
||||
let simulated = simulationRecordsProvider != nil
|
||||
let alert = UIAlertController(title: simulated ? "立即返航(本地模拟)" : "立即返航",
|
||||
message: simulated
|
||||
? "模拟返航会中断本次任务。取消返航也不会恢复已经中断的任务。\n仅验证本地请求与回执,不向无人机发送指令。"
|
||||
: "返航会中断本次任务。取消返航也不会恢复已经中断的任务。确定立即返航?", preferredStyle: .alert)
|
||||
alert.addAction(UIAlertAction(title: "取消", style: .cancel) { [weak self] _ in
|
||||
self?.logEvent("action.return_confirmation.cancelled")
|
||||
})
|
||||
alert.addAction(UIAlertAction(title: simulated ? "模拟返航" : "立即返航", style: .destructive) { [weak self] _ in
|
||||
self?.logEvent("action.return_confirmation.confirmed")
|
||||
self?.sendSafetyCommand(command)
|
||||
})
|
||||
logEvent("action.return_confirmation.shown")
|
||||
present(alert, animated: true)
|
||||
} else {
|
||||
sendSafetyCommand(command)
|
||||
}
|
||||
sendSafetyCommand(command)
|
||||
}
|
||||
|
||||
/// 同步锁只覆盖同一按钮;不同安全动作可各自等待,设备确认由 ViewModel 和快照处理。
|
||||
|
||||
@@ -86,13 +86,7 @@ final class DroneShootingOrderCardView: UIView {
|
||||
metadataLabel.text = "订单号 \(order.orderNumberText) · \(createdAt)"
|
||||
packageLabel.text = order.packageTitle
|
||||
statusLabel.text = order.statusTitle
|
||||
let tone: DroneDockStatusTone = switch order.shootStatus {
|
||||
case "pending": .blue
|
||||
case "processing": .orange
|
||||
case "completed": .green
|
||||
default: .gray
|
||||
}
|
||||
applyStatusAppearance(tone: tone)
|
||||
applyStatusAppearance(tone: order.statusTone)
|
||||
|
||||
let used = order.shotUsed.map(String.init) ?? "—"
|
||||
let total = order.shotTotal.map(String.init) ?? "—"
|
||||
|
||||
Reference in New Issue
Block a user