Files
tyapi-server/internal/domains/user/repositories/user_repository_interface.go

120 lines
5.2 KiB
Go
Raw Normal View History

2025-07-13 16:36:20 +08:00
package repositories
import (
"context"
2025-09-12 01:15:09 +08:00
"time"
2025-07-13 16:36:20 +08:00
"tyapi-server/internal/domains/user/entities"
"tyapi-server/internal/domains/user/repositories/queries"
"tyapi-server/internal/shared/interfaces"
)
// UserStats 用户统计信息
type UserStats struct {
TotalUsers int64
ActiveUsers int64
2025-07-28 01:46:39 +08:00
CertifiedUsers int64
2025-07-13 16:36:20 +08:00
TodayRegistrations int64
TodayLogins int64
}
// UserRepository 用户仓储接口
type UserRepository interface {
interfaces.Repository[entities.User]
// 基础查询 - 直接使用实体
GetByPhone(ctx context.Context, phone string) (*entities.User, error)
2025-07-20 20:53:26 +08:00
GetByUsername(ctx context.Context, username string) (*entities.User, error)
GetByUserType(ctx context.Context, userType string) ([]*entities.User, error)
2025-07-13 16:36:20 +08:00
2025-07-28 01:46:39 +08:00
// 关联查询
GetByIDWithEnterpriseInfo(ctx context.Context, id string) (entities.User, error)
2025-09-12 01:15:09 +08:00
BatchGetByIDsWithEnterpriseInfo(ctx context.Context, ids []string) ([]*entities.User, error)
2025-07-28 01:46:39 +08:00
// 企业信息查询
ExistsByUnifiedSocialCode(ctx context.Context, unifiedSocialCode string, excludeUserID string) (bool, error)
2025-07-13 16:36:20 +08:00
// 复杂查询 - 使用查询参数
ListUsers(ctx context.Context, query *queries.ListUsersQuery) ([]*entities.User, int64, error)
// 业务操作
ValidateUser(ctx context.Context, phone, password string) (*entities.User, error)
UpdateLastLogin(ctx context.Context, userID string) error
UpdatePassword(ctx context.Context, userID string, newPassword string) error
CheckPassword(ctx context.Context, userID string, password string) (bool, error)
ActivateUser(ctx context.Context, userID string) error
DeactivateUser(ctx context.Context, userID string) error
2025-07-20 20:53:26 +08:00
UpdateLoginStats(ctx context.Context, userID string) error
2025-07-13 16:36:20 +08:00
// 统计信息
GetStats(ctx context.Context) (*UserStats, error)
GetStatsByDateRange(ctx context.Context, startDate, endDate string) (*UserStats, error)
2025-09-12 01:15:09 +08:00
// 系统级别统计方法
GetSystemUserStats(ctx context.Context) (*UserStats, error)
GetSystemUserStatsByDateRange(ctx context.Context, startDate, endDate time.Time) (*UserStats, error)
GetSystemDailyUserStats(ctx context.Context, startDate, endDate time.Time) ([]map[string]interface{}, error)
GetSystemMonthlyUserStats(ctx context.Context, startDate, endDate time.Time) ([]map[string]interface{}, error)
// 排行榜查询方法
GetUserCallRankingByCalls(ctx context.Context, period string, limit int) ([]map[string]interface{}, error)
GetUserCallRankingByConsumption(ctx context.Context, period string, limit int) ([]map[string]interface{}, error)
GetRechargeRanking(ctx context.Context, period string, limit int) ([]map[string]interface{}, error)
2025-07-13 16:36:20 +08:00
}
// SMSCodeRepository 短信验证码仓储接口
type SMSCodeRepository interface {
interfaces.Repository[entities.SMSCode]
// 基础查询 - 直接使用实体
GetByPhone(ctx context.Context, phone string) (*entities.SMSCode, error)
GetLatestByPhone(ctx context.Context, phone string) (*entities.SMSCode, error)
GetValidByPhone(ctx context.Context, phone string) (*entities.SMSCode, error)
GetValidByPhoneAndScene(ctx context.Context, phone string, scene entities.SMSScene) (*entities.SMSCode, error)
// 复杂查询 - 使用查询参数
ListSMSCodes(ctx context.Context, query *queries.ListSMSCodesQuery) ([]*entities.SMSCode, int64, error)
// 业务操作
CreateCode(ctx context.Context, phone string, code string, purpose string) (entities.SMSCode, error)
ValidateCode(ctx context.Context, phone string, code string, purpose string) (bool, error)
InvalidateCode(ctx context.Context, phone string) error
CheckSendFrequency(ctx context.Context, phone string, purpose string) (bool, error)
GetTodaySendCount(ctx context.Context, phone string) (int64, error)
// 统计信息
GetCodeStats(ctx context.Context, phone string, days int) (*SMSCodeStats, error)
}
// SMSCodeStats 短信验证码统计信息
type SMSCodeStats struct {
TotalSent int64
TotalValidated int64
SuccessRate float64
TodaySent int64
}
2025-07-28 01:46:39 +08:00
// EnterpriseInfoRepository 企业信息仓储接口
type EnterpriseInfoRepository interface {
interfaces.Repository[entities.EnterpriseInfo]
// 基础查询 - 直接使用实体
GetByUserID(ctx context.Context, userID string) (*entities.EnterpriseInfo, error)
GetByUnifiedSocialCode(ctx context.Context, unifiedSocialCode string) (*entities.EnterpriseInfo, error)
CheckUnifiedSocialCodeExists(ctx context.Context, unifiedSocialCode string, excludeUserID string) (bool, error)
// 业务操作
UpdateVerificationStatus(ctx context.Context, userID string, isOCRVerified, isFaceVerified, isCertified bool) error
UpdateOCRData(ctx context.Context, userID string, rawData string, confidence float64) error
CompleteCertification(ctx context.Context, userID string) error
// 批量操作
CreateBatch(ctx context.Context, enterpriseInfos []entities.EnterpriseInfo) error
GetByIDs(ctx context.Context, ids []string) ([]entities.EnterpriseInfo, error)
UpdateBatch(ctx context.Context, enterpriseInfos []entities.EnterpriseInfo) error
DeleteBatch(ctx context.Context, ids []string) error
// 统计和列表查询
Count(ctx context.Context, options interfaces.CountOptions) (int64, error)
List(ctx context.Context, options interfaces.ListOptions) ([]entities.EnterpriseInfo, error)
Exists(ctx context.Context, id string) (bool, error)
}