41 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package repositories
 | ||
| 
 | ||
| import (
 | ||
| 	"context"
 | ||
| 	"tyapi-server/internal/domains/finance/entities"
 | ||
| 	"tyapi-server/internal/shared/interfaces"
 | ||
| 
 | ||
| 	"github.com/shopspring/decimal"
 | ||
| )
 | ||
| 
 | ||
| // 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)
 | ||
| 
 | ||
| 	// 乐观锁更新(自动重试)
 | ||
| 	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)
 | ||
| 
 | ||
| 	// 状态操作
 | ||
| 	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)
 | ||
| } |