2022-03-01 13:50:13 +08:00
|
|
|
package page
|
|
|
|
|
|
|
|
import (
|
2023-01-18 17:46:25 +08:00
|
|
|
"cutego/pkg/logging"
|
2022-03-01 13:50:13 +08:00
|
|
|
"github.com/go-xorm/xorm"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Page 分页结构体
|
|
|
|
type Page struct {
|
|
|
|
Size int `json:"size"` // 显示条数
|
|
|
|
Total int64 `json:"total"` // 总条数
|
|
|
|
List interface{} `json:"list"` // 数据
|
|
|
|
}
|
|
|
|
|
|
|
|
type Start struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// StartSize 获取分页偏移量
|
|
|
|
func StartSize(pageNum int, size int) int {
|
|
|
|
if pageNum == 0 {
|
|
|
|
pageNum = 1
|
|
|
|
}
|
|
|
|
if size == 0 {
|
|
|
|
size = 10
|
|
|
|
}
|
|
|
|
num := (pageNum - 1) * size
|
|
|
|
return num
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetTotal 获取总条数
|
|
|
|
func GetTotal(engine *xorm.Session, args ...interface{}) (int64, error) {
|
|
|
|
if args != nil {
|
|
|
|
engine.Table(args)
|
|
|
|
}
|
|
|
|
count, err := engine.Count()
|
|
|
|
if err != nil {
|
2023-01-18 17:46:25 +08:00
|
|
|
logging.ErrorLog(err.Error())
|
2022-03-01 13:50:13 +08:00
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
return count, nil
|
|
|
|
}
|