Browse Source

add mq

master
dengbiao 3 months ago
parent
commit
799057b11b
7 changed files with 67 additions and 0 deletions
  1. +15
    -0
      app/admin/svc/enterprise_manage/svc_central_kitchen_for_school.go
  2. +8
    -0
      app/cfg/cfg_app.go
  3. +2
    -0
      app/cfg/init_cfg.go
  4. +28
    -0
      app/cfg/init_rabbitmq.go
  5. +11
    -0
      app/md/mq.go
  6. +2
    -0
      go.mod
  7. +1
    -0
      main.go

+ 15
- 0
app/admin/svc/enterprise_manage/svc_central_kitchen_for_school.go View File

@@ -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()


+ 8
- 0
app/cfg/cfg_app.go View File

@@ -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"`
}

+ 2
- 0
app/cfg/init_cfg.go View File

@@ -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
}

+ 28
- 0
app/cfg/init_rabbitmq.go View File

@@ -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()
}

+ 11
- 0
app/md/mq.go View File

@@ -0,0 +1,11 @@
package md

const OrdExchange = "order"

const (
OrdRoutKeyForJudgePackageOrdOrdState = "judge_package_ord_state" //订单状态
)

type JudgePackageOrdOrdState struct {
OrdNo string `json:"ord_no"`
}

+ 2
- 0
go.mod View File

@@ -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


+ 1
- 0
main.go View File

@@ -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)


Loading…
Cancel
Save