feat: add pallet label printing

This commit is contained in:
2026-09-09 17:27:00 +08:00
parent 8f6d4fc03e
commit a47a7e9767
6 changed files with 137 additions and 2 deletions
@@ -6,6 +6,8 @@ import {
getPreloadPlan,
listConfirmedLoadingLists,
listPreloadPlans,
preparePalletLabels,
printPalletLabels,
updatePreloadTransport,
updateLoadingItemWarehouseRemark,
} from './platformLoadingLists'
@@ -158,4 +160,18 @@ describe('platform loading lists API', () => {
})
})
it('prepares and prints pallet labels by FBA warehouse', async () => {
const post = vi.spyOn(http, 'post')
.mockResolvedValueOnce({ code: '200', message: 'ok', data: { planId: 10, planNo: 'LP-1', containerNo: 'MSCU6639870', totalCount: 2, groups: [{ destinationWarehouseCode: 'ONT8', destinationWarehouseName: 'ONT8', totalCount: 2, labels: [{ labelId: 1, itemId: 2, accountId: 3, inboundId: 4, inboundCode: 'RK-1', containerNo: 'MSCU6639870', destinationWarehouseCode: 'ONT8', destinationWarehouseName: 'ONT8', palletIndex: 1, palletCode: 'MSCU6639870-ONT8-001' }] }] } })
.mockResolvedValueOnce(new Blob(['pdf'], { type: 'application/pdf' }))
const manifest = await preparePalletLabels('10', '20')
const pdf = await printPalletLabels('10', '20', 'ONT8', 1)
expect(manifest).toMatchObject({ planId: '10', groups: [{ labels: [{ labelId: '1', itemId: '2', accountId: '3', inboundId: '4' }] }] })
expect(pdf.type).toBe('application/pdf')
expect(post).toHaveBeenNthCalledWith(1, '/platform/v1/first-leg/loading-plans/10/pallet-labels/prepare', null, { params: { warehouseId: '20' } })
expect(post).toHaveBeenNthCalledWith(2, '/platform/v1/first-leg/loading-plans/10/pallet-labels/print', { destinationWarehouseCode: 'ONT8', count: 1 }, { params: { warehouseId: '20' }, responseType: 'blob', timeout: 60_000 })
})
})
@@ -256,6 +256,34 @@ function normalizeHistory(raw: LoadingHistory): LoadingHistory {
}
}
export interface PalletLabel {
labelId: string
itemId: string
accountId: string
inboundId: string
inboundCode: string
containerNo: string
destinationWarehouseCode: string
destinationWarehouseName: string | null
palletIndex: number
palletCode: string
}
export interface PalletLabelGroup {
destinationWarehouseCode: string
destinationWarehouseName: string | null
totalCount: number
labels: PalletLabel[]
}
export interface PalletLabelManifest {
planId: string
planNo: string
containerNo: string
totalCount: number
groups: PalletLabelGroup[]
}
function normalizePage<T extends LoadingListSummary>(raw: RawPage<T>, normalize: (row: T) => T): LoadingListPage<T> {
return {
records: (raw.records || []).map(normalize),
@@ -353,3 +381,26 @@ export async function getConfirmedLoadingList(planId: string, warehouseId: strin
histories: (result.histories || []).map(normalizeHistory),
}
}
export async function preparePalletLabels(planId: string, warehouseId: string) {
const response = await http.post<ApiEnvelope<PalletLabelManifest>, ApiEnvelope<PalletLabelManifest>>(
`${basePath}/loading-plans/${encodeURIComponent(planId)}/pallet-labels/prepare`, null, { params: { warehouseId } },
)
const result = unwrapApiResponse(response)
return {
...result,
planId: requiredId(result.planId),
groups: (result.groups || []).map((group) => ({
...group,
labels: (group.labels || []).map((label) => ({ ...label, labelId: requiredId(label.labelId), itemId: requiredId(label.itemId), accountId: requiredId(label.accountId), inboundId: requiredId(label.inboundId) })),
})),
}
}
export function printPalletLabels(planId: string, warehouseId: string, destinationWarehouseCode?: string, count?: number) {
return http.post<Blob, Blob>(
`${basePath}/loading-plans/${encodeURIComponent(planId)}/pallet-labels/print`,
{ destinationWarehouseCode: destinationWarehouseCode || null, count: count || null },
{ params: { warehouseId }, responseType: 'blob', timeout: 60_000 },
)
}