Commit 2b1b38d4 authored by hujiebin's avatar hujiebin

分页用新的

parent 7c043be8
...@@ -16,6 +16,7 @@ type GroupPowerExpRank struct { ...@@ -16,6 +16,7 @@ type GroupPowerExpRank struct {
// param limit: 排行榜人数 // param limit: 排行榜人数
func GetGroupPowerExpRank(model *domain.Model, beginDate, endDate string, limit int) ([]GroupPowerExpRank, error) { func GetGroupPowerExpRank(model *domain.Model, beginDate, endDate string, limit int) ([]GroupPowerExpRank, error) {
var res []GroupPowerExpRank 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). 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`"). 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 { Group("group_power_id").Order("exp DESC").Limit(limit).Find(&res).Error; err != nil {
......
...@@ -135,3 +135,29 @@ func ResponsePageOk(c *gin.Context, data interface{}, total uint, index int) { ...@@ -135,3 +135,29 @@ func ResponsePageOk(c *gin.Context, data interface{}, total uint, index int) {
traceId, _ := c.Get(mycontext.TRACEID) traceId, _ := c.Get(mycontext.TRACEID)
mylogrus.MyLog.Infof("ResponsePageOk traceId: %s, JSON takes %v", traceId, timeDiff) 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)
}
...@@ -162,7 +162,7 @@ func GroupPowerStar(c *gin.Context) (*mycontext.MyContext, error) { ...@@ -162,7 +162,7 @@ func GroupPowerStar(c *gin.Context) (*mycontext.MyContext, error) {
Score: row.Score, Score: row.Score,
}) })
} }
resp.ResponseOk(c, response) resp.ResponsePageBaseOk(c, response, 0, false)
return myContext, nil return myContext, nil
} }
......
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