diff --git a/consume/egg_canal_invite_user_nums_consume.go b/consume/egg_canal_invite_user_nums_consume.go index 7b83735..bd44c53 100644 --- a/consume/egg_canal_invite_user_nums_consume.go +++ b/consume/egg_canal_invite_user_nums_consume.go @@ -5,6 +5,8 @@ import ( "applet/app/utils/logx" "applet/consume/md" md2 "applet/es/md" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum" 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" @@ -14,6 +16,7 @@ import ( "fmt" "github.com/olivere/elastic/v7" "github.com/streadway/amqp" + "strings" "time" ) @@ -81,6 +84,15 @@ func handleEggCanalInviteUserNumsConsume(msg []byte) error { Script(script). Do(context.Background()) if err != nil { + if strings.Contains(err.Error(), "elastic: Error 404 (Not Found)") { + // 蛋蛋分数据还不存在,创建蛋蛋分数据 + now := time.Now().Format("2006-01-02 15:04:05") + err1 := egg_energy.CreateEsScoreAndAssignValuesDoc(index, id, utils2.StrToInt64(parentUid), enum.InviteUserNums, "1", now) + if err1 != nil { + return err1 + } + return nil + } fmt.Println("EggCanalInviteUserNumsConsumeFailedUpdateInviteUserNums_ERR:::::", err.Error()) return err } diff --git a/consume/egg_canal_person_add_activity_value_consume.go b/consume/egg_canal_person_add_activity_value_consume.go index 0ce0505..04ac0b6 100644 --- a/consume/egg_canal_person_add_activity_value_consume.go +++ b/consume/egg_canal_person_add_activity_value_consume.go @@ -7,6 +7,8 @@ import ( "applet/consume/md" md2 "applet/es/md" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum" 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" @@ -16,6 +18,7 @@ import ( "fmt" "github.com/olivere/elastic/v7" "github.com/streadway/amqp" + "strings" "time" ) @@ -95,6 +98,15 @@ func handleEggCanalPersonAddActivityValueConsume(msg []byte) error { Script(script). Do(context.Background()) if err != nil { + if strings.Contains(err.Error(), "elastic: Error 404 (Not Found)") { + // 蛋蛋分数据还不存在,创建蛋蛋分数据 + now := time.Now().Format("2006-01-02 15:04:05") + err1 := egg_energy.CreateEsScoreAndAssignValuesDoc(index, id, utils2.StrToInt64(uid), enum.PersonAddActivityValue, utils2.Float64ToStr(amount), now) + if err1 != nil { + return err1 + } + return nil + } fmt.Println("EggCanalPersonAddActivityValueConsumeUpdateDoc_ERR::::", err.Error()) return err } 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..c34fb7b --- /dev/null +++ b/consume/egg_canal_person_add_activity_value_consume_test.go @@ -0,0 +1,67 @@ +package consume + +import ( + utils2 "applet/app/utils" + "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" + "context" + "fmt" + "github.com/olivere/elastic/v7" + "strings" + "testing" + "time" +) + +func TestEs(t *testing.T) { + es.Init("http://123.57.140.192:9200", "elastic", "fnuo123") + year, week := time.Now().ISOWeek() + yearStr := utils2.IntToStr(year) + weekStr := utils2.IntToStr(week) + index := es2.GetAppointIndexFromAlias(yearStr, weekStr) + amount := utils2.StrToFloat64("100") + uid := "100" + id := fmt.Sprintf("%d%d_%s", year, week, uid) + script := elastic.NewScript("ctx._source.person_add_activity_value += params.inc").Param("inc", int(amount)) + updateDoc, err := es.EsClient.Update(). + Index(index). + Id(id). + Script(script). + Do(context.Background()) + now := time.Now().Format("2006-01-02 15:04:05") + if err != nil { + if strings.Contains(err.Error(), "elastic: Error 404 (Not Found)") { + // 如果记录不存在就创建记录 + m := md.EggEnergyUserEggScoreEs{ + Uid: utils2.StrToInt64(uid), + ScoreValue: 0, + ScoreValueKind: 0, + Ecpm: 0, + InviteUserNums: 0, + TeamActivityNums: 0, + SignInNums: 0, + ImActivityNums: 0, + SendRedPackageNums: 0, + EggEnergyExchangeAccountBalance: 0, + AccountBalanceExchangeEggEnergyNums: 0, + SendCircleOfFriendNums: 0, + ForumCommentsNums: 0, + CollegeLearningNums: 0, + ViolateNums: 0, + BrowseInterfaceNums: 0, + PersonAddActivityValue: 1, + CreatedAt: now, + UpdatedAt: now, + } + createDoc, err1 := es.CreateDoc(index, id, m) + if err1 != nil { + fmt.Println("EggCanalPersonAddActivityValueConsumeCreateDoc_ERR::::", err1.Error()) + return + } + fmt.Println("createDoc==========>", createDoc) + return + } + fmt.Println("EggCanalPersonAddActivityValueConsumeUpdateDoc_ERR::::", err.Error()) + } + fmt.Println("updateDoc==========>", updateDoc) +} diff --git a/consume/egg_canal_violate_nums_consume.go b/consume/egg_canal_violate_nums_consume.go index 626e191..574052d 100644 --- a/consume/egg_canal_violate_nums_consume.go +++ b/consume/egg_canal_violate_nums_consume.go @@ -7,6 +7,8 @@ import ( "applet/consume/md" md2 "applet/es/md" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum" 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" @@ -16,6 +18,7 @@ import ( "fmt" "github.com/olivere/elastic/v7" "github.com/streadway/amqp" + "strings" "time" ) @@ -95,6 +98,15 @@ func handleEggCanalViolateNumsConsume(msg []byte) error { Script(script). Do(context.Background()) if err != nil { + if strings.Contains(err.Error(), "elastic: Error 404 (Not Found)") { + // 蛋蛋分数据还不存在,创建蛋蛋分数据 + now := time.Now().Format("2006-01-02 15:04:05") + err1 := egg_energy.CreateEsScoreAndAssignValuesDoc(index, id, utils2.StrToInt64(uid), enum.ViolateNums, "1", now) + if err1 != nil { + return err1 + } + return nil + } return err } } diff --git a/consume/egg_energy_deal_user_ecpm.go b/consume/egg_energy_deal_user_ecpm.go index e6ea3d4..f960843 100644 --- a/consume/egg_energy_deal_user_ecpm.go +++ b/consume/egg_energy_deal_user_ecpm.go @@ -7,6 +7,8 @@ import ( "applet/consume/md" "code.fnuoos.com/EggPlanet/egg_system_rules.git" md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum" 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" @@ -14,6 +16,7 @@ import ( "errors" "fmt" "github.com/streadway/amqp" + "strings" "time" ) @@ -73,6 +76,15 @@ func handleEggEnergyDealUserECPMConsume(msgData []byte) error { updateMap["ecpm"] = utils2.StrToFloat64(msg.Ecpm) updateDocRet, err := es.UpdateDoc(index, id, updateMap) if err != nil { + if strings.Contains(err.Error(), "elastic: Error 404 (Not Found)") { + // 蛋蛋分数据还不存在,创建蛋蛋分数据 + now := time.Now().Format("2006-01-02 15:04:05") + err1 := egg_energy.CreateEsScoreAndAssignValuesDoc(index, id, msg.Uid, enum.Ecpm, msg.Ecpm, now) + if err1 != nil { + return err1 + } + return nil + } return err } fmt.Printf("UpdateCreateDoc ==> %+v \n\n", updateDocRet) diff --git a/consume/egg_record_active_consume.go b/consume/egg_record_active_consume.go index 4fe6eae..2b16980 100644 --- a/consume/egg_record_active_consume.go +++ b/consume/egg_record_active_consume.go @@ -8,6 +8,8 @@ import ( "applet/consume/md" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_system_rules.git" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum" md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es" "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" @@ -18,6 +20,7 @@ import ( "fmt" "github.com/olivere/elastic/v7" "github.com/streadway/amqp" + "strings" "time" ) @@ -92,6 +95,15 @@ func handleEggRecordActiveDataConsume(msgData []byte) error { Script(script). Do(context.Background()) if err != nil { + if strings.Contains(err.Error(), "elastic: Error 404 (Not Found)") { + // 蛋蛋分数据还不存在,创建蛋蛋分数据 + now := time.Now().Format("2006-01-02 15:04:05") + err1 := egg_energy.CreateEsScoreAndAssignValuesDoc(index, parentEsId, parentUid, enum.TeamActivityNums, "1", now) + if err1 != nil { + return err1 + } + return nil + } return err } } @@ -108,6 +120,15 @@ func handleEggRecordActiveDataConsume(msgData []byte) error { Script(script). Do(context.Background()) if err != nil { + if strings.Contains(err.Error(), "elastic: Error 404 (Not Found)") { + // 蛋蛋分数据还不存在,创建蛋蛋分数据 + now := time.Now().Format("2006-01-02 15:04:05") + err1 := egg_energy.CreateEsScoreAndAssignValuesDoc(index, esId, msg.Uid, enum.SignInNums, "1", now) + if err1 != nil { + return err1 + } + return nil + } return err } return nil diff --git a/consume/im_egg_energy_send_red_package_consume.go b/consume/im_egg_energy_send_red_package_consume.go index 64014ed..5d72789 100644 --- a/consume/im_egg_energy_send_red_package_consume.go +++ b/consume/im_egg_energy_send_red_package_consume.go @@ -6,6 +6,8 @@ import ( "applet/app/utils/logx" "applet/consume/md" "code.fnuoos.com/EggPlanet/egg_system_rules.git" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/enum" md3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" es2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/utils/es" "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es" @@ -16,6 +18,7 @@ import ( "fmt" "github.com/olivere/elastic/v7" "github.com/streadway/amqp" + "strings" "time" ) @@ -78,6 +81,15 @@ func handleIMEggEnergySendRedPackageConsume(msgData []byte) error { Script(script). Do(context.Background()) if err != nil { + if strings.Contains(err.Error(), "elastic: Error 404 (Not Found)") { + // 蛋蛋分数据还不存在,创建蛋蛋分数据 + now := time.Now().Format("2006-01-02 15:04:05") + err1 := egg_energy.CreateEsScoreAndAssignValuesDoc(index, id, msg.Uid, enum.SendRedPackageNums, "1", now) + if err1 != nil { + return err1 + } + return nil + } return err } return err diff --git a/consume/svc/default_create_es_score_doc.go b/consume/svc/default_create_es_score_doc.go new file mode 100644 index 0000000..c711921 --- /dev/null +++ b/consume/svc/default_create_es_score_doc.go @@ -0,0 +1,57 @@ +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 +} diff --git a/go.mod b/go.mod index ef8aff7..6f46651 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.20241225163106-a260007246d4 + code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241226020214-a56eb16f6264 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