Create audit_log SeaORM entity and audit_service::record() helper. Integrate audit recording into 35 mutation endpoints across all modules: - erp-auth: user/role/organization/department/position CRUD (15 actions) - erp-config: dictionary/menu/setting/numbering_rule CRUD (15 actions) - erp-workflow: definition/instance/task operations (8 actions) - erp-message: send/system/mark_read/delete (5 actions) Uses fire-and-forget pattern — audit failures logged but non-blocking.
28 lines
915 B
Rust
28 lines
915 B
Rust
use crate::audit::AuditLog;
|
|
use crate::entity::audit_log;
|
|
use sea_orm::{ActiveModelTrait, Set};
|
|
use tracing;
|
|
|
|
/// 持久化审计日志到 audit_logs 表。
|
|
///
|
|
/// 使用 fire-and-forget 模式:失败仅记录 warning 日志,不影响业务操作。
|
|
pub async fn record(log: AuditLog, db: &sea_orm::DatabaseConnection) {
|
|
let model = audit_log::ActiveModel {
|
|
id: Set(log.id),
|
|
tenant_id: Set(log.tenant_id),
|
|
user_id: Set(log.user_id),
|
|
action: Set(log.action),
|
|
resource_type: Set(log.resource_type),
|
|
resource_id: Set(log.resource_id),
|
|
old_value: Set(log.old_value),
|
|
new_value: Set(log.new_value),
|
|
ip_address: Set(log.ip_address),
|
|
user_agent: Set(log.user_agent),
|
|
created_at: Set(log.created_at),
|
|
};
|
|
|
|
if let Err(e) = model.insert(db).await {
|
|
tracing::warn!(error = %e, "审计日志写入失败");
|
|
}
|
|
}
|