Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
孙龙
/
kaopu-server
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
7f8d94fd
authored
Sep 14, 2020
by
Joneq
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
增加队列推送
parent
34558575
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
0 deletions
go.mod
http/internal/server/http/erp/company.go
go.mod
View file @
7f8d94fd
...
@@ -10,6 +10,7 @@ require (
...
@@ -10,6 +10,7 @@ require (
github.com/google/wire v0.4.0
github.com/google/wire v0.4.0
github.com/ichunt2019/go-msgserver v1.0.5
github.com/ichunt2019/go-msgserver v1.0.5
github.com/pkg/errors v0.8.1
github.com/pkg/errors v0.8.1
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271
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
)
)
http/internal/server/http/erp/company.go
View file @
7f8d94fd
...
@@ -4,8 +4,13 @@ import (
...
@@ -4,8 +4,13 @@ import (
"encoding/json"
"encoding/json"
"fmt"
"fmt"
bm
"github.com/go-kratos/kratos/pkg/net/http/blademaster"
bm
"github.com/go-kratos/kratos/pkg/net/http/blademaster"
"github.com/go-kratos/kratos/pkg/log"
"github.com/streadway/amqp"
"kaopu-server/http/internal/dao"
"kaopu-server/http/internal/dao"
"kaopu-server/http/internal/server/http/member"
"strings"
"strings"
"time"
"github.com/go-kratos/kratos/pkg/conf/paladin"
)
)
//erp需要获取的公司信息
//erp需要获取的公司信息
...
@@ -38,6 +43,10 @@ type ErpResultStruct struct {
...
@@ -38,6 +43,10 @@ type ErpResultStruct struct {
Result
ErpTianYanChaCompanyInfo
`json:"result"`
Result
ErpTianYanChaCompanyInfo
`json:"result"`
}
}
type
Rabitmq
struct
{
Dsn
string
//rabitmq 配置1
}
func
GetCompanyInfo
(
c
*
bm
.
Context
)
{
func
GetCompanyInfo
(
c
*
bm
.
Context
)
{
...
@@ -63,4 +72,72 @@ func GetCompanyInfo(c *bm.Context) {
...
@@ -63,4 +72,72 @@ func GetCompanyInfo(c *bm.Context) {
erpCompanyInfo
.
TianyanchaJson
=
""
erpCompanyInfo
.
TianyanchaJson
=
""
c
.
JSON
(
erpCompanyInfo
,
nil
)
c
.
JSON
(
erpCompanyInfo
,
nil
)
closedb
()
closedb
()
if
erpCompanyInfo
.
ComName
==
""
{
PushCompanyMq
(
c
,
companyName
)
}
}
//增加公司,并且推送mq
func
PushCompanyMq
(
c
*
bm
.
Context
,
companyName
string
)
{
var
(
cfg
Rabitmq
ct
paladin
.
TOML
)
if
err
:=
paladin
.
Get
(
"rabitmq.toml"
)
.
Unmarshal
(
&
ct
);
err
!=
nil
{
log
.
Error
(
err
.
Error
())
}
if
err
:=
ct
.
Get
(
"dsn1"
)
.
UnmarshalTOML
(
&
cfg
);
err
!=
nil
{
log
.
Error
(
err
.
Error
())
}
db
,
closedb
,
err
:=
dao
.
NewDB
()
currentTime
:=
time
.
Now
()
.
Unix
()
sqlResult
,
err
:=
db
.
Exec
(
c
,
member
.
INSERTCOMPANY
,
companyName
,
currentTime
,
currentTime
)
lastid
,
_
:=
sqlResult
.
LastInsertId
()
//如果添加没问题,就继续添加
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
else
{
_
,
err
=
db
.
Exec
(
c
,
member
.
INSERTCOMPANYBASICINFO
,
lastid
,
companyName
,
currentTime
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
}
closedb
()
//链接mq
conn
,
err
:=
amqp
.
Dial
(
"amqp://"
+
cfg
.
Dsn
+
"/"
)
defer
conn
.
Close
()
//通道
ch
,
err
:=
conn
.
Channel
()
defer
ch
.
Close
()
//设置数据
q
,
err
:=
ch
.
QueueDeclare
(
"fengkong_static_count"
,
// name
true
,
// durable
false
,
// delete when unused
false
,
// exclusive
false
,
// no-wait
nil
,
// arguments
)
body
:=
fmt
.
Sprintf
(
`{"com_credits_id":"%d","erp_company_code":""}`
,
lastid
)
fmt
.
Println
(
body
)
err
=
ch
.
Publish
(
"fengkong_exchange"
,
// exchange
q
.
Name
,
// routing key
false
,
// mandatory
false
,
// immediate
amqp
.
Publishing
{
ContentType
:
"text/plain"
,
Body
:
[]
byte
(
body
),
})
}
}
\ No newline at end of file
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