101 lines
3.3 KiB
TypeScript
101 lines
3.3 KiB
TypeScript
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
|
|||
|
|
|
||
|
|
export type CoLoadGroupStatus = 'ACTIVE' | 'LOCKED' | 'CONSUMED' | 'CANCELLED'
|
||
|
|
|
||
|
|
export interface CoLoadGroupMember {
|
||
|
|
tenantId: string
|
||
|
|
orderId: string
|
||
|
|
inboundId: string
|
||
|
|
fullPackageCount: number
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface CoLoadGroup {
|
||
|
|
groupId: string
|
||
|
|
groupNo: string
|
||
|
|
status: CoLoadGroupStatus
|
||
|
|
warehouseId: string
|
||
|
|
channelCode: string
|
||
|
|
destinationType: string
|
||
|
|
destinationWarehouseId: string | null
|
||
|
|
destinationCode: string | null
|
||
|
|
lockedPlanId: string | null
|
||
|
|
version: number
|
||
|
|
members: CoLoadGroupMember[]
|
||
|
|
fullPackageCount: number
|
||
|
|
createdAt: string
|
||
|
|
updatedAt: string
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface OrderCoLoadGroupInfo {
|
||
|
|
orderId: string
|
||
|
|
inboundId: string
|
||
|
|
group: CoLoadGroup
|
||
|
|
}
|
||
|
|
|
||
|
|
type RawId = string | number
|
||
|
|
type RawCoLoadGroup = Omit<CoLoadGroup, 'groupId' | 'warehouseId' | 'destinationWarehouseId' | 'lockedPlanId' | 'members'> & {
|
||
|
|
groupId: RawId
|
||
|
|
warehouseId: RawId
|
||
|
|
destinationWarehouseId: RawId | null
|
||
|
|
lockedPlanId: RawId | null
|
||
|
|
members: Array<Omit<CoLoadGroupMember, 'tenantId' | 'orderId' | 'inboundId'> & { tenantId: RawId; orderId: RawId; inboundId: RawId }>
|
||
|
|
}
|
||
|
|
type RawOrderCoLoadGroupInfo = Omit<OrderCoLoadGroupInfo, 'orderId' | 'inboundId' | 'group'> & {
|
||
|
|
orderId: RawId
|
||
|
|
inboundId: RawId
|
||
|
|
group: RawCoLoadGroup
|
||
|
|
}
|
||
|
|
|
||
|
|
const basePath = '/platform/v1/first-leg/coload-groups'
|
||
|
|
const optionalId = (value: RawId | null) => value == null ? null : String(value)
|
||
|
|
const operationId = (prefix: string) => `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 10)}`
|
||
|
|
|
||
|
|
function normalizeGroup(raw: RawCoLoadGroup): CoLoadGroup {
|
||
|
|
return {
|
||
|
|
...raw,
|
||
|
|
groupId: String(raw.groupId),
|
||
|
|
warehouseId: String(raw.warehouseId),
|
||
|
|
destinationWarehouseId: optionalId(raw.destinationWarehouseId),
|
||
|
|
lockedPlanId: optionalId(raw.lockedPlanId),
|
||
|
|
version: Number(raw.version),
|
||
|
|
fullPackageCount: Number(raw.fullPackageCount),
|
||
|
|
members: (raw.members || []).map((member) => ({
|
||
|
|
...member,
|
||
|
|
tenantId: String(member.tenantId),
|
||
|
|
orderId: String(member.orderId),
|
||
|
|
inboundId: String(member.inboundId),
|
||
|
|
fullPackageCount: Number(member.fullPackageCount),
|
||
|
|
})),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function createPlatformCoLoadGroup(orderIds: string[]) {
|
||
|
|
const response = await http.post<ApiEnvelope<RawCoLoadGroup>, ApiEnvelope<RawCoLoadGroup>>(
|
||
|
|
basePath,
|
||
|
|
{ orderIds },
|
||
|
|
{ headers: { 'Idempotency-Key': operationId('admin-coload-create') } },
|
||
|
|
)
|
||
|
|
return normalizeGroup(unwrapApiResponse(response))
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function cancelPlatformCoLoadGroup(groupId: string, expectedVersion: number, reason?: string | null) {
|
||
|
|
const response = await http.post<ApiEnvelope<RawCoLoadGroup>, ApiEnvelope<RawCoLoadGroup>>(
|
||
|
|
`${basePath}/${encodeURIComponent(groupId)}/cancel`,
|
||
|
|
{ expectedVersion, reason: reason?.trim() || null },
|
||
|
|
{ headers: { 'Idempotency-Key': operationId('admin-coload-cancel') } },
|
||
|
|
)
|
||
|
|
return normalizeGroup(unwrapApiResponse(response))
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function batchQueryPlatformCoLoadGroups(orderIds: string[]) {
|
||
|
|
const response = await http.post<ApiEnvelope<RawOrderCoLoadGroupInfo[]>, ApiEnvelope<RawOrderCoLoadGroupInfo[]>>(
|
||
|
|
`${basePath}/batch-query`,
|
||
|
|
{ orderIds },
|
||
|
|
)
|
||
|
|
return unwrapApiResponse(response).map((item) => ({
|
||
|
|
orderId: String(item.orderId),
|
||
|
|
inboundId: String(item.inboundId),
|
||
|
|
group: normalizeGroup(item.group),
|
||
|
|
}))
|
||
|
|
}
|