From 41a0b694069b98c635cf6417cb6510e96c38de7b Mon Sep 17 00:00:00 2001 From: hujiebin Date: Mon, 20 Mar 2023 17:43:23 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9ArankTop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cv/group_power_cv/group_rank.go | 5 +++ route/group_power_r/group_rank.go | 62 ++++++++++++++++++++++++++++++- route/router.go | 1 + 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/cv/group_power_cv/group_rank.go b/cv/group_power_cv/group_rank.go index 2432114..d562fa5 100644 --- a/cv/group_power_cv/group_rank.go +++ b/cv/group_power_cv/group_rank.go @@ -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"` diff --git a/route/group_power_r/group_rank.go b/route/group_power_r/group_rank.go index 04d97e6..fcbcc43 100644 --- a/route/group_power_r/group_rank.go +++ b/route/group_power_r/group_rank.go @@ -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"` diff --git a/route/router.go b/route/router.go index b143095..9c2884b 100644 --- a/route/router.go +++ b/route/router.go @@ -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)) } -- 2.22.0