@@ -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 | |||||
} |
@@ -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() | |||||
} |
@@ -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 | |||||
} |
@@ -82,6 +82,14 @@ func handleEggEnergyStartLevelDividendConsume(msgData []byte) error { | |||||
//3、给相应的用户加上个人的团队绿色能量 | //3、给相应的用户加上个人的团队绿色能量 | ||||
session := engine.NewSession() | session := engine.NewSession() | ||||
defer func() { | |||||
session.Close() | |||||
if err := recover(); err != nil { | |||||
_ = logx.Error(err) | |||||
} | |||||
}() | |||||
session.Begin() | |||||
err = rule.DealUserVirtualCoin(session, md3.DealUserVirtualCoinReq{ | err = rule.DealUserVirtualCoin(session, md3.DealUserVirtualCoinReq{ | ||||
Kind: "add", | Kind: "add", | ||||
Title: enum.UserVirtualAmountFlowTransferType.String(enum.EggEnergyCommunityDividends), | Title: enum.UserVirtualAmountFlowTransferType.String(enum.EggEnergyCommunityDividends), | ||||
@@ -91,7 +99,8 @@ func handleEggEnergyStartLevelDividendConsume(msgData []byte) error { | |||||
Amount: msg.SignDividend, | Amount: msg.SignDividend, | ||||
}) | }) | ||||
if err != nil { | if err != nil { | ||||
session.Rollback() | |||||
return err | return err | ||||
} | } | ||||
return nil | |||||
return session.Begin() | |||||
} | } |
@@ -24,6 +24,9 @@ func initConsumes() { | |||||
jobs[consumeMd.IMEggEnergyBatchSendMessageDataFunName] = IMEggEnergyBatchSendMessageDataConsume | jobs[consumeMd.IMEggEnergyBatchSendMessageDataFunName] = IMEggEnergyBatchSendMessageDataConsume | ||||
jobs[consumeMd.IMEggEnergyDelFriendCircleDataFunName] = IMEggEnergyDelFriendCircleDataConsume | jobs[consumeMd.IMEggEnergyDelFriendCircleDataFunName] = IMEggEnergyDelFriendCircleDataConsume | ||||
jobs[consumeMd.EggFinWithdrawApplyDataConsumeFunName] = EggFinWithdrawApplyDataConsume | jobs[consumeMd.EggFinWithdrawApplyDataConsumeFunName] = EggFinWithdrawApplyDataConsume | ||||
jobs[consumeMd.EggEnergySettlementPublicGiveActivityCoinFunName] = EggEnergySettlementPublicGiveActivityCoinConsume | |||||
jobs[consumeMd.EggEnergyStartExchangeGreenEnergyFunName] = EggEnergyStartExchangeGreenEnergyConsume | |||||
jobs[consumeMd.EggEnergyAutoExchangeGreenEnergyFunName] = EggEnergyAutoExchangeGreenEnergyConsume | |||||
} | } | ||||
func Run() { | func Run() { | ||||
@@ -74,14 +74,44 @@ var RabbitMqQueueKeyList = []*MqQueue{ | |||||
BindKey: "", | BindKey: "", | ||||
ConsumeFunName: "EggFinWithdrawApplyDataConsume", | 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 ( | 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" | |||||
) | ) |
@@ -1,6 +1,8 @@ | |||||
module applet | 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 | 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 ( | require ( | ||||
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241128102555-fc839292d728 | 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_es.git v1.0.1-0.20241118083738-0f22da9ba0be | ||||
code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 | code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 | ||||
github.com/boombuler/barcode v1.0.1 | github.com/boombuler/barcode v1.0.1 | ||||
@@ -19,7 +21,7 @@ require ( | |||||
github.com/go-playground/validator/v10 v10.19.0 | github.com/go-playground/validator/v10 v10.19.0 | ||||
github.com/go-redis/redis v6.15.9+incompatible | github.com/go-redis/redis v6.15.9+incompatible | ||||
github.com/go-sql-driver/mysql v1.8.1 | 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/makiuchi-d/gozxing v0.1.1 | ||||
github.com/qiniu/api.v7/v7 v7.8.2 | github.com/qiniu/api.v7/v7 v7.8.2 | ||||
github.com/shopspring/decimal v1.3.1 | github.com/shopspring/decimal v1.3.1 | ||||