Quellcode durchsuchen

update es score resp to fix es score index

master
shenjiachi vor 4 Tagen
Ursprung
Commit
2de2bf9aec
3 geänderte Dateien mit 107 neuen und 32 gelöschten Zeilen
  1. +79
    -2
      app/hdl/friend_circle/hdl_friend_circle._test.go
  2. +25
    -28
      app/hdl/hdl_member_center.go
  3. +3
    -2
      app/hdl/hdl_points_center.go

+ 79
- 2
app/hdl/friend_circle/hdl_friend_circle._test.go Datei anzeigen

@@ -2,20 +2,37 @@ package friend_circle

import (
"code.fnuoos.com/EggPlanet/egg_system_rules.git/md"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy"
"code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
"fmt"
"testing"
)

// 创建朋友圈索引
func TestCreateFriendCircleIndex(t *testing.T) {
es.Init("http://123.57.140.192:9200", "elastic", "fnuo123")
err := es.CreateIndexIfNotExists(md.EggFriendCircleEsIndex, md.EggFriendCircleEsMapping)
index := md.EggFriendCircleEsIndex
err := es.CreateIndexIfNotExists(index, md.EggFriendCircleEsMapping)
if err != nil {
fmt.Println(err)
}
fmt.Println("success")
}

// 删除朋友圈索引
func TestDeleteFriendCircleIndex(t *testing.T) {
es.Init("http://123.57.140.192:9200", "elastic", "fnuo123")

_, err := es.DeleteIndex(md.EggFriendCircleEsIndex)
if err != nil {
fmt.Println(err)
return
}

fmt.Println("success")
}

