From 4f43c7ff7b1ceca2d8406e3e0092d8bef314dddf Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Tue, 31 Dec 2024 10:48:59 +0800 Subject: [PATCH] fix: rank egg point record --- app/hdl/hdl_points_center.go | 49 ------------------------------------ app/svc/svc_points_center.go | 15 +++++++---- 2 files changed, 10 insertions(+), 54 deletions(-) diff --git a/app/hdl/hdl_points_center.go b/app/hdl/hdl_points_center.go index a40575c..3bea343 100644 --- a/app/hdl/hdl_points_center.go +++ b/app/hdl/hdl_points_center.go @@ -19,14 +19,9 @@ import ( enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum" md3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" svc2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/svc" - es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es" - "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" - "context" - "encoding/json" "errors" "fmt" "github.com/gin-gonic/gin" - "github.com/olivere/elastic/v7" "github.com/shopspring/decimal" "strconv" "time" @@ -687,50 +682,6 @@ func GetContributionValueFlow(c *gin.Context) { e.OutSuc(c, resp, nil) } -func GetPointMap(c *gin.Context) { - val, exists := c.Get("user") - if !exists { - e.OutErr(c, e.ERR_USER_CHECK_ERR, nil) - return - } - user, ok := val.(*model.User) - if !ok { - e.OutErr(c, e.ERR_USER_CHECK_ERR, nil) - return - } - now := time.Now() - // 1. 获取当期有效蛋蛋分 - nowIndex := md2.EggEnergyUserEggScoreEsAlias + "_" + es2.GetLatestEffectiveIndexFromAlias(now) - boolQuery := elastic.NewBoolQuery() - boolQuery.Filter(elastic.NewTermQuery("uid", user.Id)) - searchResult, err := es.EsClient.Search(). - Index(nowIndex). - Query(boolQuery). - Pretty(true). - Do(context.Background()) - if searchResult == nil { - e.OutErr(c, e.ERR_DB_ORM, errors.New("failed to get current egg score")) - return - } - - var results []md.UserEggFlowReqRespList - if searchResult.Hits.TotalHits.Value != 0 { - // 解析结果 - for _, hit := range searchResult.Hits.Hits { - var doc md.UserEggFlowReqRespList - err = json.Unmarshal(hit.Source, &doc) - if err != nil { - e.OutErr(c, e.ERR_UNMARSHAL, err.Error()) - return - } - results = append(results, doc) - } - } - // nowScore := utils.Float64ToStr(results[0].ScoreValue) - // todo 计算分数权重 - -} - // GetEggPointRecord // @Summary 蛋蛋星球-积分中心-蛋蛋分明细(获取) // @Tags 积分中心 diff --git a/app/svc/svc_points_center.go b/app/svc/svc_points_center.go index 99aa408..b6013e5 100644 --- a/app/svc/svc_points_center.go +++ b/app/svc/svc_points_center.go @@ -10,6 +10,7 @@ import ( "encoding/json" "errors" "github.com/olivere/elastic/v7" + "sort" "time" ) @@ -35,16 +36,18 @@ func GetEggPointRecordBase(now time.Time, uid int64, page int, limit int) ([]md. oldestIndex := aliasName + "_" + "999999" newestIndex := aliasName + "_" + "000000" for key, _ := range aliases.Indices { + // 计算可供查询的周数 + if key <= nowIndex { + indexNum++ + } else { + continue + } if key < oldestIndex { oldestIndex = key } if key > newestIndex { newestIndex = key } - // 计算可供查询的周数 - if key <= nowIndex { - indexNum++ - } } if indexNum < 1 { return nil, "60", 0, errors.New("no data") @@ -67,7 +70,6 @@ func GetEggPointRecordBase(now time.Time, uid int64, page int, limit int) ([]md. var results []md.UserEggFlowReqRespList nowScore := "60" if searchResult != nil { - var results []md.UserEggFlowReqRespList if searchResult.Hits.TotalHits.Value != 0 { // 解析结果 for _, hit := range searchResult.Hits.Hits { @@ -147,6 +149,9 @@ func GetEggPointRecordBase(now time.Time, uid int64, page int, limit int) ([]md. } list := make([]md.EggPointRecordNode, len(results)) + sort.Slice(results, func(i, j int) bool { + return results[i].UpdatedAt > results[j].UpdatedAt + }) for i, result := range results { year, week, startAt, endAt := GetWeekInfo(result.UpdatedAt) list[i].Score = utils.Float64ToStr(result.ScoreValue)