feat(drone-dock): 完成交付成片UI及首页入口适配
包含全部剩余改动:交付上传与游客确认流程、相关真机测试、drone_dock入口、后端接口与原型复核文档、截图及周报。
This commit is contained in:
@@ -0,0 +1,253 @@
|
||||
import Foundation
|
||||
|
||||
/// 演示视频选择器中的本地示例,不读取设备相册。
|
||||
struct DroneDeliveryVideo: Hashable, Sendable {
|
||||
/// 本地示例的稳定标识,用于同一点位成功上传去重。
|
||||
let id: String
|
||||
/// 选择器中的视频名称。
|
||||
let title: String
|
||||
/// 队列展示的文件名。
|
||||
let fileName: String
|
||||
/// 本地封面图片名称。
|
||||
let previewAssetName: String
|
||||
/// 可播放的本地示例文件,缺失时为 nil。
|
||||
let previewURL: URL?
|
||||
/// 真实本地示例时长,不冒充实际拍摄时长。
|
||||
let durationText: String
|
||||
/// 演示文件大小展示值。
|
||||
let sizeText: String
|
||||
|
||||
/// 映射到已有只读预览页面使用的素材快照。
|
||||
var previewMaterial: DroneMaterial {
|
||||
DroneMaterial(id: id, title: title, kind: .video, previewAssetName: previewAssetName,
|
||||
previewURL: previewURL, durationText: durationText)
|
||||
}
|
||||
}
|
||||
|
||||
/// 成片上传的单文件状态,成功项永远不由重试或继续重新上传。
|
||||
enum DroneDeliveryUploadState: Hashable, Sendable {
|
||||
case uploading(progress: Double), paused, failed(message: String), completed
|
||||
|
||||
/// 列表状态文字,全部结果都属于本地演示。
|
||||
var title: String {
|
||||
switch self {
|
||||
case .uploading: "演示上传中"
|
||||
case .paused: "上传已暂停"
|
||||
case .failed: "演示上传失败"
|
||||
case .completed: "演示交付完成"
|
||||
}
|
||||
}
|
||||
|
||||
/// 是否为明确成功,不能从百分比或暂停推断。
|
||||
var isCompleted: Bool { self == .completed }
|
||||
/// 是否为明确失败,生命周期暂停不属于失败。
|
||||
var isFailed: Bool {
|
||||
if case .failed = self { return true }
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/// 单个上传任务保留稳定文件身份,执行令牌则归批次管理。
|
||||
struct DroneDeliveryUploadItem: Hashable, Sendable {
|
||||
/// 本次新增作品的稳定身份。
|
||||
let id: String
|
||||
/// 开始上传时冻结的视频快照。
|
||||
let video: DroneDeliveryVideo
|
||||
/// 最新明确回执或暂停状态。
|
||||
var state: DroneDeliveryUploadState
|
||||
}
|
||||
|
||||
/// 上传暂停的明确生命周期入口。
|
||||
enum DroneDeliveryPauseReason: Hashable, Sendable {
|
||||
case background, locked, leavingPage
|
||||
}
|
||||
|
||||
/// 一批固定点位、固定视频的上传任务。
|
||||
struct DroneDeliveryUploadBatch: Hashable, Sendable {
|
||||
/// 执行令牌,暂停、继续与重试都会更换以拒绝旧回执。
|
||||
let id: UUID
|
||||
/// 本批作品归属的点位,不随后续浏览改变。
|
||||
let pointID: String
|
||||
/// 批次创建时的点位名称。
|
||||
let pointName: String
|
||||
/// 固定的视频队列与逐项状态。
|
||||
var items: [DroneDeliveryUploadItem]
|
||||
/// 是否等待用户手动继续。
|
||||
var isPaused: Bool
|
||||
/// 最近一次暂停原因。
|
||||
var pauseReason: DroneDeliveryPauseReason?
|
||||
}
|
||||
|
||||
/// 上传底栏使用的批次阶段。
|
||||
enum DroneDeliveryUploadPhase: Hashable, Sendable {
|
||||
case idle, uploading, paused, partialFailure, completed
|
||||
}
|
||||
|
||||
/// 可由本地演示驱动注入的明确回执,不包含真实上传服务。
|
||||
enum DroneDeliveryUploadEvent: Hashable, Sendable {
|
||||
case progress(Double), succeeded, failed(message: String)
|
||||
}
|
||||
|
||||
/// 本机演示上传成功的作品,与原素材、拍摄记录和次数独立。
|
||||
struct DroneDeliveryWork: Hashable, Sendable {
|
||||
/// 作品稳定身份,对同一上传成功回执去重。
|
||||
let id: String
|
||||
/// 原本地示例视频标识。
|
||||
let sourceVideoID: String
|
||||
/// 作品归属点位。
|
||||
let pointID: String
|
||||
/// 上传时的点位名称。
|
||||
let pointName: String
|
||||
/// 作品展示名称。
|
||||
let title: String
|
||||
/// 本地示例文件名。
|
||||
let fileName: String
|
||||
/// 本地封面资源。
|
||||
let previewAssetName: String
|
||||
/// 本地示例视频文件,缺失时只显示封面。
|
||||
let previewURL: URL?
|
||||
/// 本地示例时长。
|
||||
let durationText: String
|
||||
/// 演示文件大小。
|
||||
let sizeText: String
|
||||
/// 本机演示成功的时间,不作为真实云端凭证。
|
||||
let deliveredAt: Date
|
||||
/// 当前始终为 true,避免将演示作品冒充真实交付。
|
||||
let isSimulation: Bool
|
||||
|
||||
/// 通过既有素材预览组件打开本地示例。
|
||||
var previewMaterial: DroneMaterial {
|
||||
DroneMaterial(id: id, title: title, kind: .video, previewAssetName: previewAssetName,
|
||||
previewURL: previewURL, durationText: durationText)
|
||||
}
|
||||
}
|
||||
|
||||
/// 整单清单按点位汇总,包含各次成功上传的作品。
|
||||
struct DroneDeliveryWorkGroup: Hashable, Sendable {
|
||||
/// 分组稳定身份。
|
||||
var id: String { pointID }
|
||||
/// 所属点位。
|
||||
let pointID: String
|
||||
/// 点位展示名称。
|
||||
let pointName: String
|
||||
/// 本点全部成功作品或某次确认快照中的作品。
|
||||
let works: [DroneDeliveryWork]
|
||||
}
|
||||
|
||||
/// 商家核对和游客演示确认的不同阶段,不由刷新推断推进。
|
||||
enum DroneDeliveryConfirmationPhase: Hashable, Sendable {
|
||||
case review, awaitingConfirmation, viewing, feedback, confirmed
|
||||
|
||||
/// 确认区域展示名称。
|
||||
var title: String {
|
||||
switch self {
|
||||
case .review: "请先核对整单交付"
|
||||
case .awaitingConfirmation: "待游客确认 · 演示"
|
||||
case .viewing: "演示查看中"
|
||||
case .feedback: "成片问题待处理 · 演示"
|
||||
case .confirmed: "游客已确认 · 演示"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 原型中的四类成片问题,反馈不等于确认收货。
|
||||
enum DroneDeliveryFeedbackKind: String, CaseIterable, Hashable, Sendable {
|
||||
case missingVideo, unplayable, quality, other
|
||||
|
||||
/// 问题选项标题。
|
||||
var title: String {
|
||||
switch self {
|
||||
case .missingVideo: "视频缺失"
|
||||
case .unplayable: "无法播放"
|
||||
case .quality: "成片效果有异议"
|
||||
case .other: "其他问题"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 本机演示反馈记录,不发送真实消息。
|
||||
struct DroneDeliveryFeedback: Hashable, Sendable {
|
||||
/// 选择的问题类型。
|
||||
let kind: DroneDeliveryFeedbackKind
|
||||
/// 可选补充说明。
|
||||
let note: String
|
||||
/// 本机演示提交时间。
|
||||
let createdAt: Date
|
||||
}
|
||||
|
||||
/// 某一交付版本的确认会话,作品清单一经创建便不可替换。
|
||||
struct DroneDeliveryConfirmationSession: Hashable, Sendable {
|
||||
/// 单次确认令牌,其他订单和旧版本回执不能复用。
|
||||
let id: UUID
|
||||
/// 确认创建时的整单作品版本。
|
||||
let revision: Int
|
||||
/// 创建会话时的订单身份快照。
|
||||
let orderID: String
|
||||
/// 可见订单号快照。
|
||||
let orderNumber: String
|
||||
/// 创建时游客脱敏名称,不随后续资料改变。
|
||||
let visitorName: String
|
||||
/// 发起整单核对的工作人员名称快照。
|
||||
let operatorName: String
|
||||
/// 创建会话时的景区名称。
|
||||
let scenicName: String
|
||||
/// 创建时全部作品的值类型快照,追加作品不改变此清单。
|
||||
let works: [DroneDeliveryWork]
|
||||
/// 商家完成核对并创建会话的本机时间。
|
||||
let createdAt: Date
|
||||
/// 只有明确 Debug 事件才推进状态。
|
||||
var status: DroneDeliveryConfirmationPhase
|
||||
/// 明确模拟主动确认回执的时间。
|
||||
var confirmedAt: Date?
|
||||
/// 最近一次演示问题反馈。
|
||||
var feedback: DroneDeliveryFeedback?
|
||||
/// 本次演示查看中是否主动勾选已核对全部作品。
|
||||
var visitorAcknowledged: Bool
|
||||
|
||||
/// 供本机占位码使用的演示文本,不是网页链接或真实收货凭据。
|
||||
var demoCodeText: String { "SUIXINKAN-DEMO-\(id.uuidString)" }
|
||||
}
|
||||
|
||||
/// 游客状态仅由显式 Debug 模拟回执产生,不实现游客原生网页。
|
||||
enum DroneDeliveryConfirmationEvent: Hashable, Sendable {
|
||||
case viewing, confirmed, feedback(kind: DroneDeliveryFeedbackKind, note: String)
|
||||
}
|
||||
|
||||
/// 订单交付共享内存状态,景区及工作人员范围由缓存键隔离。
|
||||
struct DroneDeliveryLibraryState {
|
||||
/// 整单成功作品,各批次追加而不互相覆盖。
|
||||
var works: [DroneDeliveryWork] = []
|
||||
/// 每次新增成功作品递增,避免旧核对覆盖新清单。
|
||||
var revision: Int = 0
|
||||
/// 当前点位上传队列。
|
||||
var batch: DroneDeliveryUploadBatch?
|
||||
/// 商家明确核对的版本,新作品追加时失效。
|
||||
var merchantReviewedRevision: Int?
|
||||
/// 所有历史确认会话,旧清单和已确认记录保留。
|
||||
var sessions: [DroneDeliveryConfirmationSession] = []
|
||||
/// 当前版本的确认会话身份,新作品追加时清空。
|
||||
var currentSessionID: UUID?
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
/// 交付流程的本地显式验收场景。
|
||||
enum DroneDeliveryScenario: String, CaseIterable, Hashable {
|
||||
case empty, ready, uploading, paused, partialFailure, completed, awaitingConfirmation, viewing, feedback, confirmed
|
||||
|
||||
/// 场景菜单名称。
|
||||
var title: String {
|
||||
switch self {
|
||||
case .empty: "暂无交付作品"
|
||||
case .ready: "点位与演示视频选择"
|
||||
case .uploading: "成片上传中"
|
||||
case .paused: "上传暂停待继续"
|
||||
case .partialFailure: "部分上传失败"
|
||||
case .completed: "本批演示交付完成"
|
||||
case .awaitingConfirmation: "整单待游客确认"
|
||||
case .viewing: "演示查看中"
|
||||
case .feedback: "成片问题反馈"
|
||||
case .confirmed: "已确认的演示记录"
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -207,7 +207,7 @@ enum DroneShootingMaterialState: Hashable, Sendable {
|
||||
}
|
||||
}
|
||||
|
||||
/// 新版卡片中游客确认摘要的静态展示状态;本期不实现交付流程。
|
||||
/// 订单卡中的游客确认摘要,与交付清单及确认会话快照分别保存。
|
||||
enum DroneVisitorConfirmationState: Hashable, Sendable {
|
||||
case none, awaitingConfirmation, confirmed
|
||||
|
||||
|
||||
@@ -0,0 +1,433 @@
|
||||
import Foundation
|
||||
|
||||
/// 本地成片上传与整单确认规则;不访问网络、系统相册或真实游客服务。
|
||||
final class DroneDeliveryViewModel {
|
||||
/// 与机巢、订单及原素材页面共享的数据源。
|
||||
let store: DroneDockDemoStore
|
||||
/// 固定入口订单,避免列表位置变化后操作其他订单。
|
||||
let orderID: String
|
||||
/// 用户为下一批明确选择的点位;整单入口初始不自动选点。
|
||||
private(set) var selectedPointID: String?
|
||||
/// 用户选择的本地示例视频,不读取相册。
|
||||
private(set) var selectedVideoIDs: Set<String> = []
|
||||
private let context: DroneDockContext
|
||||
private let now: () -> Date
|
||||
|
||||
/// 当前景区、工作人员范围内可访问的入口订单。
|
||||
var order: DroneShootingOrder? { isCurrentContext ? store.shootingOrder(id: orderID) : nil }
|
||||
/// 配置允许选择的点位,上传不受拍摄距离约束。
|
||||
var points: [DroneShootingPoint] { order != nil ? store.shootingPreparations[key]?.points ?? [] : [] }
|
||||
/// 当前明确选择的有效点位。
|
||||
var selectedPoint: DroneShootingPoint? { points.first { $0.id == selectedPointID } }
|
||||
/// 本点尚未成功交付的四个本地视频样例。
|
||||
var availableVideos: [DroneDeliveryVideo] {
|
||||
guard let point = selectedPoint else { return [] }
|
||||
let uploadedSources = Set(works.filter { $0.pointID == point.id }.map(\.sourceVideoID))
|
||||
return Self.demoVideos(pointName: point.name).filter { !uploadedSources.contains($0.id) }
|
||||
}
|
||||
/// 当前人工选择的视频数量。
|
||||
var selectedVideoCount: Int { selectedVideoIDs.count }
|
||||
/// 上传队列未清除前冻结点位与选择,包括失败结果页。
|
||||
var isUploadLocked: Bool { batch != nil }
|
||||
/// 点位和至少一个视频均已明确选择才可开始。
|
||||
var canStartUpload: Bool { order != nil && batch == nil && selectedPoint != nil && selectedVideoCount > 0 }
|
||||
/// 当前共享上传队列及执行令牌。
|
||||
var batch: DroneDeliveryUploadBatch? { library?.batch }
|
||||
/// 本批成功项数,不代表整单交齐或游客确认。
|
||||
var uploadedCount: Int { batch?.items.filter { $0.state.isCompleted }.count ?? 0 }
|
||||
/// 本批明确失败项数。
|
||||
var failedCount: Int { batch?.items.filter { $0.state.isFailed }.count ?? 0 }
|
||||
/// 本批仍需继续的文件数,不包括明确失败项。
|
||||
var pendingCount: Int { batch?.items.filter { !$0.state.isCompleted && !$0.state.isFailed }.count ?? 0 }
|
||||
/// 本批固定文件总数。
|
||||
var totalUploadCount: Int { batch?.items.count ?? 0 }
|
||||
/// 完成文件数量占比,不从虚构网络数据推断交付成功。
|
||||
var uploadProgress: Double { totalUploadCount == 0 ? 0 : Double(uploadedCount) / Double(totalUploadCount) }
|
||||
/// 上传底栏使用的阶段。
|
||||
var uploadPhase: DroneDeliveryUploadPhase {
|
||||
guard let batch else { return .idle }
|
||||
if batch.isPaused && pendingCount > 0 { return .paused }
|
||||
if batch.items.contains(where: { if case .uploading = $0.state { return true }; return false }) { return .uploading }
|
||||
if failedCount > 0 { return .partialFailure }
|
||||
return uploadedCount == totalUploadCount ? .completed : .idle
|
||||
}
|
||||
/// 所有批次成功交付的本机演示作品。
|
||||
var works: [DroneDeliveryWork] { library?.works ?? [] }
|
||||
/// 当前整单成功作品按点位汇总。
|
||||
var workGroups: [DroneDeliveryWorkGroup] { Self.groups(works) }
|
||||
/// 当前版本是否由商家明确勾选交齐,新作品成功追加会清除此勾选。
|
||||
var isAllDeliveredReviewed: Bool {
|
||||
guard let state = library else { return false }
|
||||
return !state.works.isEmpty && state.merchantReviewedRevision == state.revision
|
||||
}
|
||||
/// 有成功作品、没有未结束上传且明确勾选交齐后才可创建整单确认。
|
||||
var canCreateConfirmation: Bool { canReviewCurrentWorks && isAllDeliveredReviewed }
|
||||
/// 当前作品版本的有效确认会话,旧清单仍保留在历史中。
|
||||
var confirmationSession: DroneDeliveryConfirmationSession? {
|
||||
guard let state = library, let id = state.currentSessionID else { return nil }
|
||||
return state.sessions.first { $0.id == id && $0.revision == state.revision }
|
||||
}
|
||||
/// 核对、等待、查看、反馈和确认保持独立,不由刷新自动推进。
|
||||
var confirmationPhase: DroneDeliveryConfirmationPhase { confirmationSession?.status ?? .review }
|
||||
/// 当前确认会话冻结清单按点位分组。
|
||||
var confirmationGroups: [DroneDeliveryWorkGroup] { Self.groups(confirmationSession?.works ?? []) }
|
||||
/// 历次已明确模拟确认的记录,追加作品后原快照仍保留。
|
||||
var confirmationRecords: [DroneDeliveryConfirmationSession] {
|
||||
(library?.sessions ?? []).enumerated().filter { $0.element.status == .confirmed }.sorted {
|
||||
let firstDate = $0.element.confirmedAt ?? $0.element.createdAt
|
||||
let secondDate = $1.element.confirmedAt ?? $1.element.createdAt
|
||||
return firstDate == secondDate ? $0.offset > $1.offset : firstDate > secondDate
|
||||
}.map(\.element)
|
||||
}
|
||||
/// 最近一次已确认的本机演示凭据,不冒充真实收货证明。
|
||||
var latestReceipt: DroneDeliveryConfirmationSession? { confirmationRecords.first }
|
||||
/// 最近已确认快照的分点清单。
|
||||
var receiptGroups: [DroneDeliveryWorkGroup] { Self.groups(latestReceipt?.works ?? []) }
|
||||
|
||||
private var isCurrentContext: Bool { store.context == context }
|
||||
private var key: DroneShootingSessionKey { DroneShootingSessionKey(context: context, orderID: orderID) }
|
||||
private var library: DroneDeliveryLibraryState? { order != nil ? store.deliveryLibraries[key] : nil }
|
||||
private var canReviewCurrentWorks: Bool { order != nil && !works.isEmpty && pendingCount == 0 && failedCount == 0 }
|
||||
|
||||
/// 指定入口订单和可选预选点位,时钟可注入以测试确认时间。
|
||||
init(store: DroneDockDemoStore, orderID: String, pointID: String? = nil, now: @escaping () -> Date = Date.init) {
|
||||
self.store = store
|
||||
self.orderID = orderID
|
||||
selectedPointID = pointID
|
||||
context = store.context
|
||||
self.now = now
|
||||
refresh()
|
||||
}
|
||||
|
||||
/// 主动读取共享状态;已存在交付摘要首次生成相应作品及确认快照。
|
||||
func refresh() {
|
||||
guard isCurrentContext, let order else {
|
||||
pauseStoredUpload(reason: .leavingPage)
|
||||
selectedVideoIDs = []
|
||||
return
|
||||
}
|
||||
store.ensureShootingPreparation(orderID: orderID)
|
||||
if store.deliveryLibraries[key] == nil {
|
||||
store.deliveryLibraries[key] = initialState(order: order)
|
||||
}
|
||||
if let batch { selectedPointID = batch.pointID }
|
||||
else if !points.contains(where: { $0.id == selectedPointID }) { selectedPointID = nil }
|
||||
if batch == nil { selectedVideoIDs.formIntersection(Set(availableVideos.map(\.id))) }
|
||||
projectOrderSummary()
|
||||
}
|
||||
|
||||
/// 点位改变清空旧视频勾选,进行中的固定批次不能改点。
|
||||
func selectPoint(id: String) {
|
||||
guard !isUploadLocked, points.contains(where: { $0.id == id }), selectedPointID != id else { return }
|
||||
selectedPointID = id
|
||||
selectedVideoIDs = []
|
||||
}
|
||||
|
||||
/// 独立切换本点仍可上传的视频选择。
|
||||
func toggleVideo(id: String) {
|
||||
guard !isUploadLocked, availableVideos.contains(where: { $0.id == id }) else { return }
|
||||
if !selectedVideoIDs.insert(id).inserted { selectedVideoIDs.remove(id) }
|
||||
}
|
||||
|
||||
/// 开始本地演示批次,只冻结已选文件,不表示真实云端已上传。
|
||||
@discardableResult
|
||||
func startUpload() -> Bool {
|
||||
guard canStartUpload, let point = selectedPoint, var state = library else { return false }
|
||||
let videos = availableVideos.filter { selectedVideoIDs.contains($0.id) }
|
||||
guard !videos.isEmpty else { return false }
|
||||
state.batch = DroneDeliveryUploadBatch(id: UUID(), pointID: point.id, pointName: point.name,
|
||||
items: videos.map { DroneDeliveryUploadItem(id: UUID().uuidString, video: $0, state: .uploading(progress: 0)) },
|
||||
isPaused: false, pauseReason: nil)
|
||||
store.deliveryLibraries[key] = state
|
||||
return true
|
||||
}
|
||||
|
||||
/// 后台、锁屏或离页停止未完成执行,已成功作品始终保留。
|
||||
func pauseUpload(reason: DroneDeliveryPauseReason) {
|
||||
guard isCurrentContext else { return }
|
||||
pauseStoredUpload(reason: reason)
|
||||
}
|
||||
|
||||
/// 用户手动继续仅处理未完成项,失败项需单独重试。
|
||||
@discardableResult
|
||||
func continueUpload() -> Bool {
|
||||
guard var state = library, let old = state.batch, old.isPaused, pendingCount > 0 else { return false }
|
||||
let items = old.items.map { item -> DroneDeliveryUploadItem in
|
||||
var item = item
|
||||
if item.state == .paused { item.state = .uploading(progress: 0) }
|
||||
return item
|
||||
}
|
||||
state.batch = renewedBatch(old, items: items, isPaused: false, reason: nil)
|
||||
store.deliveryLibraries[key] = state
|
||||
return true
|
||||
}
|
||||
|
||||
/// 仅重试明确失败的文件;已成功作品不会再次加入或上传。
|
||||
@discardableResult
|
||||
func retryFailedUploads() -> Bool {
|
||||
guard var state = library, let old = state.batch, pendingCount == 0, failedCount > 0 else { return false }
|
||||
let items = old.items.map { item -> DroneDeliveryUploadItem in
|
||||
var item = item
|
||||
if item.state.isFailed { item.state = .uploading(progress: 0) }
|
||||
return item
|
||||
}
|
||||
state.batch = renewedBatch(old, items: items, isPaused: false, reason: nil)
|
||||
store.deliveryLibraries[key] = state
|
||||
return true
|
||||
}
|
||||
|
||||
/// 明确结束已完成或失败的批次后继续同一点追加;成功作品不受影响。
|
||||
func clearUploadBatch() {
|
||||
guard var state = library, state.batch != nil, pendingCount == 0 else { return }
|
||||
state.batch = nil
|
||||
store.deliveryLibraries[key] = state
|
||||
selectedVideoIDs = []
|
||||
}
|
||||
|
||||
/// 接收本地上传回执,校验上下文、批次令牌及单项状态后才追加作品。
|
||||
func receiveUpload(_ event: DroneDeliveryUploadEvent, itemID: String, batchID: UUID) {
|
||||
guard var state = library, var batch = state.batch, batch.id == batchID, !batch.isPaused,
|
||||
let index = batch.items.firstIndex(where: { $0.id == itemID }),
|
||||
case .uploading(let previous) = batch.items[index].state else { return }
|
||||
let item = batch.items[index]
|
||||
switch event {
|
||||
case .progress(let value):
|
||||
guard value.isFinite else { return }
|
||||
batch.items[index].state = .uploading(progress: max(previous, min(1, max(0, value))))
|
||||
case .failed(let message): batch.items[index].state = .failed(message: message)
|
||||
case .succeeded:
|
||||
batch.items[index].state = .completed
|
||||
if !state.works.contains(where: { $0.id == item.id || ($0.pointID == batch.pointID && $0.sourceVideoID == item.video.id) }) {
|
||||
state.works.append(Self.work(item: item, pointID: batch.pointID, pointName: batch.pointName, date: now()))
|
||||
state.revision += 1
|
||||
state.merchantReviewedRevision = nil
|
||||
state.currentSessionID = nil
|
||||
}
|
||||
}
|
||||
state.batch = batch
|
||||
store.deliveryLibraries[key] = state
|
||||
projectOrderSummary()
|
||||
}
|
||||
|
||||
/// 商家明确核对本版本全部成功作品,不由上传完成自动勾选。
|
||||
func setAllDeliveredReviewed(_ checked: Bool) {
|
||||
guard var state = library else { return }
|
||||
state.merchantReviewedRevision = checked && canReviewCurrentWorks ? state.revision : nil
|
||||
store.deliveryLibraries[key] = state
|
||||
}
|
||||
|
||||
/// 为当前整单清单创建不可替换的本机演示确认会话,重复点击复用同一会话。
|
||||
@discardableResult
|
||||
func createConfirmationSession() -> Bool {
|
||||
guard canCreateConfirmation, var state = library, let order else { return false }
|
||||
if confirmationSession != nil { return true }
|
||||
let session = makeSession(works: state.works, revision: state.revision, order: order)
|
||||
state.sessions.append(session)
|
||||
state.currentSessionID = session.id
|
||||
store.deliveryLibraries[key] = state
|
||||
projectOrderSummary()
|
||||
return true
|
||||
}
|
||||
|
||||
/// 只刷新共享状态,不推断游客已经查看或已经确认。
|
||||
func refreshConfirmation() { refresh() }
|
||||
|
||||
/// 明确回到商家核对并废弃当前令牌,历史清单与已确认记录仍保留。
|
||||
func beginNewReview() {
|
||||
guard var state = library else { return }
|
||||
state.currentSessionID = nil
|
||||
state.merchantReviewedRevision = nil
|
||||
store.deliveryLibraries[key] = state
|
||||
projectOrderSummary()
|
||||
}
|
||||
|
||||
private func pauseStoredUpload(reason: DroneDeliveryPauseReason) {
|
||||
guard var state = store.deliveryLibraries[key], let old = state.batch,
|
||||
old.items.contains(where: { !$0.state.isCompleted && !$0.state.isFailed }) else { return }
|
||||
let items = old.items.map { item -> DroneDeliveryUploadItem in
|
||||
var item = item
|
||||
if case .uploading = item.state { item.state = .paused }
|
||||
return item
|
||||
}
|
||||
state.batch = renewedBatch(old, items: items, isPaused: true, reason: reason)
|
||||
store.deliveryLibraries[key] = state
|
||||
}
|
||||
|
||||
private func renewedBatch(_ old: DroneDeliveryUploadBatch, items: [DroneDeliveryUploadItem],
|
||||
isPaused: Bool, reason: DroneDeliveryPauseReason?) -> DroneDeliveryUploadBatch {
|
||||
DroneDeliveryUploadBatch(id: UUID(), pointID: old.pointID, pointName: old.pointName,
|
||||
items: items, isPaused: isPaused, pauseReason: reason)
|
||||
}
|
||||
|
||||
private func projectOrderSummary() {
|
||||
guard let state = library, let order else { return }
|
||||
let confirmation: DroneVisitorConfirmationState
|
||||
if state.works.isEmpty { confirmation = .none }
|
||||
else if confirmationSession?.status == .confirmed { confirmation = .confirmed }
|
||||
else { confirmation = state.sessions.isEmpty ? .none : .awaitingConfirmation }
|
||||
store.replaceShootingOrder(order.replacingDeliverySummary(count: state.works.count, confirmation: confirmation))
|
||||
}
|
||||
|
||||
private func initialState(order: DroneShootingOrder) -> DroneDeliveryLibraryState {
|
||||
var state = DroneDeliveryLibraryState()
|
||||
guard order.deliveredVideoCount > 0 else { return state }
|
||||
state.works = seededWorks(count: order.deliveredVideoCount)
|
||||
state.revision = 1
|
||||
if order.visitorConfirmationState != .none {
|
||||
var session = makeSession(works: state.works, revision: state.revision, order: order)
|
||||
if order.visitorConfirmationState == .confirmed {
|
||||
session.status = .confirmed
|
||||
session.visitorAcknowledged = true
|
||||
session.confirmedAt = now()
|
||||
}
|
||||
state.sessions = [session]
|
||||
state.currentSessionID = session.id
|
||||
state.merchantReviewedRevision = state.revision
|
||||
}
|
||||
return state
|
||||
}
|
||||
|
||||
private func makeSession(works: [DroneDeliveryWork], revision: Int, order: DroneShootingOrder) -> DroneDeliveryConfirmationSession {
|
||||
DroneDeliveryConfirmationSession(id: UUID(), revision: revision, orderID: order.id,
|
||||
orderNumber: order.orderNumber, visitorName: order.customerName, operatorName: context.photographerName,
|
||||
scenicName: context.scenicName, works: works, createdAt: now(), status: .awaitingConfirmation,
|
||||
confirmedAt: nil, feedback: nil, visitorAcknowledged: false)
|
||||
}
|
||||
|
||||
private func seededWorks(count: Int) -> [DroneDeliveryWork] {
|
||||
guard count > 0 else { return [] }
|
||||
let knownPoints = points
|
||||
return (0..<count).map { index in
|
||||
let point = knownPoints.isEmpty ? nil : knownPoints[min(index / 2, knownPoints.count - 1)]
|
||||
let video = Self.demoVideos(pointName: point?.name ?? "三皇寨")[index % 4]
|
||||
let item = DroneDeliveryUploadItem(id: "\(orderID)-existing-work-\(index + 1)",
|
||||
video: DroneDeliveryVideo(id: "existing-source-\(index + 1)", title: video.title, fileName: video.fileName,
|
||||
previewAssetName: video.previewAssetName, previewURL: video.previewURL,
|
||||
durationText: video.durationText, sizeText: video.sizeText), state: .completed)
|
||||
return Self.work(item: item, pointID: point?.id ?? "point-sanhuang", pointName: point?.name ?? "三皇寨",
|
||||
date: Date(timeIntervalSince1970: 1_792_723_000 + Double(index)))
|
||||
}
|
||||
}
|
||||
|
||||
private static func work(item: DroneDeliveryUploadItem, pointID: String, pointName: String, date: Date) -> DroneDeliveryWork {
|
||||
DroneDeliveryWork(id: item.id, sourceVideoID: item.video.id, pointID: pointID, pointName: pointName,
|
||||
title: item.video.title, fileName: item.video.fileName, previewAssetName: item.video.previewAssetName,
|
||||
previewURL: item.video.previewURL, durationText: item.video.durationText, sizeText: item.video.sizeText,
|
||||
deliveredAt: date, isSimulation: true)
|
||||
}
|
||||
|
||||
private static func groups(_ works: [DroneDeliveryWork]) -> [DroneDeliveryWorkGroup] {
|
||||
var pointIDs: [String] = []
|
||||
var grouped: [String: [DroneDeliveryWork]] = [:]
|
||||
for work in works {
|
||||
if grouped[work.pointID] == nil { pointIDs.append(work.pointID) }
|
||||
grouped[work.pointID, default: []].append(work)
|
||||
}
|
||||
return pointIDs.compactMap { id in
|
||||
guard let items = grouped[id], let first = items.first else { return nil }
|
||||
return DroneDeliveryWorkGroup(pointID: id, pointName: first.pointName, works: items)
|
||||
}
|
||||
}
|
||||
|
||||
private static func demoVideos(pointName: String) -> [DroneDeliveryVideo] {
|
||||
let url = Bundle.main.url(forResource: "drone_material_demo", withExtension: "mp4")
|
||||
let assets = ["drone_demo_tourists", "drone_demo_mountain", "drone_demo_pagoda", "drone_demo_tourists"]
|
||||
return (1...4).map { index in
|
||||
let number = String(format: "%02d", index)
|
||||
return DroneDeliveryVideo(id: "demo-video-\(index)", title: "成片视频 \(number)",
|
||||
fileName: "\(pointName)_成片\(number).mp4", previewAssetName: assets[index - 1],
|
||||
previewURL: url, durationText: "00:03", sizeText: "本地演示文件")
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
/// 演示游客主动勾选当前冻结清单,关闭或刷新不会代为勾选。
|
||||
func setVisitorAcknowledged(_ checked: Bool) {
|
||||
guard var state = library, let session = confirmationSession, session.status == .viewing,
|
||||
let index = state.sessions.firstIndex(where: { $0.id == session.id }) else { return }
|
||||
state.sessions[index].visitorAcknowledged = checked
|
||||
store.deliveryLibraries[key] = state
|
||||
}
|
||||
|
||||
/// 只在 Debug 注入游客演示回执,旧会话或旧作品版本永不修改当前确认结果。
|
||||
func receiveConfirmation(_ event: DroneDeliveryConfirmationEvent, sessionID: UUID) {
|
||||
guard var state = library, let session = confirmationSession, session.id == sessionID,
|
||||
session.status != .confirmed,
|
||||
let index = state.sessions.firstIndex(where: { $0.id == sessionID }) else { return }
|
||||
switch event {
|
||||
case .viewing:
|
||||
guard session.status == .awaitingConfirmation || session.status == .feedback else { return }
|
||||
state.sessions[index].status = .viewing
|
||||
state.sessions[index].visitorAcknowledged = false
|
||||
case .confirmed:
|
||||
guard session.status == .viewing, session.visitorAcknowledged else { return }
|
||||
state.sessions[index].status = .confirmed
|
||||
state.sessions[index].confirmedAt = now()
|
||||
case .feedback(let kind, let note):
|
||||
guard session.status == .viewing else { return }
|
||||
let trimmed = String(note.trimmingCharacters(in: .whitespacesAndNewlines).prefix(500))
|
||||
guard kind != .other || !trimmed.isEmpty else { return }
|
||||
state.sessions[index].status = .feedback
|
||||
state.sessions[index].visitorAcknowledged = false
|
||||
state.sessions[index].feedback = DroneDeliveryFeedback(kind: kind, note: trimmed, createdAt: now())
|
||||
}
|
||||
store.deliveryLibraries[key] = state
|
||||
projectOrderSummary()
|
||||
}
|
||||
|
||||
/// 仅本地替换交付验收状态,保留拍摄额度、任务、原素材和订单归类。
|
||||
func applyScenario(_ scenario: DroneDeliveryScenario) {
|
||||
guard let order else { return }
|
||||
var state = library ?? initialState(order: order)
|
||||
state.batch = nil
|
||||
if scenario == .empty { state = DroneDeliveryLibraryState() }
|
||||
store.deliveryLibraries[key] = state
|
||||
selectedVideoIDs = []
|
||||
switch scenario {
|
||||
case .empty, .ready: break
|
||||
case .uploading, .paused, .partialFailure, .completed:
|
||||
if selectedPoint == nil { selectedPointID = points.first?.id }
|
||||
let chosen = Array(availableVideos.prefix(2))
|
||||
selectedVideoIDs = Set(chosen.map(\.id))
|
||||
guard startUpload(), let batch else { projectOrderSummary(); return }
|
||||
if scenario == .uploading { break }
|
||||
if let first = batch.items.first { receiveUpload(.succeeded, itemID: first.id, batchID: batch.id) }
|
||||
if scenario == .paused { pauseUpload(reason: .background) }
|
||||
else {
|
||||
for item in batch.items.dropFirst() {
|
||||
receiveUpload(scenario == .partialFailure ? .failed(message: "演示连接中断") : .succeeded,
|
||||
itemID: item.id, batchID: batch.id)
|
||||
}
|
||||
}
|
||||
case .awaitingConfirmation, .viewing, .feedback, .confirmed:
|
||||
if state.works.isEmpty {
|
||||
state.works = seededWorks(count: 3)
|
||||
state.revision += 1
|
||||
store.deliveryLibraries[key] = state
|
||||
}
|
||||
beginNewReview()
|
||||
setAllDeliveredReviewed(true)
|
||||
guard createConfirmationSession(), let session = confirmationSession else { return }
|
||||
if scenario != .awaitingConfirmation { receiveConfirmation(.viewing, sessionID: session.id) }
|
||||
if scenario == .feedback { receiveConfirmation(.feedback(kind: .unplayable, note: "演示:有一个视频无法播放"), sessionID: session.id) }
|
||||
if scenario == .confirmed {
|
||||
setVisitorAcknowledged(true)
|
||||
receiveConfirmation(.confirmed, sessionID: session.id)
|
||||
}
|
||||
}
|
||||
projectOrderSummary()
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// 复制订单交付摘要,拍摄次数、当前任务和原素材状态原样保留。
|
||||
extension DroneShootingOrder {
|
||||
/// 只更新成功作品数和游客确认标签,不改变订单履约归类。
|
||||
func replacingDeliverySummary(count: Int, confirmation: DroneVisitorConfirmationState) -> DroneShootingOrder {
|
||||
DroneShootingOrder(id: id, scenicID: scenicID, assignedUserID: assignedUserID, customerName: customerName,
|
||||
orderNumber: orderNumber, createdAtText: createdAtText, packageName: packageName,
|
||||
totalShootingCount: totalShootingCount, successfulShootingCount: successfulShootingCount,
|
||||
activeTask: activeTask, needsRepreparation: needsRepreparation, materialState: materialState,
|
||||
deliveredVideoCount: max(0, count), visitorConfirmationState: confirmation)
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,8 @@ final class DroneDockDemoStore {
|
||||
var shootingSessions: [DroneShootingSessionKey: DroneShootingSession] = [:]
|
||||
/// 原素材和本机演示下载结果按上下文、订单隔离,页面重进时仍可读取。
|
||||
var materialLibraries: [DroneShootingSessionKey: DroneMaterialLibraryState] = [:]
|
||||
/// 成片上传和整单确认快照按上下文、订单隔离,不与原素材下载共用状态。
|
||||
var deliveryLibraries: [DroneShootingSessionKey: DroneDeliveryLibraryState] = [:]
|
||||
#if DEBUG
|
||||
/// 预览切换前的订单,恢复正常场景时不累计演示扣次。
|
||||
var shootingScenarioBaselines: [DroneShootingSessionKey: DroneShootingOrder] = [:]
|
||||
@@ -81,6 +83,7 @@ final class DroneDockDemoStore {
|
||||
shootingSessions = shootingSessions.filter { $0.key.context != context }
|
||||
shootingScenarioBaselines = shootingScenarioBaselines.filter { $0.key.context != context }
|
||||
materialLibraries = materialLibraries.filter { $0.key.context != context }
|
||||
deliveryLibraries = deliveryLibraries.filter { $0.key.context != context }
|
||||
var orders = DroneDockDemoData.orders(context: context)
|
||||
var devices = DroneDockDemoData.devices()
|
||||
switch scenario {
|
||||
|
||||
@@ -36,6 +36,7 @@ enum HomeMenuCatalog {
|
||||
HomeMenuItem(uri: "photographer_invite", title: "邀请摄影师", iconName: "envelope.open.fill"),
|
||||
HomeMenuItem(uri: "invite_record", title: "邀请记录", iconName: "list.bullet.rectangle.fill"),
|
||||
HomeMenuItem(uri: "store", title: "店铺管理", iconName: "building.2.fill"),
|
||||
HomeMenuItem(uri: "drone_dock", title: "机巢工作台", iconName: "airplane.circle.fill"),
|
||||
HomeMenuItem(uri: "fly", title: "飞行管理", iconName: "paperplane.fill"),
|
||||
HomeMenuItem(uri: "pilot_cert", title: "飞手认证", iconName: "paperplane.fill"),
|
||||
HomeMenuItem(uri: "pilot_controller", title: "飞控", iconName: "paperplane.fill"),
|
||||
|
||||
@@ -68,6 +68,8 @@ enum HomeRouteHandler {
|
||||
viewController.navigationController?.pushViewController(InviteRecordViewController(), animated: true)
|
||||
case "/scenic-queue":
|
||||
viewController.navigationController?.pushViewController(ScenicQueueViewController(), animated: true)
|
||||
case "drone_dock":
|
||||
viewController.navigationController?.pushViewController(DroneDockWorkbenchViewController(), animated: true)
|
||||
case "task_management", "task_management_editor":
|
||||
viewController.navigationController?.pushViewController(TaskAddViewController(), animated: true)
|
||||
case "travel_album":
|
||||
|
||||
Reference in New Issue
Block a user