Browse Source

fix: rank egg point record

herolist
shenjiachi 1 week ago
parent
commit
4f43c7ff7b
2 changed files with 10 additions and 54 deletions
  1. +0
    -49
      app/hdl/hdl_points_center.go
  2. +10
    -5
      app/svc/svc_points_center.go

+ 0
- 49
app/hdl/hdl_points_center.go View File

@@ -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 积分中心


+ 10
- 5
app/svc/svc_points_center.go View File

@@ -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)


Loading…
Cancel
Save