Commit d40ac5ea authored by chenweijian's avatar chenweijian

分页

parent 44f76c14
......@@ -34,9 +34,9 @@ func MakeFullUrl(url string) string {
func PageNext(total int64, pageIndex, pageSize int) (int, bool) {
var nextIdx int
var hasNext bool
if total > int64(pageIndex*pageSize) {
if total >= int64(pageIndex+pageSize) {
hasNext = true
nextIdx = pageIndex + 1
nextIdx = pageIndex + pageSize
}
return nextIdx, hasNext
}
......@@ -57,7 +57,7 @@ func (gpu *GroupPowerUser) GetBy(model *domain.Model, pageSize, pageIndex int) (
if err != nil {
return nil, 0, 0, false, err
}
err = db.Limit(pageSize).Offset(pageIndex - 1).Find(&rows).Error
err = db.Limit(pageSize).Offset(pageIndex).Find(&rows).Error
if err != nil {
return nil, 0, 0, false, err
}
......@@ -99,7 +99,7 @@ func GroupPowerQuitList(model *domain.Model, familyId uint64, pageSize, pageInde
if err != nil {
return nil, 0, false, err
}
err = db.Limit(pageSize).Offset(pageIndex - 1).Find(&rows).Error
err = db.Limit(pageSize).Offset(pageIndex).Find(&rows).Error
if err != nil {
return nil, 0, false, err
}
......
......@@ -73,7 +73,7 @@ func OptGroupPowerApplyList(model *domain.Model, familyId uint64, pageSize, page
if err != nil {
return nil, 0, false, err
}
err = db.Limit(pageSize).Offset(pageIndex - 1).Find(&rows).Error
err = db.Limit(pageSize).Offset(pageIndex).Find(&rows).Error
if err != nil {
return nil, 0, false, err
}
......
......@@ -8,6 +8,7 @@ import (
"github.com/bluele/gcache"
"gorm.io/gorm"
"hilo-group/_const/enum/group_e"
"hilo-group/common"
"hilo-group/myerr"
"hilo-group/myerr/bizerr"
"math/rand"
......@@ -523,15 +524,10 @@ func GetFamilyRooms(model *domain.Model, familyId uint64, pageSize, pageIndex in
if err != nil {
return nil, 0, false, err
}
err = db.Limit(pageSize).Offset((pageIndex - 1) * pageSize).Find(&rows).Error
err = db.Limit(pageSize).Offset(pageIndex).Find(&rows).Error
if err != nil {
return nil, 0, false, err
}
var nextIdx int
var hasNext bool
if count > int64(pageIndex*pageSize) {
hasNext = true
nextIdx = pageIndex + 1
}
nextIdx, hasNext := common.PageNext(count, pageIndex, pageSize)
return rows, nextIdx, hasNext, nil
}
......@@ -798,7 +798,7 @@ func GroupPowerInfo(c *gin.Context) (*mycontext.MyContext, error) {
// @Summary 获取某个家族房间列表
// @Param id query int true "家族id"
// @Param pageSize query int true "分页大小 默认:10" default(10)
// @Param pageIndex query int true "第几个分页,从1开始 默认:1" default(1)
// @Param pageIndex query int true "分页开始索引,偏移量" default(1)
// @Success 200 {object} []group_cv.PopularGroupInfo
// @Router /v1/groupPower/rooms [get]
func GroupPowerRooms(c *gin.Context) (*mycontext.MyContext, error) {
......@@ -819,6 +819,9 @@ func GroupPowerRooms(c *gin.Context) (*mycontext.MyContext, error) {
if err != nil {
return myContext, err
}
if pageIndex == 1 {
pageIndex = 0
}
model := domain.CreateModelContext(myContext)
rooms, nextPageIndex, hasNextPage, err := group_m.GetFamilyRooms(model, familyId, pageSize, pageIndex)
if err != nil {
......@@ -838,7 +841,7 @@ func GroupPowerRooms(c *gin.Context) (*mycontext.MyContext, error) {
// @Param userExtId query string false "用户extId,搜索时输入"
// @Param id query int true "家族id"
// @Param pageSize query int true "分页大小 默认:10" default(10)
// @Param pageIndex query int true "第几个分页,从1开始 默认:1" default(1)
// @Param pageIndex query int true "分页开始索引,偏移量" default(1)
// @Success 200 {object} []group_power_cv.FamilyMemberDetail
// @Router /v1/groupPower/members [get]
func GroupPowerMembers(c *gin.Context) (*mycontext.MyContext, error) {
......@@ -859,6 +862,9 @@ func GroupPowerMembers(c *gin.Context) (*mycontext.MyContext, error) {
if err != nil {
return myContext, err
}
if pageIndex == 1 {
pageIndex = 0
}
model := domain.CreateModelContext(myContext)
userExtId := c.Query("userExtId")
......@@ -1036,7 +1042,7 @@ func GroupPowerApplyPass(c *gin.Context) (*mycontext.MyContext, error) {
// @Tags 家族
// @Summary 申请加入列表
// @Param pageSize query int true "分页大小 默认:10" default(10)
// @Param pageIndex query int true "第几个分页,从1开始 默认:1" default(1)
// @Param pageIndex query int true "分页开始索引,偏移量" default(1)
// @Success 200
// @Router /v1/groupPower/apply/list [get]
func GroupPowerApplyList(c *gin.Context) (*mycontext.MyContext, error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment