Browse Source

fix: ecpm accumulated calculation

master
shenjiachi 1 week ago
parent
commit
89eb9f0348
2 changed files with 8 additions and 60 deletions
  1. +8
    -3
      consume/egg_energy_deal_user_ecpm.go
  2. +0
    -57
      consume/svc/default_create_es_score_doc.go

+ 8
- 3
consume/egg_energy_deal_user_ecpm.go View File

@@ -12,9 +12,11 @@ import (
es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es"
"code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
"context"
"encoding/json"
"errors"
"fmt"
"github.com/olivere/elastic/v7"
"github.com/streadway/amqp"
"strings"
"time"
@@ -72,9 +74,12 @@ func handleEggEnergyDealUserECPMConsume(msgData []byte) error {
index := es2.GetAppointIndexFromAlias(yearStr, weekStr)
id := fmt.Sprintf("%d%d_%d", year, week, msg.Uid)

updateMap := make(map[string]interface{})
updateMap["ecpm"] = utils2.StrToFloat64(msg.Ecpm)
updateDocRet, err := es.UpdateDoc(index, id, updateMap)
script := elastic.NewScript("ctx._source.ecpm += params.inc").Param("inc", utils2.StrToInt64(msg.Ecpm))
updateDocRet, err := es.EsClient.Update().
Index(index).
Id(id).
Script(script).
Do(context.Background())
if err != nil {
if strings.Contains(err.Error(), "elastic: Error 404 (Not Found)") {
// 蛋蛋分数据还不存在,创建蛋蛋分数据


+ 0
- 57
consume/svc/default_create_es_score_doc.go View File

@@ -1,57 +0,0 @@
package svc

import (
utils2 "applet/app/utils"
"code.fnuoos.com/EggPlanet/egg_system_rules.git/md"
"code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
"fmt"
)

func CreateEsScoreAndAssignValuesDoc(index, id string, uid int64, kind int, value string, now string) error {
m := md.EggEnergyUserEggScoreEs{
Uid: uid,
CreatedAt: now,
UpdatedAt: now,
}
switch kind {
case 1:
m.ScoreValue = utils2.StrToFloat64(value)
case 2:
m.ScoreValueKind = int32(utils2.StrToInt64(value))
case 3:
m.Ecpm = utils2.StrToFloat64(value)
case 4:
m.InviteUserNums = utils2.StrToInt(value)
case 5:
m.TeamActivityNums = utils2.StrToInt(value)
case 6:
m.SignInNums = utils2.StrToInt(value)
case 7:
m.ImActivityNums = utils2.StrToInt(value)
case 8:
m.SendRedPackageNums = utils2.StrToInt(value)
case 9:
m.EggEnergyExchangeAccountBalance = utils2.StrToInt(value)
case 10:
m.AccountBalanceExchangeEggEnergyNums = utils2.StrToInt(value)
case 11:
m.SendCircleOfFriendNums = utils2.StrToInt(value)
case 12:
m.ForumCommentsNums = utils2.StrToInt(value)
case 13:
m.CollegeLearningNums = utils2.StrToInt(value)
case 14:
m.ViolateNums = utils2.StrToInt(value)
case 15:
m.BrowseInterfaceNums = utils2.StrToInt(value)
case 16:
m.PersonAddActivityValue = utils2.StrToInt(value)
}
createDoc, err1 := es.CreateDoc(index, id, m)
if err1 != nil {
fmt.Println("EggCanalPersonAddActivityValueConsumeCreateDoc_ERR::::", "kind===>", kind, "::::::", err1.Error())
return err1
}
fmt.Println("createDoc==========>", createDoc)
return nil
}

Loading…
Cancel
Save