From 74096fbfa0d083b9a9b2c6a52a9d81849c6bebab Mon Sep 17 00:00:00 2001 From: Misaka_Company Date: Mon, 13 Apr 2026 11:52:14 +0800 Subject: [PATCH] feat(cleaner): add preload API for cleaner operation history Co-Authored-By: Claude Opus 4.6 --- src/main/types/ipc-api.types.ts | 45 +++++++++++++++++ src/preload/api/cleaner.ts | 33 ++++++++++++- src/preload/index.d.ts | 85 +++++++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+), 1 deletion(-) diff --git a/src/main/types/ipc-api.types.ts b/src/main/types/ipc-api.types.ts index 332c10b..0455d43 100644 --- a/src/main/types/ipc-api.types.ts +++ b/src/main/types/ipc-api.types.ts @@ -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> + + /** + * 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> + + /** + * Delete a cleaner history batch + * @param batchId - Batch ID + */ + deleteHistoryBatch: (batchId: string) => Promise> } /** diff --git a/src/preload/api/cleaner.ts b/src/preload/api/cleaner.ts index 3a26226..8ecd5d3 100644 --- a/src/preload/api/cleaner.ts +++ b/src/preload/api/cleaner.ts @@ -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> => + 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> => + invokeIpc(IPC_CHANNELS.CLEANER_HISTORY_GET_MATERIAL_DETAILS, batchId, attemptNumber, orderNumber), + + deleteHistoryBatch: (batchId: string): Promise> => + invokeIpc(IPC_CHANNELS.CLEANER_HISTORY_DELETE_BATCH, batchId) } as const diff --git a/src/preload/index.d.ts b/src/preload/index.d.ts index e3222a0..8a33d42 100644 --- a/src/preload/index.d.ts +++ b/src/preload/index.d.ts @@ -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> + getHistoryBatchDetails: (batchId: string) => Promise< + IpcResult<{ + executions: CleanerHistoryExecutionRecord[] + orders: CleanerHistoryOrderRecord[] + }> + > + getHistoryMaterialDetails: ( + batchId: string, + attemptNumber: number, + orderNumber: string + ) => Promise> + deleteHistoryBatch: (batchId: string) => Promise> +} + export interface ProcessAPI { versions: { electron: string