Files
admin-web/src/modules/overseas-warehouse/api/mojiaSkuSync.ts
T
2026-09-24 17:02:36 +08:00

117 lines
3.1 KiB
TypeScript

import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
export type MojiaSkuSyncStatus = 'PENDING' | 'SUCCESS' | 'FAILED'
export type MojiaMeasurementKind = 'BOX_LABEL' | 'SKU'
export interface MojiaSkuSyncRecord {
id: string
measurementKind: MojiaMeasurementKind
boxCode: string
inboundCode?: string | null
skuCode?: string | null
lengthCm: number
widthCm: number
heightCm: number
weightKg: number
imageFileId?: string | null
imageUrl?: string | null
measuredAt?: string | null
receivedAt?: string | null
syncStatus?: MojiaSkuSyncStatus | null
syncFailureCode?: string | null
syncFailureReason?: string | null
lingxingSkuId?: string | null
revision: number
updatedAt?: string | null
}
export interface MojiaSkuSyncPage {
records: MojiaSkuSyncRecord[]
page: number
size: number
total: number
pages: number
}
export interface MojiaSkuSyncQuery {
page: number
size: number
code?: string
measurementKind?: MojiaMeasurementKind
syncStatus?: MojiaSkuSyncStatus
}
export interface MojiaSkuSyncConfig {
autoSyncEnabled: boolean
}
export interface LingxingWarehouseTestResult {
whCode: string
reachable: boolean
matched: boolean
maintained: boolean
productSku?: string | null
barcode?: string | null
length?: number | null
width?: number | null
height?: number | null
weight?: number | null
message: string
}
export interface LingxingConnectionTestResult {
skuCode: string
warehouses: LingxingWarehouseTestResult[]
}
const basePath = '/platform/v1/firstleg/mojia-sku-sync'
export async function listMojiaSkuSync(query: MojiaSkuSyncQuery) {
const response = await http.get<ApiEnvelope<MojiaSkuSyncPage>, ApiEnvelope<MojiaSkuSyncPage>>(
basePath, { params: query },
)
return unwrapApiResponse(response)
}
export async function getMojiaSkuSyncConfig() {
const response = await http.get<ApiEnvelope<MojiaSkuSyncConfig>, ApiEnvelope<MojiaSkuSyncConfig>>(
`${basePath}/config`,
)
return unwrapApiResponse(response)
}
export async function testLingxingConnection(skuCode: string) {
const response = await http.post<ApiEnvelope<LingxingConnectionTestResult>, ApiEnvelope<LingxingConnectionTestResult>>(
`${basePath}/test-connection`, { skuCode },
)
return unwrapApiResponse(response)
}
export async function submitLingxingVerificationCode(code: string) {
const response = await http.post<ApiEnvelope<string>, ApiEnvelope<string>>(
`${basePath}/verification-code`, { code },
)
return unwrapApiResponse(response)
}
export async function updateMojiaSkuSync(id: string, data: {
skuCode: string
lengthCm: number
widthCm: number
heightCm: number
weightKg: number
revision: number
}) {
const response = await http.put<ApiEnvelope<MojiaSkuSyncRecord>, ApiEnvelope<MojiaSkuSyncRecord>>(
`${basePath}/${encodeURIComponent(id)}`, data,
)
return unwrapApiResponse(response)
}
export async function retryMojiaSkuSync(id: string, revision: number) {
const response = await http.post<ApiEnvelope<MojiaSkuSyncRecord>, ApiEnvelope<MojiaSkuSyncRecord>>(
`${basePath}/${encodeURIComponent(id)}/retry`, { revision },
)
return unwrapApiResponse(response)
}