210 lines
6.5 KiB
TypeScript
210 lines
6.5 KiB
TypeScript
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
|
|
|
|
export type PlatformFirstLegOrderStatus =
|
|
| 'DRAFT'
|
|
| 'SUBMITTED'
|
|
| 'APPROVED'
|
|
| 'ACCEPTED'
|
|
| 'REJECTED'
|
|
| 'CANCELLED'
|
|
| 'PROCESSING'
|
|
| 'COMPLETED'
|
|
|
|
export interface PlatformFirstLegOrderResource {
|
|
id: number | string
|
|
tenantId: number | string
|
|
orderNo: string | null
|
|
customerId: number | string | null
|
|
customerName: string
|
|
status: PlatformFirstLegOrderStatus
|
|
transportMode: 'SEA' | 'AIR' | 'RAIL' | 'TRUCK'
|
|
tradeTerm: string | null
|
|
destinationCountryCode: string
|
|
destinationWarehouseId: number | string | null
|
|
destinationWarehouseName: string
|
|
expectedShipDate: string | null
|
|
customerRemark: string | null
|
|
pickupMethod: string
|
|
receivingWarehouseId: number | string
|
|
receivingWarehouseName: string
|
|
receivingWarehouseAddress: string | null
|
|
receivingTime: string | null
|
|
channelCode: string
|
|
channelName: string
|
|
taxMode: string
|
|
containerMode: string | null
|
|
customsInspection: boolean | null
|
|
destinationType: string
|
|
amazonWarehouseCode: string | null
|
|
shipmentId: string | null
|
|
referenceId: string | null
|
|
expressCompany: string | null
|
|
expressTrackingNo: string | null
|
|
createdAt: string
|
|
updatedAt: string
|
|
}
|
|
|
|
export interface PlatformFirstLegCargoResource {
|
|
id: number | string
|
|
itemNo: number
|
|
cargoName: string
|
|
cargoNameEn: string | null
|
|
packageType: string
|
|
packageCount: number
|
|
grossWeightKg: number
|
|
volumeCbm: number
|
|
totalQuantity: number | null
|
|
cargoRemark: string | null
|
|
}
|
|
|
|
export interface PlatformFirstLegPartyResource {
|
|
id: number | string
|
|
partyType: 'SENDER' | 'RECEIVER' | string
|
|
companyName: string
|
|
contactName: string
|
|
phone: string
|
|
email: string | null
|
|
countryCode: string
|
|
province: string | null
|
|
city: string
|
|
district: string | null
|
|
addressLine: string
|
|
postalCode: string | null
|
|
}
|
|
|
|
export interface PlatformOrderStatusHistoryResource {
|
|
id: number | string
|
|
fromStatus: PlatformFirstLegOrderStatus | null
|
|
toStatus: PlatformFirstLegOrderStatus
|
|
action: string
|
|
reason: string | null
|
|
operatorName: string | null
|
|
occurredAt: string
|
|
}
|
|
|
|
export interface PlatformOrderInternalNoteResource {
|
|
id: number | string
|
|
content: string
|
|
createdAt: string
|
|
createdBy: number | string | null
|
|
}
|
|
|
|
export interface PlatformFirstLegOrderDetailResource {
|
|
order: PlatformFirstLegOrderResource
|
|
cargoes: PlatformFirstLegCargoResource[]
|
|
parties: PlatformFirstLegPartyResource[]
|
|
internalNotes: PlatformOrderInternalNoteResource[]
|
|
statusHistory: PlatformOrderStatusHistoryResource[]
|
|
}
|
|
|
|
export interface PlatformFirstLegOrderPageResource {
|
|
records: PlatformFirstLegOrderResource[]
|
|
page: number
|
|
size: number
|
|
total: number
|
|
pages: number
|
|
}
|
|
|
|
export interface PlatformTenantOrderStatistics {
|
|
tenantId: string
|
|
totalSubmittedOrders: number
|
|
currentMonthSubmittedOrders: number
|
|
monthStart: string
|
|
nextMonthStart: string
|
|
zoneId: 'Asia/Shanghai' | string
|
|
asOf: string
|
|
}
|
|
|
|
type PlatformFirstLegOrderPagePayload = Omit<PlatformFirstLegOrderPageResource, 'page' | 'size' | 'total' | 'pages'> & {
|
|
page: number | string
|
|
size: number | string
|
|
total: number | string
|
|
pages: number | string
|
|
}
|
|
|
|
export interface PlatformFirstLegOrderQuery {
|
|
tenantId?: string
|
|
keyword?: string
|
|
status?: PlatformFirstLegOrderStatus
|
|
customerId?: string
|
|
destinationWarehouseId?: string
|
|
createdFrom?: string
|
|
createdTo?: string
|
|
page: number
|
|
size: number
|
|
}
|
|
|
|
async function getData<T>(path: string, params?: Record<string, unknown>) {
|
|
const response = await http.get<ApiEnvelope<T>, ApiEnvelope<T>>(path, { params })
|
|
return unwrapApiResponse(response)
|
|
}
|
|
|
|
async function postData<T>(path: string, body?: unknown, params?: Record<string, unknown>) {
|
|
const response = await http.post<ApiEnvelope<T>, ApiEnvelope<T>>(path, body, { params })
|
|
return unwrapApiResponse(response)
|
|
}
|
|
|
|
function paginationNumber(value: number | string, fallback: number) {
|
|
const parsed = Number(value)
|
|
return Number.isFinite(parsed) && parsed >= 0 ? Math.trunc(parsed) : fallback
|
|
}
|
|
|
|
export async function listPlatformFirstLegOrders(query: PlatformFirstLegOrderQuery) {
|
|
const result = await getData<PlatformFirstLegOrderPagePayload>('/platform/v1/orders/first-leg', { ...query })
|
|
return {
|
|
...result,
|
|
page: paginationNumber(result.page, query.page),
|
|
size: paginationNumber(result.size, query.size),
|
|
total: paginationNumber(result.total, 0),
|
|
pages: paginationNumber(result.pages, 0),
|
|
} satisfies PlatformFirstLegOrderPageResource
|
|
}
|
|
|
|
export async function getPlatformTenantOrderStatistics(tenantId: string): Promise<PlatformTenantOrderStatistics> {
|
|
const result = await getData<Omit<PlatformTenantOrderStatistics, 'tenantId'> & { tenantId: number | string }>(
|
|
'/platform/v1/orders/first-leg/tenant-statistics',
|
|
{ tenantId },
|
|
)
|
|
return { ...result, tenantId: String(result.tenantId) }
|
|
}
|
|
|
|
export function getPlatformFirstLegOrder(tenantId: string, orderId: string) {
|
|
return getData<PlatformFirstLegOrderDetailResource>(`/platform/v1/orders/first-leg/${orderId}`, { tenantId })
|
|
}
|
|
|
|
export function approvePlatformFirstLegOrder(tenantId: string, orderId: string) {
|
|
return postData<void>(`/platform/v1/orders/first-leg/${orderId}/approve`, undefined, { tenantId })
|
|
}
|
|
|
|
export function acceptPlatformFirstLegOrder(tenantId: string, orderId: string) {
|
|
return postData<void>(`/platform/v1/orders/first-leg/${orderId}/accept`, undefined, { tenantId })
|
|
}
|
|
|
|
export function startPlatformFirstLegOrder(tenantId: string, orderId: string) {
|
|
return postData<void>(`/platform/v1/orders/first-leg/${orderId}/start`, undefined, { tenantId })
|
|
}
|
|
|
|
export function completePlatformFirstLegOrder(tenantId: string, orderId: string) {
|
|
return postData<void>(`/platform/v1/orders/first-leg/${orderId}/complete`, undefined, { tenantId })
|
|
}
|
|
|
|
export function cancelPlatformFirstLegOrder(tenantId: string, orderId: string, reason: string) {
|
|
return postData<void>(`/platform/v1/orders/first-leg/${orderId}/cancel`, { reason }, { tenantId })
|
|
}
|
|
|
|
export function addPlatformFirstLegOrderNote(tenantId: string, orderId: string, content: string) {
|
|
return postData<number | string>(`/platform/v1/orders/first-leg/${orderId}/internal-notes`, { content }, { tenantId })
|
|
}
|
|
|
|
export function updatePlatformFirstLegOrderExpress(
|
|
tenantId: string,
|
|
orderId: string,
|
|
payload: { expressCompany: string; expressTrackingNo: string },
|
|
) {
|
|
return http.put<ApiEnvelope<void>, ApiEnvelope<void>>(
|
|
`/platform/v1/orders/first-leg/${orderId}/express`,
|
|
payload,
|
|
{ params: { tenantId } },
|
|
).then(unwrapApiResponse)
|
|
}
|