2026-08-03 18:49:18 +08:00
|
|
|
import { http, unwrapApiResponse, type ApiEnvelope } from '@/shared/api/http'
|
2026-08-03 18:15:41 +08:00
|
|
|
|
|
|
|
|
export type ExportTaskStatus = 'PENDING' | 'RUNNING' | 'SUCCEEDED' | 'FAILED' | 'EXPIRED'
|
|
|
|
|
export type ExportTaskType = 'CUSTOMER_LIST' | string
|
|
|
|
|
|
|
|
|
|
export interface PlatformExportTask {
|
|
|
|
|
id: string
|
|
|
|
|
taskNo: string
|
|
|
|
|
exportType: ExportTaskType
|
|
|
|
|
format: 'XLSX' | string
|
|
|
|
|
taskName: string
|
|
|
|
|
status: ExportTaskStatus
|
|
|
|
|
totalRows: number | null
|
|
|
|
|
processedRows: number
|
|
|
|
|
fileName: string | null
|
|
|
|
|
contentType: string | null
|
|
|
|
|
sizeBytes: number | null
|
|
|
|
|
failureMessage: string | null
|
|
|
|
|
requestedBy: string
|
|
|
|
|
requestedUsername: string | null
|
|
|
|
|
requestedAt: string
|
|
|
|
|
startedAt: string | null
|
|
|
|
|
completedAt: string | null
|
|
|
|
|
expiresAt: string | null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface PlatformExportTaskPage {
|
|
|
|
|
records: PlatformExportTask[]
|
|
|
|
|
page: number
|
|
|
|
|
size: number
|
|
|
|
|
total: number
|
|
|
|
|
pages: number
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface PlatformExportTaskQuery {
|
|
|
|
|
page: number
|
|
|
|
|
size: number
|
|
|
|
|
exportType?: string
|
|
|
|
|
status?: ExportTaskStatus
|
|
|
|
|
requestedFrom?: string
|
|
|
|
|
requestedTo?: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface CreatePlatformExportTaskRequest {
|
|
|
|
|
exportType: ExportTaskType
|
|
|
|
|
format: 'XLSX'
|
|
|
|
|
taskName: string
|
|
|
|
|
parameters: Record<string, string | number | boolean | null | undefined>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const basePath = '/platform/v1/files/export-tasks'
|
|
|
|
|
|
|
|
|
|
export async function createPlatformExportTask(payload: CreatePlatformExportTaskRequest) {
|
|
|
|
|
const response = await http.post<ApiEnvelope<PlatformExportTask>, ApiEnvelope<PlatformExportTask>>(basePath, payload)
|
|
|
|
|
return unwrapApiResponse(response)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function listPlatformExportTasks(query: PlatformExportTaskQuery) {
|
|
|
|
|
const response = await http.get<ApiEnvelope<PlatformExportTaskPage>, ApiEnvelope<PlatformExportTaskPage>>(basePath, {
|
|
|
|
|
params: query,
|
|
|
|
|
})
|
|
|
|
|
const page = unwrapApiResponse(response)
|
|
|
|
|
return {
|
|
|
|
|
...page,
|
|
|
|
|
page: Number(page.page),
|
|
|
|
|
size: Number(page.size),
|
|
|
|
|
total: Number(page.total),
|
|
|
|
|
pages: Number(page.pages),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function downloadPlatformExportTask(taskId: string) {
|
|
|
|
|
return http.get<Blob, Blob>(`${basePath}/${encodeURIComponent(taskId)}/download`, { responseType: 'blob' })
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function retryPlatformExportTask(taskId: string) {
|
|
|
|
|
const response = await http.post<ApiEnvelope<PlatformExportTask>, ApiEnvelope<PlatformExportTask>>(
|
|
|
|
|
`${basePath}/${encodeURIComponent(taskId)}/retry`,
|
|
|
|
|
{},
|
|
|
|
|
)
|
|
|
|
|
return unwrapApiResponse(response)
|
|
|
|
|
}
|