Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CnChunfeng
/
photo_taking
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
7af016ed
authored
Nov 30, 2020
by
Joneq
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
提交代码
parent
d4fecf96
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
23 deletions
go.mod
internal/server/http/server.go
internal/service/rabbitmq.go
go.mod
View file @
7af016ed
...
...
@@ -15,6 +15,7 @@ require (
github.com/mushishixian/gosoap v1.2.1-0.20200424081802-b11347c911bc
github.com/pkg/errors v0.9.1 // indirect
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/grpc v1.28.1
)
internal/server/http/server.go
View file @
7af016ed
...
...
@@ -38,6 +38,7 @@ func New(s pb.DemoServer) (engine *bm.Engine, err error) {
func
initRouter
(
e
*
bm
.
Engine
)
{
e
.
Ping
(
ping
)
e
.
GET
(
"hbsdata"
,
hbsdata
)
g
:=
e
.
Group
(
"/photo_taking"
)
{
g
.
GET
(
"/start"
,
howToStart
)
...
...
@@ -51,6 +52,7 @@ func initRouter(e *bm.Engine) {
//提交订单
g
.
GET
(
"/submit_order/:ordersn"
,
submitOrder
)
}
}
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.
func
howToStart
(
c
*
bm
.
Context
)
{
k
:=
&
model
.
Kratos
{
...
...
@@ -222,38 +228,46 @@ func submitOrder(c *bm.Context) {
service
.
ErrorReturn
(
c
,
err
.
Error
())
}
var
(
soap
*
gosoap
.
Client
params
gosoap
.
ArrayParams
res
*
gosoap
.
Response
)
jsonByte
,
err
:=
json
.
Marshal
(
ErpSubmitImage
)
if
err
!=
nil
{
service
.
ErrorReturn
(
c
,
err
.
Error
())
}
log
.
Info
(
string
(
jsonByte
))
soap
,
err
=
gosoap
.
SoapClient
(
service
.
ErpConfig
.
ErpOrderRequestApi
)
if
err
!=
nil
{
if
err
=
service
.
SendSubmitOrderMqTOErp
(
jsonByte
);
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
())
}
//20201130去掉直接请求erp,改成推送队列的方式
//var (
// soap *gosoap.Client
// params gosoap.ArrayParams
// res *gosoap.Response
//)
//
//log.Info(string(jsonByte))
//
//
//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
)
}
...
...
internal/service/rabbitmq.go
0 → 100644
View file @
7af016ed
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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment