130 lines
3.7 KiB
TypeScript
130 lines
3.7 KiB
TypeScript
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
|
|
|
|
export type PlatformExpressCompanyStatus = 'ACTIVE' | 'INACTIVE'
|
|
|
|
export interface PlatformExpressCompanyResource {
|
|
id: number | string
|
|
tenantId: number | string
|
|
companyCode: string
|
|
companyName: string
|
|
servicePhone: string | null
|
|
website: string | null
|
|
trackingUrlTemplate: string | null
|
|
status: PlatformExpressCompanyStatus
|
|
remark: string | null
|
|
createdAt?: string | null
|
|
updatedAt?: string | null
|
|
}
|
|
|
|
export interface PlatformExpressCompanyPage {
|
|
records: PlatformExpressCompanyResource[]
|
|
page: number
|
|
size: number
|
|
total: number
|
|
pages: number
|
|
}
|
|
|
|
export interface SavePlatformExpressCompanyRequest {
|
|
companyCode: string
|
|
companyName: string
|
|
servicePhone: string | null
|
|
website: string | null
|
|
trackingUrlTemplate: string | null
|
|
status: PlatformExpressCompanyStatus
|
|
remark: string | null
|
|
}
|
|
|
|
export interface PlatformExpressCompanyImportError {
|
|
row: number
|
|
field: string
|
|
message: string
|
|
}
|
|
|
|
export interface PlatformExpressCompanyImportResult {
|
|
fileName: string
|
|
totalRows: number
|
|
importedRows: number
|
|
success: boolean
|
|
errors: PlatformExpressCompanyImportError[]
|
|
}
|
|
|
|
const basePath = '/platform/v1/express-companies'
|
|
|
|
export async function listPlatformExpressCompanies(
|
|
tenantId: number | string,
|
|
page = 1,
|
|
size = 20,
|
|
keyword = '',
|
|
status: PlatformExpressCompanyStatus | '' = '',
|
|
) {
|
|
const response = await http.get<ApiEnvelope<PlatformExpressCompanyPage>, ApiEnvelope<PlatformExpressCompanyPage>>(basePath, {
|
|
params: {
|
|
tenantId,
|
|
page,
|
|
size,
|
|
keyword: keyword.trim() || undefined,
|
|
status: status || undefined,
|
|
},
|
|
})
|
|
const result = unwrapApiResponse(response)
|
|
return {
|
|
...result,
|
|
page: Number(result.page),
|
|
size: Number(result.size),
|
|
total: Number(result.total),
|
|
pages: Number(result.pages),
|
|
}
|
|
}
|
|
|
|
export async function getPlatformExpressCompany(tenantId: number | string, id: number | string) {
|
|
const response = await http.get<ApiEnvelope<PlatformExpressCompanyResource>, ApiEnvelope<PlatformExpressCompanyResource>>(
|
|
`${basePath}/${id}`,
|
|
{ params: { tenantId } },
|
|
)
|
|
return unwrapApiResponse(response)
|
|
}
|
|
|
|
export async function createPlatformExpressCompany(tenantId: number | string, payload: SavePlatformExpressCompanyRequest) {
|
|
const response = await http.post<ApiEnvelope<number | string>, ApiEnvelope<number | string>>(basePath, payload, {
|
|
params: { tenantId },
|
|
})
|
|
return unwrapApiResponse(response)
|
|
}
|
|
|
|
export async function updatePlatformExpressCompany(
|
|
tenantId: number | string,
|
|
id: number | string,
|
|
payload: SavePlatformExpressCompanyRequest,
|
|
) {
|
|
const response = await http.put<ApiEnvelope<null>, ApiEnvelope<null>>(`${basePath}/${id}`, payload, {
|
|
params: { tenantId },
|
|
})
|
|
return unwrapApiResponse(response)
|
|
}
|
|
|
|
export async function changePlatformExpressCompanyStatus(
|
|
tenantId: number | string,
|
|
id: number | string,
|
|
status: PlatformExpressCompanyStatus,
|
|
) {
|
|
const response = await http.patch<ApiEnvelope<null>, ApiEnvelope<null>>(`${basePath}/${id}/status`, { status }, {
|
|
params: { tenantId },
|
|
})
|
|
return unwrapApiResponse(response)
|
|
}
|
|
|
|
export async function downloadPlatformExpressCompanyImportTemplate() {
|
|
return http.get<Blob, Blob>(`${basePath}/import-template`, { responseType: 'blob' })
|
|
}
|
|
|
|
export async function importPlatformExpressCompanies(tenantId: number | string, file: File) {
|
|
const formData = new FormData()
|
|
formData.append('file', file)
|
|
const response = await http.post<ApiEnvelope<PlatformExpressCompanyImportResult>, ApiEnvelope<PlatformExpressCompanyImportResult>>(
|
|
`${basePath}/import`,
|
|
formData,
|
|
{ params: { tenantId } },
|
|
)
|
|
return unwrapApiResponse(response)
|
|
}
|