diff --git a/domain/model/groupPower_m/group_rank.go b/domain/model/groupPower_m/group_rank.go index c7d2be76ef7854eebc13138d0b772075225c9b14..be056dc96cd0860e01fa631662cd33bf031df6a4 100644 --- a/domain/model/groupPower_m/group_rank.go +++ b/domain/model/groupPower_m/group_rank.go @@ -16,6 +16,7 @@ type GroupPowerExpRank struct { // param limit: 排行榜人数 func GetGroupPowerExpRank(model *domain.Model, beginDate, endDate string, limit int) ([]GroupPowerExpRank, error) { var res []GroupPowerExpRank + //if err := model.DB().Table("group_power_day_exp").Select("group_power_id,SUM(exp) as exp").Where("date BETWEEN ? AND ?", beginDate, endDate).Group("group_power_id") if err := model.DB().Table("group_power_day_exp p").Joins(",(SELECT @curRank := 0) p").Where("date BETWEEN ? AND ?", beginDate, endDate). Select("group_power_id,SUM(exp) as exp,@curRank := @curRank + 1 `rank`"). Group("group_power_id").Order("exp DESC").Limit(limit).Find(&res).Error; err != nil { diff --git a/resp/response.go b/resp/response.go index 21a0474f1f2e4755a8a57d1a64b6a4ebc3ed9ff2..7a40d78b35fb5c71f35d06a461c4f5bfbb9bc769 100644 --- a/resp/response.go +++ b/resp/response.go @@ -135,3 +135,29 @@ func ResponsePageOk(c *gin.Context, data interface{}, total uint, index int) { traceId, _ := c.Get(mycontext.TRACEID) mylogrus.MyLog.Infof("ResponsePageOk traceId: %s, JSON takes %v", traceId, timeDiff) } + +type PageRespBase struct { + NextPageIndex int `json:"nextPageIndex"` + HasNextPage bool `json:"hasNextPage"` + Data interface{} `json:"data"` // 需要具体自定义 +} + +// 分页返回 +// 客户端入参 PageReqBase +// 服务端返回 PageRespBase +func ResponsePageBaseOk(c *gin.Context, data interface{}, nextPageIndex int, hasNextPage bool) { + if data == nil { + data = make([]interface{}, 0) + } + response := Response{ + Code: myerr.GetSuccessCode(), + Message: myerr.GetSuccessMsg(), + OperationMessage: myerr.GetSuccessMsg(), + Data: PageRespBase{ + NextPageIndex: nextPageIndex, + HasNextPage: hasNextPage, + Data: data, + }, + } + c.JSON(http.StatusOK, response) +} diff --git a/route/group_power_r/group_rank.go b/route/group_power_r/group_rank.go index d0289f70d75274c8b758c7f1fa947cec8a6b0973..3ba6eaca15881c5661c612f98ba76c89d8aceb0b 100644 --- a/route/group_power_r/group_rank.go +++ b/route/group_power_r/group_rank.go @@ -162,7 +162,7 @@ func GroupPowerStar(c *gin.Context) (*mycontext.MyContext, error) { Score: row.Score, }) } - resp.ResponseOk(c, response) + resp.ResponsePageBaseOk(c, response, 0, false) return myContext, nil }