合并 9.9.1 机巢工作台与拍摄交付流程 #1

Merged
lujiuyin merged 70 commits from dev_9_9_1 into main 2026-11-18 07:05:44 +00:00
9 changed files with 74 additions and 22 deletions
Showing only changes of commit 082ecf96f2 - Show all commits
@@ -322,6 +322,15 @@ struct DroneDockHomeOrder: Decodable, Equatable, Sendable {
/// 邀请游客确认须拍满套餐次数,且后端明确允许发起确认。
var canInviteVisitorConfirmation: Bool { hasCompletedShootingQuota && canConfirm == true }
/// 已确认订单允许再次交付,兼容旧接口在完成后返回 false;旧摘要缺少订单状态时仍使用交付权限。
var canDeliverFilm: Bool {
switch orderStatus {
case 30: true
case 20, nil: canUploadFilm == true
default: false
}
}
/// 后端选定的执行中任务优先于新增拍摄;无任务时沿用交付和次数规则。
var primaryAction: String? {
if activeTaskID != nil { return "view_task" }
@@ -58,6 +58,11 @@ final class DroneDockDeliveryViewModel {
guard let selectedTask, selectedTask.film != nil else { return false }
return !isPendingFilm(selectedTask)
}
/// 云端上传以重新读取的订单状态和交付资格为准。
var canUpload: Bool {
guard let order = detail?.order, order.orderStatus != nil else { return false }
return order.canDeliverFilm
}
/// 只有最新可交付订单中的有效任务可选择视频。
var canChooseVideo: Bool {
!isLoading && !isSubmitting && loadErrorMessage == nil && canUpload && selectedTask != nil
@@ -223,7 +228,7 @@ final class DroneDockDeliveryViewModel {
}
pendingUpload = PendingUpload(videoID: video.id, taskID: task.id, url: url)
fileURL = url
// 上传期间订单可能完成、任务可能失效或成片被他人替换,保存前再次核对。
// 上传期间交付资格、任务或成片可能变化,保存前再次核对。
phase = .validating
onProgress(progress)
let current = try await readSnapshot(requestGeneration)
@@ -273,8 +278,6 @@ final class DroneDockDeliveryViewModel {
return number
}
private var canUpload: Bool { detail?.order.canUploadFilm == true && detail?.order.orderStatus == 20 }
private func isPendingFilm(_ task: DroneDockMaterialTask) -> Bool {
guard let pendingUpload, pendingUpload.videoID == video?.id, pendingUpload.taskID == task.id else { return false }
return task.film?.fileURL == pendingUpload.url
@@ -197,8 +197,8 @@ final class DroneDockDeliveryViewController: BaseViewController {
cell.apply(title: "交付尚未完成", body: error, id: "drone.delivery.error")
} else if let success = viewModel.successMessage {
cell.apply(title: success, body: viewModel.refreshWarning ?? "成片已保存,可返回素材库查看", id: "drone.delivery.success")
} else if viewModel.detail?.order.canUploadFilm != true {
cell.apply(title: "当前订单暂不可上传成片", body: viewModel.detail?.order.orderStatus == 30 ? "订单已完成,无法继续上传或替换成片" : "请确认订单已付款且已有有效拍摄任务,刷新后重试", id: "drone.delivery.unavailable")
} else if !viewModel.canUpload {
cell.apply(title: "当前订单暂不可上传成片", body: "请确认订单已付款且已有有效拍摄任务,刷新后重试", id: "drone.delivery.unavailable")
} else { cell.apply(title: "云端上传", body: "选择视频后点击上传,保存成功后游客可在小程序相册查看", id: "drone.delivery.hint") }
default: break
}
@@ -174,7 +174,7 @@ final class DroneDockMaterialsViewController: BaseViewController {
case .task(let taskID):
let cell = collection.dequeueReusableCell(withReuseIdentifier: "record", for: path) as! DroneDockMaterialRecordCell
if let task = self.task(taskID) {
cell.apply(task: task, canDeliver: self.operation == nil && !self.selectionLocked && self.viewModel.detail?.order.canUploadFilm == true) { [weak self] in
cell.apply(task: task, canDeliver: self.operation == nil && !self.selectionLocked && self.viewModel.detail?.order.canDeliverFilm == true) { [weak self] in
self?.openDelivery(taskID: taskID)
}
}
@@ -324,7 +324,7 @@ final class DroneDockMaterialsViewController: BaseViewController {
private func openDelivery(taskID: Int) {
guard operation == nil, !selectionLocked, presentedViewController == nil,
let order = viewModel.detail?.order, order.canUploadFilm == true, task(taskID) != nil else { return }
let order = viewModel.detail?.order, order.canDeliverFilm, task(taskID) != nil else { return }
let sheet = DroneDockDeliveryEntry.makeMethodSheet(order: order, context: viewModel.context,
taskID: taskID, controllerFactory: deliveryControllerFactory) { [weak self] in
guard let self else { return }
@@ -235,7 +235,7 @@ final class DroneDockOrdersViewController: BaseViewController {
private func openDelivery(orderID: String) {
guard operation == nil, presentedViewController == nil,
let order = viewModel.orders.first(where: { $0.orderID == orderID }),
order.canUploadFilm == true else { return }
order.canDeliverFilm else { return }
let sheet = DroneDockDeliveryEntry.makeMethodSheet(order: order, context: viewModel.context,
controllerFactory: deliveryControllerFactory) { [weak self] in
guard let self, self.viewIfLoaded?.window != nil else { return }
@@ -314,7 +314,7 @@ final class DroneShootingOrderCardView: UIView {
private func applyRemoteActions(order: DroneDockHomeOrder, identifier: String) {
let canShoot = order.activeTaskID != nil || order.canCreateTask == true
let canConfirm = order.canInviteVisitorConfirmation
let canDeliver = order.canUploadFilm == true
let canDeliver = order.canDeliverFilm
primaryButton.isHidden = !canShoot && !canConfirm && !canDeliver
primaryButton.isEnabled = !primaryButton.isHidden
primaryButton.backgroundColor = DroneDockStyle.primary
@@ -398,7 +398,7 @@ final class DroneShootingOrderCardView: UIView {
@objc private func secondaryTapped() {
if let order = displayedHomeOrder {
guard !secondaryButton.isHidden, secondaryButton.isEnabled, order.canUploadFilm == true else { return }
guard !secondaryButton.isHidden, secondaryButton.isEnabled, order.canDeliverFilm else { return }
onDeliveryTap?()
return
}
@@ -415,7 +415,7 @@ final class DroneShootingOrderCardView: UIView {
guard !primaryButton.isHidden, primaryButton.isEnabled else { return }
if order.activeTaskID != nil || order.canCreateTask == true { onShootingTap?() }
else if order.canInviteVisitorConfirmation { onConfirmationTap?() }
else if order.canUploadFilm == true { onDeliveryTap?() }
else if order.canDeliverFilm { onDeliveryTap?() }
return
}
guard let displayedOrder else { return }
@@ -71,6 +71,39 @@ final class DroneDockDeliveryIntegrationTests: XCTestCase {
XCTAssertNil(fixture.model.uploadedFileURL)
}
/// 已确认订单兼容旧权限字段,可在同一任务上再次选择视频并替换成片。
func testConfirmedOrderAllowsRepeatedDeliveryAndExplicitReplacement() async throws {
let fixture = try makeFixture()
fixture.backend.orderStatus = 30
fixture.backend.canUpload = false
await fixture.prepare()
await fixture.model.submit()
let original = try XCTUnwrap(fixture.model.selectedTask?.film)
XCTAssertEqual(fixture.model.phase, .succeeded)
XCTAssertTrue(fixture.model.canChooseVideo)
XCTAssertFalse(fixture.model.canSubmit)
let replacement = DroneDockDeliveryVideo(url: fixture.video.url, fileName: "重新交付.mp4", fileSize: fixture.video.fileSize)
fixture.model.selectVideo(replacement)
XCTAssertTrue(fixture.model.canSubmit)
XCTAssertTrue(fixture.model.needsReplacementConfirmation)
await fixture.model.submit()
XCTAssertEqual(fixture.transport.calls.count, 1)
XCTAssertEqual(fixture.model.selectedTask?.film, original)
await fixture.model.submit(confirmReplacement: true)
let saves = fixture.backend.requests.filter { $0.url?.path == DeliveryIntegrationBackend.savePath }
XCTAssertEqual(saves.count, 2)
XCTAssertEqual(fixture.transport.calls.count, 2)
XCTAssertEqual(fixture.model.selectedTask?.film?.fileName, replacement.fileName)
XCTAssertNotEqual(fixture.model.selectedTask?.film?.fileURL, original.fileURL)
XCTAssertEqual(fixture.model.detail?.order.orderStatus, 30)
XCTAssertEqual(fixture.model.detail?.order.confirmStatus, 2)
XCTAssertEqual(fixture.model.phase, .succeeded)
}
/// 业务文件名完整保留,中文、空格和井号均不会进入 OSS 对象地址。
func testSpecialFileNamesRemainInBusinessMetadataWithASCIIObjectURLs() async throws {
for name in ["中文成片.mp4", "test film.MOV", "test#film.MP4"] {
@@ -135,7 +168,6 @@ final class DroneDockDeliveryIntegrationTests: XCTestCase {
let backend = fixture.backend
fixture.transport.onPut = {
backend.canUpload = false
backend.orderStatus = 30
}
fixture.backend.events.removeAll()
@@ -145,7 +177,7 @@ final class DroneDockDeliveryIntegrationTests: XCTestCase {
XCTAssertEqual(fixture.transport.calls.count, 1)
XCTAssertFalse(fixture.backend.requests.contains { $0.url?.path == DeliveryIntegrationBackend.savePath })
XCTAssertEqual(fixture.model.detail?.order.canUploadFilm, false)
XCTAssertEqual(fixture.model.detail?.order.orderStatus, 30)
XCTAssertEqual(fixture.model.detail?.order.orderStatus, 20)
XCTAssertNotNil(fixture.model.uploadedFileURL)
XCTAssertNotNil(fixture.model.submissionErrorMessage)
XCTAssertNil(fixture.model.successMessage)
@@ -215,6 +247,7 @@ private final class DeliveryIntegrationBackend {
var detailPayload: [String: Any] {
["order_number": "INTEGRATION-ORDER", "order_status": orderStatus, "can_upload_film": canUpload,
"confirm_status": orderStatus == 30 ? 2 : 0,
"film_count": savedFilm == nil ? 0 : 1, "shoot_count": 5, "shot_count": 1, "remaining_count": 4,
"spot": [["scenic_spot_id": 201, "scenic_spot_name": "集成测试点位"]]]
}
@@ -58,9 +58,9 @@ final class DroneDockDeliveryViewModelTests: XCTestCase {
XCTAssertFalse(fixture.model.canSubmit)
}
/// 未读取、无上传权限、已完成订单及不支持的视频不发送写请求。
/// 无上传权限、已取消、已退款和不支持的视频均不发送写请求。
func testPermissionAndVideoValidationDisableSubmission() async throws {
for (allowed, status) in [(false, 20), (true, 30)] {
for (allowed, status) in [(false, 20), (true, 10), (true, 40), (true, 50)] {
let fixture = try DeliveryVMFixture(initialTaskID: 11)
fixture.service.detailValue = try DeliveryVMData.detail(allowed: allowed, status: status)
await fixture.prepare()
@@ -135,11 +135,11 @@ final class DroneDockDeliveryViewModelTests: XCTestCase {
XCTAssertNotNil(fixture.model.submissionErrorMessage)
}
/// 上传期间订单完成时不再调用成片保存接口,已上传地址留作核对而非交付成功。
func testCompletionDuringUploadStopsSave() async throws {
/// 上传期间订单取消时不再调用成片保存接口,已上传地址留作核对。
func testCancellationDuringUploadStopsSave() async throws {
let fixture = try DeliveryVMFixture(initialTaskID: 11)
await fixture.prepare()
fixture.uploader.onUpload = { fixture.service.detailValue = try! DeliveryVMData.detail(allowed: false, status: 30) }
fixture.uploader.onUpload = { fixture.service.detailValue = try! DeliveryVMData.detail(allowed: false, status: 40) }
await fixture.model.submit()
XCTAssertEqual(fixture.uploader.calls, 1)
XCTAssertTrue(fixture.service.saves.isEmpty)
+11 -4
View File
@@ -342,11 +342,11 @@ final class DroneDockOrdersViewTests: XCTestCase {
XCTAssertEqual(session.requests.count, 1)
}
/// 主、副交付按钮先展示方式弹窗;选择云端后才在弹窗内读取真实交付数据。
/// 主、副交付按钮及已确认订单先展示方式弹窗,再按所选方式加载交付。
func testDeliveryButtonsOpenSharedPageWithoutPreselectingTask() async throws {
for hasShootingPermission in [true, false] {
var order = record("DELIVERY", status: "processing")
order["can_upload_film"] = true
for (hasShootingPermission, isConfirmed) in [(true, false), (false, false), (false, true)] {
var order = record("DELIVERY", status: isConfirmed ? "completed" : "processing")
order["can_upload_film"] = !isConfirmed
order["can_create_task"] = hasShootingPermission
var destinationSession: MockURLSession?
var factoryCount = 0
@@ -366,6 +366,13 @@ final class DroneDockOrdersViewTests: XCTestCase {
let suffix = hasShootingPermission ? "delivery" : "primary"
let action = try button(in: cell, id: "drone.orders.order.TEST-ORDER-DELIVERY.\(suffix)")
XCTAssertEqual(action.title(for: .normal), "交付成片")
XCTAssertFalse(action.isHidden)
XCTAssertTrue(action.isEnabled)
if isConfirmed {
let confirmation = try XCTUnwrap(find(in: cell, id: "drone.orders.order.TEST-ORDER-DELIVERY.confirmation") as? UIControl)
XCTAssertTrue(confirmation.isEnabled)
XCTAssertTrue(confirmation.accessibilityLabel?.contains("查看记录") == true)
}
action.sendActions(for: .touchUpInside)
try await settle(window) { self.deliveryNavigation(from: controller)?.topViewController is DroneDockDeliveryMethodViewController }
let sheet = try XCTUnwrap(deliveryNavigation(from: controller))