feat(admin): 排车默认发布散板需求并直接确认装车

This commit is contained in:
2026-10-21 18:51:10 +08:00
parent 7c43fcacc4
commit a4cb6c3757
18 changed files with 216 additions and 36 deletions
@@ -0,0 +1,15 @@
import { beforeEach, expect, it, vi } from 'vitest'
import { http } from '@/shared/api/http'
import { listDispatchCapacityDemands } from './dispatchCapacityDemands'
vi.mock('@/shared/api/http', () => ({ http: { get: vi.fn() }, unwrapApiResponse: (value: { data: unknown }) => value.data }))
beforeEach(() => vi.clearAllMocks())
it('reads only dispatch demand summaries and preserves unknown quantities distinctly from zero', async () => {
vi.mocked(http.get).mockResolvedValue({ data: { page: '1', size: '20', total: '1', pages: '1', records: [{ dispatchNo: 'PC-1', vehiclePalletSpaces: '30', scheduledPalletCount: '0', remainingPalletSpaces: null, remainingWeightKg: null, remainingVolumeCbm: null, capacityKnown: false }] } })
const value=await listDispatchCapacityDemands({page:1,size:20,origin:'测试仓'})
expect(http.get).toHaveBeenCalledExactlyOnceWith('/platform/v1/last-leg/dispatches/capacity-demands',{params:{page:1,size:20,origin:'测试仓'}})
expect(value).toMatchObject({total:1,records:[{dispatchNo:'PC-1',vehiclePalletSpaces:30,scheduledPalletCount:0,remainingPalletSpaces:null}]})
})
it.each(['invalid', -1, true])('rejects invalid capacity quantities %s', async remainingPalletSpaces => {
vi.mocked(http.get).mockResolvedValue({data:{page:1,size:20,total:1,pages:1,records:[{remainingPalletSpaces}]}})
await expect(listDispatchCapacityDemands({page:1,size:20})).rejects.toThrow('数量无效')
})
@@ -0,0 +1,23 @@
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
export interface DispatchCapacityDemand {
dispatchNo: string; warehouseName: string; route: string | null; plannedDepartureAt: string | null
vehiclePalletSpaces: number | null; scheduledPalletCount: number | null; remainingPalletSpaces: number | null
remainingWeightKg: number | null; remainingVolumeCbm: number | null; capacityKnown: boolean; capacityReason: string | null
}
interface Page { records: DispatchCapacityDemand[]; page: number; size: number; total: number; pages: number }
interface Query { page: number; size: number; origin?: string; destination?: string }
const quantity = (value: unknown): number => {
if (value == null || typeof value === 'string' && value.trim() === '') throw new Error('散板需求数量缺失')
if (typeof value !== 'number' && typeof value !== 'string') throw new Error('散板需求数量无效')
const parsed = Number(value)
if (!Number.isFinite(parsed) || parsed < 0) throw new Error('散板需求数量无效')
return parsed
}
export async function listDispatchCapacityDemands(query: Query): Promise<Page> {
const value = unwrapApiResponse(await http.get<ApiEnvelope<Page>, ApiEnvelope<Page>>('/platform/v1/last-leg/dispatches/capacity-demands', { params: query }))
const nullable = (number: unknown) => number == null ? null : quantity(number)
return { ...value, page: quantity(value.page), size: quantity(value.size), total: quantity(value.total), pages: quantity(value.pages), records: value.records.map(row => ({ ...row,
vehiclePalletSpaces: nullable(row.vehiclePalletSpaces), scheduledPalletCount: nullable(row.scheduledPalletCount), remainingPalletSpaces: nullable(row.remainingPalletSpaces),
remainingWeightKg: nullable(row.remainingWeightKg), remainingVolumeCbm: nullable(row.remainingVolumeCbm),
})) }
}