Browse Source

update

tmp
shenjiachi 4 weeks ago
parent
commit
1a9570ec8e
1 changed files with 33 additions and 18 deletions
  1. +33
    -18
      app/svc/svc_points_center.go

+ 33
- 18
app/svc/svc_points_center.go View File

@@ -38,14 +38,21 @@ func GetEggPointRecordBase(now time.Time, uid int64, page int, limit int) ([]md.
} }
// 3. 获取最老有效索引及年份周数 // 3. 获取最老有效索引及年份周数
oldestIndex := aliasName + "_" + "999999" oldestIndex := aliasName + "_" + "999999"
newestIndex := aliasName + "_" + "000000"
for key, _ := range aliases.Indices { for key, _ := range aliases.Indices {
if key < oldestIndex { if key < oldestIndex {
oldestIndex = key oldestIndex = key
} }
if key > newestIndex {
newestIndex = key
}
} }
oldestYearStr, oldestWeekStr := GetYearsAndWeekStr(oldestIndex) oldestYearStr, oldestWeekStr := GetYearsAndWeekStr(oldestIndex)
oldestYear := utils.StrToInt(oldestYearStr) oldestYear := utils.StrToInt(oldestYearStr)
oldestWeek := utils.StrToInt(oldestWeekStr) oldestWeek := utils.StrToInt(oldestWeekStr)
newestYearStr, newestWeekStr := GetYearsAndWeekStr(newestIndex)
newestYear := utils.StrToInt(newestYearStr)
newestWeek := utils.StrToInt(newestWeekStr)


// 4. 获取当期有效蛋蛋分 // 4. 获取当期有效蛋蛋分
nowIndex := md2.EggEnergyUserEggScoreEsAlias + "_" + es2.GetLatestEffectiveIndexFromAlias(now) nowIndex := md2.EggEnergyUserEggScoreEsAlias + "_" + es2.GetLatestEffectiveIndexFromAlias(now)
@@ -56,25 +63,26 @@ func GetEggPointRecordBase(now time.Time, uid int64, page int, limit int) ([]md.
Query(boolQuery). Query(boolQuery).
Pretty(true). Pretty(true).
Do(context.Background()) Do(context.Background())
if searchResult == nil {
return nil, "", 0, errors.New("failed to get current egg score")
}

var results []md.UserEggFlowReqRespList 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 {
return nil, "", 0, errors.New("failed to unmarshal")
var nowScore string
if searchResult != nil {
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 {
return nil, "", 0, errors.New("failed to unmarshal")
}
results = append(results, doc)
} }
results = append(results, doc)
} }
nowScore = utils.Float64ToStr(results[0].ScoreValue)
} else {
nowScore = "60"
} }


nowScore := utils.Float64ToStr(results[0].ScoreValue)

indexes := make([]string, 0, limit) indexes := make([]string, 0, limit)
// 5. 构造分页索引列表 查询历史蛋蛋分 // 5. 构造分页索引列表 查询历史蛋蛋分
for i := 0; i < limit; i++ { for i := 0; i < limit; i++ {
@@ -94,6 +102,13 @@ func GetEggPointRecordBase(now time.Time, uid int64, page int, limit int) ([]md.
} else if tempYear < oldestYear { } else if tempYear < oldestYear {
break break
} }
// 判断是否超过最新索引时间
if tempYear > newestYear {
continue
}
if tempYear == newestYear && tempWeek > newestWeek {
continue
}
tempIndex := es2.GetAppointIndexFromAlias(utils.IntToStr(tempYear), utils.IntToStr(tempWeek)) tempIndex := es2.GetAppointIndexFromAlias(utils.IntToStr(tempYear), utils.IntToStr(tempWeek))
indexes = append(indexes, tempIndex) indexes = append(indexes, tempIndex)
} }
@@ -108,22 +123,22 @@ func GetEggPointRecordBase(now time.Time, uid int64, page int, limit int) ([]md.
if searchRecordResult == nil { if searchRecordResult == nil {
return nil, "", 0, errors.New("failed to get egg score flows") return nil, "", 0, errors.New("failed to get egg score flows")
} }
var recordResults []md.UserEggFlowReqRespList
//var recordResults []md.UserEggFlowReqRespList
// 检查是否有结果 // 检查是否有结果
if searchRecordResult.Hits.TotalHits.Value != 0 { if searchRecordResult.Hits.TotalHits.Value != 0 {
// 解析结果 // 解析结果
for _, hit := range searchResult.Hits.Hits {
for _, hit := range searchRecordResult.Hits.Hits {
var doc md.UserEggFlowReqRespList var doc md.UserEggFlowReqRespList
err = json.Unmarshal(hit.Source, &doc) err = json.Unmarshal(hit.Source, &doc)
if err != nil { if err != nil {
return nil, "", 0, errors.New("failed to unmarshal") return nil, "", 0, errors.New("failed to unmarshal")
} }
recordResults = append(recordResults, doc)
results = append(results, doc)
} }
} }


list := make([]md.EggPointRecordNode, len(results)) list := make([]md.EggPointRecordNode, len(results))
for i, result := range recordResults {
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)
list[i].Year = year list[i].Year = year


Loading…
Cancel
Save