优化
This commit is contained in:
@@ -82,11 +82,20 @@ describe('inbound weight OCR API', () => {
|
||||
)
|
||||
})
|
||||
|
||||
it('loads same-warehouse pallet snapshots through Firstleg', async () => {
|
||||
const options = [{ palletId: '11', palletCode: 'TP-11', palletType: '木托盘', capacityCbm: 1.2, tareWeightKg: 12 }]
|
||||
vi.mocked(http.get).mockResolvedValue({ code: '200', message: 'success', data: options })
|
||||
it('normalizes the formal paged pallet response returned by Firstleg', async () => {
|
||||
const records = [
|
||||
{ palletId: '2092803000000000001', palletCode: 'TP-11', palletType: '木托盘', capacityCbm: 1.2, tareWeightKg: 12 },
|
||||
{ palletId: '2092803000000000002', palletCode: 'TP-12', palletType: '塑料托盘', capacityCbm: 1.1, tareWeightKg: 10 },
|
||||
]
|
||||
vi.mocked(http.get).mockResolvedValue({
|
||||
code: '200',
|
||||
message: 'success',
|
||||
data: { records, page: '1', size: '20', total: '2', pages: '1' },
|
||||
})
|
||||
|
||||
await expect(getWeightPalletOptions('10001', '20001')).resolves.toEqual(options)
|
||||
await expect(getWeightPalletOptions('10001', '20001')).resolves.toEqual({
|
||||
records, page: 1, size: 20, total: 2, pages: 1,
|
||||
})
|
||||
expect(http.get).toHaveBeenCalledWith(
|
||||
'/platform/v1/first-leg/inbounds/20001/weight-pallet-options',
|
||||
{ params: { tenantId: '10001' } },
|
||||
@@ -94,7 +103,9 @@ describe('inbound weight OCR API', () => {
|
||||
})
|
||||
|
||||
it('passes an abort signal without changing the frozen pallet endpoint parameters', async () => {
|
||||
vi.mocked(http.get).mockResolvedValue({ code: '200', message: 'success', data: [] })
|
||||
vi.mocked(http.get).mockResolvedValue({
|
||||
code: '200', message: 'success', data: { records: [], page: '1', size: '20', total: '0', pages: '0' },
|
||||
})
|
||||
const controller = new AbortController()
|
||||
|
||||
await getWeightPalletOptions('10001', '20001', controller.signal)
|
||||
|
||||
@@ -6,6 +6,7 @@ import type {
|
||||
CreateWeightResultRequest,
|
||||
WeightImageUploadResult,
|
||||
WeightPalletOption,
|
||||
WeightPalletOptionPage,
|
||||
WeightResultResource,
|
||||
WeightWorkspaceResource,
|
||||
} from '../types'
|
||||
@@ -15,10 +16,23 @@ const imageBasePath = '/platform/v1/files/measurements'
|
||||
const maxErrorEnvelopeBytes = 1024 * 1024
|
||||
const confidenceScale = 100_000
|
||||
|
||||
interface WeightPalletOptionPageResponse {
|
||||
records: WeightPalletOption[]
|
||||
page: number | string
|
||||
size: number | string
|
||||
total: number | string
|
||||
pages: number | string
|
||||
}
|
||||
|
||||
function segment(value: string) {
|
||||
return encodeURIComponent(value)
|
||||
}
|
||||
|
||||
function normalizedPageNumber(value: number | string, fallback: number, minimum: number) {
|
||||
const parsed = typeof value === 'number' ? value : Number(value)
|
||||
return Number.isFinite(parsed) ? Math.max(minimum, Math.trunc(parsed)) : fallback
|
||||
}
|
||||
|
||||
export function normalizeWeightConfidence(value: number | null) {
|
||||
if (value == null || !Number.isFinite(value)) return null
|
||||
const clamped = Math.min(1, Math.max(0, value))
|
||||
@@ -61,11 +75,18 @@ export async function getWeightWorkspace(tenantId: string, inboundId: string) {
|
||||
}
|
||||
|
||||
export async function getWeightPalletOptions(tenantId: string, inboundId: string, signal?: AbortSignal) {
|
||||
const response = await http.get<ApiEnvelope<WeightPalletOption[]>, ApiEnvelope<WeightPalletOption[]>>(
|
||||
const response = await http.get<ApiEnvelope<WeightPalletOptionPageResponse>, ApiEnvelope<WeightPalletOptionPageResponse>>(
|
||||
`${measurementBasePath}/${segment(inboundId)}/weight-pallet-options`,
|
||||
{ params: { tenantId }, ...(signal ? { signal } : {}) },
|
||||
)
|
||||
return unwrapApiResponse(response)
|
||||
const page = unwrapApiResponse(response)
|
||||
return {
|
||||
records: page.records,
|
||||
page: normalizedPageNumber(page.page, 1, 1),
|
||||
size: normalizedPageNumber(page.size, page.records.length, 0),
|
||||
total: normalizedPageNumber(page.total, page.records.length, 0),
|
||||
pages: normalizedPageNumber(page.pages, 0, 0),
|
||||
} satisfies WeightPalletOptionPage
|
||||
}
|
||||
|
||||
export async function uploadWeightImage(tenantId: string, inboundId: string, file: File) {
|
||||
|
||||
Reference in New Issue
Block a user