Commit 7af016ed by Joneq

提交代码

parent d4fecf96
...@@ -15,6 +15,7 @@ require ( ...@@ -15,6 +15,7 @@ require (
github.com/mushishixian/gosoap v1.2.1-0.20200424081802-b11347c911bc github.com/mushishixian/gosoap v1.2.1-0.20200424081802-b11347c911bc
github.com/pkg/errors v0.9.1 // indirect github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/common v0.9.1 github.com/prometheus/common v0.9.1
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94
google.golang.org/genproto v0.0.0-20200402124713-8ff61da6d932 google.golang.org/genproto v0.0.0-20200402124713-8ff61da6d932
google.golang.org/grpc v1.28.1 google.golang.org/grpc v1.28.1
) )
...@@ -38,6 +38,7 @@ func New(s pb.DemoServer) (engine *bm.Engine, err error) { ...@@ -38,6 +38,7 @@ func New(s pb.DemoServer) (engine *bm.Engine, err error) {
func initRouter(e *bm.Engine) { func initRouter(e *bm.Engine) {
e.Ping(ping) e.Ping(ping)
e.GET("hbsdata",hbsdata)
g := e.Group("/photo_taking") g := e.Group("/photo_taking")
{ {
g.GET("/start", howToStart) g.GET("/start", howToStart)
...@@ -51,6 +52,7 @@ func initRouter(e *bm.Engine) { ...@@ -51,6 +52,7 @@ func initRouter(e *bm.Engine) {
//提交订单 //提交订单
g.GET("/submit_order/:ordersn",submitOrder) g.GET("/submit_order/:ordersn",submitOrder)
} }
} }
func ping(ctx *bm.Context) { func ping(ctx *bm.Context) {
...@@ -60,6 +62,10 @@ func ping(ctx *bm.Context) { ...@@ -60,6 +62,10 @@ func ping(ctx *bm.Context) {
} }
} }
func hbsdata(c *bm.Context) {
c.Writer.Write([]byte("ok"))
}
// example for http request handler. // example for http request handler.
func howToStart(c *bm.Context) { func howToStart(c *bm.Context) {
k := &model.Kratos{ k := &model.Kratos{
...@@ -222,38 +228,46 @@ func submitOrder(c *bm.Context) { ...@@ -222,38 +228,46 @@ func submitOrder(c *bm.Context) {
service.ErrorReturn(c,err.Error()) service.ErrorReturn(c,err.Error())
} }
var (
soap *gosoap.Client
params gosoap.ArrayParams
res *gosoap.Response
)
jsonByte, err := json.Marshal(ErpSubmitImage) jsonByte, err := json.Marshal(ErpSubmitImage)
if err != nil { if err != nil {
service.ErrorReturn(c,err.Error()) service.ErrorReturn(c,err.Error())
} }
log.Info(string(jsonByte)) if err = service.SendSubmitOrderMqTOErp(jsonByte); err != nil {
soap, err = gosoap.SoapClient(service.ErpConfig.ErpOrderRequestApi)
if err != nil {
service.ErrorReturn(c,err.Error()) service.ErrorReturn(c,err.Error())
} }
params = gosoap.ArrayParams{ //20201130去掉直接请求erp,改成推送队列的方式
{"json", string(jsonByte)},
} //var (
// soap *gosoap.Client
res, err = soap.Call(service.ErpConfig.ErpOrderSubmitMethod, params) // params gosoap.ArrayParams
if err != nil { // res *gosoap.Response
service.ErrorReturn(c,string(res.Body)) //)
} //
//log.Info(string(jsonByte))
err = service.CheckSubmitOrderData(res) //
if err != nil { //
service.ErrorReturn(c,err.Error()) //soap, err = gosoap.SoapClient(service.ErpConfig.ErpOrderRequestApi)
} //if err != nil {
// service.ErrorReturn(c,err.Error())
//}
//
//params = gosoap.ArrayParams{
// {"json", string(jsonByte)},
//}
//
//res, err = soap.Call(service.ErpConfig.ErpOrderSubmitMethod, params)
//if err != nil {
// service.ErrorReturn(c,string(res.Body))
//}
//
//err = service.CheckSubmitOrderData(res)
//if err != nil {
// service.ErrorReturn(c,err.Error())
//}
c.JSON("提交成功",nil) c.JSON("提交成功",nil)
} }
......
package service
import "github.com/streadway/amqp"
func SendSubmitOrderMqTOErp(content []byte)(err error) {
//链接mq
conn, err := amqp.Dial("amqp://huntmouser:jy2y2900@119.23.79.136:5672/");
if err != nil {
return
}
defer conn.Close()
//通道
ch, err := conn.Channel()
if err != nil {
return
}
defer ch.Close()
//设置数据
q, err := ch.QueueDeclare(
"photo_scan_submit_order_to_erp", // name
false, // durable
false, // delete when unused
false, // exclusive
false, // no-wait
nil, // arguments
)
if err != nil {
return
}
err = ch.Publish(
"", // exchange
q.Name, // routing key
false, // mandatory
false, // immediate
amqp.Publishing {
ContentType: "text/plain",
Body: content,
})
return nil
}
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