From d40ac5ea992647a18358fffab51870033058acb2 Mon Sep 17 00:00:00 2001 From: chenweijian <820961417@qq.com> Date: Wed, 15 Mar 2023 11:02:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/utils.go | 4 ++-- domain/model/groupPower_m/family.go | 4 ++-- domain/model/groupPower_m/group_power_apply.go | 2 +- domain/model/group_m/groupInfo.go | 10 +++------- route/group_power_r/group_power.go | 12 +++++++++--- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/common/utils.go b/common/utils.go index fe1faa1..d9c0237 100755 --- a/common/utils.go +++ b/common/utils.go @@ -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 } diff --git a/domain/model/groupPower_m/family.go b/domain/model/groupPower_m/family.go index f7ac83f..6bb6fbd 100644 --- a/domain/model/groupPower_m/family.go +++ b/domain/model/groupPower_m/family.go @@ -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 } diff --git a/domain/model/groupPower_m/group_power_apply.go b/domain/model/groupPower_m/group_power_apply.go index c1f5480..ddd6ee1 100644 --- a/domain/model/groupPower_m/group_power_apply.go +++ b/domain/model/groupPower_m/group_power_apply.go @@ -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 } diff --git a/domain/model/group_m/groupInfo.go b/domain/model/group_m/groupInfo.go index b9f0ff9..0c91c58 100644 --- a/domain/model/group_m/groupInfo.go +++ b/domain/model/group_m/groupInfo.go @@ -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 } diff --git a/route/group_power_r/group_power.go b/route/group_power_r/group_power.go index 887acb0..d25e1ec 100644 --- a/route/group_power_r/group_power.go +++ b/route/group_power_r/group_power.go @@ -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) { -- 2.22.0