@@ -72,21 +72,16 @@ func handleEggCanalUserDownConsume(msgData []byte, ch *rabbit.Channel) error { | |||||
return nil | return nil | ||||
} | } | ||||
sort.Slice(levelAll, func(i, j int) bool { | sort.Slice(levelAll, func(i, j int) bool { | ||||
return levelAll[i].LevelWeight > levelAll[j].LevelWeight | |||||
return levelAll[i].LevelWeight <= levelAll[j].LevelWeight | |||||
}) | }) | ||||
isHas := 0 | |||||
task := make([]map[string]string, 0) | task := make([]map[string]string, 0) | ||||
for _, v := range levelAll { | for _, v := range levelAll { | ||||
if v.Id == user.Level { | |||||
isHas = 1 | |||||
} | |||||
if isHas == 1 { | |||||
task, err = rule.UserUpgradeTask(engine, int(user.Id), v.Id) | |||||
if err != nil { | |||||
continue | |||||
} | |||||
level = v.Id | |||||
task1, err := rule.UserUpgradeTask(engine, int(user.Id), v.Id) | |||||
if err != nil { | |||||
continue | |||||
} | } | ||||
level = v.Id | |||||
task = task1 | |||||
} | } | ||||
//升级 | //升级 | ||||
oldLevel := user.Level | oldLevel := user.Level | ||||
@@ -0,0 +1,101 @@ | |||||
package consume | |||||
import ( | |||||
"applet/app/cfg" | |||||
"applet/app/db" | |||||
"applet/app/utils" | |||||
"applet/app/utils/logx" | |||||
"applet/consume/md" | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement" | |||||
"code.fnuoos.com/EggPlanet/egg_models.git/src/model" | |||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git" | |||||
"code.fnuoos.com/EggPlanet/egg_system_rules.git/rule" | |||||
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" | |||||
"encoding/json" | |||||
"errors" | |||||
"fmt" | |||||
"github.com/streadway/amqp" | |||||
"sort" | |||||
"time" | |||||
) | |||||
func EggCanalUserUpConsume(queue md.MqQueue) { | |||||
fmt.Println(">>>>>>>>>>>>EggCanalUserUpConsume>>>>>>>>>>>>") | |||||
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(100) | |||||
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 = handleEggCanalUserUpConsume(res.Body, ch) | |||||
err = res.Ack(true) | |||||
fmt.Println("err ::: ", err) | |||||
} else { | |||||
panic(errors.New("error getting message")) | |||||
} | |||||
} | |||||
fmt.Println("get msg done") | |||||
} | |||||
func handleEggCanalUserUpConsume(msgData []byte, ch *rabbit.Channel) error { | |||||
var msg *md.CommUserId | |||||
err := json.Unmarshal(msgData, &msg) | |||||
if err != nil { | |||||
return err | |||||
} | |||||
engine := db.Db | |||||
NewUserDb := implement.NewUserDb(engine) | |||||
user, _ := NewUserDb.GetUser(utils.StrToInt64(msg.Uid)) | |||||
if user == nil { | |||||
return nil | |||||
} | |||||
levelDb := implement.NewUserLevelDb(engine) | |||||
levelAll, _ := levelDb.UserLevelAllByAsc() | |||||
level := 0 | |||||
if len(levelAll) == 0 { | |||||
return nil | |||||
} | |||||
sort.Slice(levelAll, func(i, j int) bool { | |||||
return levelAll[i].LevelWeight > levelAll[j].LevelWeight | |||||
}) | |||||
task := make([]map[string]string, 0) | |||||
for _, v := range levelAll { | |||||
if level > 0 { | |||||
continue | |||||
} | |||||
task, err = rule.UserUpgradeTask(engine, int(user.Id), v.Id) | |||||
if err != nil { | |||||
continue | |||||
} | |||||
level = v.Id | |||||
} | |||||
//升级 | |||||
oldLevel := user.Level | |||||
user.Level = level | |||||
_, err = engine.Where("id=?", user.Id).Cols("level").Update(user) | |||||
if err != nil { | |||||
return err | |||||
} | |||||
var tmp = model.UserUpgradeLevel{ | |||||
Uid: int(user.Id), | |||||
Level: level, | |||||
OldLv: oldLevel, | |||||
CreateTime: time.Now(), | |||||
Task: utils.SerializeStr(task), | |||||
} | |||||
engine.Insert(&tmp) | |||||
return nil | |||||
} |
@@ -17,7 +17,9 @@ func Init() { | |||||
// 增加消费任务队列 | // 增加消费任务队列 | ||||
func initConsumes() { | func initConsumes() { | ||||
jobs[consumeMd.EggCanalUserDownConsume] = EggCanalUserDownConsume //监听 自动降级 | |||||
jobs[consumeMd.EggCanalUserUpConsume] = EggCanalUserUpConsume // 自动升级 | |||||
jobs[consumeMd.EggCanalUserDownConsume] = EggCanalUserDownConsume // 自动降级 | |||||
jobs[consumeMd.EggSlowAutoUpLvConsume] = EggSlowAutoUpLvConsume //缓慢 自动升级 | jobs[consumeMd.EggSlowAutoUpLvConsume] = EggSlowAutoUpLvConsume //缓慢 自动升级 | ||||
jobs[consumeMd.EggEnergyUserActivityConsume] = EggEnergyUserActivityConsume //监听 自动升级 | jobs[consumeMd.EggEnergyUserActivityConsume] = EggEnergyUserActivityConsume //监听 自动升级 | ||||
@@ -293,6 +293,15 @@ var RabbitMqQueueKeyList = []*MqQueue{ | |||||
BindKey: "", | BindKey: "", | ||||
ConsumeFunName: "EggCanalUserDownConsume", | ConsumeFunName: "EggCanalUserDownConsume", | ||||
}, | }, | ||||
{ | |||||
ExchangeName: "egg.user", | |||||
Name: "egg_canal_user_up", | |||||
Type: DirectQueueType, | |||||
IsPersistent: false, | |||||
RoutKey: "egg_canal_user_up", | |||||
BindKey: "", | |||||
ConsumeFunName: "EggCanalUserUpConsume", | |||||
}, | |||||
{ | { | ||||
ExchangeName: "egg.energy", | ExchangeName: "egg.energy", | ||||
Name: "egg_energy_team_assistance_back", | Name: "egg_energy_team_assistance_back", | ||||
@@ -354,6 +363,7 @@ const ( | |||||
EggEnergyUserActivityConsume = "EggEnergyUserActivityConsume" | EggEnergyUserActivityConsume = "EggEnergyUserActivityConsume" | ||||
EggCanalUserConsume = "EggCanalUserConsume" | EggCanalUserConsume = "EggCanalUserConsume" | ||||
EggCanalUserDownConsume = "EggCanalUserDownConsume" | EggCanalUserDownConsume = "EggCanalUserDownConsume" | ||||
EggCanalUserUpConsume = "EggCanalUserUpConsume" | |||||
JpushRecordFunName = "JpushRecordConsume" | JpushRecordFunName = "JpushRecordConsume" | ||||
AliyunSmsRecordFunName = "AliyunSmsRecordConsume" | AliyunSmsRecordFunName = "AliyunSmsRecordConsume" | ||||
EggEnergyStartLevelDividendFunName = "EggEnergyStartLevelDividendConsume" | EggEnergyStartLevelDividendFunName = "EggEnergyStartLevelDividendConsume" | ||||