From 799057b11b00c536450f94a6658526db641b6650 Mon Sep 17 00:00:00 2001 From: dengbiao Date: Tue, 3 Sep 2024 17:47:20 +0800 Subject: [PATCH] add mq --- .../svc_central_kitchen_for_school.go | 15 ++++++++++ app/cfg/cfg_app.go | 8 ++++++ app/cfg/init_cfg.go | 2 ++ app/cfg/init_rabbitmq.go | 28 +++++++++++++++++++ app/md/mq.go | 11 ++++++++ go.mod | 2 ++ main.go | 1 + 7 files changed, 67 insertions(+) create mode 100644 app/cfg/init_rabbitmq.go create mode 100644 app/md/mq.go diff --git a/app/admin/svc/enterprise_manage/svc_central_kitchen_for_school.go b/app/admin/svc/enterprise_manage/svc_central_kitchen_for_school.go index ecae2bf..1f50098 100644 --- a/app/admin/svc/enterprise_manage/svc_central_kitchen_for_school.go +++ b/app/admin/svc/enterprise_manage/svc_central_kitchen_for_school.go @@ -8,7 +8,9 @@ import ( "applet/app/db/model" "applet/app/e" enum2 "applet/app/enum" + md2 "applet/app/md" "applet/app/utils" + "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" "errors" "fmt" "github.com/gin-gonic/gin" @@ -2439,6 +2441,19 @@ func CentralKitchenForSchoolBatchAskForLeaveByClass(req md.CentralKitchenForScho // JudgePackageOrdOrdState 判断订单状态 func JudgePackageOrdOrdState(outTradeNo string) (err error) { + rabbitMqCh, err := rabbit.Cfg.Pool.GetChannel() + if err != nil { + fmt.Println("err:::::11111:::::HoneyCollectContribution", err.Error()) + return + } + rabbitMqCh.Publish(md2.OrdExchange, md2.JudgePackageOrdOrdState{ + OrdNo: outTradeNo, + }, md2.OrdRoutKeyForJudgePackageOrdOrdState) + return +} + +// DealJudgePackageOrdOrdState 判断订单状态 +func DealJudgePackageOrdOrdState(outTradeNo string) (err error) { centralKitchenForSchoolPackageOrd := db.CentralKitchenForSchoolPackageOrd{} centralKitchenForSchoolPackageOrd.Set(outTradeNo) ord, err := centralKitchenForSchoolPackageOrd.GetCentralKitchenForSchoolPackageOrd() diff --git a/app/cfg/cfg_app.go b/app/cfg/cfg_app.go index 1d499de..af23c22 100644 --- a/app/cfg/cfg_app.go +++ b/app/cfg/cfg_app.go @@ -12,6 +12,7 @@ type Config struct { RedisPassword string `yaml:"redis_password"` SmartCanteenPay string `yaml:"smart_canteen_pay"` DB DBCfg `yaml:"db"` + MQ MQCfg `yaml:"mq"` Log LogCfg `yaml:"log"` } @@ -42,3 +43,10 @@ type LogCfg struct { FileMaxSize int `yaml:"file_max_size"` FileMaxAge int `yaml:"file_max_age"` } + +type MQCfg struct { + Host string `yaml:"host"` + Port string `yaml:"port"` + User string `yaml:"user"` + Pwd string `yaml:"pwd"` +} diff --git a/app/cfg/init_cfg.go b/app/cfg/init_cfg.go index 9533c2d..dc9ea58 100644 --- a/app/cfg/init_cfg.go +++ b/app/cfg/init_cfg.go @@ -16,6 +16,7 @@ var ( RedisAddr string RedisPassword string DB *DBCfg + MQ *MQCfg Log *LogCfg ) @@ -47,4 +48,5 @@ func InitCfg() { RedisPassword = conf.RedisPassword SmartCanteenPay = conf.SmartCanteenPay SrvAddr = conf.SrvAddr + MQ = &conf.MQ } diff --git a/app/cfg/init_rabbitmq.go b/app/cfg/init_rabbitmq.go new file mode 100644 index 0000000..f04cd5e --- /dev/null +++ b/app/cfg/init_rabbitmq.go @@ -0,0 +1,28 @@ +package cfg + +import ( + "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" + "encoding/json" + "os" + "strings" + "time" +) + +func InitMq() { + data, _ := json.Marshal(MQ) + filePutContents("init_rabbit_mq", string(data)) + err := rabbit.Init(MQ.Host, MQ.Port, MQ.User, MQ.Pwd) + if err != nil { + filePutContents("init_rabbit_mq", err.Error()) + return + } +} + +func filePutContents(fileName string, content string) { + fd, _ := os.OpenFile("./tmp/"+fileName+".log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644) + fd_time := time.Now().Format("2006-01-02 15:04:05") + fd_content := strings.Join([]string{"[", fd_time, "] ", content, "\n"}, "") + buf := []byte(fd_content) + fd.Write(buf) + fd.Close() +} diff --git a/app/md/mq.go b/app/md/mq.go new file mode 100644 index 0000000..feb85e3 --- /dev/null +++ b/app/md/mq.go @@ -0,0 +1,11 @@ +package md + +const OrdExchange = "order" + +const ( + OrdRoutKeyForJudgePackageOrdOrdState = "judge_package_ord_state" //订单状态 +) + +type JudgePackageOrdOrdState struct { + OrdNo string `json:"ord_no"` +} diff --git a/go.mod b/go.mod index 7ff3c86..c76eb6d 100644 --- a/go.mod +++ b/go.mod @@ -31,6 +31,7 @@ require ( ) require ( + code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 // indirect github.com/chromedp/cdproto v0.0.0-20230802225258-3cf4e6d46a89 // indirect github.com/chromedp/sysutil v1.0.0 // indirect github.com/gin-contrib/sse v0.1.0 // indirect @@ -53,6 +54,7 @@ require ( github.com/onsi/ginkgo v1.15.0 // indirect github.com/onsi/gomega v1.10.5 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/streadway/amqp v1.0.0 // indirect github.com/syndtr/goleveldb v1.0.0 // indirect github.com/ugorji/go/codec v1.2.5 // indirect go.uber.org/atomic v1.7.0 // indirect diff --git a/main.go b/main.go index dbfcc41..5e690a7 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,7 @@ func init() { cfg.InitCfg() //配置初始化 cfg.InitLog() //日志初始化 cfg.InitCache() //缓存初始化 + cfg.InitMq() //队列初始化 if cfg.Debug { //判断是否是debug if err := db.InitDB(cfg.DB); err != nil { //主数据库初始化 panic(err)