69 lines
3.1 KiB
Swift
69 lines
3.1 KiB
Swift
import Foundation
|
|
|
|
/// 首页三个独立只读数据源;设备由朱工提供,订单与统计由张工提供。
|
|
protocol DroneDockHomeServing: Sendable {
|
|
/// 读取当前景区的机巢摘要;门店用于验证本地身份,不作为查询参数。
|
|
@MainActor
|
|
func home(scenicID: Int, storeID: Int) async throws -> DroneDockHomeResponse
|
|
/// 分页读取本人当前景区的全部类型 25 拍摄订单。
|
|
@MainActor
|
|
func orders(scenicID: Int, page: Int, pageSize: Int) async throws -> DroneDockOrdersResponse
|
|
/// 读取本人当前景区当天的成交和确认完成统计。
|
|
@MainActor
|
|
func todayStats(scenicID: Int) async throws -> DroneDockHomeToday
|
|
}
|
|
|
|
/// 机巢首页三接口适配,复用统一凭证及业务错误处理,不创建订单或飞行任务。
|
|
@MainActor
|
|
final class DroneDockAPI: DroneDockHomeServing {
|
|
private let client: APIClient
|
|
private let orderPrefix = "/api/yf-handset-app/photog/multi-plane"
|
|
|
|
/// 注入统一网络客户端,供正式页面及网络测试使用。
|
|
init(client: APIClient) { self.client = client }
|
|
|
|
/// 朱工 home 只传 scenic_id,响应仅用于设备区域。
|
|
func home(scenicID: Int, storeID: Int) async throws -> DroneDockHomeResponse {
|
|
guard scenicID > 0, storeID > 0 else {
|
|
throw APIError.networkFailed("请先选择景区和门店")
|
|
}
|
|
return try await client.send(APIRequest(
|
|
method: .get, path: "/api/app/airport/home",
|
|
queryItems: [URLQueryItem(name: "scenic_id", value: String(scenicID))]
|
|
))
|
|
}
|
|
|
|
/// 张工 orders 由当前登录身份限定归属,不传其他摄影师或门店 ID。
|
|
func orders(scenicID: Int, page: Int, pageSize: Int) async throws -> DroneDockOrdersResponse {
|
|
try validateScenic(scenicID)
|
|
guard page > 0, (1...100).contains(pageSize) else {
|
|
throw APIError.networkFailed("订单分页参数无效")
|
|
}
|
|
let response: DroneDockOrdersResponse = try await client.send(APIRequest(
|
|
method: .get, path: orderPrefix + "/orders",
|
|
queryItems: [URLQueryItem(name: "scenic_id", value: String(scenicID)),
|
|
URLQueryItem(name: "status", value: "all"),
|
|
URLQueryItem(name: "page", value: String(page)),
|
|
URLQueryItem(name: "page_size", value: String(pageSize))]
|
|
))
|
|
guard response.page == page else {
|
|
throw APIError.decodeFailed("订单页码与请求不一致")
|
|
}
|
|
return response
|
|
}
|
|
|
|
/// 张工 today-stats 负责统计口径与上海时区日界限,客户端不传本地日期。
|
|
func todayStats(scenicID: Int) async throws -> DroneDockHomeToday {
|
|
try validateScenic(scenicID)
|
|
return try await client.send(APIRequest(
|
|
method: .get, path: orderPrefix + "/today-stats",
|
|
queryItems: [URLQueryItem(name: "scenic_id", value: String(scenicID))]
|
|
))
|
|
}
|
|
|
|
/// 没有选择景区时阻止范围不明的请求。
|
|
private func validateScenic(_ scenicID: Int) throws {
|
|
guard scenicID > 0 else { throw APIError.networkFailed("请先选择景区") }
|
|
}
|
|
}
|