diff --git a/src/main/ipc/cleaner-history-handler.ts b/src/main/ipc/cleaner-history-handler.ts index e1bd8d6..dc322d5 100644 --- a/src/main/ipc/cleaner-history-handler.ts +++ b/src/main/ipc/cleaner-history-handler.ts @@ -19,7 +19,9 @@ import type { CleanerExecutionRecord, CleanerOrderRecord, CleanerMaterialRecord, - GetCleanerBatchesOptions + GetCleanerBatchesOptions, + SearchCleanerHistoryOptions, + CleanerHistorySearchResult } from '../types/cleaner-history.types' const log = createLogger('CleanerHistoryHandler') @@ -152,5 +154,42 @@ export function registerCleanerHistoryHandlers(): void { } ) + /** + * Search across all history levels (batches, orders, materials) + * Admin users search all records, regular users search only their own + */ + ipcMain.handle( + IPC_CHANNELS.CLEANER_HISTORY_SEARCH, + async ( + _event, + options: SearchCleanerHistoryOptions + ): Promise> => { + return withErrorHandling(async () => { + const currentUser = SessionManager.getInstance().getUserInfo() + + if (!currentUser) { + throw new Error('用户未登录') + } + + if (!options.query || options.query.trim().length === 0) { + return { batches: [], totalMatches: 0 } + } + + const userId = currentUser.userType === 'Admin' ? undefined : currentUser.id + + log.info('Searching cleaner history', { + userId: currentUser.id, + userType: currentUser.userType, + query: options.query + }) + + return await dao.searchBatches(userId, { + ...options, + query: options.query.trim() + }) + }, 'cleanerHistory:search') + } + ) + log.info('Cleaner history IPC handlers registered') }