优化
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { beforeEach, expect, it, vi } from 'vitest'
|
||||
import { http } from '@/shared/api/http'
|
||||
import { assignTransport } from './transportTasks'
|
||||
vi.mock('@/shared/api/http', () => ({ http: { post: vi.fn() }, unwrapApiResponse: (value: { data: unknown }) => value.data }))
|
||||
vi.mock('@/modules/overseas-master-data', () => ({ normalizeTripDetail: (value: unknown) => value }))
|
||||
beforeEach(() => vi.resetAllMocks())
|
||||
const body = { recordVersion: 4, vehicleId: '1', driverId: '2', reason: '保存照片', reviewPhotos: { vehicleFileIds: ['21'], driverPhotoFileIds: ['22'], licenseFileIds: [] }, masterLicenseFileId: '33' }
|
||||
it('does not submit photo changes when the backend has not supplied the dispatch version', () => {
|
||||
expect(() => assignTransport('PC1', body)).toThrow('照片保存版本')
|
||||
expect(http.post).not.toHaveBeenCalled()
|
||||
})
|
||||
it('preserves zero dispatch version and opaque photo IDs in the assignment', async () => {
|
||||
vi.mocked(http.post).mockResolvedValue({ data: { dispatchNo: 'PC1', taskType: 'PICKUP', dispatchRecordVersion: '1', resources: { vehicle: { evidenceFileIds: ['21'] } }, execution: {}, pickups: [] } })
|
||||
const result = await assignTransport('PC1', { ...body, dispatchRecordVersion: 0 })
|
||||
expect(http.post).toHaveBeenCalledWith('/platform/v1/last-leg/dispatches/transport-tasks/PC1/assign', { ...body, dispatchRecordVersion: 0 })
|
||||
expect(result.resources?.vehicle?.evidenceFileIds).toEqual(['21'])
|
||||
})
|
||||
@@ -1,9 +1,11 @@
|
||||
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
|
||||
import { normalizeTripDetail, type TripDetail, type PickupTask, type PickupCandidate, type PickupEvidence, type PickupPlan, type TripAssignment, type TripResourceRelease } from '@/modules/overseas-master-data'
|
||||
import type { Resources, ReviewAttachments, Version } from '../dispatchContracts'
|
||||
|
||||
export type TransportType = 'PICKUP' | 'LOCAL_TRUCK'
|
||||
export const transportLabels = { DELIVERY: '仓库派送', PICKUP: '到仓取货', LOCAL_TRUCK: '本土卡车' }
|
||||
export interface TransportDetail { dispatchNo: string; taskType: TransportType; execution: TripDetail; customerId: string | null; orderNo: string | null; pickups: PickupTask[]; completionEvidence: PickupEvidence[] }
|
||||
export interface TransportDetail { dispatchNo: string; taskType: TransportType; execution: TripDetail; customerId: string | null; orderNo: string | null; pickups: PickupTask[]; completionEvidence: PickupEvidence[]; dispatchRecordVersion: Version; resources: Resources | null }
|
||||
export type TransportAssignment = TripAssignment & { dispatchRecordVersion?: Version; reviewPhotos?: ReviewAttachments; masterLicenseFileId?: string | null }
|
||||
export interface TruckCandidate { customerId: string; orderNo: string; origin: string; originAddress: string; destination: string; destinationAddress: string; palletCount: number; packageCount: number }
|
||||
export interface TruckPlan { customerId: string; orderNo: string; warehouseId: string; plannedDepartureAt: string; expectedDriverEndAt: string; idempotencyKey: string }
|
||||
type WireDetail = Omit<TransportDetail, 'execution'> & { execution: Parameters<typeof normalizeTripDetail>[0] }
|
||||
@@ -17,7 +19,10 @@ export const pickupCandidates = () => get<{ records: PickupCandidate[]; total: n
|
||||
export const truckCandidates = () => get<TruckCandidate[]>(`${base}/truck-candidates`)
|
||||
export const createTransportPickup = (body: PickupPlan) => post<WireDetail>(`${base}/pickup`, body).then(normalize)
|
||||
export const createTransportTruck = (body: TruckPlan) => post<WireDetail>(`${base}/truck`, body).then(normalize)
|
||||
export const assignTransport = (number: string, body: TripAssignment) => post<WireDetail>(`${path(number)}/assign`, body).then(normalize)
|
||||
export const assignTransport = (number: string, body: TransportAssignment) => {
|
||||
if (body.reviewPhotos && body.dispatchRecordVersion == null) throw new Error('未读取到照片保存版本,请更新本地后端并刷新后重试')
|
||||
return post<WireDetail>(`${path(number)}/assign`, body).then(normalize)
|
||||
}
|
||||
export const transportOccupancy = (number: string, kind: 'VEHICLE' | 'DRIVER', resourceIds: string[]) => resourceIds.length ? post<Array<{ resourceId: string; occupiedTripNo: string | null; available: boolean }>>(`${path(number)}/resource-occupancy`, { kind, resourceIds }) : Promise.resolve([])
|
||||
export const cancelTransport = (number: string, body: object) => post(`${path(number)}/cancel`, body)
|
||||
export const releaseTransport = (number: string, body: TripResourceRelease) => post(`${path(number)}/release`, body)
|
||||
|
||||
Reference in New Issue
Block a user