From ee33335d9e2cd6a5ac569774e34495dc78b22ac5 Mon Sep 17 00:00:00 2001 From: dengbiao Date: Wed, 4 Dec 2024 22:50:33 +0800 Subject: [PATCH] update --- .../egg_energy_auto_exchange_green_energy.go | 69 ++++++++++++++++ ...gy_settlement_public_give_activity_coin.go | 81 +++++++++++++++++++ .../egg_energy_start_exchange_green_energy.go | 69 ++++++++++++++++ ...egg_energy_start_level_dividend_consume.go | 11 ++- consume/init.go | 3 + consume/md/consume_key.go | 44 ++++++++-- go.mod | 8 +- 7 files changed, 274 insertions(+), 11 deletions(-) create mode 100644 consume/egg_energy_auto_exchange_green_energy.go create mode 100644 consume/egg_energy_settlement_public_give_activity_coin.go create mode 100644 consume/egg_energy_start_exchange_green_energy.go diff --git a/consume/egg_energy_auto_exchange_green_energy.go b/consume/egg_energy_auto_exchange_green_energy.go new file mode 100644 index 0000000..0481e27 --- /dev/null +++ b/consume/egg_energy_auto_exchange_green_energy.go @@ -0,0 +1,69 @@ +package consume + +import ( + "applet/app/cfg" + utils2 "applet/app/utils" + "applet/app/utils/logx" + "applet/consume/md" + db "code.fnuoos.com/EggPlanet/egg_models.git/src" + "code.fnuoos.com/EggPlanet/egg_system_rules.git" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy" + md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" + "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" + "encoding/json" + "errors" + "fmt" + "github.com/streadway/amqp" +) + +func EggEnergyAutoExchangeGreenEnergyConsume(queue md.MqQueue) { + fmt.Println(">>>>>>>>>>>>EggEnergyAutoExchangeGreenEnergyConsume>>>>>>>>>>>>") + 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 = handleEggEnergyAutoExchangeGreenEnergyConsume(res.Body) + if err != nil { + fmt.Println("EggEnergyAutoExchangeGreenEnergyConsume_ERR:::::", err.Error()) + utils2.FilePutContents("EggEnergyAutoExchangeGreenEnergyConsume_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")) + } + } + fmt.Println("get msg done") +} + +func handleEggEnergyAutoExchangeGreenEnergyConsume(msgData []byte) error { + //1、解析mq中queue的数据结构体 + var msg *md2.EggEnergyStructForAutoExchangeGreenEnergy + err := json.Unmarshal(msgData, &msg) + if err != nil { + return err + } + engine := db.Db + + //2、调用制度方法 + err = egg_energy.ActivityCoinAutoExchangeEggPersonEnergy(engine, *msg) + return err +} diff --git a/consume/egg_energy_settlement_public_give_activity_coin.go b/consume/egg_energy_settlement_public_give_activity_coin.go new file mode 100644 index 0000000..3d2e065 --- /dev/null +++ b/consume/egg_energy_settlement_public_give_activity_coin.go @@ -0,0 +1,81 @@ +package consume + +import ( + "applet/app/cfg" + utils2 "applet/app/utils" + "applet/app/utils/logx" + "applet/consume/md" + db "code.fnuoos.com/EggPlanet/egg_models.git/src" + "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" + "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" + "encoding/json" + "errors" + "fmt" + "github.com/streadway/amqp" +) + +func EggEnergySettlementPublicGiveActivityCoinConsume(queue md.MqQueue) { + fmt.Println(">>>>>>>>>>>>EggEnergySettlementPublicGiveActivityCoinConsume>>>>>>>>>>>>") + 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 = handleEggEnergySettlementPublicGiveActivityCoinConsume(res.Body) + if err != nil { + fmt.Println("EggEnergySettlementPublicGiveActivityCoinConsume_ERR:::::", err.Error()) + utils2.FilePutContents("EggEnergySettlementPublicGiveActivityCoinConsume_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")) + } + } + fmt.Println("get msg done") +} + +func handleEggEnergySettlementPublicGiveActivityCoinConsume(msgData []byte) error { + //1、解析mq中queue的数据结构体 + var msg *md2.DealUserVirtualCoinReq + err := json.Unmarshal(msgData, &msg) + if err != nil { + return err + } + engine := db.Db + session := engine.NewSession() + defer func() { + session.Close() + if err := recover(); err != nil { + _ = logx.Error(err) + } + }() + session.Begin() + + //3、给相应的用户加上个人的团队活跃积分 + err = rule.DealUserVirtualCoin(session, *msg) + if err != nil { + session.Rollback() + return err + } + return session.Begin() +} diff --git a/consume/egg_energy_start_exchange_green_energy.go b/consume/egg_energy_start_exchange_green_energy.go new file mode 100644 index 0000000..203a027 --- /dev/null +++ b/consume/egg_energy_start_exchange_green_energy.go @@ -0,0 +1,69 @@ +package consume + +import ( + "applet/app/cfg" + utils2 "applet/app/utils" + "applet/app/utils/logx" + "applet/consume/md" + db "code.fnuoos.com/EggPlanet/egg_models.git/src" + "code.fnuoos.com/EggPlanet/egg_system_rules.git" + "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy" + md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" + "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" + "encoding/json" + "errors" + "fmt" + "github.com/streadway/amqp" +) + +func EggEnergyStartExchangeGreenEnergyConsume(queue md.MqQueue) { + fmt.Println(">>>>>>>>>>>>EggEnergyStartExchangeGreenEnergyConsume>>>>>>>>>>>>") + 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 = handleEggEnergyStartExchangeGreenEnergyConsume(res.Body, ch) + if err != nil { + fmt.Println("EggEnergyStartExchangeGreenEnergyConsume_ERR:::::", err.Error()) + utils2.FilePutContents("EggEnergyStartExchangeGreenEnergyConsume_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")) + } + } + fmt.Println("get msg done") +} + +func handleEggEnergyStartExchangeGreenEnergyConsume(msgData []byte, ch *rabbit.Channel) error { + //1、解析mq中queue的数据结构体 + var msg *md2.EggEnergyStructForStartExchangeGreenEnergy + err := json.Unmarshal(msgData, &msg) + if err != nil { + return err + } + engine := db.Db + + //2、调用制度方法 + err = egg_energy.ActivityCoinStartExchangeEggEnergy(engine, *msg, ch) + return err +} diff --git a/consume/egg_energy_start_level_dividend_consume.go b/consume/egg_energy_start_level_dividend_consume.go index d1c0f08..3109d9b 100644 --- a/consume/egg_energy_start_level_dividend_consume.go +++ b/consume/egg_energy_start_level_dividend_consume.go @@ -82,6 +82,14 @@ func handleEggEnergyStartLevelDividendConsume(msgData []byte) error { //3、给相应的用户加上个人的团队绿色能量 session := engine.NewSession() + defer func() { + session.Close() + if err := recover(); err != nil { + _ = logx.Error(err) + } + }() + session.Begin() + err = rule.DealUserVirtualCoin(session, md3.DealUserVirtualCoinReq{ Kind: "add", Title: enum.UserVirtualAmountFlowTransferType.String(enum.EggEnergyCommunityDividends), @@ -91,7 +99,8 @@ func handleEggEnergyStartLevelDividendConsume(msgData []byte) error { Amount: msg.SignDividend, }) if err != nil { + session.Rollback() return err } - return nil + return session.Begin() } diff --git a/consume/init.go b/consume/init.go index b5e37c4..88895a8 100644 --- a/consume/init.go +++ b/consume/init.go @@ -24,6 +24,9 @@ func initConsumes() { jobs[consumeMd.IMEggEnergyBatchSendMessageDataFunName] = IMEggEnergyBatchSendMessageDataConsume jobs[consumeMd.IMEggEnergyDelFriendCircleDataFunName] = IMEggEnergyDelFriendCircleDataConsume jobs[consumeMd.EggFinWithdrawApplyDataConsumeFunName] = EggFinWithdrawApplyDataConsume + jobs[consumeMd.EggEnergySettlementPublicGiveActivityCoinFunName] = EggEnergySettlementPublicGiveActivityCoinConsume + jobs[consumeMd.EggEnergyStartExchangeGreenEnergyFunName] = EggEnergyStartExchangeGreenEnergyConsume + jobs[consumeMd.EggEnergyAutoExchangeGreenEnergyFunName] = EggEnergyAutoExchangeGreenEnergyConsume } func Run() { diff --git a/consume/md/consume_key.go b/consume/md/consume_key.go index 257b015..e378076 100644 --- a/consume/md/consume_key.go +++ b/consume/md/consume_key.go @@ -74,14 +74,44 @@ var RabbitMqQueueKeyList = []*MqQueue{ BindKey: "", ConsumeFunName: "EggFinWithdrawApplyDataConsume", }, + { + ExchangeName: "egg.energy", + Name: "egg_energy_settlement_public_give_activity_coin", + Type: DirectQueueType, + IsPersistent: false, + RoutKey: "settlement_public_give_activity_coin", + BindKey: "", + ConsumeFunName: "EggEnergySettlementPublicGiveActivityCoinConsume", + }, + { + ExchangeName: "egg.energy", + Name: "egg_energy_start_exchange_egg_energy", + Type: DirectQueueType, + IsPersistent: false, + RoutKey: "start_exchange_egg_energy", + BindKey: "", + ConsumeFunName: "EggEnergyStartExchangeGreenEnergyConsume", + }, + { + ExchangeName: "egg.energy", + Name: "egg_energy_auto_exchange_egg_energy", + Type: DirectQueueType, + IsPersistent: false, + RoutKey: "start_exchange_egg_energy", + BindKey: "", + ConsumeFunName: "EggEnergyAutoExchangeGreenEnergyConsume", + }, } const ( - EggEnergyStartLevelDividendFunName = "EggEnergyStartLevelDividendConsume" - EggEnergyDealFundDataFunName = "EggEnergyDealFundDataConsume" - EggEnergyDealPlatformRevenueDataFunName = "EggEnergyDealPlatformRevenueDataConsume" - EggEnergyDealUserVirtualCoinDataFunName = "EggEnergyDealUserVirtualCoinDataConsume" - IMEggEnergyBatchSendMessageDataFunName = "IMEggEnergyBatchSendMessageDataConsume" - IMEggEnergyDelFriendCircleDataFunName = "IMEggEnergyDelFriendCircleDataConsume" - EggFinWithdrawApplyDataConsumeFunName = "EggFinWithdrawApplyDataConsume" + EggEnergyStartLevelDividendFunName = "EggEnergyStartLevelDividendConsume" + EggEnergyDealFundDataFunName = "EggEnergyDealFundDataConsume" + EggEnergyDealPlatformRevenueDataFunName = "EggEnergyDealPlatformRevenueDataConsume" + EggEnergyDealUserVirtualCoinDataFunName = "EggEnergyDealUserVirtualCoinDataConsume" + IMEggEnergyBatchSendMessageDataFunName = "IMEggEnergyBatchSendMessageDataConsume" + IMEggEnergyDelFriendCircleDataFunName = "IMEggEnergyDelFriendCircleDataConsume" + EggFinWithdrawApplyDataConsumeFunName = "EggFinWithdrawApplyDataConsume" + EggEnergySettlementPublicGiveActivityCoinFunName = "EggEnergySettlementPublicGiveActivityCoinConsume" + EggEnergyStartExchangeGreenEnergyFunName = "EggEnergyStartExchangeGreenEnergyConsume" + EggEnergyAutoExchangeGreenEnergyFunName = "EggEnergyAutoExchangeGreenEnergyConsume" ) diff --git a/go.mod b/go.mod index e7d3c47..492b85c 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,8 @@ module applet -go 1.19 +go 1.21 + +toolchain go1.23.2 replace code.fnuoos.com/EggPlanet/egg_models.git => E:/company/Egg/egg_models @@ -8,7 +10,7 @@ replace code.fnuoos.com/EggPlanet/egg_system_rules.git => E:/company/Egg/egg_sys require ( code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241128102555-fc839292d728 - code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.2 + code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241204141838-eb4db34e4419 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 @@ -19,7 +21,7 @@ require ( github.com/go-playground/validator/v10 v10.19.0 github.com/go-redis/redis v6.15.9+incompatible github.com/go-sql-driver/mysql v1.8.1 - github.com/gomodule/redigo v2.0.0+incompatible + github.com/gomodule/redigo v1.9.2 github.com/makiuchi-d/gozxing v0.1.1 github.com/qiniu/api.v7/v7 v7.8.2 github.com/shopspring/decimal v1.3.1