|
|
@@ -17,9 +17,10 @@ func GetEggPointRecordBase(now time.Time, uid int64, page int, limit int) ([]md. |
|
|
|
aliasName := md2.EggEnergyUserEggScoreEsAlias |
|
|
|
// 1. 判断当周分数是否生效 |
|
|
|
getLastWeek := true |
|
|
|
if now.Weekday() > time.Wednesday || (now.Weekday() > time.Wednesday && now.Hour() > 14) { |
|
|
|
if now.Weekday() > time.Wednesday || (now.Weekday() == time.Wednesday && now.Hour() > 14) { |
|
|
|
getLastWeek = false |
|
|
|
} |
|
|
|
nowIndex := md2.EggEnergyUserEggScoreEsAlias + "_" + es2.GetLatestEffectiveIndexFromAlias(now) |
|
|
|
|
|
|
|
// 2. 计算有效周数数量 |
|
|
|
aliases, err := es.EsClient.Aliases(). |
|
|
@@ -28,15 +29,9 @@ func GetEggPointRecordBase(now time.Time, uid int64, page int, limit int) ([]md. |
|
|
|
if err != nil { |
|
|
|
return nil, "", 0, err |
|
|
|
} |
|
|
|
indexNum := len(aliases.Indices) |
|
|
|
if getLastWeek == true { |
|
|
|
// 如果当期未生效 有效周数 - 1 |
|
|
|
indexNum-- |
|
|
|
} |
|
|
|
if indexNum < 1 { |
|
|
|
return nil, "", 0, errors.New("no data") |
|
|
|
} |
|
|
|
|
|
|
|
// 3. 获取最老有效索引及年份周数 |
|
|
|
indexNum := 0 |
|
|
|
oldestIndex := aliasName + "_" + "999999" |
|
|
|
newestIndex := aliasName + "_" + "000000" |
|
|
|
for key, _ := range aliases.Indices { |
|
|
@@ -46,6 +41,13 @@ func GetEggPointRecordBase(now time.Time, uid int64, page int, limit int) ([]md. |
|
|
|
if key > newestIndex { |
|
|
|
newestIndex = key |
|
|
|
} |
|
|
|
// 计算可供查询的周数 |
|
|
|
if key <= nowIndex { |
|
|
|
indexNum++ |
|
|
|
} |
|
|
|
} |
|
|
|
if indexNum < 1 { |
|
|
|
return nil, "60", 0, errors.New("no data") |
|
|
|
} |
|
|
|
oldestYearStr, oldestWeekStr := GetYearsAndWeekStr(oldestIndex) |
|
|
|
oldestYear := utils.StrToInt(oldestYearStr) |
|
|
@@ -55,7 +57,6 @@ func GetEggPointRecordBase(now time.Time, uid int64, page int, limit int) ([]md. |
|
|
|
newestWeek := utils.StrToInt(newestWeekStr) |
|
|
|
|
|
|
|
// 4. 获取当期有效蛋蛋分 |
|
|
|
nowIndex := md2.EggEnergyUserEggScoreEsAlias + "_" + es2.GetLatestEffectiveIndexFromAlias(now) |
|
|
|
boolQuery := elastic.NewBoolQuery() |
|
|
|
boolQuery.Filter(elastic.NewTermQuery("uid", uid)) |
|
|
|
searchResult, err := es.EsClient.Search(). |
|
|
@@ -64,7 +65,7 @@ func GetEggPointRecordBase(now time.Time, uid int64, page int, limit int) ([]md. |
|
|
|
Pretty(true). |
|
|
|
Do(context.Background()) |
|
|
|
var results []md.UserEggFlowReqRespList |
|
|
|
var nowScore string |
|
|
|
nowScore := "60" |
|
|
|
if searchResult != nil { |
|
|
|
var results []md.UserEggFlowReqRespList |
|
|
|
if searchResult.Hits.TotalHits.Value != 0 { |
|
|
@@ -80,16 +81,15 @@ func GetEggPointRecordBase(now time.Time, uid int64, page int, limit int) ([]md. |
|
|
|
} |
|
|
|
if len(results) > 0 { |
|
|
|
nowScore = utils.Float64ToStr(results[0].ScoreValue) |
|
|
|
} else { |
|
|
|
nowScore = "60" |
|
|
|
if nowScore == "0" { |
|
|
|
nowScore = "60" |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
nowScore = "60" |
|
|
|
} |
|
|
|
|
|
|
|
indexes := make([]string, 0, limit) |
|
|
|
var indexes []string |
|
|
|
// 5. 构造分页索引列表 查询历史蛋蛋分 |
|
|
|
for i := 0; i < limit; i++ { |
|
|
|
for i := 0; i < limit && i < indexNum; i++ { |
|
|
|
var tempDays int |
|
|
|
if getLastWeek { |
|
|
|
// 未到周三下午两点,从上上周开始查询 |
|
|
@@ -139,6 +139,9 @@ func GetEggPointRecordBase(now time.Time, uid int64, page int, limit int) ([]md. |
|
|
|
if err != nil { |
|
|
|
return nil, "", 0, errors.New("failed to unmarshal") |
|
|
|
} |
|
|
|
if doc.ScoreValue == 0 { |
|
|
|
doc.ScoreValue = 60 |
|
|
|
} |
|
|
|
results = append(results, doc) |
|
|
|
} |
|
|
|
} |
|
|
|