优化
This commit is contained in:
@@ -93,3 +93,12 @@ it('accepts unknown transport ownership without guessing current master data', a
|
||||
expect(result.row.vehicle.ownership).toBeNull()
|
||||
expect(result.row.actualPalletCount).toBeNull()
|
||||
})
|
||||
|
||||
it('accepts transport rows when nullable ownership is omitted by JSON serialization', async () => {
|
||||
const detail = ownedBusinessFixture()
|
||||
const { ownership: _omitted, ...vehicle } = detail.row.vehicle
|
||||
vi.mocked(http.get).mockResolvedValue({ data: { ...detail, row: { ...detail.row, taskType: 'PICKUP', actualPalletCount: null, vehicle } } })
|
||||
const result = await getOwnedBusiness(detail.row.dispatchNo)
|
||||
expect(result.row.taskType).toBe('PICKUP')
|
||||
expect(result.row.vehicle.ownership).toBeUndefined()
|
||||
})
|
||||
|
||||
@@ -16,7 +16,11 @@ function operations(value: OwnedBusinessOperations): OwnedBusinessOperations {
|
||||
return { ...value, money: value.money ? { ...value.money, amount: decimal(value.money.amount, 2, 18)! } : null, actualDistanceMiles: decimal(value.actualDistanceMiles,3,12), fuelConsumptionLitresPer100Km: decimal(value.fuelConsumptionLitresPer100Km,3,12) }
|
||||
}
|
||||
function row(value: OwnedBusinessRow): OwnedBusinessRow {
|
||||
if (!value.dispatchNo || !['AFTER_LOADING','DELIVERING','DELIVERED'].includes(value.stage) || !(['OWNED','DISPATCHED'].includes(value.vehicle?.ownership || '') || (value.vehicle?.ownership === null && ['LOCAL_TRUCK','PICKUP'].includes(value.taskType || '')))) throw new Error('自有排车来源或阶段不完整,请重新读取')
|
||||
// Jackson omits nullable ownership fields from transport rows. Treat both
|
||||
// null and omitted values as the same transport snapshot state.
|
||||
const ownership = value.vehicle?.ownership
|
||||
const transportWithoutVehicleOwnership = ownership == null && ['LOCAL_TRUCK','PICKUP'].includes(value.taskType || '')
|
||||
if (!value.dispatchNo || !['AFTER_LOADING','DELIVERING','DELIVERED'].includes(value.stage) || !(['OWNED','DISPATCHED'].includes(ownership || '') || transportWithoutVehicleOwnership)) throw new Error('自有排车来源或阶段不完整,请重新读取')
|
||||
return { ...value, operations: operations(value.operations), unitPrice: decimal(value.unitPrice,2,18), recordVersion: ownedBusinessVersion(value.recordVersion), dispatchRecordVersion: ownedBusinessVersion(value.dispatchRecordVersion), actualPalletCount: value.actualPalletCount == null ? null : count(value.actualPalletCount), photoSummary: { loadingCount: count(value.photoSummary.loadingCount), fuelCount: count(value.photoSummary.fuelCount) } }
|
||||
}
|
||||
function detail(value: OwnedBusinessDetail): OwnedBusinessDetail { if (value.row.dispatchNo !== value.dispatch.dispatchNo) throw new Error('运营资料与原排车单不一致'); return { ...value, row: row(value.row) } }
|
||||
|
||||
Reference in New Issue
Block a user