feat(drone-dock): 完善真实联调、状态轮询与准备页反馈
开放 Release 真实操作并保留 Debug 拦截;恢复前台 shooting 串行轮询;统一打印机巢请求与完整原值响应;优化长点位名称、未拍摄文案、报备失败及已结束任务提示,移除成功回执 UI。补充相关测试、离线策略检查和联调说明。
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import Foundation
|
||||
|
||||
/// 拍摄任务状态及可选控制流程,始终复用同一任务;禁飞调试仅为本地模拟注入操作服务。
|
||||
/// 拍摄任务状态及可选控制流程,始终复用同一任务;Release 真实入口与隔离模拟入口按策略注入操作服务。
|
||||
final class DroneDockShootingTaskViewModel {
|
||||
/// 页面绑定的账号、景区和门店身份。
|
||||
let context: DroneDockHomeContext
|
||||
@@ -62,7 +62,7 @@ final class DroneDockShootingTaskViewModel {
|
||||
// 回查仍提供的已受理指令分别保留防重锁,避免另一条指令受理覆盖旧锁。
|
||||
private var pendingAcceptedCommands: Set<DroneDockSafetyCommand> = []
|
||||
|
||||
/// 默认只读;仅显式注入模拟操作服务时开放对应动作,当前正式入口不注入。
|
||||
/// 默认只读;仅显式注入操作服务时开放对应动作,Release 入口按授权注入。
|
||||
init(context: DroneDockHomeContext, taskID: Int, order: DroneDockHomeOrder,
|
||||
service: any DroneDockShootingServing,
|
||||
startService: (any DroneDockStartShooting)? = nil,
|
||||
@@ -85,6 +85,18 @@ final class DroneDockShootingTaskViewModel {
|
||||
await refreshSnapshot(allowWhileStarting: false)
|
||||
}
|
||||
|
||||
/// 后端建议间隔限制为 2~30 秒;缺失或无效时默认 5 秒,从上次请求结束后计时。
|
||||
var pollIntervalNanoseconds: UInt64 {
|
||||
let hint = response?.planeStatus?.pollHintMS ?? 5_000
|
||||
return UInt64(min(max(hint > 0 ? hint : 5_000, 2_000), 30_000)) * 1_000_000
|
||||
}
|
||||
|
||||
/// 身份失效或缺少任务信息时停止安排下一次读取。
|
||||
var canContinuePolling: Bool {
|
||||
!identityInvalidated && context.canLoad && taskID > 0
|
||||
&& DroneDockHomeMetric.usableText(order.orderNumber) != nil
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func refreshSnapshot(allowWhileStarting: Bool, allowWhileCommand: Bool = false,
|
||||
allowWhileResummoning: Bool = false) async {
|
||||
@@ -114,6 +126,12 @@ final class DroneDockShootingTaskViewModel {
|
||||
throw APIError.decodeFailed("拍摄任务返回的任务、订单或景区与当前页面不一致,请重新读取")
|
||||
}
|
||||
response = value
|
||||
DroneDockDiagnostics.event("shooting.snapshot_applied", taskID: taskID, fields: [
|
||||
"phase": presentation.phase.rawValue,
|
||||
"plane_id": value.currentPlane?.id as Any? ?? NSNull(),
|
||||
"can_execute": value.executeGate?.canExecute as Any? ?? NSNull(),
|
||||
"primary_action": value.executeGate?.primaryAction as Any? ?? NSNull()
|
||||
])
|
||||
if awaitingResummonSnapshot, [.navigating, .ready, .shooting, .paused, .returning, .completed].contains(resolvedDisplayPhase().0) {
|
||||
awaitingResummonSnapshot = false
|
||||
}
|
||||
@@ -121,6 +139,9 @@ final class DroneDockShootingTaskViewModel {
|
||||
} catch {
|
||||
guard accepts(requestGeneration) else { return }
|
||||
errorMessage = error is CancellationError ? nil : error.localizedDescription
|
||||
DroneDockDiagnostics.event("shooting.refresh_failed", taskID: taskID, fields: [
|
||||
"retained_snapshot": response != nil, "error": DroneDockDiagnostics.errorFields(error)
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +170,7 @@ final class DroneDockShootingTaskViewModel {
|
||||
}
|
||||
}
|
||||
|
||||
/// 只在有效读取明确到达、锁定飞机并允许 start_shoot 后开放;默认真实页面保持禁用。
|
||||
/// 只在有效读取明确到达、锁定飞机并允许 start_shoot 后开放;Debug 真实页面保持禁用。
|
||||
var canStartShooting: Bool {
|
||||
startService != nil && context.canLoad && taskID > 0 && !identityInvalidated
|
||||
&& !isLoading && !isStartingShooting && !isSendingCommand && !isResummoning && errorMessage == nil
|
||||
@@ -161,7 +182,7 @@ final class DroneDockShootingTaskViewModel {
|
||||
&& (response?.currentPlane?.id ?? 0) > 0
|
||||
}
|
||||
|
||||
/// 提交一次开拍并单次读取同任务;失败保留原快照,不轮询、不重建、不自动重发。
|
||||
/// 提交一次开拍并单次读取同任务;失败保留原快照,不重建、不自动重发控制请求。
|
||||
@MainActor
|
||||
func startShooting(onStateChange: @escaping @MainActor () -> Void = {}) async {
|
||||
guard canStartShooting, let startService else { return }
|
||||
@@ -200,6 +221,7 @@ final class DroneDockShootingTaskViewModel {
|
||||
throw APIError.decodeFailed("开始拍摄回执与当前任务或飞机不一致,请先核对任务状态")
|
||||
}
|
||||
startResponse = value
|
||||
DroneDockDiagnostics.event("start.receipt_accepted", taskID: taskID)
|
||||
hasSubmittedStart = true
|
||||
startOutcomeUnknown = false
|
||||
onStateChange()
|
||||
@@ -287,6 +309,7 @@ final class DroneDockShootingTaskViewModel {
|
||||
throw APIError.decodeFailed("安全指令回执与当前任务或指令不一致,请先核对任务状态")
|
||||
}
|
||||
commandResponse = value
|
||||
DroneDockDiagnostics.event("command.receipt_accepted", taskID: taskID)
|
||||
pendingAcceptedCommands.insert(command)
|
||||
commandOutcomeUnknown = false
|
||||
onStateChange()
|
||||
@@ -363,6 +386,7 @@ final class DroneDockShootingTaskViewModel {
|
||||
throw APIError.decodeFailed("重新召唤回执与当前任务或订单不一致,请先核对任务状态")
|
||||
}
|
||||
resummonResponse = value
|
||||
DroneDockDiagnostics.event("resummon.receipt_accepted", taskID: taskID)
|
||||
hasSubmittedResummon = true
|
||||
resummonOutcomeUnknown = false
|
||||
awaitingResummonSnapshot = true
|
||||
@@ -557,6 +581,7 @@ final class DroneDockShootingTaskViewModel {
|
||||
}
|
||||
|
||||
private func markResummonUnknown(reason: String? = nil) {
|
||||
DroneDockDiagnostics.event("resummon.outcome_unknown", taskID: taskID)
|
||||
resummonOutcomeUnknown = true
|
||||
resummonErrorMessage = (reason.map { "\($0)。" } ?? "") + "重新召唤结果待核对,请刷新任务状态,勿重复提交"
|
||||
}
|
||||
@@ -575,11 +600,13 @@ final class DroneDockShootingTaskViewModel {
|
||||
}
|
||||
|
||||
private func markCommandUnknown(reason: String? = nil) {
|
||||
DroneDockDiagnostics.event("command.outcome_unknown", taskID: taskID)
|
||||
commandOutcomeUnknown = true
|
||||
commandErrorMessage = (reason.map { "\($0)。" } ?? "") + "安全指令结果待核对,请刷新任务状态,勿重复提交"
|
||||
}
|
||||
|
||||
private func markStartUnknown(reason: String? = nil) {
|
||||
DroneDockDiagnostics.event("start.outcome_unknown", taskID: taskID)
|
||||
startOutcomeUnknown = true
|
||||
startErrorMessage = (reason.map { "\($0)。" } ?? "") + "开始拍摄结果待核对,请刷新任务状态,勿重复提交"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user