fix
This commit is contained in:
@@ -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