feat(cleaner): add preload API for cleaner operation history

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-04-13 11:52:14 +08:00
parent 73656dada8
commit 74096fbfa0
3 changed files with 162 additions and 1 deletions

View File

@@ -11,6 +11,12 @@ import type {
ExportResultItem,
ExportResultResponse
} from './cleaner.types'
import type {
CleanerBatchStats,
CleanerExecutionRecord,
CleanerOrderRecord,
CleanerMaterialRecord
} from './cleaner-history.types'
import type { IpcResult } from './ipc.types'
/**
@@ -113,6 +119,45 @@ export interface CleanerAPI {
* @returns Unsubscribe function
*/
onProgress: (callback: (data: CleanerProgress) => void) => () => void
/**
* Get cleaner operation history batches
* @param options - Query options (limit, offset, usernames)
*/
getHistoryBatches: (options?: {
limit?: number
offset?: number
usernames?: string[]
}) => Promise<IpcResult<CleanerBatchStats[]>>
/**
* Get detailed execution and order records for a specific batch
* @param batchId - Batch ID
*/
getHistoryBatchDetails: (batchId: string) => Promise<
IpcResult<{
executions: CleanerExecutionRecord[]
orders: CleanerOrderRecord[]
}>
>
/**
* Get material-level details for a specific order in a batch attempt
* @param batchId - Batch ID
* @param attemptNumber - Attempt number
* @param orderNumber - Order number
*/
getHistoryMaterialDetails: (
batchId: string,
attemptNumber: number,
orderNumber: string
) => Promise<IpcResult<CleanerMaterialRecord[]>>
/**
* Delete a cleaner history batch
* @param batchId - Batch ID
*/
deleteHistoryBatch: (batchId: string) => Promise<IpcResult<{ deleted: boolean }>>
}
/**

View File

@@ -3,6 +3,14 @@ import type {
CleanerProgress,
ExportResultItem
} from '../../main/types/cleaner.types'
import type {
CleanerBatchStats,
CleanerExecutionRecord,
CleanerOrderRecord,
CleanerMaterialRecord,
GetCleanerBatchesOptions
} from '../../main/types/cleaner-history.types'
import type { IpcResult } from '../../main/types/ipc.types'
import { IPC_CHANNELS } from '../../shared/ipc-channels'
import { invokeIpc, ipcRenderer } from '../lib/ipc'
@@ -15,5 +23,28 @@ export const cleanerApi = {
callback(data)
ipcRenderer.on(IPC_CHANNELS.CLEANER_PROGRESS, subscription)
return () => ipcRenderer.removeListener(IPC_CHANNELS.CLEANER_PROGRESS, subscription)
}
},
// Cleaner operation history
getHistoryBatches: (options?: GetCleanerBatchesOptions): Promise<IpcResult<CleanerBatchStats[]>> =>
invokeIpc(IPC_CHANNELS.CLEANER_HISTORY_GET_BATCHES, options),
getHistoryBatchDetails: (
batchId: string
): Promise<
IpcResult<{
executions: CleanerExecutionRecord[]
orders: CleanerOrderRecord[]
}>
> => invokeIpc(IPC_CHANNELS.CLEANER_HISTORY_GET_BATCH_DETAILS, batchId),
getHistoryMaterialDetails: (
batchId: string,
attemptNumber: number,
orderNumber: string
): Promise<IpcResult<CleanerMaterialRecord[]>> =>
invokeIpc(IPC_CHANNELS.CLEANER_HISTORY_GET_MATERIAL_DETAILS, batchId, attemptNumber, orderNumber),
deleteHistoryBatch: (batchId: string): Promise<IpcResult<{ deleted: boolean }>> =>
invokeIpc(IPC_CHANNELS.CLEANER_HISTORY_DELETE_BATCH, batchId)
} as const

View File

@@ -190,6 +190,91 @@ export interface OperationHistoryRecord {
errorMessage: string | null
}
export interface CleanerHistoryBatchStats {
batchId: string
userId: number
username: string
operationTime: string
status: string
totalAttempts: number
totalOrders: number
ordersProcessed: number
totalMaterialsDeleted: number
totalMaterialsFailed: number
successCount: number
failedCount: number
isDryRun: boolean
}
export interface CleanerHistoryExecutionRecord {
id?: number
batchId: string
attemptNumber: number
userId: number
username: string
operationTime: Date
endTime: Date | null
status: string
isDryRun: boolean
totalOrders: number
ordersProcessed: number
totalMaterialsDeleted: number
totalMaterialsSkipped: number
totalMaterialsFailed: number
totalUncertainDeletions: number
errorMessage: string | null
appVersion: string | null
}
export interface CleanerHistoryOrderRecord {
id?: number
batchId: string
attemptNumber: number
orderNumber: string
status: string
materialsDeleted: number
materialsSkipped: number
materialsFailed: number
uncertainDeletions: number
retryCount: number
retrySuccess: boolean
errorMessage: string | null
}
export interface CleanerHistoryMaterialRecord {
id?: number
batchId: string
attemptNumber: number
orderNumber: string
materialCode: string
materialName: string
rowNumber: number
result: string
reason: string | null
attemptCount: number
finalErrorCategory: string | null
}
export interface CleanerHistoryAPI {
getHistoryBatches: (options?: {
limit?: number
offset?: number
usernames?: string[]
}) => Promise<IpcResult<CleanerHistoryBatchStats[]>>
getHistoryBatchDetails: (batchId: string) => Promise<
IpcResult<{
executions: CleanerHistoryExecutionRecord[]
orders: CleanerHistoryOrderRecord[]
}>
>
getHistoryMaterialDetails: (
batchId: string,
attemptNumber: number,
orderNumber: string
) => Promise<IpcResult<CleanerHistoryMaterialRecord[]>>
deleteHistoryBatch: (batchId: string) => Promise<IpcResult<{ deleted: boolean }>>
}
export interface ProcessAPI {
versions: {
electron: string