feat(cleaner-history): add search IPC handler

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-04-17 11:07:20 +08:00
parent 3a30694684
commit 5faf26df3f

View File

@@ -19,7 +19,9 @@ import type {
CleanerExecutionRecord, CleanerExecutionRecord,
CleanerOrderRecord, CleanerOrderRecord,
CleanerMaterialRecord, CleanerMaterialRecord,
GetCleanerBatchesOptions GetCleanerBatchesOptions,
SearchCleanerHistoryOptions,
CleanerHistorySearchResult
} from '../types/cleaner-history.types' } from '../types/cleaner-history.types'
const log = createLogger('CleanerHistoryHandler') 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<IpcResult<CleanerHistorySearchResult>> => {
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') log.info('Cleaner history IPC handlers registered')
} }