From bee33f9548e451f76919b29d66d6ee48442c7fb5 Mon Sep 17 00:00:00 2001 From: dengbiao Date: Tue, 31 Dec 2024 23:45:46 +0800 Subject: [PATCH] update --- consume/egg_energy_auto_score_consume.go | 103 ++++++++++++----------- consume/init.go | 4 +- k8s/zyos-go-mq-consume-prd.yaml | 12 +-- 3 files changed, 61 insertions(+), 58 deletions(-) diff --git a/consume/egg_energy_auto_score_consume.go b/consume/egg_energy_auto_score_consume.go index c2173b1..5a23137 100644 --- a/consume/egg_energy_auto_score_consume.go +++ b/consume/egg_energy_auto_score_consume.go @@ -66,62 +66,65 @@ func handleEggEnergyAutoScoreDataConsume(msgData []byte) error { return err } - // 2. 请求获取预测分数 - req := md.GetPredictReq{ - Ecpm: msg.Ecpm, - InviteUserNums: msg.InviteUserNums, - TeamActivityNums: msg.TeamActivityNums, - SignInNums: msg.SignInNums, - ImActivityNums: msg.ImActivityNums, - SendRedPackageNums: msg.SendRedPackageNums, - EggEnergyExchangeAccountBalance: msg.EggEnergyExchangeAccountBalance, - AccountBalanceExchangeEggEnergyNums: msg.AccountBalanceExchangeEggEnergyNums, - SendCircleOfFriendNums: msg.SendCircleOfFriendNums, - ForumCommentsNums: msg.ForumCommentsNums, - CollegeLearningNums: msg.CollegeLearningNums, - ViolateNums: msg.ViolateNums, - BrowseInterfaceNums: msg.BrowseInterfaceNums, - PersonAddActivityValue: msg.PersonAddActivityValue, - } - - reqBytes, err := json.Marshal(req) - if err != nil { - fmt.Println("EggEnergyAutoScoreConsumeFailedMarshal_ERR:::::", err.Error()) - return err - } - - url := "http://ddf.ddstaros.cn/predict" - - request, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(reqBytes)) - if err != nil { - fmt.Println("EggEnergyAutoScoreConsumeFailedNewRequest_ERR:::::", err.Error()) - return err - } - request.Header.Set("Content-Type", "application/json") - client := &http.Client{Timeout: 5 * time.Second} // 设置请求超时时长5s - resp, err := client.Do(request) - if err != nil { - fmt.Println("EggEnergyAutoScoreConsumeFailedPostRequest_ERR:::::", err.Error()) - return err - } - defer resp.Body.Close() + var scoreValue float64 + if msg.Ecpm == 0 && msg.SignInNums == 0 { + scoreValue = 60 + } else { + // 2. 请求获取预测分数 + req := md.GetPredictReq{ + Ecpm: msg.Ecpm, + InviteUserNums: msg.InviteUserNums, + TeamActivityNums: msg.TeamActivityNums, + SignInNums: msg.SignInNums, + ImActivityNums: msg.ImActivityNums, + SendRedPackageNums: msg.SendRedPackageNums, + EggEnergyExchangeAccountBalance: msg.EggEnergyExchangeAccountBalance, + AccountBalanceExchangeEggEnergyNums: msg.AccountBalanceExchangeEggEnergyNums, + SendCircleOfFriendNums: msg.SendCircleOfFriendNums, + ForumCommentsNums: msg.ForumCommentsNums, + CollegeLearningNums: msg.CollegeLearningNums, + ViolateNums: msg.ViolateNums, + BrowseInterfaceNums: msg.BrowseInterfaceNums, + PersonAddActivityValue: msg.PersonAddActivityValue, + } + reqBytes, err := json.Marshal(req) + if err != nil { + fmt.Println("EggEnergyAutoScoreConsumeFailedMarshal_ERR:::::", err.Error()) + return err + } + url := "http://ddf.ddstaros.cn/predict" + request, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(reqBytes)) + if err != nil { + fmt.Println("EggEnergyAutoScoreConsumeFailedNewRequest_ERR:::::", err.Error()) + return err + } + request.Header.Set("Content-Type", "application/json") + client := &http.Client{Timeout: 5 * time.Second} // 设置请求超时时长5s + resp, err := client.Do(request) + if err != nil { + fmt.Println("EggEnergyAutoScoreConsumeFailedPostRequest_ERR:::::", err.Error()) + return err + } + defer resp.Body.Close() - respBody, err := ioutil.ReadAll(resp.Body) - if err != nil { - fmt.Println("EggEnergyAutoScoreConsumeFailedIOReadAll_ERR:::::", err.Error()) - return err - } + respBody, err := ioutil.ReadAll(resp.Body) + if err != nil { + fmt.Println("EggEnergyAutoScoreConsumeFailedIOReadAll_ERR:::::", err.Error()) + return err + } - var score md.GetPredictResp - err = json.Unmarshal(respBody, &score) - if err != nil { - fmt.Println("EggEnergyAutoScoreConsumeFailedUnmarshal_ERR:::::", err.Error()) - return err + var score md.GetPredictResp + err = json.Unmarshal(respBody, &score) + if err != nil { + fmt.Println("EggEnergyAutoScoreConsumeFailedUnmarshal_ERR:::::", err.Error()) + return err + } + scoreValue = score.PredictedScore } // 3. 更新上周得分 updateMap := make(map[string]interface{}) - updateMap["score_value"] = score.PredictedScore + updateMap["score_value"] = scoreValue updateMap["score_value_kind"] = 2 now := time.Now() lastWeek := now.AddDate(0, 0, -7) diff --git a/consume/init.go b/consume/init.go index 86ff65d..817d6be 100644 --- a/consume/init.go +++ b/consume/init.go @@ -30,8 +30,8 @@ func initConsumes() { jobs[consumeMd.IMEggEnergyDelFriendCircleDataFunName] = IMEggEnergyDelFriendCircleDataConsume // 删除朋友圈 jobs[consumeMd.EggFinWithdrawApplyDataConsumeFunName] = EggFinWithdrawApplyDataConsume // 提现 - jobs[consumeMd.EggEnergyDealUserECPMFunName] = EggEnergyDealUserECPMConsume // 处理给用户Ecpm值 - jobs[consumeMd.EggEnergyTemporaryDealUserECPMFunName] = TemporaryEggEnergyDealUserECPMConsume // 临时处理给用户Ecpm值 + jobs[consumeMd.EggEnergyDealUserECPMFunName] = EggEnergyDealUserECPMConsume // 处理给用户Ecpm值 + //jobs[consumeMd.EggEnergyTemporaryDealUserECPMFunName] = TemporaryEggEnergyDealUserECPMConsume // 临时处理给用户Ecpm值 jobs[consumeMd.EggCanalInviteUserNumsFunName] = EggCanalInviteUserNumsConsume // 处理拉新人数 jobs[consumeMd.EggCanalViolateNumsFunName] = EggCanalViolateNumsConsume // 处理违规次数 jobs[consumeMd.IMEggEnergySendRedPackageFunName] = IMEggEnergySendRedPackageConsume // 处理用户发送红包次数 diff --git a/k8s/zyos-go-mq-consume-prd.yaml b/k8s/zyos-go-mq-consume-prd.yaml index d630b94..62a6387 100644 --- a/k8s/zyos-go-mq-consume-prd.yaml +++ b/k8s/zyos-go-mq-consume-prd.yaml @@ -2,10 +2,10 @@ kind: Deployment apiVersion: apps/v1 # 元数据 metadata: - name: egg-go-mq-consume + name: egg-gim-mq-consume-v1 namespace: egg labels: - app: egg-go-mq-consume + app: egg-gim-mq-consume-v1 annotations: kubesphere.io/creator: dengbiao # deployment主要部分 @@ -14,12 +14,12 @@ spec: selector: matchLabels: # 名称与上面的labels对应 - app: egg-go-mq-consume + app: egg-gim-mq-consume-v1 template: metadata: labels: # 名称与上面的matchLabels对应 - app: egg-go-mq-consume + app: egg-gim-mq-consume-v1 spec: # 声明挂载卷(将外部已存在的pvc、config等挂载进来) volumes: @@ -36,9 +36,9 @@ spec: defaultMode: 420 containers: # 主容器 - - name: egg-go-mq-consume + - name: egg-gim-mq-consume-v1 # 镜像地址(提前打包好并推送的镜像仓库) - image: 'registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/egg-go-mq-consume:0.0.1' + image: 'registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/egg-gim-mq-consume-v1:0.0.1' # 将前面volume声明的需要用到的pvc、config挂载上来 volumeMounts: - name: host-time