优化构架

This commit is contained in:
2026-08-03 18:49:18 +08:00
parent 1241d11c01
commit 44c33a6280
133 changed files with 651 additions and 603 deletions
@@ -0,0 +1,92 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { http } from '@/shared/api/http'
import {
changePlatformWarehouseStatus,
createPlatformWarehouse,
getPlatformWarehouse,
listPlatformWarehouses,
updatePlatformWarehouse,
type SavePlatformWarehouseRequest,
} from './platformWarehouses'
vi.mock('@/shared/api/http', () => ({
http: { get: vi.fn(), post: vi.fn(), put: vi.fn(), patch: vi.fn() },
unwrapApiResponse: <T>(response: { data: T }) => response.data,
}))
const payload: SavePlatformWarehouseRequest = {
tenantId: 10001,
warehouseCode: 'CN-YW-01',
warehouseName: '义乌收货仓',
warehouseType: 'DOMESTIC',
countryCode: 'CN',
timezone: 'Asia/Shanghai',
contactName: '仓库客服',
contactPhone: '0579-12345678',
contactEmail: null,
status: 'ACTIVE',
remark: null,
address: {
addressType: 'OPERATING',
countryCode: 'CN',
stateProvince: '浙江省',
city: '义乌市',
district: null,
postalCode: null,
addressLine1: '北苑街道 1 号库',
addressLine2: null,
latitude: null,
longitude: null,
},
capabilities: [{
capabilityCode: 'RECEIVING',
capabilityName: '收货服务',
enabled: true,
cutoffTime: null,
description: '周一至周六 08:30-18:00',
}],
}
describe('platform warehouse API', () => {
beforeEach(() => {
vi.mocked(http.get).mockReset()
vi.mocked(http.post).mockReset()
vi.mocked(http.put).mockReset()
vi.mocked(http.patch).mockReset()
})
it('lists and loads warehouse details for the target tenant', async () => {
const page = { records: [], page: 1, size: 200, total: 0, pages: 0 }
const detail = { warehouse: {}, addresses: [], capabilities: [] }
vi.mocked(http.get)
.mockResolvedValueOnce({ code: '200', message: 'success', data: page })
.mockResolvedValueOnce({ code: '200', message: 'success', data: detail })
await expect(listPlatformWarehouses(10001)).resolves.toEqual(page)
await expect(getPlatformWarehouse(10001, '19001')).resolves.toEqual(detail)
expect(http.get).toHaveBeenNthCalledWith(1, '/platform/v1/warehouse-admin', {
params: { tenantId: 10001, page: 1, size: 200 },
})
expect(http.get).toHaveBeenNthCalledWith(2, '/platform/v1/warehouse-admin/19001', {
params: { tenantId: 10001 },
})
})
it('uses the implemented create, update, and status routes', async () => {
vi.mocked(http.post).mockResolvedValue({ code: '200', message: 'success', data: '19001' })
vi.mocked(http.put).mockResolvedValue({ code: '200', message: 'success', data: null })
vi.mocked(http.patch).mockResolvedValue({ code: '200', message: 'success', data: null })
await expect(createPlatformWarehouse(payload)).resolves.toBe('19001')
await expect(updatePlatformWarehouse(10001, '19001', payload)).resolves.toBeNull()
await expect(changePlatformWarehouseStatus(10001, '19001', 'INACTIVE')).resolves.toBeNull()
expect(http.post).toHaveBeenCalledWith('/platform/v1/warehouse-admin', payload)
expect(http.put).toHaveBeenCalledWith('/platform/v1/warehouse-admin/19001', payload, {
params: { tenantId: 10001 },
})
expect(http.patch).toHaveBeenCalledWith('/platform/v1/warehouse-admin/19001/status', undefined, {
params: { tenantId: 10001, status: 'INACTIVE' },
})
})
})
@@ -0,0 +1,138 @@
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
export type PlatformWarehouseStatus = 'ACTIVE' | 'INACTIVE'
export interface PlatformWarehouseResource {
id: number | string
tenantId: number | string
warehouseCode: string
warehouseName: string
warehouseType: string
countryCode: string
timezone: string
contactName: string | null
contactPhone: string | null
contactEmail: string | null
status: PlatformWarehouseStatus
remark: string | null
createdAt?: string | null
updatedAt?: string | null
}
export interface PlatformWarehouseAddressResource {
id: number | string
tenantId: number | string
warehouseId: number | string
addressType: string
countryCode: string
stateProvince: string | null
city: string
district: string | null
postalCode: string | null
addressLine1: string
addressLine2: string | null
latitude: number | string | null
longitude: number | string | null
}
export interface PlatformWarehouseCapabilityResource {
id: number | string
tenantId: number | string
warehouseId: number | string
capabilityCode: string
capabilityName: string
enabled: boolean | null
cutoffTime: string | null
description: string | null
}
export interface PlatformWarehouseDetailResource {
warehouse: PlatformWarehouseResource
addresses: PlatformWarehouseAddressResource[]
capabilities: PlatformWarehouseCapabilityResource[]
}
export interface PlatformWarehousePage {
records: PlatformWarehouseResource[]
page: number
size: number
total: number
pages: number
}
export interface PlatformWarehouseAddressRequest {
addressType: string
countryCode: string
stateProvince: string | null
city: string
district: string | null
postalCode: string | null
addressLine1: string
addressLine2: string | null
latitude: number | string | null
longitude: number | string | null
}
export interface PlatformWarehouseCapabilityRequest {
capabilityCode: string
capabilityName: string
enabled: boolean
cutoffTime: string | null
description: string | null
}
export interface SavePlatformWarehouseRequest {
tenantId: number
warehouseCode: string
warehouseName: string
warehouseType: string
countryCode: string
timezone: string
contactName: string | null
contactPhone: string | null
contactEmail: string | null
status: PlatformWarehouseStatus
remark: string | null
address: PlatformWarehouseAddressRequest
capabilities: PlatformWarehouseCapabilityRequest[]
}
const basePath = '/platform/v1/warehouse-admin'
export async function listPlatformWarehouses(tenantId: number, page = 1, size = 200) {
const response = await http.get<ApiEnvelope<PlatformWarehousePage>, ApiEnvelope<PlatformWarehousePage>>(basePath, {
params: { tenantId, page, size },
})
return unwrapApiResponse(response)
}
export async function getPlatformWarehouse(tenantId: number, warehouseId: number | string) {
const response = await http.get<ApiEnvelope<PlatformWarehouseDetailResource>, ApiEnvelope<PlatformWarehouseDetailResource>>(
`${basePath}/${warehouseId}`,
{ params: { tenantId } },
)
return unwrapApiResponse(response)
}
export async function createPlatformWarehouse(payload: SavePlatformWarehouseRequest) {
const response = await http.post<ApiEnvelope<number | string>, ApiEnvelope<number | string>>(basePath, payload)
return unwrapApiResponse(response)
}
export async function updatePlatformWarehouse(tenantId: number, warehouseId: number | string, payload: SavePlatformWarehouseRequest) {
const response = await http.put<ApiEnvelope<null>, ApiEnvelope<null>>(`${basePath}/${warehouseId}`, payload, {
params: { tenantId },
})
return unwrapApiResponse(response)
}
export async function changePlatformWarehouseStatus(
tenantId: number,
warehouseId: number | string,
status: PlatformWarehouseStatus,
) {
const response = await http.patch<ApiEnvelope<null>, ApiEnvelope<null>>(`${basePath}/${warehouseId}/status`, undefined, {
params: { tenantId, status },
})
return unwrapApiResponse(response)
}