// 创建朋友圈点赞索引
func TestCreateFriendCircleCommentLikeIndex(t *testing.T) {
es.Init("http://123.57.140.192:9200", "elastic", "fnuo123")
for i := 0; i < 10; i++ {
@@ -29,6 +46,22 @@ func TestCreateFriendCircleCommentLikeIndex(t *testing.T) {
fmt.Println("success")
}

// 删除朋友圈点赞索引
func TestDeleteFriendCircleCommentLikeIndex(t *testing.T) {
es.Init("http://123.57.140.192:9200", "elastic", "fnuo123")
for i := 0; i < 10; i++ {
index := fmt.Sprintf("%s%d", md.EggFriendCircleLikeEsIndex, i)
_, err := es.DeleteIndex(index)
if err != nil {
fmt.Println(err)
return
}
}

fmt.Println("success")
}

// 创建朋友圈评论索引
func TestCreateFriendCircleCommentIndex(t *testing.T) {
es.Init("http://123.57.140.192:9200", "elastic", "fnuo123")
for i := 0; i < 10; i++ {
@@ -42,7 +75,8 @@ func TestCreateFriendCircleCommentIndex(t *testing.T) {
fmt.Println("success")
}

func TestDeleteIndex(t *testing.T) {
// 删除朋友圈评论索引
func TestDeleteFriendCircleCommentIndex(t *testing.T) {
es.Init("http://123.57.140.192:9200", "elastic", "fnuo123")
for i := 0; i < 10; i++ {
index := fmt.Sprintf("%s%d", md.EggFriendCircleCommentEsIndex, i)
@@ -52,6 +86,49 @@ func TestDeleteIndex(t *testing.T) {
return
}
}
fmt.Println("success")
}

// 删除蛋蛋分记录
func TestDeleteEggScoreIndex(t *testing.T) {
es.Init("http://120.55.48.175:9200", "elastic", "fnuo123")
index := fmt.Sprintf("%s_%d", md.EggEnergyUserEggScoreEsAlias, 202451)
_, err := es.DeleteIndex(index)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("success")
}

// 创建临时蛋蛋分记录
func TestCreateTempEggScoreIndex(t *testing.T) {
es.Init("http://120.55.48.175:9200", "elastic", "fnuo123")
index := fmt.Sprintf("%s_%d_1", md.EggEnergyUserEggScoreEsAlias, 202451)
err := es.CreateIndexIfNotExists(index, md.EggEnergyUserEggScoreEsMapping)
if err != nil {
fmt.Println(err)
}

for i := 1; i < 650; i++ {
egg_energy.ExistOrDefaultUserEggScore(int64(i))
}

fmt.Println("success")
}

// 创建蛋蛋分记录
func TestCreateEggScoreIndex(t *testing.T) {
es.Init("http://120.55.48.175:9200", "elastic", "fnuo123")
index := fmt.Sprintf("%s_%d", md.EggEnergyUserEggScoreEsAlias, 202451)
err := es.CreateIndexIfNotExists(index, md.EggEnergyUserEggScoreEsMapping)
if err != nil {
fmt.Println(err)
}

for i := 1; i < 650; i++ {
egg_energy.ExistOrDefaultUserEggScore(int64(i))
}

fmt.Println("success")
}

+ 25
- 28
app/hdl/hdl_member_center.go Datei anzeigen

@@ -8,15 +8,9 @@ import (
"applet/app/utils"
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
"code.fnuoos.com/EggPlanet/egg_models.git/src/model"
md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md"
es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es"
"code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
"encoding/json"
"fmt"
"github.com/gin-gonic/gin"
"github.com/olivere/elastic/v7"
"github.com/shopspring/decimal"
"time"
)

// MemberCenterGetBasic
@@ -114,16 +108,18 @@ func MemberCenterGetBasic(c *gin.Context) {

// 5. 查询蛋蛋分
score := 60.00
now := time.Now()
esIndex := es2.GetLatestEffectiveIndexFromAlias(now)
esIndexName := md2.EggEnergyUserEggScoreEsAlias + "_" + esIndex
results, err := es.FirstDoc(esIndexName, esIndex+"_"+utils.Int64ToStr(user.Id))
if err != nil {
if !elastic.IsNotFound(err) {
e.OutErr(c, e.ERR, err.Error())
return
}
}
// todo 解除注释
//now := time.Now()
//esIndex := es2.GetLatestEffectiveIndexFromAlias(now)
//esIndexName := md2.EggEnergyUserEggScoreEsAlias + "_" + esIndex
//results, err := es.FirstDoc(esIndexName, esIndex+"_"+utils.Int64ToStr(user.Id))
//if err != nil {
// if !elastic.IsNotFound(err) {
// e.OutErr(c, e.ERR, err.Error())
// return
// }
//}
// todo 解除注释
//// 构建查询条件
//boolQuery := elastic.NewBoolQuery()
//boolQuery.Filter(elastic.NewTermQuery("uid", user.Id))
@@ -142,18 +138,19 @@ func MemberCenterGetBasic(c *gin.Context) {
//if searchResult.Hits.TotalHits.Value != 0 {
// // 解析结果
// for _, hit := range searchResult.Hits.Hits {
if !elastic.IsNotFound(err) {
var doc md.UserEggFlowReqRespList
err = json.Unmarshal(results.Source, &doc)
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, nil)
return
}
// results = append(results, doc)
// }
//}
score = doc.ScoreValue
}
// todo 解除注释
//if !elastic.IsNotFound(err) {
// var doc md.UserEggFlowReqRespList
// err = json.Unmarshal(results.Source, &doc)
// if err != nil {
// e.OutErr(c, e.ERR_DB_ORM, nil)
// return
// }
// // results = append(results, doc)
// // }
// //}
// score = doc.ScoreValue
//}
ratio := decimal.NewFromInt(1).Div(nowPrice).StringFixed(16)
ratioStr := fmt.Sprintf("%s:1", ratio)



+ 3
- 2
app/hdl/hdl_points_center.go Datei anzeigen

@@ -726,7 +726,7 @@ func GetPointMap(c *gin.Context) {
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/v1/pointsCenter/record [GET]
func GetEggPointRecord(c *gin.Context) {
// todo 待补充
pageStr := c.DefaultQuery("page", "1")
limitStr := c.DefaultQuery("limit", "5")
page := utils.StrToInt(pageStr)
@@ -744,9 +744,10 @@ func GetEggPointRecord(c *gin.Context) {
now := time.Now()

list, nowScore, indexNum, err := svc.GetEggPointRecordBase(now, user.Id, page, limit)
err = errors.New("修改es索引默认返回")
if err != nil {
resp := md.GetEggPointRecordResp{
NowScore: "0",
NowScore: "60",
List: nil,
Paginate: md.Paginate{
Limit: limit,


Laden…
Abbrechen
Speichern