feat(drone-dock): 完善真实联调、状态轮询与准备页反馈
开放 Release 真实操作并保留 Debug 拦截;恢复前台 shooting 串行轮询;统一打印机巢请求与完整原值响应;优化长点位名称、未拍摄文案、报备失败及已结束任务提示,移除成功回执 UI。补充相关测试、离线策略检查和联调说明。
This commit is contained in:
@@ -38,6 +38,20 @@ final class DroneDockPreparationViewModel {
|
||||
private(set) var shootErrorMessage: String?
|
||||
/// 召唤写请求结果不明确时禁止重发,等待后续核对任务状态。
|
||||
private(set) var summonOutcomeUnknown = false
|
||||
/// 后端明确说明原任务已结束时,转为查看原任务,禁止继续重复首次召唤。
|
||||
private(set) var summonRequiresTaskReview = false
|
||||
|
||||
/// 创建失败的用户提示;成功回执仅供业务与日志使用,不在页面输出。
|
||||
var creationFailure: DroneDockPreparationFailure? {
|
||||
guard createdTask == nil, let message = taskCreationErrorMessage else { return nil }
|
||||
return DroneDockPreparationFailure(message: message, stage: .creation, outcomeUnknown: taskCreationOutcomeUnknown)
|
||||
}
|
||||
|
||||
/// 召唤失败与创建失败分开表达,保留已经创建的任务。
|
||||
var summonFailure: DroneDockPreparationFailure? {
|
||||
guard let message = shootErrorMessage else { return nil }
|
||||
return DroneDockPreparationFailure(message: message, stage: .summon, outcomeUnknown: summonOutcomeUnknown)
|
||||
}
|
||||
|
||||
private let service: any DroneDockPreparationServing
|
||||
private let planeStatusService: any DroneDockPlaneStatusServing
|
||||
@@ -96,18 +110,18 @@ final class DroneDockPreparationViewModel {
|
||||
var isTaskSelectionLocked: Bool {
|
||||
isCreatingTask || isSummoning || isPerformingPrimaryAction || hasCreatedTask || taskCreationOutcomeUnknown
|
||||
}
|
||||
/// 仅展示真实返回的 data JSON,不拼造业务包裹或召唤结果。
|
||||
/// 为诊断保留实际 data JSON,正式准备页不展示此内容。
|
||||
var creationDataJSON: String? { createdTask?.dataJSON }
|
||||
/// 仅保留 shoot 实际返回的 data;缺失时不拼造成功 JSON。
|
||||
var shootDataJSON: String? { shootResponse?.dataJSON }
|
||||
/// 创建回执携带的最新订单摘要优先于创建前购买摘要。
|
||||
var latestOrderSummary: DroneDockHomeOrder? { createdTask?.order ?? projectInfo?.order }
|
||||
|
||||
/// 召唤已明确受理后只允许查看原任务,导航与再次提交召唤分开判断。
|
||||
/// 已受理或后端明确要求核对已结束的任务时允许查看,导航不重复提交召唤。
|
||||
var canOpenShootingTask: Bool {
|
||||
context.canLoad && !creationContextInvalidated && !isLoading && !isCreatingTask
|
||||
&& !isSummoning && !isPerformingPrimaryAction && !taskCreationOutcomeUnknown
|
||||
&& !summonOutcomeUnknown && hasSubmittedSummon && shootResponse != nil
|
||||
&& !summonOutcomeUnknown && ((hasSubmittedSummon && shootResponse != nil) || summonRequiresTaskReview)
|
||||
&& (createdTask?.taskID ?? 0) > 0
|
||||
}
|
||||
|
||||
@@ -115,7 +129,7 @@ final class DroneDockPreparationViewModel {
|
||||
var isPrimaryActionEnabled: Bool {
|
||||
guard allowsTaskSubmission, context.canLoad, !creationContextInvalidated, !isLoading, !isCreatingTask,
|
||||
!isSummoning, !isPerformingPrimaryAction, !taskCreationOutcomeUnknown,
|
||||
!hasSubmittedSummon, !summonOutcomeUnknown else { return false }
|
||||
!hasSubmittedSummon, !summonOutcomeUnknown, !summonRequiresTaskReview else { return false }
|
||||
if let createdTask { return createdTask.taskID > 0 }
|
||||
return canCreateTask
|
||||
}
|
||||
@@ -166,6 +180,7 @@ final class DroneDockPreparationViewModel {
|
||||
let response = try await shootService.shoot(taskID: taskID)
|
||||
guard acceptsSummon(requestGeneration, taskID: taskID) else { return }
|
||||
shootResponse = response
|
||||
DroneDockDiagnostics.event("summon.receipt_accepted", taskID: taskID)
|
||||
hasSubmittedSummon = true
|
||||
summonOutcomeUnknown = false
|
||||
} catch {
|
||||
@@ -177,6 +192,7 @@ final class DroneDockPreparationViewModel {
|
||||
shootErrorMessage = DeviceCommandDebugPolicy.blockedMessage
|
||||
} else if case APIError.serverCode = error {
|
||||
shootErrorMessage = error.localizedDescription
|
||||
summonRequiresTaskReview = DroneDockPreparationFailure.requiresTaskReview(error.localizedDescription)
|
||||
} else {
|
||||
markSummonUnknown(reason: error.localizedDescription)
|
||||
}
|
||||
@@ -195,6 +211,7 @@ final class DroneDockPreparationViewModel {
|
||||
if creationContextInvalidated {
|
||||
shootResponse = nil
|
||||
shootErrorMessage = nil
|
||||
summonRequiresTaskReview = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,6 +264,7 @@ final class DroneDockPreparationViewModel {
|
||||
throw APIError.decodeFailed("创建回执与当前订单或项目不一致,请核对任务")
|
||||
}
|
||||
createdTask = response
|
||||
DroneDockDiagnostics.event("create.receipt_accepted", taskID: response.taskID)
|
||||
hasCreatedTask = true
|
||||
taskCreationOutcomeUnknown = false
|
||||
} catch {
|
||||
@@ -430,7 +448,7 @@ final class DroneDockPreparationViewModel {
|
||||
var primaryButtonTitle: String {
|
||||
if isCreatingTask { return "正在创建任务…" }
|
||||
if isSummoning { return "正在召唤无人机…" }
|
||||
if hasSubmittedSummon { return "查看拍摄任务" }
|
||||
if hasSubmittedSummon || summonRequiresTaskReview { return "查看拍摄任务" }
|
||||
if !allowsTaskSubmission { return "仅限模拟调试" }
|
||||
if summonOutcomeUnknown { return "召唤结果待核对" }
|
||||
if hasCreatedTask { return shootErrorMessage == nil ? "确认并召唤" : "重试召唤" }
|
||||
@@ -445,13 +463,13 @@ final class DroneDockPreparationViewModel {
|
||||
if isSummoning { return "任务已创建,正在提交召唤请求" }
|
||||
if creationContextInvalidated, let errorMessage { return errorMessage }
|
||||
if !allowsTaskSubmission && !hasSubmittedSummon { return DeviceCommandDebugPolicy.blockedMessage }
|
||||
if let createdTask {
|
||||
if hasSubmittedSummon { return "任务 \(createdTask.taskID) 的召唤请求已提交,请等待任务状态更新" }
|
||||
if let shootErrorMessage { return shootErrorMessage }
|
||||
if createdTask != nil {
|
||||
if hasSubmittedSummon { return "召唤请求已提交,请等待任务状态更新" }
|
||||
if let summonFailure { return summonFailure.message }
|
||||
if summonOutcomeUnknown { return "召唤结果待核对,请勿重复提交" }
|
||||
return "任务 \(createdTask.taskID) 已创建,等待召唤"
|
||||
return "任务已创建,等待召唤"
|
||||
}
|
||||
if let taskCreationErrorMessage { return taskCreationErrorMessage }
|
||||
if let creationFailure { return creationFailure.message }
|
||||
if taskCreationOutcomeUnknown { return "创建结果待核对,请勿重复提交" }
|
||||
if isLoading { return "正在获取拍摄准备信息" }
|
||||
if let errorMessage { return errorMessage }
|
||||
@@ -555,11 +573,13 @@ final class DroneDockPreparationViewModel {
|
||||
}
|
||||
|
||||
private func markSummonUnknown(reason: String? = nil) {
|
||||
DroneDockDiagnostics.event("summon.outcome_unknown", taskID: createdTask?.taskID)
|
||||
summonOutcomeUnknown = true
|
||||
shootErrorMessage = (reason.map { "\($0)。" } ?? "") + "召唤结果待核对,请先核对任务状态,勿重复提交"
|
||||
}
|
||||
|
||||
private func markTaskCreationUnknown(reason: String? = nil) {
|
||||
DroneDockDiagnostics.event("taskcreation.outcome_unknown", taskID: createdTask?.taskID)
|
||||
taskCreationOutcomeUnknown = true
|
||||
taskCreationErrorMessage = (reason.map { "\($0)。" } ?? "") + "创建结果待核对,请先查看订单任务,勿重复提交"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user