//! 交易域仓储接口 use async_trait::async_trait; use chrono::{DateTime, Utc}; use super::entity::*; use crate::error::Result; /// 系统交易仓储接口 #[async_trait] pub trait SystemTransactionRepository: Send + Sync { /// 根据ID查询 async fn find_by_id(&self, id: i64) -> Result>; /// 根据交易号查询 async fn find_by_txn_no(&self, txn_no: &str) -> Result>; /// 根据银行参考号查询 async fn find_by_bank_ref_no(&self, bank_ref_no: &str) -> Result>; /// 根据来源幂等键查询 async fn find_by_source_key(&self, source_key: &str) -> Result>; /// 查询待处理交易 async fn find_pending(&self) -> Result>; /// 查询需要对账的交易 async fn find_needs_reconciliation(&self) -> Result>; /// 根据状态查询交易 async fn find_by_status(&self, status: TransactionStatus) -> Result>; /// 查询超时交易(BankSubmitted 状态且超过指定秒数) async fn find_timeout(&self, timeout_seconds: i64) -> Result>; /// 条件查询 async fn query(&self, query: &TransactionQuery) -> Result>; /// 创建交易 async fn create(&self, request: &CreateSystemTransactionRequest) -> Result; /// 更新状态 async fn update_status(&self, id: i64, status: TransactionStatus) -> Result<()>; /// 设置银行参考号 async fn set_bank_ref_no(&self, id: i64, bank_ref_no: &str) -> Result<()>; /// 设置提交银行时间 async fn set_submitted_at(&self, id: i64, submitted_at: DateTime) -> Result<()>; /// 确认交易 async fn confirm(&self, id: i64, confirmed_at: DateTime) -> Result<()>; } /// 银行交易仓储接口 #[async_trait] pub trait BankTransactionRepository: Send + Sync { /// 根据ID查询 async fn find_by_id(&self, id: i64) -> Result>; /// 根据银行参考号查询 async fn find_by_bank_ref_no(&self, bank_ref_no: &str) -> Result>; /// 查询未匹配的交易 async fn find_unmatched(&self, physical_account_id: i64) -> Result>; /// 根据实体账户和时间范围查询 async fn find_by_account_and_time_range( &self, physical_account_id: i64, start: DateTime, end: DateTime, ) -> Result>; /// 同步银行交易 async fn sync(&self, request: &SyncBankTransactionRequest) -> Result; /// 批量同步 async fn batch_sync(&self, requests: &[SyncBankTransactionRequest]) -> Result>; /// 更新匹配状态 async fn update_match_status( &self, id: i64, status: MatchStatus, matched_txn_no: Option<&str>, ) -> Result<()>; }