修改查询排序

This commit is contained in:
孙肖扬 2025-03-05 15:01:03 +08:00
parent 0feb18d82c
commit 72a2c4dbcc

View File

@ -7,6 +7,7 @@ import (
"exhibition-register/pkg/app" "exhibition-register/pkg/app"
"exhibition-register/pkg/msg" "exhibition-register/pkg/msg"
"fmt" "fmt"
"go.uber.org/zap" "go.uber.org/zap"
"gorm.io/gorm" "gorm.io/gorm"
) )
@ -79,12 +80,12 @@ func RecordList(in *exhibition.RecordListReq) (data []*model.RegisterRecord, tot
if total == 0 { if total == 0 {
return return
} }
sortBy := "created_at desc" sortBy := "create_at %s,id %s"
if in.SortKey == 1 { if in.SortKey == 1 {
sortBy = fmt.Sprintf("created_at%s%s", " ", in.Sort) sortBy = fmt.Sprintf(sortBy, "ASC", "ASC")
} }
if in.SortKey == 2 { if in.SortKey == 2 {
sortBy = fmt.Sprintf("updated_at%s%s", " ", in.Sort) sortBy = fmt.Sprintf(sortBy, "DESC", "DESC")
} }
if err = dbLink.Order(sortBy).Limit(int(in.PageSize)).Offset(int(offset)).Find(&data).Error; err != nil { if err = dbLink.Order(sortBy).Limit(int(in.PageSize)).Offset(int(offset)).Find(&data).Error; err != nil {