import { Repository, DataSource } from 'typeorm'; import { ManualOperationLogEntity, EntityTransactionEntity } from '../entities'; import { AuditContextService } from './audit-context.service'; import { ManualLogOptions } from '../interfaces'; import { AuditTransactionStatus } from '../enums'; /** * 手动审计日志服务 * * 提供标准的依赖注入方式记录操作日志 */ export declare class ManualAuditLogService { private readonly manualLogRepository; private readonly transactionRepository; private readonly contextService; private readonly dataSource; constructor(manualLogRepository: Repository, transactionRepository: Repository, contextService: AuditContextService, dataSource: DataSource); /** * 记录操作日志 * * @description * 支持三种记录模式: * 1. 模板键模式:从数据库查找模板 * 2. 直接描述模式:直接传入字符串或多语言描述 * 3. 内联模板模式:传入多语言模板 + 参数 * * @example * // 模式1:模板键模式 * await this.manualAuditLogService.log({ * templateKey: 'user.login', * descriptionParams: { * username: 'john.doe', * loginTime: new Date().toISOString(), * }, * }); * * @example * // 模式2:直接描述模式(字符串) * await this.manualAuditLogService.log({ * description: '用户登录系统', * }); * * @example * // 模式2:直接描述模式(多语言) * await this.manualAuditLogService.log({ * description: { * zh: '用户登录系统', * en: 'User logged in', * }, * }); * * @example * // 模式3:内联模板模式 * await this.manualAuditLogService.log({ * descriptionTemplate: { * zh: '用户 {username} 在 {time} 登录了系统', * en: 'User {username} logged in at {time}', * }, * descriptionParams: { * username: 'john.doe', * time: new Date().toISOString(), * }, * }); */ log(options: ManualLogOptions): Promise; /** * 实例方法:记录操作日志 */ logOperation(options: ManualLogOptions): Promise; /** * 开始事务 * * @example * ```typescript * const txId = await this.manualAuditLogService.beginTransaction('user-123', 'John Doe'); * * await this.manualAuditLogService.log({ * templateKey: 'order.create', * descriptionParams: { orderId: 'order-1' }, * transactionId: txId, * autoCreateTransaction: false, * }); * * await this.manualAuditLogService.log({ * templateKey: 'payment.process', * descriptionParams: { paymentId: 'pay-1' }, * transactionId: txId, * autoCreateTransaction: false, * }); * * await this.manualAuditLogService.commitTransaction(txId); * ``` */ beginTransaction(userId?: string, username?: string): Promise; /** * 提交事务 */ commitTransaction(transactionId: string): Promise; /** * 回滚事务 */ rollbackTransaction(transactionId: string): Promise; /** * 创建事务 */ createTransaction(userId?: string, username?: string): Promise; /** * 更新事务状态 */ updateTransactionStatus(transactionId: string, status: AuditTransactionStatus): Promise; /** * 生成事务ID */ private generateTransactionId; /** * 批量记录操作日志 * * @description * 批量记录多个操作,支持所有三种记录模式 * * @example * ```typescript * // 混合使用多种模式 * await this.manualAuditLogService.logBatch([ * { * templateKey: 'product.update', * descriptionParams: { productId: 'p1', field: 'price' }, * }, * { * description: '批量更新库存', * }, * { * descriptionTemplate: { * zh: '更新产品 {productId} 的 {field}', * en: 'Update {field} of product {productId}', * }, * descriptionParams: { productId: 'p3', field: 'stock' }, * }, * ]); * ``` */ logBatch(operations: ManualLogOptions[], sharedTransactionId?: string): Promise; /** * 查询操作日志 */ findLogs(options: { templateKey?: string; userId?: string; transactionId?: string; startTime?: Date; endTime?: Date; limit?: number; }): Promise; }