107 lines
4.4 KiB
Go
107 lines
4.4 KiB
Go
package repositories
|
|
|
|
import (
|
|
"context"
|
|
"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
|
|
CertifiedUsers int64
|
|
TodayRegistrations int64
|
|
TodayLogins int64
|
|
}
|
|
|
|
// UserRepository 用户仓储接口
|
|
type UserRepository interface {
|
|
interfaces.Repository[entities.User]
|
|
|
|
// 基础查询 - 直接使用实体
|
|
GetByPhone(ctx context.Context, phone string) (*entities.User, error)
|
|
GetByUsername(ctx context.Context, username string) (*entities.User, error)
|
|
GetByUserType(ctx context.Context, userType string) ([]*entities.User, error)
|
|
|
|
// 关联查询
|
|
GetByIDWithEnterpriseInfo(ctx context.Context, id string) (entities.User, error)
|
|
|
|
// 企业信息查询
|
|
ExistsByUnifiedSocialCode(ctx context.Context, unifiedSocialCode string, excludeUserID string) (bool, error)
|
|
|
|
// 复杂查询 - 使用查询参数
|
|
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
|
|
UpdateLoginStats(ctx context.Context, userID string) error
|
|
|
|
// 统计信息
|
|
GetStats(ctx context.Context) (*UserStats, error)
|
|
GetStatsByDateRange(ctx context.Context, startDate, endDate string) (*UserStats, error)
|
|
}
|
|
|
|
// 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
|
|
}
|
|
|
|
// 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)
|
|
} |