Commit 41a0b694 authored by hujiebin's avatar hujiebin

feat:rankTop

parent 1f15d4a0
......@@ -40,6 +40,11 @@ type CvGroupPowerRank struct {
Items []CvGroupPowerRankData `json:"items"` // 列表
}
type CvGroupPowerRankTop3 struct {
Period string `json:"period"` // 榜单周期 day:日 week:周 month:月
Items []CvGroupPowerRankData `json:"items"` // 列表
}
type CvGroupPowerRankData struct {
CvGroupPowerBase `json:",inline"`
CvGroupPowerGrade `json:",inline"`
......
......@@ -24,7 +24,7 @@ import (
// @Param token header string true "token"
// @Param nonce header string true "随机数字"
// @Param period path string true "榜单周期 day:日 week:周 month:月"
// @Success 200 {object} group_power_cv.CvGroupPowerRank
// @Success 200 {object} []group_power_cv.CvGroupPowerRankTop3
// @Router /v1/groupPower/rank/{period} [get]
func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) {
myContext := mycontext.CreateMyContext(c.Keys)
......@@ -107,6 +107,66 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) {
return myContext, nil
}
// @Tags 国家势力
// @Summary 家族日周月榜单top3
// @Param token header string true "token"
// @Param nonce header string true "随机数字"
// @Success 200 {object} []group_power_cv.CvGroupPowerRankTop3
// @Router /v1/groupPower/rankTop [get]
func GroupPowerRankTop(c *gin.Context) (*mycontext.MyContext, error) {
myContext := mycontext.CreateMyContext(c.Keys)
periods := []string{"day", "week", "month"}
var response []group_power_cv.CvGroupPowerRankTop3
for _, period := range periods {
var beginDate, endDate string
switch period {
case "day":
beginDate, endDate = time.Now().Format("2006-01-02"), time.Now().Format("2006-01-02")
case "week":
beginDate, endDate = utils.GetMonday(time.Now()).Format("2006-01-02"), utils.GetMonday(time.Now()).AddDate(0, 0, 6).Format("2006-01-02")
case "month":
beginDate, endDate = now.BeginningOfMonth().Format("2006-01-02"), now.EndOfMonth().Format("2006-01-02")
}
var model = domain.CreateModelContext(myContext)
rank, err := groupPower_m.GetGroupPowerExpRank(model, beginDate, endDate, 3)
if err != nil {
return myContext, err
}
var ids []mysql.ID
for _, g := range rank {
ids = append(ids, g.GroupPowerId)
}
grades, err := groupPower_m.MGetGroupPowerGrade(model, ids)
if err != nil {
return myContext, err
}
groupPowers, err := groupPower_m.MGetGroupPowerInfoMap(model, ids)
if err != nil {
return myContext, err
}
data := group_power_cv.CvGroupPowerRankTop3{Period: period}
for _, v := range rank {
data.Items = append(data.Items, group_power_cv.CvGroupPowerRankData{
CvGroupPowerBase: group_power_cv.CvGroupPowerBase{
Id: v.GroupPowerId,
Icon: groupPowers[v.GroupPowerId].Icon,
Name: groupPowers[v.GroupPowerId].Name,
Nameplate: groupPowers[v.GroupPowerId].Nameplate,
},
CvGroupPowerGrade: group_power_cv.CvGroupPowerGrade{
Grade: grades[v.GroupPowerId].Grade,
Exp: v.Exp,
},
Rank: v.Rank,
})
}
response = append(response, data)
}
resp.ResponseOk(c, response)
return myContext, nil
}
type GroupPowerStarReq struct {
GroupPowerId mysql.ID `form:"groupPowerId" binding:"required"`
Type groupPower_e.GroupPowerStarType `form:"type" binding:"required"`
......
......@@ -137,6 +137,7 @@ func InitRouter() *gin.Engine {
groupPower.GET("/quit/list", wrapper(group_power_r.GroupPowerQuitList))
groupPower.POST("/admin", wrapper(group_power_r.GroupPowerSetAdmin))
groupPower.GET("/rank/:period", wrapper(group_power_r.GroupPowerRank))
groupPower.GET("/rankTop", wrapper(group_power_r.GroupPowerRankTop))
groupPower.GET("/star", wrapper(group_power_r.GroupPowerStar))
groupPower.POST("/info/set", wrapper(group_power_r.GroupPowerSetInfo))
}
......
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