feat(drone-dock): 接通任务召唤与状态页并固定拍摄布局
接入 plane-status、tasks/create、shoot 与 shooting,保持同一任务 ID 串接、重复提交保护和只读单次刷新。拍摄任务页固定顶部参数与底部安全控制,中间状态区域适配小屏且不滚动;同步接口记录、脱敏响应及相关测试。
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import Foundation
|
||||
|
||||
/// 准备页的独立无人机状态只读服务,不读取定位或创建飞行任务。
|
||||
protocol DroneDockPlaneStatusServing: Sendable {
|
||||
/// 读取当前景区可展示的设备状态与实时电量。
|
||||
@MainActor
|
||||
func planeStatus(scenicID: Int) async throws -> DroneDockPlaneStatusResponse
|
||||
}
|
||||
|
||||
/// 朱工 plane-status 接口适配,复用统一 Token 与业务错误处理。
|
||||
@MainActor
|
||||
final class DroneDockPlaneStatusAPI: DroneDockPlaneStatusServing {
|
||||
private let client: APIClient
|
||||
|
||||
/// 注入统一客户端,便于替换网络测试依赖。
|
||||
init(client: APIClient) { self.client = client }
|
||||
|
||||
/// 明确请求实时电量,返回景区不一致时拒绝将状态回填当前页面。
|
||||
func planeStatus(scenicID: Int) async throws -> DroneDockPlaneStatusResponse {
|
||||
guard scenicID > 0 else { throw APIError.networkFailed("请先选择景区") }
|
||||
let response: DroneDockPlaneStatusResponse = try await client.send(APIRequest(
|
||||
method: .get,
|
||||
path: "/api/app/airport/plane-status",
|
||||
queryItems: [URLQueryItem(name: "scenic_id", value: String(scenicID)),
|
||||
URLQueryItem(name: "live_battery", value: "1")]
|
||||
))
|
||||
guard response.scenicID == scenicID else {
|
||||
throw APIError.decodeFailed("无人机状态与当前景区不一致,请刷新重试")
|
||||
}
|
||||
return response
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import Foundation
|
||||
|
||||
/// 对已创建的订单飞行任务请求召唤,复用该任务及服务端锁定的飞机。
|
||||
protocol DroneDockShootServing: Sendable {
|
||||
/// 只提交已有任务 ID;调用方负责防止重复提交及核对不确定结果。
|
||||
@MainActor
|
||||
func shoot(taskID: Int) async throws -> DroneDockShootResponse
|
||||
}
|
||||
|
||||
/// 朱工 shoot 接口适配,业务成功仅表示接口受理结果,不推断飞机已经到达。
|
||||
@MainActor
|
||||
final class DroneDockShootAPI: DroneDockShootServing {
|
||||
private let client: APIClient
|
||||
|
||||
/// 注入统一网络客户端,沿用登录凭证、HTTP 与业务码处理。
|
||||
init(client: APIClient) { self.client = client }
|
||||
|
||||
/// 仅发送一次召唤 POST;不创建任务、不重试、不修改任务已选航线。
|
||||
func shoot(taskID: Int) async throws -> DroneDockShootResponse {
|
||||
try Task.checkCancellation()
|
||||
guard taskID > 0 else { throw APIError.networkFailed("缺少有效拍摄任务 ID,请先创建任务") }
|
||||
do {
|
||||
return try await client.send(APIRequest(
|
||||
method: .post,
|
||||
path: "/api/app/airport/shoot",
|
||||
body: ShootBody(taskID: taskID)
|
||||
))
|
||||
} catch APIError.emptyData {
|
||||
// 统一客户端仅在 HTTP 和业务码均成功后抛 emptyData;此接口尚未约定成功 data 结构。
|
||||
return DroneDockShootResponse(dataJSON: nil)
|
||||
}
|
||||
}
|
||||
|
||||
/// 本轮联调仅发送任务身份和非重启标记,完全省略 plane_id 与航线覆盖字段。
|
||||
private struct ShootBody: Encodable {
|
||||
let taskID: Int
|
||||
let restart = false
|
||||
|
||||
/// 朱工已建任务召唤参数映射。
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case taskID = "id", restart
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import Foundation
|
||||
|
||||
/// 朱工拍摄任务信息只读服务,读取张工已创建的任务,不发送飞行控制。
|
||||
protocol DroneDockShootingServing: Sendable {
|
||||
/// 按已有任务 ID 获取拍摄页信息;读取失败后可对同一 ID 再次读取。
|
||||
@MainActor
|
||||
func shooting(taskID: Int, liveBattery: Bool) async throws -> DroneDockShootingResponse
|
||||
}
|
||||
|
||||
/// shooting GET 接口适配,鉴权及业务码由统一客户端处理。
|
||||
@MainActor
|
||||
final class DroneDockShootingAPI: DroneDockShootingServing {
|
||||
private let client: APIClient
|
||||
|
||||
/// 注入共享网络客户端,便于验证请求只包含已创建任务的查询参数。
|
||||
init(client: APIClient) { self.client = client }
|
||||
|
||||
/// 仅发送一次无请求体的 GET,不创建任务、不召唤、不调用 start-shoot。
|
||||
func shooting(taskID: Int, liveBattery: Bool = true) async throws -> DroneDockShootingResponse {
|
||||
try Task.checkCancellation()
|
||||
guard taskID > 0 else { throw APIError.networkFailed("缺少有效拍摄任务 ID,请先创建任务") }
|
||||
return try await client.send(APIRequest(
|
||||
method: .get,
|
||||
path: "/api/app/airport/shooting",
|
||||
queryItems: [URLQueryItem(name: "id", value: String(taskID)),
|
||||
URLQueryItem(name: "live_battery", value: liveBattery ? "1" : "0")]
|
||||
))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
import Foundation
|
||||
|
||||
/// 创建张工订单待飞任务,不派机、不调用朱工召唤或开始拍摄接口。
|
||||
protocol DroneDockTaskCreating: Sendable {
|
||||
/// 提交当前订单购买范围内的点位与航线,返回任务身份及订单摘要。
|
||||
@MainActor
|
||||
func createTask(scenicID: Int, orderNumber: String, spotID: Int, airLineID: Int) async throws -> DroneDockCreatedTask
|
||||
}
|
||||
|
||||
/// 张工 tasks/create 接口,登录凭证和业务码由统一客户端处理。
|
||||
@MainActor
|
||||
final class DroneDockTaskCreationAPI: DroneDockTaskCreating {
|
||||
private let client: APIClient
|
||||
|
||||
/// 注入共享网络客户端,测试可替换传输层。
|
||||
init(client: APIClient) { self.client = client }
|
||||
|
||||
/// 单次调用仅发一次创建请求;响应身份异常交由页面核对,不自动重试写入。
|
||||
func createTask(scenicID: Int, orderNumber: String, spotID: Int, airLineID: Int) async throws -> DroneDockCreatedTask {
|
||||
try Task.checkCancellation()
|
||||
guard scenicID > 0, spotID > 0, airLineID > 0, !orderNumber.isEmpty,
|
||||
orderNumber.count <= 128,
|
||||
orderNumber == orderNumber.trimmingCharacters(in: .whitespacesAndNewlines),
|
||||
orderNumber.rangeOfCharacter(from: .controlCharacters) == nil else {
|
||||
throw APIError.networkFailed("缺少有效景区、订单、拍摄点或航线,请刷新准备信息")
|
||||
}
|
||||
let response: DroneDockCreatedTask = try await client.send(APIRequest(
|
||||
method: .post, path: "/api/yf-handset-app/photog/multi-plane/tasks/create",
|
||||
body: CreateTaskBody(scenicID: scenicID, orderNumber: orderNumber, spotID: spotID, airLineID: airLineID)
|
||||
))
|
||||
guard response.order.orderNumber == orderNumber else {
|
||||
throw APIError.decodeFailed("创建任务返回的订单与当前订单不一致,请先核对任务结果")
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
/// 创建仅提交四项身份,不发送选机、位置或任何起飞参数。
|
||||
private struct CreateTaskBody: Encodable {
|
||||
let scenicID: Int
|
||||
let orderNumber: String
|
||||
let spotID: Int
|
||||
let airLineID: Int
|
||||
|
||||
/// 张工创建待飞任务参数名。
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case scenicID = "scenic_id", orderNumber = "order_number"
|
||||
case spotID = "scenic_spot_id", airLineID = "air_line_id"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user