优化
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { overseasHttp } from '@/shared/api/overseasHttp'
|
||||
import { getInboundPlan, listInboundPlans } from './inboundPlans'
|
||||
|
||||
vi.mock('@/shared/api/overseasHttp', () => ({ overseasHttp: { get: vi.fn() } }))
|
||||
describe('inbound plan overseas API', () => {
|
||||
beforeEach(() => vi.mocked(overseasHttp.get).mockReset())
|
||||
it('pages plans with explicit customer scope', async () => {
|
||||
vi.mocked(overseasHttp.get).mockResolvedValue({ code: '200', message: 'ok', data: { records: [], page: 1, size: 20, total: 0, pages: 0 } })
|
||||
await listInboundPlans({ customerId: '190000000000000001', page: 1, size: 20, inboundCode: 'IN-1' })
|
||||
expect(overseasHttp.get).toHaveBeenCalledWith('/platform/v1/last-leg/inbound-plans', { params: { customerId: '190000000000000001', page: 1, size: 20, inboundCode: 'IN-1' } })
|
||||
})
|
||||
it('gets detail by encoded plan number', async () => {
|
||||
vi.mocked(overseasHttp.get).mockResolvedValue({ code: '200', message: 'ok', data: { id: '1', planNo: 'IP/1', customerId: '2', sourceOrderId: '190000000000000099', lineCount: 0, palletCount: 0, totalVolumeCbm: 0, lines: [], pallets: [], allocations: [] } })
|
||||
await getInboundPlan('IP/1', '2')
|
||||
expect(overseasHttp.get).toHaveBeenCalledWith('/platform/v1/last-leg/inbound-plans/IP%2F1', { params: { customerId: '2' } })
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,66 @@
|
||||
import { overseasHttp } from '@/shared/api/overseasHttp'
|
||||
import { unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
|
||||
import type { OverseasPageResult } from './lastMileOrders'
|
||||
|
||||
export interface InboundPlanQuery {
|
||||
customerId: string
|
||||
page: number
|
||||
size: number
|
||||
planNo?: string
|
||||
inboundCode?: string
|
||||
status?: string
|
||||
overseasWarehouseId?: string
|
||||
destinationWarehouseCode?: string
|
||||
fbaWarehouseCode?: string
|
||||
appointmentStatus?: string
|
||||
createdFrom?: string
|
||||
createdTo?: string
|
||||
}
|
||||
|
||||
export interface InboundPlanSummaryDto {
|
||||
id: string
|
||||
planNo: string
|
||||
sourceOrderId: string
|
||||
customerId: string
|
||||
customerName?: string | null
|
||||
orderType?: string | null
|
||||
inboundCode?: string | null
|
||||
containerNo?: string | null
|
||||
overseasWarehouseId?: string | null
|
||||
overseasWarehouseName?: string | null
|
||||
destinationWarehouseId?: string | null
|
||||
destinationWarehouseCode?: string | null
|
||||
destinationWarehouseName?: string | null
|
||||
fbaWarehouseCode?: string | null
|
||||
packageCount?: number | null
|
||||
totalVolumeCbm?: number | null
|
||||
palletCount?: number | null
|
||||
status?: string | null
|
||||
appointmentStatus?: string | null
|
||||
createdAt?: string | null
|
||||
updatedAt?: string | null
|
||||
}
|
||||
|
||||
export interface InboundPlanDetailDto {
|
||||
id: string
|
||||
planNo: string
|
||||
customerId: string
|
||||
sourceOrderId: string
|
||||
containerNo?: string | null
|
||||
status?: string | null
|
||||
lineCount: number
|
||||
palletCount: number
|
||||
totalVolumeCbm: number
|
||||
lines: Array<{ id: string; orderId: string; inboundCode?: string | null; fbaWarehouseCode?: string | null; destinationWarehouseId?: string | null; destinationWarehouseCode?: string | null; destinationWarehouseName?: string | null; volumeCbm?: number | null; requiredPackageCount: number; plannedPalletCount: number }>
|
||||
pallets: Array<{ id: string; palletNo?: string | null; destinationWarehouseId?: string | null; destinationWarehouseCode?: string | null; destinationWarehouseName?: string | null; capacityCbm?: number | null; allocatedVolumeCbm?: number | null; sequenceNo: number; warehousePalletId?: string | null; warehouseLocationId?: string | null; warehouseResourceLockId?: string | null; assignmentStatus?: string | null; lockedAt?: string | null; actualVolumeCbm?: number | null; actualPackageCount: number }>
|
||||
allocations: Array<{ lineId: string; palletId: string; allocatedVolumeCbm?: number | null; plannedPackageCount: number; countedPackageCount: number; pickedPackageCount: number; actualVolumeCbm?: number | null; status?: string | null; version: number }>
|
||||
}
|
||||
|
||||
export async function listInboundPlans(query: InboundPlanQuery) {
|
||||
const { customerId, ...params } = query
|
||||
return unwrapApiResponse(await overseasHttp.get<ApiEnvelope<OverseasPageResult<InboundPlanSummaryDto>>, ApiEnvelope<OverseasPageResult<InboundPlanSummaryDto>>>('/platform/v1/last-leg/inbound-plans', { params: { customerId, ...params } }))
|
||||
}
|
||||
|
||||
export async function getInboundPlan(planNo: string, customerId: string) {
|
||||
return unwrapApiResponse(await overseasHttp.get<ApiEnvelope<InboundPlanDetailDto>, ApiEnvelope<InboundPlanDetailDto>>(`/platform/v1/last-leg/inbound-plans/${encodeURIComponent(planNo)}`, { params: { customerId } }))
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { overseasHttp } from '@/shared/api/overseasHttp'
|
||||
import { getInventorySummary, listInventoryBalances, listInventoryLedger, listInventoryPositions } from './inventory'
|
||||
vi.mock('@/shared/api/overseasHttp', () => ({ overseasHttp: { get: vi.fn() } }))
|
||||
describe('inventory overseas API', () => {
|
||||
beforeEach(() => vi.mocked(overseasHttp.get).mockReset())
|
||||
it('queries SKU balances with explicit customer scope', async () => { vi.mocked(overseasHttp.get).mockResolvedValue({ code: '200', message: 'ok', data: { records: [], page: 1, size: 20, total: 0, pages: 0 } }); await listInventoryBalances({ customerId: '9', page: 1, size: 20, skuCode: 'SKU-1', productName: '产品' }); expect(overseasHttp.get).toHaveBeenCalledWith('/platform/v1/last-leg/inventory/balances', { params: { customerId: '9', page: 1, size: 20, skuCode: 'SKU-1', productName: '产品' } }) })
|
||||
it('uses read-only summary, positions and ledger endpoints', async () => { vi.mocked(overseasHttp.get).mockResolvedValue({ code: '200', message: 'ok', data: {} }); await getInventorySummary({ customerId: '9', skuCode: 'SKU-1' }); await listInventoryPositions('190000000000000099', '9'); await listInventoryLedger({ customerId: '9', page: 1, size: 20 }); expect(vi.mocked(overseasHttp.get).mock.calls.map((call) => call[0])).toEqual(['/platform/v1/last-leg/inventory/summary', '/platform/v1/last-leg/inventory/balances/190000000000000099/positions', '/platform/v1/last-leg/inventory/ledger']) })
|
||||
it('does not expose stock-leaving commands', () => { const source = `${listInventoryBalances}${getInventorySummary}${listInventoryPositions}${listInventoryLedger}`; expect(source).not.toMatch(/allocate|unallocate|pick|ship/) })
|
||||
})
|
||||
@@ -0,0 +1,33 @@
|
||||
import { overseasHttp } from '@/shared/api/overseasHttp'
|
||||
import { unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
|
||||
import type { OverseasPageResult } from './lastMileOrders'
|
||||
|
||||
export interface InventoryBalanceQuery {
|
||||
customerId: string
|
||||
page: number
|
||||
size: number
|
||||
customerName?: string
|
||||
overseasWarehouseId?: string
|
||||
overseasWarehouseCode?: string
|
||||
destinationWarehouseCode?: string
|
||||
inboundOrderNo?: string
|
||||
inboundCode?: string
|
||||
businessOrderNo?: string
|
||||
skuCode?: string
|
||||
productName?: string
|
||||
inventoryStatus?: string
|
||||
}
|
||||
export interface InventoryBalanceDto {
|
||||
id: string; customerId: string; customerName?: string | null; overseasWarehouseId?: string | null; overseasWarehouseCode?: string | null; overseasWarehouseName?: string | null
|
||||
destinationWarehouseId?: string | null; destinationWarehouseCode?: string | null; destinationWarehouseName?: string | null; inboundOrderId?: string | null; inboundOrderNo?: string | null; inboundCode?: string | null
|
||||
skuCode?: string | null; productNameZh?: string | null; productNameEn?: string | null; totalPackages: number; availablePackages: number; holdPackages: number; allocatedPackages: number; pickedPackages: number
|
||||
inTransitPackages: number; receivingPackages: number; procurementPackages: number; updatedAt?: string | null
|
||||
}
|
||||
export interface InventoryDashboardDto { inboundOrderCount: number; palletCount: number; totalPackages: number; availablePackages: number; holdPackages: number; allocatedPackages: number; pickedPackages: number; inTransitPackages: number; receivingPackages: number; procurementPackages: number }
|
||||
export interface InventoryPositionDto { id: string; balanceId: string; customerId: string; overseasWarehouseId?: string | null; destinationWarehouseCode?: string | null; inboundOrderId?: string | null; inboundOrderNo?: string | null; inboundCode?: string | null; palletId?: string | null; palletNo?: string | null; batchNo?: string | null; warehouseLocationId?: string | null; warehouseLocationCode?: string | null; totalPackages: number; availablePackages: number; holdPackages: number; allocatedPackages: number; pickedPackages: number; receivingPackages: number; status?: string | null; updatedAt?: string | null }
|
||||
export interface InventoryLedgerDto { id: string; customerId: string; overseasWarehouseId?: string | null; destinationWarehouseCode?: string | null; inboundOrderId?: string | null; inboundOrderNo?: string | null; inboundCode?: string | null; palletNo?: string | null; batchNo?: string | null; warehouseLocationCode?: string | null; businessType?: string | null; businessOrderNo?: string | null; outboundOrderNo?: string | null; statusFrom?: string | null; statusTo?: string | null; beforePackages: number; deltaPackages: number; afterPackages: number; operatorId?: string | null; remark?: string | null; occurredAt?: string | null }
|
||||
|
||||
export async function listInventoryBalances(query: InventoryBalanceQuery) { const { customerId, ...params } = query; return unwrapApiResponse(await overseasHttp.get<ApiEnvelope<OverseasPageResult<InventoryBalanceDto>>, ApiEnvelope<OverseasPageResult<InventoryBalanceDto>>>('/platform/v1/last-leg/inventory/balances', { params: { customerId, ...params } })) }
|
||||
export async function getInventorySummary(query: Omit<InventoryBalanceQuery, 'page' | 'size'>) { const { customerId, ...params } = query; return unwrapApiResponse(await overseasHttp.get<ApiEnvelope<InventoryDashboardDto>, ApiEnvelope<InventoryDashboardDto>>('/platform/v1/last-leg/inventory/summary', { params: { customerId, ...params } })) }
|
||||
export async function listInventoryPositions(balanceId: string, customerId: string, query: { palletNo?: string; batchNo?: string; inventoryStatus?: string } = {}) { return unwrapApiResponse(await overseasHttp.get<ApiEnvelope<InventoryPositionDto[]>, ApiEnvelope<InventoryPositionDto[]>>(`/platform/v1/last-leg/inventory/balances/${encodeURIComponent(balanceId)}/positions`, { params: { customerId, ...query } })) }
|
||||
export async function listInventoryLedger(query: { customerId: string; page: number; size: number; overseasWarehouseId?: string; destinationWarehouseCode?: string; businessType?: string; businessOrderNo?: string; inboundOrderNo?: string; inboundCode?: string; outboundOrderNo?: string; palletNo?: string; batchNo?: string; occurredFrom?: string; occurredTo?: string }) { const { customerId, ...params } = query; return unwrapApiResponse(await overseasHttp.get<ApiEnvelope<OverseasPageResult<InventoryLedgerDto>>, ApiEnvelope<OverseasPageResult<InventoryLedgerDto>>>('/platform/v1/last-leg/inventory/ledger', { params: { customerId, ...params } })) }
|
||||
@@ -0,0 +1,9 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { overseasHttp } from '@/shared/api/overseasHttp'
|
||||
import { createPallet, getPallet, listPallets, updatePallet } from './pallets'
|
||||
vi.mock('@/shared/api/overseasHttp', () => ({ overseasHttp: { get: vi.fn(), post: vi.fn(), put: vi.fn() } }))
|
||||
describe('public overseas pallet API', () => {
|
||||
beforeEach(() => { vi.mocked(overseasHttp.get).mockReset(); vi.mocked(overseasHttp.post).mockReset(); vi.mocked(overseasHttp.put).mockReset() })
|
||||
it('does not send a customer isolation parameter for public pallet reads', async () => { vi.mocked(overseasHttp.get).mockResolvedValue({ code: '200', message: 'ok', data: { records: [], page: 1, size: 20, total: 0, pages: 0 } }); await listPallets('190000000000000001', { page: 1, size: 20, status: 'IDLE' }); expect(overseasHttp.get).toHaveBeenCalledWith('/platform/v1/warehouse-admin/190000000000000001/pallets', { params: { page: 1, size: 20, status: 'IDLE' } }); expect(JSON.stringify(vi.mocked(overseasHttp.get).mock.calls)).not.toContain('customerId') })
|
||||
it('uses the public resource path for detail, create and update', async () => { vi.mocked(overseasHttp.get).mockResolvedValue({ code: '200', message: 'ok', data: {} }); vi.mocked(overseasHttp.post).mockResolvedValue({ code: '200', message: 'ok', data: '8' }); vi.mocked(overseasHttp.put).mockResolvedValue({ code: '200', message: 'ok', data: null }); const payload = { palletType: '木托盘', capacityCbm: 2, unitPrice: 10, status: 'IDLE' }; await getPallet('1', '2'); await createPallet('1', payload); await updatePallet('1', '2', payload); expect(overseasHttp.get).toHaveBeenCalledWith('/platform/v1/warehouse-admin/1/pallets/2'); expect(overseasHttp.post).toHaveBeenCalledWith('/platform/v1/warehouse-admin/1/pallets', payload); expect(overseasHttp.put).toHaveBeenCalledWith('/platform/v1/warehouse-admin/1/pallets/2', payload) })
|
||||
})
|
||||
@@ -0,0 +1,12 @@
|
||||
import { overseasHttp } from '@/shared/api/overseasHttp'
|
||||
import { unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
|
||||
import type { OverseasPageResult } from './lastMileOrders'
|
||||
|
||||
export interface OverseasWarehouseDto { id: string; customerId: string; warehouseCode: string; warehouseName: string; warehouseType?: string | null; countryCode?: string | null; status?: string | null }
|
||||
export interface PalletDto { id: string; customerId: string; warehouseId: string; locationId?: string | null; palletCode: string; palletType: string; capacityCbm: number; unitPrice: number; status: string; remark?: string | null; createdAt?: string | null; updatedAt?: string | null }
|
||||
export interface PalletSave { palletCode?: string; palletType: string; capacityCbm?: number; unitPrice: number; status: string; locationId?: string; remark?: string }
|
||||
export async function listOverseasWarehouses(customerId: string, page: number, size = 200) { return unwrapApiResponse(await overseasHttp.get<ApiEnvelope<OverseasPageResult<OverseasWarehouseDto>>, ApiEnvelope<OverseasPageResult<OverseasWarehouseDto>>>('/platform/v1/warehouse-admin', { params: { customerId, page, size, status: 'ACTIVE' } })) }
|
||||
export async function listPallets(warehouseId: string, query: { page: number; size: number; palletType?: string; status?: string; locationId?: string; keyword?: string }) { return unwrapApiResponse(await overseasHttp.get<ApiEnvelope<OverseasPageResult<PalletDto>>, ApiEnvelope<OverseasPageResult<PalletDto>>>(`/platform/v1/warehouse-admin/${encodeURIComponent(warehouseId)}/pallets`, { params: query })) }
|
||||
export async function getPallet(warehouseId: string, palletId: string) { return unwrapApiResponse(await overseasHttp.get<ApiEnvelope<PalletDto>, ApiEnvelope<PalletDto>>(`/platform/v1/warehouse-admin/${encodeURIComponent(warehouseId)}/pallets/${encodeURIComponent(palletId)}`)) }
|
||||
export async function createPallet(warehouseId: string, payload: PalletSave) { return unwrapApiResponse(await overseasHttp.post<ApiEnvelope<string>, ApiEnvelope<string>>(`/platform/v1/warehouse-admin/${encodeURIComponent(warehouseId)}/pallets`, payload)) }
|
||||
export async function updatePallet(warehouseId: string, palletId: string, payload: PalletSave) { unwrapApiResponse(await overseasHttp.put<ApiEnvelope<null>, ApiEnvelope<null>>(`/platform/v1/warehouse-admin/${encodeURIComponent(warehouseId)}/pallets/${encodeURIComponent(palletId)}`, payload)) }
|
||||
Reference in New Issue
Block a user