//! 异步操作日志 Worker use async_trait::async_trait; use sqlx::PgPool; use serde::{Serialize, Deserialize}; use crate::error::SaasResult; use super::Worker; #[derive(Debug, Serialize, Deserialize)] pub struct LogOperationArgs { pub account_id: String, pub action: String, pub target_type: String, pub target_id: String, pub details: Option, pub ip_address: Option, } pub struct LogOperationWorker; #[async_trait] impl Worker for LogOperationWorker { type Args = LogOperationArgs; fn name(&self) -> &str { "log_operation" } async fn perform(&self, db: &PgPool, args: Self::Args) -> SaasResult<()> { let now = chrono::Utc::now(); sqlx::query( "INSERT INTO operation_logs (account_id, action, target_type, target_id, details, ip_address, created_at) VALUES ($1, $2, $3, $4, $5, $6, $7)" ) .bind(&args.account_id) .bind(&args.action) .bind(&args.target_type) .bind(&args.target_id) .bind(&args.details) .bind(&args.ip_address) .bind(&now) .execute(db) .await?; Ok(()) } }