完善机巢任务实时同步并开放双构建真实操作

订阅明确无缓存时使用新发起的有效 HTTP 全量响应衔接首包,保留任务、批次和版本校验。
移除 Debug/Release 的设备指令、图传和 RTC 构建拦截,保留后端权限、身份、防重复提交及结果未知保护。
更新开发约定并补充隔离传输、飞控状态和页面回归测试。

验证:iPhone 真机 500 项相关测试通过;iOS Release 无签名编译通过。
This commit is contained in:
2026-11-05 10:59:26 +08:00
parent 477bf611e6
commit 34ee60b8b2
46 changed files with 914 additions and 461 deletions
@@ -108,9 +108,7 @@ final class DroneDockShootingTaskViewModel {
self.hasInitialTravelReceipt = context.canLoad && initialSummonReceipt?.confirmsTravel(
taskID: taskID, orderNumber: order.orderNumber, scenicID: context.scenicID) == true
recordTaskEvent("task.created", fields: ["initial_travel_receipt": hasInitialTravelReceipt,
"summon_receipt": DroneDockTaskTraceFields.summon(initialSummonReceipt),
"debug_flight_blocked": DeviceCommandDebugPolicy.blocksFlightRequests,
"debug_live_blocked": DeviceCommandDebugPolicy.blocksLiveRequests])
"summon_receipt": DroneDockTaskTraceFields.summon(initialSummonReceipt)])
}
/// 页面与业务层共享会话标识,串联准备页导航、快照和按钮事件。
@@ -154,6 +152,12 @@ final class DroneDockShootingTaskViewModel {
await refreshSnapshot(allowWhileStarting: false)
}
/// 无缓存订阅只认此调用新读取且采纳的 HTTP 结果;读取未发起、失败或旧版本均返回 nil。
@MainActor
func refreshForRealtimeSeed() async -> DroneDockHTTPSnapshotResult? {
await refreshSnapshot(allowWhileStarting: false)
}
/// 操作提交前仅作废在途读取,保留快照和操作防重锁;迟到的旧读取不能覆盖操作回查。
@MainActor
func invalidatePendingRefresh() {
@@ -174,10 +178,11 @@ final class DroneDockShootingTaskViewModel {
}
@MainActor
@discardableResult
private func refreshSnapshot(allowWhileStarting: Bool, allowWhileCommand: Bool = false,
allowWhileResummoning: Bool = false) async {
allowWhileResummoning: Bool = false) async -> DroneDockHTTPSnapshotResult? {
guard !isLoading, !identityInvalidated, readAccessError == nil, !isStartingShooting || allowWhileStarting,
!isResummoning || allowWhileResummoning else { return }
!isResummoning || allowWhileResummoning else { return nil }
generation &+= 1
let requestGeneration = generation
let revisionAtRequest = snapshotRevision
@@ -189,12 +194,12 @@ final class DroneDockShootingTaskViewModel {
isLoading = false
}
}
guard accepts(requestGeneration) else { return }
guard accepts(requestGeneration) else { return nil }
guard context.canLoad, taskID > 0,
DroneDockHomeMetric.usableText(order.orderNumber) != nil else {
response = nil
errorMessage = "缺少有效任务、订单或景区信息,请返回工作台重新进入"
return
return nil
}
do {
let value = try await service.shooting(taskID: taskID, liveBattery: false)
@@ -202,24 +207,31 @@ final class DroneDockShootingTaskViewModel {
recordTaskEvent("snapshot.http_ignored", fields: ["read_generation": requestGeneration,
"current_generation": generation, "reason": "cancelled_or_stale_read",
"incoming": DroneDockTaskTraceFields.snapshot(value)])
return
return nil
}
if applyTaskSnapshot(value, source: .http) == .invalid {
let acceptance = applyTaskSnapshot(value, source: .http)
if acceptance == .invalid {
response = nil
throw APIError.decodeFailed("拍摄任务返回的任务、订单或景区与当前页面不一致,请重新读取")
}
switch acceptance {
case .applied, .duplicate:
return DroneDockHTTPSnapshotResult(snapshot: value, acceptance: acceptance)
case .outdated, .invalid: return nil
}
} catch {
guard accepts(requestGeneration) else { return }
guard accepts(requestGeneration) else { return nil }
if Self.stopsTaskReading(error) {
stopReading(message: error.localizedDescription)
return
return nil
}
// 迟到 HTTP 失败不能覆盖请求期间已收到的有效实时状态。
guard snapshotRevision == revisionAtRequest else { return }
guard snapshotRevision == revisionAtRequest else { return nil }
if !(error is CancellationError) { errorMessage = error.localizedDescription }
recordTaskEvent("snapshot.http_failed", fields: [
"retained_snapshot": response != nil, "error": DroneDockDiagnostics.errorFields(error)
])
return nil
}
}
@@ -353,7 +365,7 @@ final class DroneDockShootingTaskViewModel {
}
}
/// 只在有效读取明确到达、锁定飞机并允许 start_shoot 后开放;Debug 真实页面保持禁用。
/// 只在有效读取明确到达、锁定飞机并允许 start_shoot 后开放。
var canStartShooting: Bool {
startService != nil && context.canLoad && taskID > 0 && !identityInvalidated
&& hasControlSnapshotIdentity
@@ -418,11 +430,8 @@ final class DroneDockShootingTaskViewModel {
guard acceptsStart(requestGeneration) else { return }
await refreshSnapshot(allowWhileStarting: true)
} catch {
if error is DeviceCommandDebugBlockedError, startGeneration == requestGeneration { didSendStart = false }
guard acceptsStart(requestGeneration) else { return }
if error is DeviceCommandDebugBlockedError {
startErrorMessage = DeviceCommandDebugPolicy.blockedMessage
} else if case APIError.serverCode = error {
if case APIError.serverCode = error {
startErrorMessage = error.localizedDescription
} else {
markStartUnknown(reason: error.localizedDescription)
@@ -629,10 +638,7 @@ final class DroneDockShootingTaskViewModel {
fields: ["reason": "stale_task_context", "error": DroneDockDiagnostics.errorFields(error)])
return
}
if error is DeviceCommandDebugBlockedError {
commandOperations[operation.command]?.phase = .finished
commandOperations[operation.command]?.error = DeviceCommandDebugPolicy.blockedMessage
} else if case APIError.serverCode = error {
if case APIError.serverCode = error {
commandOperations[operation.command]?.phase = .finished
commandOperations[operation.command]?.error = error.localizedDescription
} else {
@@ -731,11 +737,8 @@ final class DroneDockShootingTaskViewModel {
guard acceptsResummon(requestGeneration) else { return }
await refreshSnapshot(allowWhileStarting: false, allowWhileResummoning: true)
} catch {
if error is DeviceCommandDebugBlockedError, resummonGeneration == requestGeneration { didSendResummon = false }
guard acceptsResummon(requestGeneration) else { return }
if error is DeviceCommandDebugBlockedError {
resummonErrorMessage = DeviceCommandDebugPolicy.blockedMessage
} else if case APIError.serverCode = error {
if case APIError.serverCode = error {
didSendResummon = false
resummonErrorMessage = error.localizedDescription
} else {