# Conflicts: # go.modmaster
@@ -23,6 +23,10 @@ ENV TZ="Asia/Shanghai" | |||
RUN rm -f /etc/localtime \ | |||
&& ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ | |||
&& echo "Asia/Shanghai" > /etc/timezone | |||
# 更新 CA 证书库 | |||
RUN apt-get update && apt-get install -y ca-certificates | |||
# 在build阶段复制可执行的go二进制文件app | |||
COPY --from=build /go/release/egg ./egg | |||
@@ -9,7 +9,7 @@ echo "GET the Commit ID for git -> $ZYOS_APP_COMMIT_ID" | |||
echo "Start build image " | |||
image_name=registry-vpc.cn-shenzhen.aliyuncs.com/fnuoos-prd/zyos-mall:${ZYOS_APP_COMMIT_ID} | |||
image_name=registry-vpc.cn-shenzhen.aliyuncs.com/fnuoos-prd/egg-go-mq-consume:${ZYOS_APP_COMMIT_ID} | |||
#final_image_name=registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/zyos:${ZYOS_APP_COMMIT_ID} | |||
docker build -t ${image_name} . | |||
@@ -0,0 +1,141 @@ | |||
package consume | |||
import ( | |||
"applet/app/cfg" | |||
utils2 "applet/app/utils" | |||
"applet/app/utils/logx" | |||
"applet/consume/md" | |||
"bytes" | |||
"code.fnuoos.com/EggPlanet/egg_system_rules.git" | |||
md3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/md" | |||
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" | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" | |||
"encoding/json" | |||
"errors" | |||
"fmt" | |||
"github.com/streadway/amqp" | |||
"io/ioutil" | |||
"net/http" | |||
"time" | |||
) | |||
func EggEnergyAutoScoreConsume(queue md.MqQueue) { | |||
fmt.Println(">>>>>>>>>>>>EggEnergyAutoScoreConsume>>>>>>>>>>>>") | |||
ch, err := rabbit.Cfg.Pool.GetChannel() | |||
if err != nil { | |||
logx.Error(err) | |||
return | |||
} | |||
defer ch.Release() | |||
//1、将自己绑定到交换机上 | |||
ch.Bind(queue.Name, queue.ExchangeName, queue.RoutKey) | |||
//2、取出数据进行消费 | |||
ch.Qos(1) | |||
delivery := ch.Consume(queue.Name, false) | |||
egg_system_rules.Init(cfg.RedisAddr) | |||
var res amqp.Delivery | |||
var ok bool | |||
for { | |||
res, ok = <-delivery | |||
if ok == true { | |||
err = handleEggEnergyAutoScoreDataConsume(res.Body) | |||
if err != nil { | |||
fmt.Println("EggEnergyAutoScoreConsume_ERR:::::", err.Error()) | |||
utils2.FilePutContents("EggEnergyAutoScoreConsume_ERR", utils2.SerializeStr(map[string]interface{}{ | |||
"body": res.Body, | |||
"err": err.Error(), | |||
})) | |||
} | |||
//_ = res.Reject(false) | |||
err = res.Ack(true) | |||
fmt.Println("err ::: ", err) | |||
} else { | |||
panic(errors.New("error getting message")) | |||
} | |||
} | |||
} | |||
func handleEggEnergyAutoScoreDataConsume(msgData []byte) error { | |||
time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 | |||
// 1.解析mq中queue的数据结构体 | |||
var msg *md2.EggStructForAutoScoreData | |||
err := json.Unmarshal(msgData, &msg) | |||
if err != nil { | |||
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() | |||
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 | |||
} | |||
// 3. 更新上周得分 | |||
esScore := md3.EggEnergyUserEggScoreEs{ | |||
ScoreValue: score.PredictedScore, | |||
} | |||
now := time.Now() | |||
lastWeek := now.AddDate(0, 0, -7) | |||
year, week := lastWeek.ISOWeek() | |||
yearString := utils2.IntToStr(year) | |||
weekString := utils2.IntToStr(week) | |||
LastWeekIndex := es2.GetAppointIndexFromAlias(yearString, weekString) | |||
updateDocRet, err := es.UpdateDoc(LastWeekIndex, msg.DocId, esScore) | |||
if err != nil { | |||
fmt.Println("EggEnergyAutoScoreConsumeFailedUpdateEs_ERR:::::", err.Error()) | |||
return err | |||
} | |||
fmt.Printf("updateDoc ==> %+v \n\n", updateDocRet) | |||
return nil | |||
} |
@@ -48,6 +48,7 @@ func initConsumes() { | |||
jobs[consumeMd.EggEnergySettlementPublicGiveActivityCoinFunName] = EggEnergySettlementPublicGiveActivityCoinConsume | |||
jobs[consumeMd.EggEnergyStartExchangeGreenEnergyFunName] = EggEnergyStartExchangeGreenEnergyConsume | |||
jobs[consumeMd.EggEnergyAutoExchangeGreenEnergyFunName] = EggEnergyAutoExchangeGreenEnergyConsume | |||
jobs[consumeMd.EggEnergyAutoScoreDataFunName] = EggEnergyAutoScoreConsume // 自动打分 | |||
} | |||
@@ -45,7 +45,7 @@ var RabbitMqQueueKeyList = []*MqQueue{ | |||
IsPersistent: false, | |||
RoutKey: "deal_user_virtual_coin", | |||
BindKey: "", | |||
ConsumeFunName: "EggEnergyDealUserVirtualCoinDataConsume ", | |||
ConsumeFunName: "EggEnergyDealUserVirtualCoinDataConsume", | |||
}, | |||
{ | |||
ExchangeName: "im.egg.energy", | |||
@@ -147,7 +147,7 @@ var RabbitMqQueueKeyList = []*MqQueue{ | |||
ConsumeFunName: "EggEnergyNewUserRegisterDataConsume", | |||
}, | |||
{ | |||
ExchangeName: "egg.app", | |||
ExchangeName: "egg.energy", | |||
Name: "egg_energy_user_ecpm", | |||
Type: DirectQueueType, | |||
IsPersistent: false, | |||
@@ -162,7 +162,7 @@ var RabbitMqQueueKeyList = []*MqQueue{ | |||
IsPersistent: false, | |||
RoutKey: "egg_canal_invite_user_nums", | |||
BindKey: "", | |||
ConsumeFunName: "EggEnergyDealUserECPMConsume", | |||
ConsumeFunName: "EggCanalInviteUserNumsConsume", | |||
}, | |||
{ | |||
ExchangeName: "egg.canal.topic", | |||
@@ -227,6 +227,15 @@ var RabbitMqQueueKeyList = []*MqQueue{ | |||
BindKey: "", | |||
ConsumeFunName: "UserDeleteConsume", | |||
}, | |||
{ | |||
ExchangeName: "egg.app", | |||
Name: "egg_auto_score_queue", | |||
Type: DirectQueueType, | |||
IsPersistent: false, | |||
RoutKey: "egg_auto_score", | |||
BindKey: "", | |||
ConsumeFunName: "EggEnergyAutoScoreConsume", | |||
}, | |||
} | |||
const ( | |||
@@ -254,4 +263,5 @@ const ( | |||
VideoRewardFunName = "VideoRewardFunName" | |||
PlayletRewardFunName = "PlayletRewardFunName" | |||
UserDeleteFunName = "UserDeleteConsume" | |||
EggEnergyAutoScoreDataFunName = "EggEnergyAutoScoreConsume" | |||
) |
@@ -0,0 +1,22 @@ | |||
package md | |||
type GetPredictReq struct { | |||
Ecpm float64 `json:"ecpm"` | |||
InviteUserNums int `json:"invite_user_nums"` | |||
TeamActivityNums int `json:"team_activity_nums"` | |||
SignInNums int `json:"sign_in_nums"` | |||
ImActivityNums int `json:"im_activity_nums"` | |||
SendRedPackageNums int `json:"send_red_package_nums"` | |||
EggEnergyExchangeAccountBalance int `json:"egg_energy_exchange_account_balance"` | |||
AccountBalanceExchangeEggEnergyNums int `json:"account_balance_exchange_egg_energy_nums"` | |||
SendCircleOfFriendNums int `json:"send_circle_of_friend_nums"` | |||
ForumCommentsNums int `json:"forum_comments_nums"` | |||
CollegeLearningNums int `json:"college_learning_nums"` | |||
ViolateNums int `json:"violate_nums"` | |||
BrowseInterfaceNums int `json:"browse_interface_nums"` | |||
PersonAddActivityValue int `json:"person_add_activity_value"` | |||
} | |||
type GetPredictResp struct { | |||
PredictedScore float64 `json:"predicted_score"` | |||
} |
@@ -95,83 +95,58 @@ func handleUserDeleteConsume(backEg *xorm.Engine, ch *rabbit.Channel, msgData [] | |||
} | |||
} | |||
//2.用户关系链 | |||
if utils2.StrToInt(msg.ParentUid) > 0 { | |||
//查出所有下级 | |||
var relate []model.UserRelate | |||
err = eg.Where("parent_uid=?", msg.Uid).Find(&relate) | |||
if len(relate) > 0 { | |||
backEg.Insert(&relate) | |||
} | |||
var relateParent []model.UserRelate | |||
err = eg.Where("uid=?", msg.Uid).Find(&relateParent) | |||
var relateParent1 []model.UserRelate | |||
err = eg.Where("uid=?", msg.ParentUid).Find(&relateParent1) | |||
var parentIds = make([]int64, 0) | |||
//查出所有下级 | |||
var relate []model.UserRelate | |||
err = eg.Where("parent_uid=?", msg.Uid).Find(&relate) | |||
if len(relate) > 0 { | |||
backEg.Insert(&relate) | |||
} | |||
var relateParent []model.UserRelate | |||
err = eg.Where("uid=?", msg.Uid).Find(&relateParent) | |||
var relateParent1 []model.UserRelate | |||
err = eg.Where("uid=?", msg.ParentUid).Find(&relateParent1) | |||
var parentIds = make([]int64, 0) | |||
if len(relateParent) > 0 { | |||
backEg.Insert(&relateParent) | |||
for _, v := range relateParent { | |||
parentIds = append(parentIds, v.ParentUid) | |||
} | |||
if len(relateParent) > 0 { | |||
backEg.Insert(&relateParent) | |||
for _, v := range relateParent { | |||
parentIds = append(parentIds, v.ParentUid) | |||
} | |||
var ids = make([]int64, 0) | |||
for _, v := range relate { | |||
ids = append(ids, v.Uid) | |||
} | |||
var ids = make([]int64, 0) | |||
for _, v := range relate { | |||
ids = append(ids, v.Uid) | |||
} | |||
//读出所有下级重新处理 | |||
var allRelate []model.UserRelate | |||
err = eg.In("uid", ids).Desc("level").Find(&allRelate) | |||
for _, v := range allRelate { | |||
if utils2.InArrInt64(v.ParentUid, parentIds) { | |||
eg.Where("id=?", v.Id).Delete(&model.UserRelate{}) | |||
continue | |||
} | |||
//读出所有下级重新处理 | |||
var allRelate []model.UserRelate | |||
err = eg.In("uid", ids).Asc("level").Find(&allRelate) | |||
for _, v := range allRelate { | |||
if utils2.InArrInt64(v.ParentUid, parentIds) { | |||
eg.Where("id=?", v.Id).Delete(&model.UserRelate{}) | |||
continue | |||
if v.ParentUid == utils2.StrToInt64(msg.Uid) && utils2.StrToInt64(msg.ParentUid) > 0 { //如果相等 | |||
level := v.Level | |||
var tmp = model.UserRelate{ | |||
ParentUid: utils2.StrToInt64(msg.ParentUid), | |||
Uid: v.Uid, | |||
Level: level, | |||
InviteTime: v.InviteTime, | |||
} | |||
if v.ParentUid == utils2.StrToInt64(msg.Uid) { //如果相等 | |||
eg.Where("id=?", v.Id).Cols("parent_uid").Update(&model.UserRelate{ParentUid: utils2.StrToInt64(msg.ParentUid)}) | |||
level := v.Level | |||
for _, v1 := range relateParent1 { | |||
level++ | |||
var tmp = model.UserRelate{ | |||
ParentUid: v1.ParentUid, | |||
Uid: v1.Uid, | |||
Level: level, | |||
InviteTime: v.InviteTime, | |||
} | |||
eg.Insert(&tmp) | |||
eg.Insert(&tmp) | |||
for _, v1 := range relateParent1 { | |||
level++ | |||
var tmp1 = model.UserRelate{ | |||
ParentUid: v1.ParentUid, | |||
Uid: v.Uid, | |||
Level: level, | |||
InviteTime: v.InviteTime, | |||
} | |||
eg.Insert(&tmp1) | |||
} | |||
} | |||
eg.Where("parent_uid=?", msg.Uid).Cols("parent_uid").Update(&model.User{ParentUid: utils2.StrToInt64(msg.ParentUid)}) | |||
} else { | |||
//查出所有下级 | |||
var relate []model.UserRelate | |||
err = eg.Where("parent_uid=?", msg.Uid).Find(&relate) | |||
if len(relate) > 0 { | |||
backEg.Insert(&relate) | |||
} | |||
var ids = make([]int64, 0) | |||
for _, v := range relate { | |||
ids = append(ids, v.Uid) | |||
} | |||
var relateParent []model.UserRelate | |||
err = eg.Where("uid=?", msg.Uid).Find(&relateParent) | |||
if len(relateParent) > 0 { | |||
backEg.Insert(&relateParent) | |||
} | |||
//读出所有下级重新处理 | |||
var allRelate []model.UserRelate | |||
err = eg.In("uid", ids).Asc("level").Find(&allRelate) | |||
var relateMap = make(map[int64]int) | |||
for _, v := range allRelate { | |||
if v.ParentUid == utils2.StrToInt64(msg.Uid) { //如果相等就删掉 | |||
eg.Where("id=?", v.Id).Delete(&model.UserRelate{}) | |||
} else { | |||
relateMap[v.Uid]++ | |||
eg.Where("id=?", v.Id).Cols("level").Update(&model.UserRelate{Level: relateMap[v.Uid]}) | |||
} | |||
} | |||
eg.Where("parent_uid=?", msg.Uid).Cols("parent_uid").Update(&model.User{ParentUid: user.ParentUid}) | |||
} | |||
eg.Where("parent_uid=?", msg.Uid).Cols("parent_uid").Update(&model.User{ParentUid: utils2.StrToInt64(msg.ParentUid)}) | |||
_, err = eg.Where("parent_uid=?", msg.Uid).Delete(&model.UserRelate{}) | |||
_, err = eg.Where("uid=?", msg.Uid).Delete(&model.UserRelate{}) | |||