2025-07-28 01:46:39 +08:00
|
|
|
|
package repositories
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"context"
|
|
|
|
|
|
"tyapi-server/internal/domains/finance/entities"
|
|
|
|
|
|
"tyapi-server/internal/shared/interfaces"
|
2025-09-12 01:15:09 +08:00
|
|
|
|
|
|
|
|
|
|
"github.com/shopspring/decimal"
|
2025-07-28 01:46:39 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// FinanceStats 财务统计信息
|
|
|
|
|
|
type FinanceStats struct {
|
|
|
|
|
|
TotalWallets int64
|
|
|
|
|
|
ActiveWallets int64
|
|
|
|
|
|
TotalBalance string
|
|
|
|
|
|
TodayTransactions int64
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// WalletRepository 钱包仓储接口
|
|
|
|
|
|
// 只保留核心方法,聚合服务负责业务规则
|
|
|
|
|
|
// 业务操作只保留乐观锁更新和基础更新
|
|
|
|
|
|
|
|
|
|
|
|
type WalletRepository interface {
|
|
|
|
|
|
interfaces.Repository[entities.Wallet]
|
|
|
|
|
|
|
|
|
|
|
|
// 基础查询
|
|
|
|
|
|
GetByUserID(ctx context.Context, userID string) (*entities.Wallet, error)
|
|
|
|
|
|
|
|
|
|
|
|
// 乐观锁更新(自动重试)
|
2025-09-12 01:15:09 +08:00
|
|
|
|
UpdateBalanceWithVersion(ctx context.Context, walletID string, amount decimal.Decimal, operation string) (bool, error)
|
|
|
|
|
|
// 乐观锁更新(通过用户ID直接更新,避免重复查询)
|
|
|
|
|
|
UpdateBalanceByUserID(ctx context.Context, userID string, amount decimal.Decimal, operation string) (bool, error)
|
2025-07-28 01:46:39 +08:00
|
|
|
|
|
|
|
|
|
|
// 状态操作
|
|
|
|
|
|
ActivateWallet(ctx context.Context, walletID string) error
|
|
|
|
|
|
DeactivateWallet(ctx context.Context, walletID string) error
|
|
|
|
|
|
|
|
|
|
|
|
// 统计
|
|
|
|
|
|
GetStats(ctx context.Context) (*FinanceStats, error)
|
|
|
|
|
|
GetUserWalletStats(ctx context.Context, userID string) (*FinanceStats, error)
|
|
|
|
|
|
}
|