feat 初始化

This commit is contained in:
2026-10-29 10:12:22 +08:00
parent 332d812347
commit 09c1df8a22
81 changed files with 2211 additions and 7821 deletions

62
utils/page.go Normal file
View 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
}