|
|
@@ -1,34 +1,34 @@
|
|
|
package common
|
|
|
|
|
|
type PageParams struct {
|
|
|
- Page int64 `protobuf:"varint,1,opt,name=page,proto3" json:"page"`
|
|
|
- Num int64 `protobuf:"varint,2,opt,name=num,proto3" json:"num"`
|
|
|
- Total int64 `protobuf:"varint,3,opt,name=total,proto3" json:"total"`
|
|
|
- Last bool `protobuf:"varint,4,opt,name=last,proto3" json:"last"`
|
|
|
+ Page int64 `protobuf:"varint,1,opt,name=page,proto3" json:"page"`
|
|
|
+ PageSize int64 `protobuf:"varint,2,opt,name=pageSize,proto3" json:"pageSize"`
|
|
|
+ Total int64 `protobuf:"varint,3,opt,name=total,proto3" json:"total"`
|
|
|
+ Last bool `protobuf:"varint,4,opt,name=last,proto3" json:"last"`
|
|
|
}
|
|
|
|
|
|
//从0开始的分页
|
|
|
func (this *PageParams) GetPageParams() (limit int, offset int) {
|
|
|
- _offset := this.Page * this.Num
|
|
|
- if this.Total <= this.Num {
|
|
|
+ _offset := this.Page * this.PageSize
|
|
|
+ if this.Total <= this.PageSize {
|
|
|
this.Page = 0
|
|
|
this.Last = true
|
|
|
return int(this.Total), 0
|
|
|
}
|
|
|
- _start := (this.Page + 1) * this.Num
|
|
|
+ _start := (this.Page + 1) * this.PageSize
|
|
|
|
|
|
if this.Total-_start < 0 {
|
|
|
this.Last = true
|
|
|
- pageCount := this.Total / this.Num
|
|
|
+ pageCount := this.Total / this.PageSize
|
|
|
this.Page = pageCount
|
|
|
- num := this.Total - pageCount*this.Num
|
|
|
+ num := this.Total - pageCount*this.PageSize
|
|
|
if num == 0 {
|
|
|
pageCount = pageCount - 1
|
|
|
- return int(this.Num), int(pageCount * this.Num)
|
|
|
+ return int(this.PageSize), int(pageCount * this.PageSize)
|
|
|
}
|
|
|
- return int(num), int(pageCount * this.Num)
|
|
|
+ return int(num), int(pageCount * this.PageSize)
|
|
|
} else if this.Total-_start == 0 {
|
|
|
this.Last = true
|
|
|
}
|
|
|
- return int(this.Num), int(_offset)
|
|
|
+ return int(this.PageSize), int(_offset)
|
|
|
}
|