This commit is contained in:
2026-08-03 14:58:17 +08:00
parent bc44a7942d
commit ee997ae894
17 changed files with 1694 additions and 303 deletions
+58 -2
View File
@@ -1,14 +1,17 @@
import { http, unwrapApiResponse, type ApiEnvelope } from '@/api/http'
export type PlatformPartnerType = 'CUSTOMER' | 'SUPPLIER' | 'BOTH'
export type PlatformPartnerType = 'CUSTOMER' | 'SUPPLIER' | 'CARRIER' | 'CUSTOMS_BROKER' | 'SHIPPER' | 'CONSIGNEE'
export type PlatformPartnerLegacyType = PlatformPartnerType | 'BOTH'
export type PlatformPartnerStatus = 'ACTIVE' | 'INACTIVE'
export interface PlatformPartnerResource {
id: number | string
tenantId: number | string
dataScopeId: number | string
partnerCode: string
partnerName: string
partnerType: PlatformPartnerType
partnerType: PlatformPartnerLegacyType
types: PlatformPartnerType[]
contactName: string
contactPhone: string
contactEmail: string | null
@@ -19,6 +22,7 @@ export interface PlatformPartnerResource {
addressLine: string
postalCode: string | null
status: PlatformPartnerStatus
remark: string | null
createdAt?: string | null
updatedAt?: string | null
}
@@ -50,6 +54,7 @@ export interface SavePlatformPartnerRequest {
partnerCode: string
partnerName: string
partnerType: PlatformPartnerType
types: PlatformPartnerType[]
contactName: string
contactPhone: string
contactEmail: string | null
@@ -60,10 +65,37 @@ export interface SavePlatformPartnerRequest {
addressLine: string
postalCode: string | null
status: PlatformPartnerStatus
remark: string | null
}
export interface PlatformPartnerImportError {
row: number
field: string
message: string
}
export interface PlatformPartnerImportResult {
fileName: string
totalRows: number
importedRows: number
success: boolean
errors: PlatformPartnerImportError[]
}
const basePath = '/platform/v1/partners'
function normalizePartner(resource: PlatformPartnerResource): PlatformPartnerResource {
const legacyTypes: PlatformPartnerType[] = resource.partnerType === 'BOTH'
? ['CUSTOMER', 'SUPPLIER']
: [resource.partnerType]
return {
...resource,
dataScopeId: resource.dataScopeId ?? resource.tenantId,
types: resource.types?.length ? resource.types : legacyTypes,
remark: resource.remark ?? null,
}
}
export async function listPlatformPartners(tenantId: number, query: PlatformPartnerQuery) {
const response = await http.get<ApiEnvelope<PlatformPartnerPagePayload>, ApiEnvelope<PlatformPartnerPagePayload>>(basePath, {
params: { tenantId, ...query },
@@ -71,6 +103,7 @@ export async function listPlatformPartners(tenantId: number, query: PlatformPart
const page = unwrapApiResponse(response)
return {
...page,
records: page.records.map(normalizePartner),
page: Number(page.page),
size: Number(page.size),
total: Number(page.total),
@@ -78,6 +111,29 @@ export async function listPlatformPartners(tenantId: number, query: PlatformPart
}
}
export async function getPlatformPartner(tenantId: number, partnerId: number | string) {
const response = await http.get<ApiEnvelope<PlatformPartnerResource>, ApiEnvelope<PlatformPartnerResource>>(
`${basePath}/${partnerId}`,
{ params: { tenantId } },
)
return normalizePartner(unwrapApiResponse(response))
}
export async function downloadPlatformPartnerImportTemplate() {
return http.get<Blob, Blob>(`${basePath}/import-template`, { responseType: 'blob' })
}
export async function importPlatformPartners(tenantId: number, file: File) {
const form = new FormData()
form.append('file', file)
const response = await http.post<ApiEnvelope<PlatformPartnerImportResult>, ApiEnvelope<PlatformPartnerImportResult>>(
`${basePath}/import`,
form,
{ params: { tenantId } },
)
return unwrapApiResponse(response)
}
export async function createPlatformPartner(tenantId: number, payload: SavePlatformPartnerRequest) {
const response = await http.post<ApiEnvelope<number | string>, ApiEnvelope<number | string>>(basePath, payload, {
params: { tenantId },