Commit a67e1521 by 朱继来
parents fb525736 75b36ee1
...@@ -4,3 +4,4 @@ ...@@ -4,3 +4,4 @@
/logs/* /logs/*
/log/* /log/*
/config/*.toml /config/*.toml
/cmd/*
...@@ -32,3 +32,17 @@ example: ...@@ -32,3 +32,17 @@ example:
erp便签库服务
window
go run .\erp\main.go -configDir=.\config\ -logDir=.\log\
linux
cd /home/gocode/golang-queue-server
git pull
go build -o ./cmd/erpLabel ./erp/main.go
./cmd/erpLabel
...@@ -5,4 +5,10 @@ send_mail="http://crm.liexin.net/api/sendCaiGouEmailByOrderAdmin" ...@@ -5,4 +5,10 @@ send_mail="http://crm.liexin.net/api/sendCaiGouEmailByOrderAdmin"
[Ding_msg] [Ding_msg]
webhook="https://oapi.dingtalk.com/robot/send?access_token=ec03b2cba0d62ef0bd7b9ebb16aaf69b5f626658dfb6b194045381324b0786cf" webhook="https://oapi.dingtalk.com/robot/send?access_token=ec03b2cba0d62ef0bd7b9ebb16aaf69b5f626658dfb6b194045381324b0786cf"
jingDiao="https://oapi.dingtalk.com/robot/send?access_token=eaeae1253e9c125a053bc8a7bcfec5096a23625a98044eaa346591863449ba17" jingDiao="https://oapi.dingtalk.com/robot/send?access_token=eaeae1253e9c125a053bc8a7bcfec5096a23625a98044eaa346591863449ba17"
tuangou_webhook="https://oapi.dingtalk.com/robot/send?access_token=a13d6128de5f918fc0f0a4cef70cab8b1962fca709649f7856aea4b1ca4dddf5" tuangou_webhook="https://oapi.dingtalk.com/robot/send?access_token=a13d6128de5f918fc0f0a4cef70cab8b1962fca709649f7856aea4b1ca4dddf5"
\ No newline at end of file erpLabel_webhook="https://oapi.dingtalk.com/robot/send?access_token=3966b80b7e56e8ffdff5ed2aefa1ea465c0f944a0db6ec5519eeef8721d1eb43"
yaoHaoYou_hook="https://oapi.dingtalk.com/robot/send?access_token=087c11504fb541d004507f06285da88c2501fc1a4ecacd0216b9da964aa65518"
[Api_domain]
api_url="http://api.liexin.com/"
\ No newline at end of file
...@@ -5,4 +5,10 @@ send_mail="http://crm.ichunt.net/api/sendCaiGouEmailByOrderAdmin" ...@@ -5,4 +5,10 @@ send_mail="http://crm.ichunt.net/api/sendCaiGouEmailByOrderAdmin"
[Ding_msg] [Ding_msg]
webhook="https://oapi.dingtalk.com/robot/send?access_token=ec03b2cba0d62ef0bd7b9ebb16aaf69b5f626658dfb6b194045381324b0786cf" webhook="https://oapi.dingtalk.com/robot/send?access_token=ec03b2cba0d62ef0bd7b9ebb16aaf69b5f626658dfb6b194045381324b0786cf"
jingDiao="https://oapi.dingtalk.com/robot/send?access_token=eaeae1253e9c125a053bc8a7bcfec5096a23625a98044eaa346591863449ba17" jingDiao="https://oapi.dingtalk.com/robot/send?access_token=eaeae1253e9c125a053bc8a7bcfec5096a23625a98044eaa346591863449ba17"
tuangou_webhook="https://oapi.dingtalk.com/robot/send?access_token=a13d6128de5f918fc0f0a4cef70cab8b1962fca709649f7856aea4b1ca4dddf5" tuangou_webhook="https://oapi.dingtalk.com/robot/send?access_token=a13d6128de5f918fc0f0a4cef70cab8b1962fca709649f7856aea4b1ca4dddf5"
\ No newline at end of file erpLabel_webhook="https://oapi.dingtalk.com/robot/send?access_token=ba4ed87924ee03b37d2b96ba0f0cb1a28d476bda3af6b2e75a2458b08b5ae39c"
yaoHaoYou_hook="https://oapi.dingtalk.com/robot/send?access_token=09333ef25d736b34268fff237d58a4f27c7d33b01be37aa5c0c30acf5a7356e4"
[Api_domain]
api_url="http://api.ichunt.com/"
\ No newline at end of file
...@@ -2,6 +2,12 @@ ...@@ -2,6 +2,12 @@
[Liexin_databases] [Liexin_databases]
dns="liexin:liexin#zsyM@tcp(192.168.2.232:3306)/liexin?parseTime=true" dns="liexin:liexin#zsyM@tcp(192.168.2.232:3306)/liexin?parseTime=true"
[LiexinLabel_databases]
dns="lie_labels:lie_labels#zsyM@tcp(192.168.2.232:3306)/lie_labels?parseTime=true"
[Liexincms_databases]
dns="ichuntcms:ichuntcms#zsyM@tcp(192.168.2.232:3306)/ichuntcms?parseTime=true"
[rabbitmq_ichunt] [rabbitmq_ichunt]
queue_name="send_buyer_mail" queue_name="send_buyer_mail"
routing_key="send_buyer_mail" routing_key="send_buyer_mail"
...@@ -15,7 +21,23 @@ password="icDb29mLy2s" ...@@ -15,7 +21,23 @@ password="icDb29mLy2s"
port="6379" port="6379"
[rabbitmq_order_push_stock] [rabbitmq_order_push_stock]
queue_name="order_push_stock" queue_name="order_push_stock"
dns="amqp://guest:guest@192.168.2.232:5672/" dns="amqp://guest:guest@192.168.2.232:5672/"
[rabbitmq_erp_label]
queue_name="sales_labels"
routing_key="sales_label"
exchange="erp_to_webservice"
type="direct"
dns="amqp://guest:guest@192.168.2.232:5672/"
[rabbitmq_yaohaoyou]
queue_name="ichunt_addorder_yaohaoyou"
routing_key="ichunt_addorder_yaohaoyou"
exchange=""
type="direct"
dns="amqp://guest:guest@192.168.2.232:5672/"
\ No newline at end of file
...@@ -2,6 +2,12 @@ ...@@ -2,6 +2,12 @@
[Liexin_databases] [Liexin_databases]
dns="huntdbuser:mLssy2@@!!@$#yy@tcp(172.18.137.21:3306)/hunt2016?parseTime=true" dns="huntdbuser:mLssy2@@!!@$#yy@tcp(172.18.137.21:3306)/hunt2016?parseTime=true"
[LiexinLabel_databases]
dns="LabxsuT:Plz2#$afsPqmz@#5@tcp(172.18.137.34:3306)/lie_labels?parseTime=true"
[Liexincms_databases]
dns="dtuser:dAtaL#ym2902m2lLX2y33@tcp(172.18.137.21:3306)/icdata?parseTime=true"
[rabbitmq_ichunt] [rabbitmq_ichunt]
queue_name="send_buyer_mail" queue_name="send_buyer_mail"
routing_key="send_buyer_mail" routing_key="send_buyer_mail"
...@@ -19,3 +25,18 @@ port="6379" ...@@ -19,3 +25,18 @@ port="6379"
queue_name="order_push_stock" queue_name="order_push_stock"
dns="amqp://WmsQue:EizM9I1TAxoO0tmzoOm@172.18.137.33:5672/" dns="amqp://WmsQue:EizM9I1TAxoO0tmzoOm@172.18.137.33:5672/"
[rabbitmq_erp_label]
queue_name="sales_labels"
routing_key="sales_label"
exchange="erp_to_webservice"
type="direct"
dns="amqp://WmsQue:EizM9I1TAxoO0tmzoOm@172.18.137.33:5672/"
[rabbitmq_yaohaoyou]
queue_name="ichunt_addorder_yaohaoyou"
routing_key="ichunt_addorder_yaohaoyou"
exchange=""
type="direct"
dns="amqp://WmsQue:EizM9I1TAxoO0tmzoOm@172.18.137.33:5672/"
package db package db
import ( import (
_ "github.com/go-sql-driver/mysql" _ "github.com/go-sql-driver/mysql"
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
...@@ -6,6 +7,8 @@ import ( ...@@ -6,6 +7,8 @@ import (
var ( var (
DB *sqlx.DB DB *sqlx.DB
LabelDB *sqlx.DB
CmsDB *sqlx.DB
) )
func Init(dns string) error { func Init(dns string) error {
...@@ -19,7 +22,52 @@ func Init(dns string) error { ...@@ -19,7 +22,52 @@ func Init(dns string) error {
if err != nil { if err != nil {
return err return err
} }
DB.SetMaxOpenConns(100) DB.SetMaxOpenConns(50)
DB.SetMaxIdleConns(16) DB.SetMaxIdleConns(10)
return nil
}
func InitLabelDB(dns string) error{
var err error
LabelDB, err = sqlx.Open("mysql", dns)
if err != nil {
return err
}
err = LabelDB.Ping()
if err != nil {
return err
}
LabelDB.SetMaxOpenConns(50)
LabelDB.SetMaxIdleConns(10)
return nil return nil
} }
func InitCmslDB(dns string) error{
var err error
CmsDB, err = sqlx.Open("mysql", dns)
if err != nil {
return err
}
err = CmsDB.Ping()
if err != nil {
return err
}
CmsDB.SetMaxOpenConns(50)
CmsDB.SetMaxIdleConns(10)
return nil
}
func CreateDB(action string,dns string) error{
var err error
switch action {
case "Init":
err = Init(dns)
case "InitLabelDB":
err = InitLabelDB(dns)
case "InitCmsDB":
err = InitCmslDB(dns)
}
return err
}
package label
import (
"errors"
"fmt"
"go-queue-server/dal/db"
"strconv"
"strings"
"time"
)
type Entrys struct {
TemplateId int `json:"templateId"`
Sale_order_sn string `json:"sale_order_sn"`
Goods_type string `json:"goods_type"`
Goods_brand string `json:"goods_brand"`
Goods_number int `json:"goods_number"`
Sku_code string `json:"sku_code"`
Customer_code string `json:"customer_code"`
Customer_type string `json:"customer_type"`
Customer_order string `json:"customer_order"`
}
type TemplateRelation struct {
CreateUser string `json:"createUser"`
Customer_com string `json:"customer_com"`
ENTRYS *[]Entrys `json:"ENTRYS"`
}
type SaleOrderLists struct {
Id string `json:"id" db:"id"`
Sale_order_sn string `json:"sale_order_sn" db:"sale_order_sn"`
Goods_type string `json:"goods_type" db:"goods_type"`
Goods_brand string `json:"goods_brand" db:"goods_brand"`
Goods_number string `json:"goods_number" db:"goods_number"`
Sku_code string `json:"sku_code" db:"sku_code"`
Customer_code string `json:"customer_code" db:"customer_code"`
Customer_type string `json:"customer_type" db:"customer_type"`
Customer_com string `json:"customer_com" db:"customer_com"`
CreateUser string `json:"createUser" db:"createUser"`
Create_time int `json:"create_time" db:"create_time"`
}
type UserInfo struct {
UserId int `db:"userId"`
}
func unicodeToZW(str string) string{
sUnicodev := strings.Split(str, "\\u")
var context string
for _, v := range sUnicodev {
if len(v) < 1 {
continue
}
temp, err := strconv.ParseInt(v, 16, 32)
if err != nil {
panic(err)
}
context += fmt.Sprintf("%c", temp)
}
return context
}
func AddTmplRelations(relations TemplateRelation) error{
var(
err error
sale_order_lists_id int64
)
//找出销售员对应后台登陆的用户id
userInfo := UserInfo{}
err = db.CmsDB.Get(&userInfo,"select userId from user_info where name = ? ",fmt.Sprintf(relations.CreateUser));
if err != nil{
return errors.New(fmt.Sprintf("没找到对应的销售员: %s error %s",relations.CreateUser,err))
}
tx, _ := db.LabelDB.Beginx()
for _,item := range *relations.ENTRYS{
insertSql1 := `insert into lie_sale_order_lists(sale_order_sn,goods_type,goods_brand,goods_number,sku_code,customer_code,customer_type,customer_com,createUser,create_time) values (?,?,?,?,?,?,?,?,?,?)`
result, err := tx.Exec(insertSql1,item.Sale_order_sn,item.Goods_type,item.Goods_brand,item.Goods_number,item.Sku_code,item.Customer_code,item.Customer_type,relations.Customer_com,relations.CreateUser,time.Now().Unix())
if err != nil{
break
}
sale_order_lists_id,err = result.LastInsertId()
if(err != nil){
break
}
insertSql2 := `insert into lie_tmpl_relations (template_id,type_id,type,create_time,create_userid,create_username) values (?,?,?,?,?,?)`
_, err = tx.Exec(insertSql2,item.TemplateId,sale_order_lists_id,1,time.Now().Unix(),userInfo.UserId,relations.CreateUser)
if(err != nil){
break
}
}
if err != nil{
tx.Rollback()
return err
}
err = tx.Commit()
return err
}
package YaoHaoYou
import (
"errors"
"fmt"
"github.com/ichunt2019/logger"
"github.com/jmoiron/sqlx"
"go-queue-server/dal/db"
)
type UserInvitefriendModel struct {
ID int64 `json:"id" db:"id"`
UserId int64 `json:"user_id" db:"user_id"`
InviteUserId int64 `json:"invite_user_id" db:"invite_user_id"`
Type int `json:"type" db:"type"`
TypeId int64 `json:"type_id" db:"type_id"`
Status int `json:"status" db:"status"`
GoodsId string `json:"goods_id" db:"goods_id"`
}
type UserInfo struct {
UserId string `json:"user_id" db:"user_id"`
Mobile string `json:"mobile" db:"mobile"`
Email string `json:"email" db:"email"`
}
type OrderItems struct {
OrderId string `json:"order_id" db:"order_id"`
GoodsNumbers int `json:"gnums" db:"gnums"`
}
func UpdateuserInvitefriend (order_id int64) (err error){
userInvitefriendModel := &UserInvitefriendModel{}
tx := db.DB.MustBegin()
//获取该记录信息
sql := "select id,user_id,invite_user_id,type,type_id,status,goods_id from lie_user_invitefriend where type =1 and type_id = ? limit 1"
err = tx.Get(userInvitefriendModel,sql,order_id)
if err != nil{
logger.Info(fmt.Sprintf("没有找到相关的邀请好友订单 订单id: %d error : %s",order_id,err))
return errors.New(fmt.Sprintf("没有找到相关的邀请好友订单信息 订单id: %d error : %s",order_id,err))
}
//更新邀好友活动记录表
updateUserinvitefriendSql := `update lie_user_invitefriend set status = 1 where type = 1 and type_id = ?`
_ = tx.MustExec(updateUserinvitefriendSql,order_id)
//新增邀好友活动推送消息记录表
//下单成功消息
err = add_user_invitefriend_msg(userInvitefriendModel,tx,1)
err = add_user_invitefriend_msg(userInvitefriendModel,tx,2)
err = add_user_invitefriend_msg(userInvitefriendModel,tx,3)
//邀请人消息
err = tx.Commit()
if err != nil{
return err
}
return nil
}
func add_user_invitefriend_msg(uifModel *UserInvitefriendModel,tx *sqlx.Tx ,msg_type int) (err error){
var user_id int64
//判断用户和邀请用户
if msg_type == 1{
user_id = uifModel.UserId
}else if msg_type == 2 || msg_type == 3 {
user_id = uifModel.InviteUserId
}
userInfo,err:= getUserInfo(user_id)
var (
username string
msg_conente string
)
if err != nil{
//没有找到相关的用户信息
logger.Error(fmt.Sprintf("没有相关推送消息的用户信息 用户id %d",uifModel.UserId))
}else{
user_invitefriend_msg := `insert into lie_user_invitefriend_msg (user_id,invite_user_id,type,type_id,msg_type,username,status,goods_num)
values(?,?,?,?,?,?,?,?) ON DUPLICATE KEY UPDATE goods_num= ? ,username=?`
goods_num := 0 //默认为0
//用户名加密132xxxx9723
if userInfo.Mobile != "" && len(userInfo.Mobile) > 4 {
username = fmt.Sprintf("%sxxxx%s",userInfo.Mobile[0:3],userInfo.Mobile[7:11])
}else if userInfo.Email != ""{
username = userInfo.Email
}else{
username = fmt.Sprintf("%s",uifModel.UserId)
}
//消息类型 1用户下单 2邀好友 3返利
if msg_type == 1{
msg_conente = fmt.Sprintf("%s",username)
}else if msg_type == 2{
msg_conente = fmt.Sprintf("%s",username)
}else if msg_type == 3{
msg_conente = fmt.Sprintf("%s",username)
orderItems,err :=getOrderInfo(uifModel.TypeId)
if err != nil{
logger.Error(fmt.Sprintf("没有找到需要推送的奖品信息 订单数量有问题 用户id %d,订单id:%d",uifModel.UserId,uifModel.TypeId))
return nil
}else{
goods_num = orderItems.GoodsNumbers
}
}
_ = tx.MustExec(user_invitefriend_msg,uifModel.UserId,uifModel.InviteUserId,uifModel.Type,
uifModel.TypeId,msg_type,msg_conente,1,goods_num,goods_num,msg_conente)
}
return nil
}
/*
获取用户信息
*/
func getUserInfo(user_id int64) (userInfo *UserInfo,err error) {
userInfo = &UserInfo{}
sql := `select mobile,user_id,email from lie_user_main where user_id = ?`
err = db.DB.Get(userInfo,sql,user_id)
if err != nil{
return nil,err
}
return userInfo,nil
}
/*
获取订单的购买数量
*/
func getOrderInfo(order_id int64) (orderItems *OrderItems,err error){
orderItems = &OrderItems{}
sql := `select sum(goods_number) as gnums from lie_order_items where order_id = ? and status = 1`
err = db.DB.Get(orderItems,sql,order_id)
if err != nil{
return nil,err
}
return orderItems,nil
}
\ No newline at end of file
package label
import (
"encoding/json"
"github.com/ichunt2019/logger"
"go-queue-server/dal/label"
)
/*
添加销售单到标签模板
*/
func AddTemplateRelations(erpData []byte) (err error){
templateRelations := label.TemplateRelation{}
//fmt.Println(string(erpData))
err = json.Unmarshal(erpData,&templateRelations )
if err != nil{
logger.Error("解析erp传输的销售单json报错: %s", err)
return err
}
err = label.AddTmplRelations(templateRelations)
if err != nil{
logger.Error("插入销售单数据错误 %s", err)
}
return err
}
package main
import (
"flag"
"fmt"
"github.com/ichunt2019/golang-rbmq-sl/utils/rabbitmq"
"github.com/ichunt2019/logger"
"go-queue-server/dal/db"
"go-queue-server/erp/label"
"go-queue-server/util"
"go-queue-server/util/ding"
_ "sync"
_ "time"
)
type RecvPro struct {
}
//// 实现消费者 消费消息失败 自动进入延时尝试 尝试3次之后入库db
func (t *RecvPro) Consumer(dataByte []byte) error {
logger.Info(string(dataByte))
error := label.AddTemplateRelations(dataByte)
return error
}
//消息已经消费3次 失败了 请进行处理
func (t *RecvPro) FailAction(err error,dataByte []byte) error {
logger.Error("任务处理失败了,我要进入db日志库了")
logger.Error("任务处理失败了,发送钉钉消息通知主人")
logger.Error(string(dataByte))
logger.Error("错误原因:%s",err)
ding.Send(
util.Configs.Ding_msg.ErpLabelWebhook,
"@所有人 标签库系统告警:\n",
fmt.Sprintf("失败原因:%s \n %s",err,string(dataByte)) ,
make([]string,0),
false,
)
return nil
}
func initDb(action string,dns string) (err error) {
err = db.CreateDB(action,dns)
if err != nil {
fmt.Println(err)
return
}
return
}
var ConfigDir string
var LogDir string
// 解析命令行参数
func initArgs() {
// worker -config ./worker.json
// worker -h
flag.StringVar(&ConfigDir, "configDir", "", "配置文件")
flag.StringVar(&LogDir, "logDir", "", "日志目录")
flag.Parse()
}
func main() {
initArgs()
//初始化配置文件
util.Init(ConfigDir)
//
logConfig := make(map[string]string)
logConfig["log_path"] = LogDir+"erp/label"
logConfig["log_chan_size"] = "1000"
logger.InitLogger("file",logConfig)
logger.Init()
//初始化db
//initDb("Init",util.Configs.Liexin_databases.Dns)
initDb("InitLabelDB",util.Configs.LiexinLabel_databases.Dns)
initDb("InitCmsDB",util.Configs.Liexincms_databases.Dns)
t := &RecvPro{}
rabbitmq.Recv(rabbitmq.QueueExchange{
util.Configs.Rabbitmq_erp_label.QueueName,
util.Configs.Rabbitmq_erp_label.RoutingKey,
util.Configs.Rabbitmq_erp_label.Exchange,
util.Configs.Rabbitmq_erp_label.Type,
util.Configs.Rabbitmq_erp_label.Dns,
},t,3)
}
\ No newline at end of file
...@@ -9,10 +9,11 @@ require ( ...@@ -9,10 +9,11 @@ require (
github.com/go-sql-driver/mysql v1.4.1 github.com/go-sql-driver/mysql v1.4.1
github.com/gomodule/redigo v2.0.0+incompatible github.com/gomodule/redigo v2.0.0+incompatible
github.com/ichunt2019/go-msgserver v1.0.4 github.com/ichunt2019/go-msgserver v1.0.4
github.com/ichunt2019/go-rabbitmq v1.0.1 // indirect github.com/ichunt2019/golang-rbmq-sl v0.0.0-20200515075131-59a37ab77d7d
github.com/ichunt2019/logger v1.0.5 github.com/ichunt2019/logger v1.0.5
github.com/jmoiron/sqlx v1.2.0 github.com/jmoiron/sqlx v1.2.0
github.com/prometheus/common v0.7.0 // indirect github.com/prometheus/common v0.7.0 // indirect
github.com/streadway/amqp v0.0.0-20200108173154-1c71cc93ed71 github.com/streadway/amqp v0.0.0-20200108173154-1c71cc93ed71
github.com/tealeg/xlsx v1.0.5 github.com/tealeg/xlsx v1.0.5
github.com/tidwall/gjson v1.6.0
) )
...@@ -37,6 +37,8 @@ github.com/ichunt2019/go-msgserver v1.0.4/go.mod h1:fWAvbry0W9nhmkqgT2agwRqYCWlg ...@@ -37,6 +37,8 @@ github.com/ichunt2019/go-msgserver v1.0.4/go.mod h1:fWAvbry0W9nhmkqgT2agwRqYCWlg
github.com/ichunt2019/go-msgserver v1.0.5 h1:yanQ95Ld0etJzVhyZql0jhXXE18qGFX48qFgTCim5hg= github.com/ichunt2019/go-msgserver v1.0.5 h1:yanQ95Ld0etJzVhyZql0jhXXE18qGFX48qFgTCim5hg=
github.com/ichunt2019/go-rabbitmq v1.0.1 h1:qHhpGm9v7jnhSBo3f3viX+BSky9yugp9lCSV03eYsF4= github.com/ichunt2019/go-rabbitmq v1.0.1 h1:qHhpGm9v7jnhSBo3f3viX+BSky9yugp9lCSV03eYsF4=
github.com/ichunt2019/go-rabbitmq v1.0.1/go.mod h1:TQsZ1XWULyvm4UwpYHwNPtOXYbuVvLLI0GM7g/BRy68= github.com/ichunt2019/go-rabbitmq v1.0.1/go.mod h1:TQsZ1XWULyvm4UwpYHwNPtOXYbuVvLLI0GM7g/BRy68=
github.com/ichunt2019/golang-rbmq-sl v0.0.0-20200515075131-59a37ab77d7d h1:wN4ay65hYnXyqn1BWc/WgCpPf+IYwYDRbLASYZyQrPw=
github.com/ichunt2019/golang-rbmq-sl v0.0.0-20200515075131-59a37ab77d7d/go.mod h1:sUQJFISXhgUd5EjkbKphSoxHiGL5BMkTQ/9rfT0lVCw=
github.com/ichunt2019/logger v1.0.3 h1:sH4HfpzYIP9jGGx2AGqN1vRMaph299jB5/L7mwfUMwY= github.com/ichunt2019/logger v1.0.3 h1:sH4HfpzYIP9jGGx2AGqN1vRMaph299jB5/L7mwfUMwY=
github.com/ichunt2019/logger v1.0.3/go.mod h1:5IWMrrqJIWwOIGav9ACWOI+KOuYeteUvOei4zubclwg= github.com/ichunt2019/logger v1.0.3/go.mod h1:5IWMrrqJIWwOIGav9ACWOI+KOuYeteUvOei4zubclwg=
github.com/ichunt2019/logger v1.0.4 h1:y8xfaOLk/5Q++YBoq3x+NCf5Z4WpsQe4juCD2n/ul14= github.com/ichunt2019/logger v1.0.4 h1:y8xfaOLk/5Q++YBoq3x+NCf5Z4WpsQe4juCD2n/ul14=
...@@ -90,6 +92,12 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV ...@@ -90,6 +92,12 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/tealeg/xlsx v1.0.5 h1:+f8oFmvY8Gw1iUXzPk+kz+4GpbDZPK1FhPiQRd+ypgE= github.com/tealeg/xlsx v1.0.5 h1:+f8oFmvY8Gw1iUXzPk+kz+4GpbDZPK1FhPiQRd+ypgE=
github.com/tealeg/xlsx v1.0.5/go.mod h1:btRS8dz54TDnvKNosuAqxrM1QgN1udgk9O34bDCnORM= github.com/tealeg/xlsx v1.0.5/go.mod h1:btRS8dz54TDnvKNosuAqxrM1QgN1udgk9O34bDCnORM=
github.com/tidwall/gjson v1.6.0 h1:9VEQWz6LLMUsUl6PueE49ir4Ka6CzLymOAZDxpFsTDc=
github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls=
github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc=
github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E=
github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4=
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
......
...@@ -116,6 +116,11 @@ func main() { ...@@ -116,6 +116,11 @@ func main() {
// time.Sleep(time.Microsecond*10) // time.Sleep(time.Microsecond*10)
//} //}
/*
{"data":[{"orderNum":"ZTY-HK202004150001","goods":"RC0402JR-070RL","purchasingPrice":"0.001300","unitPrice":"0.001300","brand":"Yageo","nums":"10472","currency":"\u7f8e\u5143","totalPrice":"13.61","remarks":"xxx","material":"E6nwafP+T1+NIcwhjrlPh4iIKlg=","purchasing":"\u5e73\u53f0","projectId":1,"deliveryTime":"v001","send_email":"pingtai@ichunt.com"}],"toUser":["pingtai@ichunt.com"],"ccUser":["zgj@ichunt.com","admin@ichunt.com","long@ichunt.com","zjl@ichunt.com"],"combined":"13.61","order_amount":"13.61","date":"2020-04-17","kefu_remark":"","id":"\u5f20\u5a77\u7389","order_id":3644,"operator_id":1000,"operator_event":"\u53d1\u9001\u90ae\u4ef6\u6210\u529f\uff0c\u6536\u4ef6\u4eba\u90ae\u7bb1\uff1a[\"pingtai@ichunt.com\"]\uff0c\u6284\u9001\u4eba\u90ae\u7bb1\uff1a[\"zgj@ichunt.com\",\"admin@ichunt.com\",\"long@ichunt.com\",\"zjl@ichunt.com\"]"}
*/
rabbitmq.Recv(rabbitmq.QueueExchange{ rabbitmq.Recv(rabbitmq.QueueExchange{
util.Configs.Rabbitmq_ichunt.QueueName, util.Configs.Rabbitmq_ichunt.QueueName,
util.Configs.Rabbitmq_ichunt.RoutingKey, util.Configs.Rabbitmq_ichunt.RoutingKey,
......
package main
import (
"flag"
"fmt"
"github.com/ichunt2019/golang-rbmq-sl/utils/rabbitmq"
"github.com/ichunt2019/logger"
"go-queue-server/dal/db"
"go-queue-server/order/yaoHaoYou/services"
"go-queue-server/util"
"go-queue-server/util/ding"
_ "sync"
_ "time"
)
type RecvPro struct {
}
//// 实现消费者 消费消息失败 自动进入延时尝试 尝试3次之后入库db
func (t *RecvPro) Consumer(dataByte []byte) error {
logger.Info(string(dataByte))
fmt.Println(string(dataByte))
services.YaohaoyouOrder(string(dataByte));
return nil
}
//消息已经消费3次 失败了 请进行处理
func (t *RecvPro) FailAction(err error,dataByte []byte) error {
logger.Error("任务处理失败了,我要进入db日志库了")
logger.Error("任务处理失败了,发送钉钉消息通知主人")
logger.Error(string(dataByte))
logger.Error("错误原因:%s",err)
ding.Send(
util.Configs.Ding_msg.YaoHaoYouWebhook,
"@所有人 邀好友下单告警:\n",
fmt.Sprintf("失败原因:%s \n %s",err,string(dataByte)) ,
make([]string,0),
false,
)
return nil
}
func initDb(action string,dns string) (err error) {
err = db.CreateDB(action,dns)
if err != nil {
fmt.Println(err)
panic(err)
return
}
return
}
var ConfigDir string
var LogDir string
// 解析命令行参数
func initArgs() {
// worker -config ./worker.json
// worker -h
flag.StringVar(&ConfigDir, "configDir", "", "配置文件")
flag.StringVar(&LogDir, "logDir", "", "日志目录")
flag.Parse()
}
func main() {
initArgs()
//初始化配置文件
util.Init(ConfigDir)
//
logConfig := make(map[string]string)
logConfig["log_path"] = LogDir+"yaohaoyou/"
logConfig["log_chan_size"] = "1000"
logger.InitLogger("file",logConfig)
logger.Init()
//初始化db
initDb("Init",util.Configs.Liexin_databases.Dns)
//initDb("InitLabelDB",util.Configs.LiexinLabel_databases.Dns)
//initDb("InitCmsDB",util.Configs.Liexincms_databases.Dns)
t := &RecvPro{}
rabbitmq.Recv(rabbitmq.QueueExchange{
util.Configs.Rabbitmq_yaohaoyou.QueueName,
util.Configs.Rabbitmq_yaohaoyou.QueueName,
"",
util.Configs.Rabbitmq_yaohaoyou.Type,
util.Configs.Rabbitmq_yaohaoyou.Dns,
},t,2)
}
\ No newline at end of file
package services
import (
"github.com/tidwall/gjson"
"go-queue-server/dal/order/YaoHaoYou"
)
type OrderYHY struct {
OrderoId int64 `json:"order_id"`
}
/*
邀好友
处理邀好友活动 好友邀请用户 用户下单后续操作
1,修改邀好友活动记录表
2,增加消息
*/
func YaohaoyouOrder(order string){
order_id := gjson.Get(order, "order_id")
//修改记录
YaoHaoYou.UpdateuserInvitefriend(order_id.Int())
}
package api_service_log
import (
"encoding/json"
"fmt"
"github.com/ichunt2019/golang-rbmq-sl/utils/rabbitmq"
"time"
)
type DataParams struct {
InterfaceType string `json:"interface_type"`
AccessUrl string `json:"access_url"`
RequestParams string `json:"request_params"`
ErrMsg string `json:"err_msg"`
ErrCode string `json:"err_code"`
Uid string `json:"uid"`
UserName string `json:"user_name"`
UserIp string `json:"user_ip"`
Remakr string `json:"remark"`
CreateTime int64 `json:"create_time"`
CreateTimeStr string `json:"create_time_str"`
}
func AddMsgtoRbmq(msg string){
queueExchange := rabbitmq.QueueExchange{
"ichunt_monitor_user_behavior",
"ichunt_monitor_user_behavior",
"ichunt_monitor_behavior",
"direct",
"amqp://huntmouser:jy2y2900@172.18.137.23:5672/",
}
rbmqMsg := &DataParams{
InterfaceType: "20",
AccessUrl: "",
RequestParams: "",
ErrMsg: "python服务仓库推送监控超时",
ErrCode: "",
Uid: "",
UserName: "",
UserIp: "",
Remakr: fmt.Sprintf("%s",msg),
CreateTime: time.Now().Unix(),
CreateTimeStr: "",
}
_msg, _ := json.Marshal(rbmqMsg)
fmt.Println(string(_msg))
rabbitmq.Send(queueExchange,string(_msg))
}
\ No newline at end of file
package main
import (
"flag"
"fmt"
"github.com/ichunt2019/golang-rbmq-sl/utils/rabbitmq"
"go-queue-server/dal/db"
"go-queue-server/pyMonit/api-service-log"
_ "sync"
_ "time"
)
type RecvPro struct {
}
//// 实现消费者 消费消息失败 自动进入延时尝试 尝试3次之后入库db
func (t *RecvPro) Consumer(dataByte []byte) error {
fmt.Println(string(dataByte))
api_service_log.AddMsgtoRbmq(string(dataByte))
return nil
}
//消息已经消费3次 失败了 请进行处理
func (t *RecvPro) FailAction(err error,dataByte []byte) error {
//logger.Error("任务处理失败了,我要进入db日志库了")
//logger.Error("任务处理失败了,发送钉钉消息通知主人")
//logger.Error(string(dataByte))
//logger.Error("错误原因:%s",err)
//ding.Send(
// util.Configs.Ding_msg.ErpLabelWebhook,
// "@所有人 标签库系统告警:\n",
// fmt.Sprintf("失败原因:%s \n %s",err,string(dataByte)) ,
// make([]string,0),
// false,
// )
return nil
}
func initDb(action string,dns string) (err error) {
err = db.CreateDB(action,dns)
if err != nil {
fmt.Println(err)
return
}
return
}
var ConfigDir string
var LogDir string
// 解析命令行参数
func initArgs() {
// worker -config ./worker.json
// worker -h
flag.StringVar(&ConfigDir, "configDir", "", "配置文件")
flag.StringVar(&LogDir, "logDir", "", "日志目录")
flag.Parse()
}
func main() {
t := &RecvPro{}
rabbitmq.Recv(rabbitmq.QueueExchange{
"api_service_log",
"api_service_log",
"",
"",
"amqp://WmsQue:EizM9I1TAxoO0tmzoOm@172.18.137.33:5672/",
},t,1)
}
\ No newline at end of file
package util package util
import ( import (
"fmt"
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
) )
//订制配置文件解析载体 //订制配置文件解析载体
type Config struct{ type Config struct{
Liexin_databases *LiexinMysqlConfig Liexin_databases *LiexinMysqlConfig
LiexinLabel_databases *LiexinLabelMysqlConfig
Liexincms_databases *LiexinCmsMysqlConfig
Rabbitmq_ichunt *RabbitmqIchunt Rabbitmq_ichunt *RabbitmqIchunt
Rabbitmq_erp_label *RabbitmqErpLabel
Rabbitmq_order_push_stock *RabbitmqOrderPushStock Rabbitmq_order_push_stock *RabbitmqOrderPushStock
Rabbitmq_yaohaoyou *RabbitmqYaoHaoYou
Crm_domain *SendMail Crm_domain *SendMail
Ding_msg *Ding Ding_msg *Ding
Api_domain *ApiDomain Api_domain *ApiDomain
...@@ -21,6 +24,13 @@ type LiexinMysqlConfig struct{ ...@@ -21,6 +24,13 @@ type LiexinMysqlConfig struct{
Dns string `toml:"dns"` Dns string `toml:"dns"`
} }
type LiexinLabelMysqlConfig struct{
Dns string `toml:"dns"`
}
type LiexinCmsMysqlConfig struct{
Dns string `toml:"dns"`
}
type RabbitmqIchunt struct { type RabbitmqIchunt struct {
QueueName string `toml:"queue_name"` QueueName string `toml:"queue_name"`
RoutingKey string `toml:"routing_key"` RoutingKey string `toml:"routing_key"`
...@@ -29,11 +39,25 @@ type RabbitmqIchunt struct { ...@@ -29,11 +39,25 @@ type RabbitmqIchunt struct {
Dns string `toml:"dns"` Dns string `toml:"dns"`
} }
type RabbitmqErpLabel struct {
QueueName string `toml:"queue_name"`
RoutingKey string `toml:"routing_key"`
Exchange string `toml:"exchange"`
Type string `toml:"type"`
Dns string `toml:"dns"`
}
type RabbitmqOrderPushStock struct { type RabbitmqOrderPushStock struct {
QueueName string `toml:"queue_name"` QueueName string `toml:"queue_name"`
Dns string `toml:"dns"` Dns string `toml:"dns"`
} }
type RabbitmqYaoHaoYou struct {
QueueName string `toml:"queue_name"`
Type string `toml:"type"`
Dns string `toml:"dns"`
}
type SendMail struct{ type SendMail struct{
SendMailUrl string `toml:"send_mail"` SendMailUrl string `toml:"send_mail"`
} }
...@@ -42,6 +66,8 @@ type Ding struct { ...@@ -42,6 +66,8 @@ type Ding struct {
Webhook string `toml:"webhook"` Webhook string `toml:"webhook"`
JingDiao string `toml:"jingDiao"` JingDiao string `toml:"jingDiao"`
TuangouWebhook string `toml:"tuangou_webhook"` TuangouWebhook string `toml:"tuangou_webhook"`
ErpLabelWebhook string `toml:"erpLabel_webhook"`
YaoHaoYouWebhook string `toml:"yaoHaoYou_hook"`
} }
type ApiDomain struct { type ApiDomain struct {
...@@ -62,15 +88,6 @@ func Init(ConfigDir string){ ...@@ -62,15 +88,6 @@ func Init(ConfigDir string){
_, err = toml.DecodeFile(ConfigDir+"config.toml",Configs) _, err = toml.DecodeFile(ConfigDir+"config.toml",Configs)
_, err = toml.DecodeFile(ConfigDir+"db.toml",Configs) _, err = toml.DecodeFile(ConfigDir+"db.toml",Configs)
if err!=nil{ if err!=nil{
fmt.Println(err) panic(err)
} }
//fmt.Printf("%+v",Configs.Liexin_databases)
//fmt.Printf("%+v",Configs.Rabbitmq_ichunt)
//fmt.Printf("%+v",Configs.Crm_domain)
//fmt.Printf("%+v",Configs.Ding_msg)
//
//fmt.Printf("%+v",Configs.Crm_domain)
//fmt.Printf("%+v",Configs.Rabbitmq_ichunt)
//fmt.Printf("%+v",Configs.Redis_config)
//fmt.Printf("%+v",Configs.Rabbitmq_order_push_stock)
} }
go run ./order/yaoHaoYou/main.go -configDir=./config/ -logDir=./log/
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment