@@ -19,14 +19,9 @@ import ( | |||||
enum2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum" | 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" | 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" | 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" | "errors" | ||||
"fmt" | "fmt" | ||||
"github.com/gin-gonic/gin" | "github.com/gin-gonic/gin" | ||||
"github.com/olivere/elastic/v7" | |||||
"github.com/shopspring/decimal" | "github.com/shopspring/decimal" | ||||
"strconv" | "strconv" | ||||
"time" | "time" | ||||
@@ -687,50 +682,6 @@ func GetContributionValueFlow(c *gin.Context) { | |||||
e.OutSuc(c, resp, nil) | 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 | // GetEggPointRecord | ||||
// @Summary 蛋蛋星球-积分中心-蛋蛋分明细(获取) | // @Summary 蛋蛋星球-积分中心-蛋蛋分明细(获取) | ||||
// @Tags 积分中心 | // @Tags 积分中心 | ||||
@@ -10,6 +10,7 @@ import ( | |||||
"encoding/json" | "encoding/json" | ||||
"errors" | "errors" | ||||
"github.com/olivere/elastic/v7" | "github.com/olivere/elastic/v7" | ||||
"sort" | |||||
"time" | "time" | ||||
) | ) | ||||
@@ -35,16 +36,18 @@ func GetEggPointRecordBase(now time.Time, uid int64, page int, limit int) ([]md. | |||||
oldestIndex := aliasName + "_" + "999999" | oldestIndex := aliasName + "_" + "999999" | ||||
newestIndex := aliasName + "_" + "000000" | newestIndex := aliasName + "_" + "000000" | ||||
for key, _ := range aliases.Indices { | for key, _ := range aliases.Indices { | ||||
// 计算可供查询的周数 | |||||
if key <= nowIndex { | |||||
indexNum++ | |||||
} else { | |||||
continue | |||||
} | |||||
if key < oldestIndex { | if key < oldestIndex { | ||||
oldestIndex = key | oldestIndex = key | ||||
} | } | ||||
if key > newestIndex { | if key > newestIndex { | ||||
newestIndex = key | newestIndex = key | ||||
} | } | ||||
// 计算可供查询的周数 | |||||
if key <= nowIndex { | |||||
indexNum++ | |||||
} | |||||
} | } | ||||
if indexNum < 1 { | if indexNum < 1 { | ||||
return nil, "60", 0, errors.New("no data") | 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 | var results []md.UserEggFlowReqRespList | ||||
nowScore := "60" | nowScore := "60" | ||||
if searchResult != nil { | if searchResult != nil { | ||||
var results []md.UserEggFlowReqRespList | |||||
if searchResult.Hits.TotalHits.Value != 0 { | if searchResult.Hits.TotalHits.Value != 0 { | ||||
// 解析结果 | // 解析结果 | ||||
for _, hit := range searchResult.Hits.Hits { | 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)) | 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 { | for i, result := range results { | ||||
year, week, startAt, endAt := GetWeekInfo(result.UpdatedAt) | year, week, startAt, endAt := GetWeekInfo(result.UpdatedAt) | ||||
list[i].Score = utils.Float64ToStr(result.ScoreValue) | list[i].Score = utils.Float64ToStr(result.ScoreValue) | ||||