- 实现账户管理改进设计文档中的所有核心功能 - 三科目余额管理 (个人余额、劳动报酬、冻结余额) - 交易状态机 (created → pending → bank_submitted → success/failed/timeout → reversed) - 三键幂等体系 (JZTxId/BankTxId/SourceKey) - 优先级扣款规则 (先个人后劳动) - 在途资金管理 (可用→在途→结转/回退) - 三账对账闭环 (总账 = 银行账 + 在途净额) - 补偿服务域 (超时检测、重试、死信队列) - 虚拟银行模拟器用于业务测试 - 完整的集成测试套件 (133 个测试全部通过) - Docker 容器化部署配置 - 前端 Vue3 + TypeScript 项目结构
91 lines
3.0 KiB
Rust
91 lines
3.0 KiB
Rust
//! 交易域仓储接口
|
||
|
||
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<Option<SystemTransaction>>;
|
||
|
||
/// 根据交易号查询
|
||
async fn find_by_txn_no(&self, txn_no: &str) -> Result<Option<SystemTransaction>>;
|
||
|
||
/// 根据银行参考号查询
|
||
async fn find_by_bank_ref_no(&self, bank_ref_no: &str) -> Result<Option<SystemTransaction>>;
|
||
|
||
/// 根据来源幂等键查询
|
||
async fn find_by_source_key(&self, source_key: &str) -> Result<Option<SystemTransaction>>;
|
||
|
||
/// 查询待处理交易
|
||
async fn find_pending(&self) -> Result<Vec<SystemTransaction>>;
|
||
|
||
/// 查询需要对账的交易
|
||
async fn find_needs_reconciliation(&self) -> Result<Vec<SystemTransaction>>;
|
||
|
||
/// 根据状态查询交易
|
||
async fn find_by_status(&self, status: TransactionStatus) -> Result<Vec<SystemTransaction>>;
|
||
|
||
/// 查询超时交易(BankSubmitted 状态且超过指定秒数)
|
||
async fn find_timeout(&self, timeout_seconds: i64) -> Result<Vec<SystemTransaction>>;
|
||
|
||
/// 条件查询
|
||
async fn query(&self, query: &TransactionQuery) -> Result<Vec<SystemTransaction>>;
|
||
|
||
/// 创建交易
|
||
async fn create(&self, request: &CreateSystemTransactionRequest) -> Result<SystemTransaction>;
|
||
|
||
/// 更新状态
|
||
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<Utc>) -> Result<()>;
|
||
|
||
/// 确认交易
|
||
async fn confirm(&self, id: i64, confirmed_at: DateTime<Utc>) -> Result<()>;
|
||
}
|
||
|
||
/// 银行交易仓储接口
|
||
#[async_trait]
|
||
pub trait BankTransactionRepository: Send + Sync {
|
||
/// 根据ID查询
|
||
async fn find_by_id(&self, id: i64) -> Result<Option<BankTransaction>>;
|
||
|
||
/// 根据银行参考号查询
|
||
async fn find_by_bank_ref_no(&self, bank_ref_no: &str) -> Result<Option<BankTransaction>>;
|
||
|
||
/// 查询未匹配的交易
|
||
async fn find_unmatched(&self, physical_account_id: i64) -> Result<Vec<BankTransaction>>;
|
||
|
||
/// 根据实体账户和时间范围查询
|
||
async fn find_by_account_and_time_range(
|
||
&self,
|
||
physical_account_id: i64,
|
||
start: DateTime<Utc>,
|
||
end: DateTime<Utc>,
|
||
) -> Result<Vec<BankTransaction>>;
|
||
|
||
/// 同步银行交易
|
||
async fn sync(&self, request: &SyncBankTransactionRequest) -> Result<BankTransaction>;
|
||
|
||
/// 批量同步
|
||
async fn batch_sync(&self, requests: &[SyncBankTransactionRequest]) -> Result<Vec<BankTransaction>>;
|
||
|
||
/// 更新匹配状态
|
||
async fn update_match_status(
|
||
&self,
|
||
id: i64,
|
||
status: MatchStatus,
|
||
matched_txn_no: Option<&str>,
|
||
) -> Result<()>;
|
||
}
|
||
|
||
|