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
e9a41102
authored
Mar 16, 2023
by
CnChunfeng
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
增加post数据获取
parent
d85da14b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
24 deletions
http/internal/server/http/erp/company.go
http/internal/server/http/server.go
http/internal/server/http/erp/company.go
View file @
e9a41102
...
...
@@ -3,14 +3,15 @@ package erp
import
(
"encoding/json"
"fmt"
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/server/http/member"
"strings"
"time"
"github.com/go-kratos/kratos/pkg/conf/paladin"
"github.com/go-kratos/kratos/pkg/log"
bm
"github.com/go-kratos/kratos/pkg/net/http/blademaster"
"github.com/streadway/amqp"
)
//erp需要获取的公司信息
...
...
@@ -31,7 +32,6 @@ type ErpCompanyInfo struct {
TianyanchaInfo
ErpTianYanChaCompanyInfo
`json:"tyc_info"`
//'tycjson'
}
type
ErpTianYanChaCompanyInfo
struct
{
RegNumber
string
`json:"regNumber"`
CreditCode
string
`json:"creditCode"`
...
...
@@ -48,41 +48,46 @@ type Rabitmq struct {
Dsn
string
//rabitmq 配置1
}
func
GetCompanyInfo
(
c
*
bm
.
Context
)
{
var
erpCompanyInfo
ErpCompanyInfo
var
erpJson
ErpResultStruct
companyName
,
_
:=
c
.
Params
.
Get
(
"company_name"
)
db
,
closedb
,
err
:=
dao
.
NewDB
()
//如果get没有就获取post
companyName
,
isok
:=
c
.
Params
.
Get
(
"company_name"
)
if
!
isok
{
companyName
=
c
.
Request
.
PostFormValue
(
"company_name"
)
}
db
,
closedb
,
err
:=
dao
.
NewDB
()
if
err
!=
nil
{
log
.
Error
(
err
.
Error
())
}
err
=
db
.
QueryRow
(
c
,
SELECTERPCOMBASIC
,
companyName
)
.
Scan
(
&
erpCompanyInfo
.
ComName
,
&
erpCompanyInfo
.
ComOrganization
,
&
erpCompanyInfo
.
EstanlishmentTime
,
&
erpCompanyInfo
.
CustomerProperty
,
&
erpCompanyInfo
.
RegisteredCapital
,
&
erpCompanyInfo
.
LegalRepresentative
,
&
erpCompanyInfo
.
TianyanchaJson
,
&
erpCompanyInfo
.
ComAddress
)
err
=
db
.
QueryRow
(
c
,
SELECTERPCOMBASIC
,
companyName
)
.
Scan
(
&
erpCompanyInfo
.
ComName
,
&
erpCompanyInfo
.
ComOrganization
,
&
erpCompanyInfo
.
EstanlishmentTime
,
&
erpCompanyInfo
.
CustomerProperty
,
&
erpCompanyInfo
.
RegisteredCapital
,
&
erpCompanyInfo
.
LegalRepresentative
,
&
erpCompanyInfo
.
TianyanchaJson
,
&
erpCompanyInfo
.
ComAddress
)
if
err
!=
nil
{
log
.
Error
(
err
.
Error
())
}
jsonArr
:=
strings
.
Split
(
erpCompanyInfo
.
TianyanchaJson
,
"||||"
)
jsonArr
:=
strings
.
Split
(
erpCompanyInfo
.
TianyanchaJson
,
"||||"
)
if
len
(
jsonArr
)
>
1
{
err
=
json
.
Unmarshal
([]
byte
(
jsonArr
[
0
]),
&
erpJson
)
err
=
json
.
Unmarshal
([]
byte
(
jsonArr
[
0
]),
&
erpJson
)
erpCompanyInfo
.
TianyanchaInfo
=
erpJson
.
Result
}
erpCompanyInfo
.
TianyanchaJson
=
""
c
.
JSON
(
erpCompanyInfo
,
nil
)
c
.
JSON
(
erpCompanyInfo
,
nil
)
closedb
()
if
erpCompanyInfo
.
ComName
==
""
{
PushCompanyMq
(
c
,
companyName
)
PushCompanyMq
(
c
,
companyName
)
}
}
//增加公司,并且推送mq
func
PushCompanyMq
(
c
*
bm
.
Context
,
companyName
string
)
{
func
PushCompanyMq
(
c
*
bm
.
Context
,
companyName
string
)
{
var
(
var
(
cfg
Rabitmq
ct
paladin
.
TOML
)
...
...
@@ -94,17 +99,16 @@ func PushCompanyMq(c *bm.Context,companyName string) {
log
.
Error
(
err
.
Error
())
}
db
,
closedb
,
err
:=
dao
.
NewDB
()
db
,
closedb
,
err
:=
dao
.
NewDB
()
currentTime
:=
time
.
Now
()
.
Unix
()
sqlResult
,
err
:=
db
.
Exec
(
c
,
member
.
INSERTCOMPANY
,
companyName
,
currentTime
,
currentTime
)
lastid
,
err
:=
sqlResult
.
LastInsertId
()
sqlResult
,
err
:=
db
.
Exec
(
c
,
member
.
INSERTCOMPANY
,
companyName
,
currentTime
,
currentTime
)
lastid
,
err
:=
sqlResult
.
LastInsertId
()
//如果添加没问题,就继续添加
if
err
!=
nil
{
log
.
Error
(
err
.
Error
())
}
else
{
_
,
err
=
db
.
Exec
(
c
,
member
.
INSERTCOMPANYBASICINFO
,
lastid
,
companyName
,
currentTime
)
}
else
{
_
,
err
=
db
.
Exec
(
c
,
member
.
INSERTCOMPANYBASICINFO
,
lastid
,
companyName
,
currentTime
)
if
err
!=
nil
{
log
.
Error
(
err
.
Error
())
}
...
...
@@ -113,7 +117,7 @@ func PushCompanyMq(c *bm.Context,companyName string) {
closedb
()
//链接mq
conn
,
err
:=
amqp
.
Dial
(
"amqp://"
+
cfg
.
Dsn
+
"/"
)
conn
,
err
:=
amqp
.
Dial
(
"amqp://"
+
cfg
.
Dsn
+
"/"
)
defer
conn
.
Close
()
//通道
...
...
@@ -130,14 +134,14 @@ func PushCompanyMq(c *bm.Context,companyName string) {
nil
,
// arguments
)
body
:=
fmt
.
Sprintf
(
`{"com_credits_id":"%d","erp_company_code":""}`
,
lastid
)
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
{
amqp
.
Publishing
{
ContentType
:
"text/plain"
,
Body
:
[]
byte
(
body
),
})
...
...
http/internal/server/http/server.go
View file @
e9a41102
...
...
@@ -7,6 +7,7 @@ import (
pb
"kaopu-server/http/api"
"kaopu-server/http/internal/model"
"github.com/go-kratos/kratos/pkg/conf/paladin"
"github.com/go-kratos/kratos/pkg/log"
bm
"github.com/go-kratos/kratos/pkg/net/http/blademaster"
...
...
@@ -45,6 +46,7 @@ func initRouter(e *bm.Engine) {
//会员系统的接口
g
.
GET
(
"/erp/company_info/:company_name"
,
erp
.
GetCompanyInfo
)
g
.
POST
(
"/erp/company_info"
,
erp
.
GetCompanyInfo
)
}
}
...
...
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