fix
This commit is contained in:
@@ -198,7 +198,7 @@ func (r *GormCertificationQueryRepository) ListByUserIDs(ctx context.Context, us
|
||||
}
|
||||
|
||||
var certifications []*entities.Certification
|
||||
if err := r.GetDB(ctx).Where("user_id IN ?", userIDs).Find(&certifications).Error; err != nil {
|
||||
if err := r.GetDB(ctx).Where("user_id IN ?", userIDs).Order("created_at DESC").Find(&certifications).Error; err != nil {
|
||||
return nil, fmt.Errorf("根据用户ID列表查询认证失败: %w", err)
|
||||
}
|
||||
|
||||
@@ -207,7 +207,7 @@ func (r *GormCertificationQueryRepository) ListByUserIDs(ctx context.Context, us
|
||||
|
||||
// ListByStatus 根据状态查询
|
||||
func (r *GormCertificationQueryRepository) ListByStatus(ctx context.Context, status enums.CertificationStatus, limit int) ([]*entities.Certification, error) {
|
||||
db := r.GetDB(ctx).Where("status = ?", status)
|
||||
db := r.GetDB(ctx).Where("status = ?", status).Order("created_at DESC")
|
||||
if limit > 0 {
|
||||
db = db.Limit(limit)
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ func (r *GormWalletRepository) CreateBatch(ctx context.Context, wallets []entiti
|
||||
|
||||
func (r *GormWalletRepository) GetByIDs(ctx context.Context, ids []string) ([]entities.Wallet, error) {
|
||||
var wallets []entities.Wallet
|
||||
err := r.GetDB(ctx).Where("id IN ?", ids).Find(&wallets).Error
|
||||
err := r.GetDB(ctx).Where("id IN ?", ids).Order("created_at DESC").Find(&wallets).Error
|
||||
return wallets, err
|
||||
}
|
||||
|
||||
@@ -120,6 +120,9 @@ func (r *GormWalletRepository) List(ctx context.Context, options interfaces.List
|
||||
order += " ASC"
|
||||
}
|
||||
query = query.Order(order)
|
||||
} else {
|
||||
// 默认按创建时间倒序
|
||||
query = query.Order("created_at DESC")
|
||||
}
|
||||
if options.Page > 0 && options.PageSize > 0 {
|
||||
offset := (options.Page - 1) * options.PageSize
|
||||
|
||||
@@ -70,7 +70,7 @@ func (r *GormProductCategoryRepository) FindByCode(ctx context.Context, code str
|
||||
// FindVisible 查找可见分类
|
||||
func (r *GormProductCategoryRepository) FindVisible(ctx context.Context) ([]*entities.ProductCategory, error) {
|
||||
var categories []entities.ProductCategory
|
||||
err := r.GetDB(ctx).Where("is_visible = ? AND is_enabled = ?", true, true).Find(&categories).Error
|
||||
err := r.GetDB(ctx).Where("is_visible = ? AND is_enabled = ?", true, true).Order("sort ASC, created_at DESC").Find(&categories).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -86,7 +86,7 @@ func (r *GormProductCategoryRepository) FindVisible(ctx context.Context) ([]*ent
|
||||
// FindEnabled 查找启用分类
|
||||
func (r *GormProductCategoryRepository) FindEnabled(ctx context.Context) ([]*entities.ProductCategory, error) {
|
||||
var categories []entities.ProductCategory
|
||||
err := r.GetDB(ctx).Where("is_enabled = ?", true).Find(&categories).Error
|
||||
err := r.GetDB(ctx).Where("is_enabled = ?", true).Order("sort ASC, created_at DESC").Find(&categories).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -130,7 +130,7 @@ func (r *GormProductCategoryRepository) ListCategories(ctx context.Context, quer
|
||||
dbQuery = dbQuery.Order(order)
|
||||
} else {
|
||||
// 默认按排序字段和创建时间排序
|
||||
dbQuery = dbQuery.Order("sort ASC, created_at ASC")
|
||||
dbQuery = dbQuery.Order("sort ASC, created_at DESC")
|
||||
}
|
||||
|
||||
// 应用分页
|
||||
@@ -193,7 +193,7 @@ func (r *GormProductCategoryRepository) Count(ctx context.Context, options inter
|
||||
// GetByIDs 根据ID列表获取分类
|
||||
func (r *GormProductCategoryRepository) GetByIDs(ctx context.Context, ids []string) ([]entities.ProductCategory, error) {
|
||||
var categories []entities.ProductCategory
|
||||
err := r.GetDB(ctx).Where("id IN ?", ids).Find(&categories).Error
|
||||
err := r.GetDB(ctx).Where("id IN ?", ids).Order("sort ASC, created_at DESC").Find(&categories).Error
|
||||
return categories, err
|
||||
}
|
||||
|
||||
@@ -238,6 +238,9 @@ func (r *GormProductCategoryRepository) List(ctx context.Context, options interf
|
||||
order += " ASC"
|
||||
}
|
||||
query = query.Order(order)
|
||||
} else {
|
||||
// 默认按排序字段和创建时间倒序
|
||||
query = query.Order("sort ASC, created_at DESC")
|
||||
}
|
||||
|
||||
// 应用分页
|
||||
|
||||
@@ -82,7 +82,7 @@ func (r *GormProductRepository) FindByOldID(ctx context.Context, oldID string) (
|
||||
// FindByCategoryID 根据分类ID查找产品
|
||||
func (r *GormProductRepository) FindByCategoryID(ctx context.Context, categoryID string) ([]*entities.Product, error) {
|
||||
var productEntities []entities.Product
|
||||
err := r.GetDB(ctx).Preload("Category").Where("category_id = ?", categoryID).Find(&productEntities).Error
|
||||
err := r.GetDB(ctx).Preload("Category").Where("category_id = ?", categoryID).Order("created_at DESC").Find(&productEntities).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -98,7 +98,7 @@ func (r *GormProductRepository) FindByCategoryID(ctx context.Context, categoryID
|
||||
// FindVisible 查找可见产品
|
||||
func (r *GormProductRepository) FindVisible(ctx context.Context) ([]*entities.Product, error) {
|
||||
var productEntities []entities.Product
|
||||
err := r.GetDB(ctx).Preload("Category").Where("is_visible = ? AND is_enabled = ?", true, true).Find(&productEntities).Error
|
||||
err := r.GetDB(ctx).Preload("Category").Where("is_visible = ? AND is_enabled = ?", true, true).Order("created_at DESC").Find(&productEntities).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -114,7 +114,7 @@ func (r *GormProductRepository) FindVisible(ctx context.Context) ([]*entities.Pr
|
||||
// FindEnabled 查找启用产品
|
||||
func (r *GormProductRepository) FindEnabled(ctx context.Context) ([]*entities.Product, error) {
|
||||
var productEntities []entities.Product
|
||||
err := r.GetDB(ctx).Preload("Category").Where("is_enabled = ?", true).Find(&productEntities).Error
|
||||
err := r.GetDB(ctx).Preload("Category").Where("is_enabled = ?", true).Order("created_at DESC").Find(&productEntities).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -303,7 +303,7 @@ func (r *GormProductRepository) ListProductsWithSubscriptionStatus(ctx context.C
|
||||
// FindSubscribableProducts 查找可订阅产品
|
||||
func (r *GormProductRepository) FindSubscribableProducts(ctx context.Context, userID string) ([]*entities.Product, error) {
|
||||
var productEntities []entities.Product
|
||||
err := r.GetDB(ctx).Where("is_enabled = ? AND is_visible = ?", true, true).Find(&productEntities).Error
|
||||
err := r.GetDB(ctx).Where("is_enabled = ? AND is_visible = ?", true, true).Order("created_at DESC").Find(&productEntities).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -318,7 +318,7 @@ func (r *GormProductRepository) FindSubscribableProducts(ctx context.Context, us
|
||||
// FindProductsByIDs 根据ID列表查找产品
|
||||
func (r *GormProductRepository) FindProductsByIDs(ctx context.Context, ids []string) ([]*entities.Product, error) {
|
||||
var productEntities []entities.Product
|
||||
err := r.GetDB(ctx).Where("id IN ?", ids).Find(&productEntities).Error
|
||||
err := r.GetDB(ctx).Where("id IN ?", ids).Order("created_at DESC").Find(&productEntities).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -379,7 +379,7 @@ func (r *GormProductRepository) Count(ctx context.Context, options interfaces.Co
|
||||
// GetByIDs 根据ID列表获取产品
|
||||
func (r *GormProductRepository) GetByIDs(ctx context.Context, ids []string) ([]entities.Product, error) {
|
||||
var products []entities.Product
|
||||
err := r.GetDB(ctx).Where("id IN ?", ids).Find(&products).Error
|
||||
err := r.GetDB(ctx).Where("id IN ?", ids).Order("created_at DESC").Find(&products).Error
|
||||
return products, err
|
||||
}
|
||||
|
||||
@@ -424,6 +424,9 @@ func (r *GormProductRepository) List(ctx context.Context, options interfaces.Lis
|
||||
order += " ASC"
|
||||
}
|
||||
query = query.Order(order)
|
||||
} else {
|
||||
// 默认按创建时间倒序
|
||||
query = query.Order("created_at DESC")
|
||||
}
|
||||
|
||||
// 应用分页
|
||||
|
||||
@@ -60,7 +60,7 @@ func (r *GormSubscriptionRepository) Update(ctx context.Context, entity entities
|
||||
// FindByUserID 根据用户ID查找订阅
|
||||
func (r *GormSubscriptionRepository) FindByUserID(ctx context.Context, userID string) ([]*entities.Subscription, error) {
|
||||
var subscriptions []entities.Subscription
|
||||
err := r.GetDB(ctx).WithContext(ctx).Where("user_id = ?", userID).Find(&subscriptions).Error
|
||||
err := r.GetDB(ctx).WithContext(ctx).Where("user_id = ?", userID).Order("created_at DESC").Find(&subscriptions).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -76,7 +76,7 @@ func (r *GormSubscriptionRepository) FindByUserID(ctx context.Context, userID st
|
||||
// FindByProductID 根据产品ID查找订阅
|
||||
func (r *GormSubscriptionRepository) FindByProductID(ctx context.Context, productID string) ([]*entities.Subscription, error) {
|
||||
var subscriptions []entities.Subscription
|
||||
err := r.GetDB(ctx).WithContext(ctx).Where("product_id = ?", productID).Find(&subscriptions).Error
|
||||
err := r.GetDB(ctx).WithContext(ctx).Where("product_id = ?", productID).Order("created_at DESC").Find(&subscriptions).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -243,7 +243,7 @@ func (r *GormSubscriptionRepository) Count(ctx context.Context, options interfac
|
||||
// GetByIDs 根据ID列表获取订阅
|
||||
func (r *GormSubscriptionRepository) GetByIDs(ctx context.Context, ids []string) ([]entities.Subscription, error) {
|
||||
var subscriptions []entities.Subscription
|
||||
err := r.GetDB(ctx).WithContext(ctx).Where("id IN ?", ids).Find(&subscriptions).Error
|
||||
err := r.GetDB(ctx).WithContext(ctx).Where("id IN ?", ids).Order("created_at DESC").Find(&subscriptions).Error
|
||||
return subscriptions, err
|
||||
}
|
||||
|
||||
@@ -288,6 +288,9 @@ func (r *GormSubscriptionRepository) List(ctx context.Context, options interface
|
||||
order += " ASC"
|
||||
}
|
||||
query = query.Order(order)
|
||||
} else {
|
||||
// 默认按创建时间倒序
|
||||
query = query.Order("created_at DESC")
|
||||
}
|
||||
|
||||
// 应用分页
|
||||
|
||||
@@ -211,7 +211,7 @@ func (r *GormEnterpriseInfoRepository) CreateBatch(ctx context.Context, enterpri
|
||||
// GetByIDs 根据ID列表获取企业信息
|
||||
func (r *GormEnterpriseInfoRepository) GetByIDs(ctx context.Context, ids []string) ([]entities.EnterpriseInfo, error) {
|
||||
var enterpriseInfos []entities.EnterpriseInfo
|
||||
err := r.db.WithContext(ctx).Where("id IN ?", ids).Find(&enterpriseInfos).Error
|
||||
err := r.db.WithContext(ctx).Where("id IN ?", ids).Order("created_at DESC").Find(&enterpriseInfos).Error
|
||||
return enterpriseInfos, err
|
||||
}
|
||||
|
||||
@@ -246,6 +246,9 @@ func (r *GormEnterpriseInfoRepository) List(ctx context.Context, options interfa
|
||||
order = options.Order
|
||||
}
|
||||
query = query.Order(options.Sort + " " + order)
|
||||
} else {
|
||||
// 默认按创建时间倒序
|
||||
query = query.Order("created_at DESC")
|
||||
}
|
||||
|
||||
if options.Page > 0 && options.PageSize > 0 {
|
||||
|
||||
@@ -72,7 +72,7 @@ func (r *GormSMSCodeRepository) CreateBatch(ctx context.Context, smsCodes []enti
|
||||
// GetByIDs 根据ID列表获取短信验证码
|
||||
func (r *GormSMSCodeRepository) GetByIDs(ctx context.Context, ids []string) ([]entities.SMSCode, error) {
|
||||
var smsCodes []entities.SMSCode
|
||||
err := r.GetDB(ctx).Where("id IN ?", ids).Find(&smsCodes).Error
|
||||
err := r.GetDB(ctx).Where("id IN ?", ids).Order("created_at DESC").Find(&smsCodes).Error
|
||||
return smsCodes, err
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ func (r *GormUserRepository) CreateBatch(ctx context.Context, users []entities.U
|
||||
|
||||
func (r *GormUserRepository) GetByIDs(ctx context.Context, ids []string) ([]entities.User, error) {
|
||||
var users []entities.User
|
||||
err := r.GetDB(ctx).Where("id IN ?", ids).Find(&users).Error
|
||||
err := r.GetDB(ctx).Where("id IN ?", ids).Order("created_at DESC").Find(&users).Error
|
||||
return users, err
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ func (r *GormUserRepository) GetByUsername(ctx context.Context, username string)
|
||||
|
||||
func (r *GormUserRepository) GetByUserType(ctx context.Context, userType string) ([]*entities.User, error) {
|
||||
var users []*entities.User
|
||||
err := r.GetDB(ctx).Where("user_type = ?", userType).Find(&users).Error
|
||||
err := r.GetDB(ctx).Where("user_type = ?", userType).Order("created_at DESC").Find(&users).Error
|
||||
return users, err
|
||||
}
|
||||
|
||||
@@ -214,6 +214,9 @@ func (r *GormUserRepository) ListUsers(ctx context.Context, query *queries.ListU
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// 应用排序(默认按创建时间倒序)
|
||||
db = db.Order("users.created_at DESC")
|
||||
|
||||
// 应用分页
|
||||
offset := (query.Page - 1) * query.PageSize
|
||||
if err := db.Offset(offset).Limit(query.PageSize).Find(&users).Error; err != nil {
|
||||
|
||||
Reference in New Issue
Block a user