feat 初始化
This commit is contained in:
62
utils/page.go
Normal file
62
utils/page.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"math"
|
||||
|
||||
"git.hlsq.asia/alex/proto/proto/rs/rscommon"
|
||||
"gorm.io/gen/field"
|
||||
)
|
||||
|
||||
func PageGetOffSet(page *rscommon.PageArgs) int {
|
||||
if page == nil || page.PageSize <= 0 {
|
||||
return 0
|
||||
}
|
||||
return int((page.PageIndex - 1) * page.PageSize)
|
||||
}
|
||||
|
||||
func CalcTotalPage(totalCount, pageSize int32) int32 {
|
||||
if pageSize <= 0 {
|
||||
return 0
|
||||
}
|
||||
return int32(math.Ceil(float64(totalCount) / float64(pageSize)))
|
||||
}
|
||||
|
||||
func BuildPageInfoReply(page *rscommon.PageArgs, totalCount int32) *rscommon.PageInfoReply {
|
||||
if page == nil {
|
||||
page = &rscommon.PageArgs{PageIndex: 1, PageSize: 10}
|
||||
}
|
||||
if page.PageSize <= 0 {
|
||||
page.PageSize = 10
|
||||
}
|
||||
if page.PageIndex <= 0 {
|
||||
page.PageIndex = 1
|
||||
}
|
||||
if totalCount <= 0 {
|
||||
totalCount = 0
|
||||
return &rscommon.PageInfoReply{
|
||||
PageIndex: page.PageIndex,
|
||||
PageSize: page.PageSize,
|
||||
TotalCount: totalCount,
|
||||
}
|
||||
}
|
||||
return &rscommon.PageInfoReply{
|
||||
PageIndex: page.PageIndex,
|
||||
PageSize: page.PageSize,
|
||||
TotalCount: totalCount,
|
||||
}
|
||||
}
|
||||
|
||||
func GetOrderInfo(orderList []*rscommon.OrderInfo, getField func(field string) field.OrderExpr) []field.Expr {
|
||||
orders := make([]field.Expr, 0, len(orderList))
|
||||
for _, order := range orderList {
|
||||
expr := getField(order.Field)
|
||||
if expr != nil {
|
||||
if order.Asc {
|
||||
orders = append(orders, expr.Asc())
|
||||
} else {
|
||||
orders = append(orders, expr.Desc())
|
||||
}
|
||||
}
|
||||
}
|
||||
return orders
|
||||
}
|
||||
Reference in New Issue
Block a user