From a85c480052349734fe1bc09566fc3c36b67fbdfe Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Fri, 27 Dec 2024 15:39:15 +0800 Subject: [PATCH] fix: update ecpm and PersonAddActivityValue es struct --- ...canal_person_add_activity_value_consume.go | 2 +- ..._person_add_activity_value_consume_test.go | 49 +++++++++++++++++++ consume/egg_energy_deal_user_ecpm.go | 6 ++- consume/egg_energy_deal_user_ecpm_test.go | 24 +++++++++ .../md/md_egg_energy_auto_score_consume.go | 2 +- go.mod | 2 +- 6 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 consume/egg_canal_person_add_activity_value_consume_test.go create mode 100644 consume/egg_energy_deal_user_ecpm_test.go diff --git a/consume/egg_canal_person_add_activity_value_consume.go b/consume/egg_canal_person_add_activity_value_consume.go index 04ac0b6..a5ca767 100644 --- a/consume/egg_canal_person_add_activity_value_consume.go +++ b/consume/egg_canal_person_add_activity_value_consume.go @@ -91,7 +91,7 @@ func handleEggCanalPersonAddActivityValueConsume(msg []byte) error { // 3. 增加个人活跃积分 amount := utils2.StrToFloat64(item.Amount) - script := elastic.NewScript("ctx._source.person_add_activity_value += params.inc").Param("inc", int(amount)) + script := elastic.NewScript("ctx._source.person_add_activity_value += params.inc").Param("inc", amount) updateDoc, err := es.EsClient.Update(). Index(index). Id(id). diff --git a/consume/egg_canal_person_add_activity_value_consume_test.go b/consume/egg_canal_person_add_activity_value_consume_test.go new file mode 100644 index 0000000..01f6e28 --- /dev/null +++ b/consume/egg_canal_person_add_activity_value_consume_test.go @@ -0,0 +1,49 @@ +package consume + +import ( + "applet/consume/md" + md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" + "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" + "testing" + "time" +) + +func TestHandleEggCanalPersonAddActivityValueConsume(t *testing.T) { + data := md.CanalUserVirtualCoinFlow{ + Id: "1", + Uid: "16", + CoinId: "3", + Direction: "1", + Title: "测试", + Amount: "40", + BeforeAmount: "0", + AfterAmount: "80", + SysFee: "0", + TransferType: "6", + } + + message := md.CanalUserVirtualCoinFlowMessage[md.CanalUserVirtualCoinFlow]{ + Data: []md.CanalUserVirtualCoinFlow{data}, + Database: "test_db", + ES: time.Now().UnixNano(), + ID: 1, + IsDdl: false, + Old: nil, + PkNames: []string{"id"}, + Table: "user_virtual_coin_flow", + TS: time.Now().Unix(), + Type: "INSERT", + } + + err := rabbit.Init("120.77.153.180", "5672", "guest", "guest") + if err != nil { + return + } + ch, err := rabbit.Cfg.Pool.GetChannel() + if err != nil { + return + } + defer ch.Release() + ch.Publish(md2.EggCanalExchange, message, "egg_canal_user_virtual_coin_flow") + +} diff --git a/consume/egg_energy_deal_user_ecpm.go b/consume/egg_energy_deal_user_ecpm.go index 401265a..45cae8e 100644 --- a/consume/egg_energy_deal_user_ecpm.go +++ b/consume/egg_energy_deal_user_ecpm.go @@ -73,8 +73,10 @@ func handleEggEnergyDealUserECPMConsume(msgData []byte) error { weekStr := utils2.IntToStr(week) index := es2.GetAppointIndexFromAlias(yearStr, weekStr) id := fmt.Sprintf("%d%d_%d", year, week, msg.Uid) + id = "202453_16" + index = "egg_energy_user_egg_score_202453" - script := elastic.NewScript("ctx._source.ecpm += params.inc").Param("inc", utils2.StrToInt64(msg.Ecpm)) + script := elastic.NewScript("ctx._source.ecpm += params.inc").Param("inc", utils2.StrToFloat64(msg.Ecpm)) updateDocRet, err := es.EsClient.Update(). Index(index). Id(id). @@ -92,6 +94,6 @@ func handleEggEnergyDealUserECPMConsume(msgData []byte) error { } return err } - fmt.Printf("UpdateCreateDoc ==> %+v \n\n", updateDocRet) + fmt.Printf("UpdateDoc ==> %+v \n\n", updateDocRet) return err } diff --git a/consume/egg_energy_deal_user_ecpm_test.go b/consume/egg_energy_deal_user_ecpm_test.go new file mode 100644 index 0000000..3bc1e86 --- /dev/null +++ b/consume/egg_energy_deal_user_ecpm_test.go @@ -0,0 +1,24 @@ +package consume + +import ( + "code.fnuoos.com/EggPlanet/egg_system_rules.git/md" + "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" + "encoding/json" + "fmt" + "testing" +) + +func TestHandleEggEnergyDealUserECPMConsume(t *testing.T) { + + es.Init("http://123.57.140.192:9200", "elastic", "fnuo123") + m := md.DealUserEcpmReq{ + Uid: 16, + Ecpm: "694.704000", + } + bytes, err := json.Marshal(m) + err = handleEggEnergyDealUserECPMConsume(bytes) + if err != nil { + fmt.Println(err) + return + } +} diff --git a/consume/md/md_egg_energy_auto_score_consume.go b/consume/md/md_egg_energy_auto_score_consume.go index d8b9dfe..54732cd 100644 --- a/consume/md/md_egg_energy_auto_score_consume.go +++ b/consume/md/md_egg_energy_auto_score_consume.go @@ -14,7 +14,7 @@ type GetPredictReq struct { CollegeLearningNums int `json:"college_learning_nums"` ViolateNums int `json:"violate_nums"` BrowseInterfaceNums int `json:"browse_interface_nums"` - PersonAddActivityValue int `json:"person_add_activity_value"` + PersonAddActivityValue float64 `json:"person_add_activity_value"` } type GetPredictResp struct { diff --git a/go.mod b/go.mod index 3bc06b5..ddc5ab4 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ go 1.19 require ( code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241224090637-89a57f7fbb1e - code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241226101642-a072d33f3449 + code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241227073118-a441564375e2 code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 github.com/boombuler/barcode v1.0.1