@@ -0,0 +1,111 @@ | |||
package consume | |||
import ( | |||
"applet/app/cfg" | |||
"applet/app/db" | |||
utils2 "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" | |||
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" | |||
"time" | |||
) | |||
func EggEnergyTeamAssistanceConsume(queue md.MqQueue) { | |||
fmt.Println(">>>>>>>>>>>>EggEnergyTeamAssistanceConsume>>>>>>>>>>>>") | |||
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 = handleEggEnergyTeamAssistanceDataConsume(res.Body) | |||
if err != nil { | |||
fmt.Println("EggEnergyTeamAssistanceConsume_ERR:::::", err.Error()) | |||
utils2.FilePutContents("EggEnergyTeamAssistance_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 handleEggEnergyTeamAssistanceDataConsume(msgData []byte) error { | |||
time.Sleep(time.Duration(100) * time.Millisecond) //休眠100毫秒 | |||
// 1.解析mq中queue的数据结构体 | |||
var msg *md2.EggEnergyTeamAssistanceReq | |||
err := json.Unmarshal(msgData, &msg) | |||
if err != nil { | |||
return err | |||
} | |||
// 2.查询用户是否已经助力过 | |||
session := db.Db.NewSession() | |||
defer session.Close() | |||
callbackDb := implement.NewAdvertisingCallbackDb(db.Db) | |||
exist, err := callbackDb.AdvertisingCallbackExistBySession(session, utils2.Int64ToStr(msg.AssistanceUid), msg.SignStart, msg.SignEnd, "") | |||
if err != nil { | |||
return err | |||
} | |||
// 3. 变更数据 | |||
assistanceDb := implement.NewEggEnergyTeamAssistanceDb(db.Db) | |||
now := time.Now() | |||
date := now.Format("2006-01-02") | |||
teamAssistance, err := assistanceDb.EggEnergyTeamAssistanceGetOneBySession(session, msg.Uid, date) | |||
if err != nil { | |||
return err | |||
} | |||
if teamAssistance == nil { | |||
m := model.EggEnergyTeamAssistance{ | |||
Uid: msg.Uid, | |||
AssistedNum: 1, | |||
RewardScore: utils2.Float64ToStr(msg.AssistanceValue), | |||
Date: date, | |||
CreateAt: now.Format("2006-01-02 15:04:05"), | |||
UpdateAt: now.Format("2006-01-02 15:04:05"), | |||
} | |||
_, err = assistanceDb.EggEnergyTeamAssistanceInsertBySession(session, &m) | |||
if err != nil { | |||
session.Rollback() | |||
return err | |||
} | |||
} else { | |||
teamAssistance.RewardScore = utils2.Float64ToStr(msg.AssistanceValue + utils2.StrToFloat64(teamAssistance.RewardScore)) | |||
if !exist { | |||
teamAssistance.AssistedNum++ | |||
} | |||
_, err = assistanceDb.EggEnergyTeamAssistanceUpdateBySession(session, teamAssistance.Id, teamAssistance, "assisted_num", "reward_score") | |||
if err != nil { | |||
session.Rollback() | |||
return err | |||
} | |||
} | |||
return session.Commit() | |||
} |
@@ -49,7 +49,8 @@ func initConsumes() { | |||
jobs[consumeMd.EggEnergySettlementPublicGiveActivityCoinFunName] = EggEnergySettlementPublicGiveActivityCoinConsume | |||
jobs[consumeMd.EggEnergyStartExchangeGreenEnergyFunName] = EggEnergyStartExchangeGreenEnergyConsume | |||
jobs[consumeMd.EggEnergyAutoExchangeGreenEnergyFunName] = EggEnergyAutoExchangeGreenEnergyConsume | |||
jobs[consumeMd.EggEnergyAutoScoreDataFunName] = EggEnergyAutoScoreConsume // 自动打分 | |||
jobs[consumeMd.EggEnergyAutoScoreDataFunName] = EggEnergyAutoScoreConsume // 自动打分 | |||
jobs[consumeMd.EggEnergyTeamAssistanceConsumeFunName] = EggEnergyTeamAssistanceConsume // 更新团队助力数据 | |||
} | |||
@@ -272,6 +272,15 @@ var RabbitMqQueueKeyList = []*MqQueue{ | |||
BindKey: "", | |||
ConsumeFunName: "EggCanalUserConsume", | |||
}, | |||
{ | |||
ExchangeName: "egg.energy", | |||
Name: "egg_energy_team_assistance", | |||
Type: DirectQueueType, | |||
IsPersistent: false, | |||
RoutKey: "egg_energy_team_assistance", | |||
BindKey: "", | |||
ConsumeFunName: "EggEnergyTeamAssistanceConsume", | |||
}, | |||
} | |||
const ( | |||
@@ -302,4 +311,5 @@ const ( | |||
UserDeleteFunName = "UserDeleteConsume" | |||
EggEnergyAutoScoreDataFunName = "EggEnergyAutoScoreConsume" | |||
PublicPlatoonUserRelationCommissionConsumeFunName = "AddPublicPlatoonUserRelationCommissionConsume" | |||
EggEnergyTeamAssistanceConsumeFunName = "EggEnergyTeamAssistanceConsume" | |||
) |
@@ -8,65 +8,65 @@ local: true | |||
redis_addr: '127.0.0.1:6379' | |||
redis_password: '' | |||
#db: | |||
# host: '119.23.182.117:3306' | |||
# name: 'egg' | |||
# user: 'root' | |||
# psw: 'Fnuo123com@' | |||
# show_log: true | |||
# max_lifetime: 30 | |||
# max_open_conns: 100 | |||
# max_idle_conns: 100 | |||
# path: 'tmp/%s.log' | |||
db: | |||
host: 'advertisement-db.rwlb.rds.aliyuncs.com:3306' | |||
host: '119.23.182.117:3306' | |||
name: 'egg' | |||
user: 'canal' | |||
psw: 'DengBiao@1997' | |||
user: 'root' | |||
psw: 'Fnuo123com@' | |||
show_log: true | |||
max_lifetime: 30 | |||
max_open_conns: 100 | |||
max_idle_conns: 100 | |||
path: 'tmp/%s.log' | |||
#db_back: | |||
# host: '119.23.182.117:3306' | |||
# name: 'egg-data-back-up' | |||
# user: 'root' | |||
# psw: 'Fnuo123com@' | |||
#db: | |||
# host: 'advertisement-db.rwlb.rds.aliyuncs.com:3306' | |||
# name: 'egg' | |||
# user: 'canal' | |||
# psw: 'DengBiao@1997' | |||
# show_log: true | |||
# max_lifetime: 30 | |||
# max_open_conns: 100 | |||
# max_idle_conns: 100 | |||
# path: 'tmp/%s.log' | |||
db_back: | |||
host: 'advertisement-db.rwlb.rds.aliyuncs.com:3306' | |||
host: '119.23.182.117:3306' | |||
name: 'egg-data-back-up' | |||
user: 'canal' | |||
psw: 'DengBiao@1997' | |||
user: 'root' | |||
psw: 'Fnuo123com@' | |||
show_log: true | |||
path: 'tmp/%s.log' | |||
#im_db: | |||
# host: '119.23.182.117:3306' | |||
# name: 'egg-im' | |||
# user: 'root' | |||
# psw: 'Fnuo123com@' | |||
#db_back: | |||
# host: 'advertisement-db.rwlb.rds.aliyuncs.com:3306' | |||
# name: 'egg-data-back-up' | |||
# user: 'canal' | |||
# psw: 'DengBiao@1997' | |||
# show_log: true | |||
# max_lifetime: 30 | |||
# max_open_conns: 100 | |||
# max_idle_conns: 100 | |||
# path: 'tmp/%s.log' | |||
im_db: | |||
host: 'advertisement-db.rwlb.rds.aliyuncs.com:3306' | |||
host: '119.23.182.117:3306' | |||
name: 'egg-im' | |||
user: 'canal' | |||
psw: 'DengBiao@1997' | |||
user: 'root' | |||
psw: 'Fnuo123com@' | |||
show_log: true | |||
max_lifetime: 30 | |||
max_open_conns: 100 | |||
max_idle_conns: 100 | |||
path: 'tmp/%s.log' | |||
#im_db: | |||
# host: 'advertisement-db.rwlb.rds.aliyuncs.com:3306' | |||
# name: 'egg-im' | |||
# user: 'canal' | |||
# psw: 'DengBiao@1997' | |||
# show_log: true | |||
# max_lifetime: 30 | |||
# max_open_conns: 100 | |||
# max_idle_conns: 100 | |||
# path: 'tmp/%s.log' | |||
# 日志 | |||
log: | |||
app_name: 'applet' | |||
@@ -2,12 +2,12 @@ module applet | |||
go 1.19 | |||
//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 | |||
//replace code.fnuoos.com/EggPlanet/egg_system_rules.git => E:/company/Egg/egg_system_rules | |||
require ( | |||
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241214095356-fdac2df9537f | |||
code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241219061302-9c0299d2292a | |||
code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241219043645-3f6b3590ae75 | |||
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 | |||
@@ -41,6 +41,7 @@ require ( | |||
github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.10 // indirect | |||
github.com/alibabacloud-go/debug v1.0.1 // indirect | |||
github.com/alibabacloud-go/dypnsapi-20170525/v2 v2.2.3 // indirect | |||
github.com/alibabacloud-go/dysmsapi-20170525/v4 v4.1.0 // indirect | |||
github.com/alibabacloud-go/endpoint-util v1.1.0 // indirect | |||
github.com/alibabacloud-go/openapi-util v0.1.0 // indirect | |||
github.com/alibabacloud-go/tea v1.2.2 // indirect | |||