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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
55 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
...
@@ -3,14 +3,15 @@ package erp
import
(
import
(
"encoding/json"
"encoding/json"
"fmt"
"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/dao"
"kaopu-server/http/internal/server/http/member"
"kaopu-server/http/internal/server/http/member"
"strings"
"strings"
"time"
"time"
"github.com/go-kratos/kratos/pkg/conf/paladin"
"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需要获取的公司信息
//erp需要获取的公司信息
...
@@ -20,24 +21,23 @@ const SELECTERPCOMBASIC = "select " +
...
@@ -20,24 +21,23 @@ const SELECTERPCOMBASIC = "select " +
" from lie_com_basicinfos where com_name = ?"
" from lie_com_basicinfos where com_name = ?"
type
ErpCompanyInfo
struct
{
type
ErpCompanyInfo
struct
{
ComName
string
`json:"com_name"`
//'公司名称'
ComName
string
`json:"com_name"`
//'公司名称'
ComOrganization
string
`json:"com_organization"`
//'组织结构代码'
ComOrganization
string
`json:"com_organization"`
//'组织结构代码'
EstanlishmentTime
int64
`json:"establishment_time"`
//'公司成立时间'
EstanlishmentTime
int64
`json:"establishment_time"`
//'公司成立时间'
RegisteredCapital
string
`json:"registered_capital"`
//'注册资本'
RegisteredCapital
string
`json:"registered_capital"`
//'注册资本'
CustomerProperty
string
`json:"customer_property"`
//'客户性质'
CustomerProperty
string
`json:"customer_property"`
//'客户性质'
LegalRepresentative
string
`json:"legal_representative"`
//'法定代表人'
LegalRepresentative
string
`json:"legal_representative"`
//'法定代表人'
TianyanchaJson
string
`json:"tianyancha_json"`
TianyanchaJson
string
`json:"tianyancha_json"`
ComAddress
string
`json:"com_address"`
//'公司地址'
ComAddress
string
`json:"com_address"`
//'公司地址'
TianyanchaInfo
ErpTianYanChaCompanyInfo
`json:"tyc_info"`
//'tycjson'
TianyanchaInfo
ErpTianYanChaCompanyInfo
`json:"tyc_info"`
//'tycjson'
}
}
type
ErpTianYanChaCompanyInfo
struct
{
type
ErpTianYanChaCompanyInfo
struct
{
RegNumber
string
`json:"regNumber"`
RegNumber
string
`json:"regNumber"`
CreditCode
string
`json:"creditCode"`
CreditCode
string
`json:"creditCode"`
TaxNumber
string
`json:"taxNumber"`
TaxNumber
string
`json:"taxNumber"`
PhoneNumber
string
`json:"phoneNumber"`
PhoneNumber
string
`json:"phoneNumber"`
RegCapitalCurrency
string
`json:"regCapitalCurrency"`
RegCapitalCurrency
string
`json:"regCapitalCurrency"`
}
}
type
ErpResultStruct
struct
{
type
ErpResultStruct
struct
{
...
@@ -45,46 +45,51 @@ type ErpResultStruct struct {
...
@@ -45,46 +45,51 @@ type ErpResultStruct struct {
}
}
type
Rabitmq
struct
{
type
Rabitmq
struct
{
Dsn
string
//rabitmq 配置1
Dsn
string
//rabitmq 配置1
}
}
func
GetCompanyInfo
(
c
*
bm
.
Context
)
{
func
GetCompanyInfo
(
c
*
bm
.
Context
)
{
var
erpCompanyInfo
ErpCompanyInfo
var
erpCompanyInfo
ErpCompanyInfo
var
erpJson
ErpResultStruct
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
{
if
err
!=
nil
{
log
.
Error
(
err
.
Error
())
log
.
Error
(
err
.
Error
())
}
}
err
=
db
.
QueryRow
(
c
,
SELECTERPCOMBASIC
,
companyName
)
.
Scan
(
&
erpCompanyInfo
.
ComName
,
&
erpCompanyInfo
.
ComOrganization
,
&
erpCompanyInfo
.
EstanlishmentTime
,
err
=
db
.
QueryRow
(
c
,
SELECTERPCOMBASIC
,
companyName
)
.
Scan
(
&
erpCompanyInfo
.
ComName
,
&
erpCompanyInfo
.
ComOrganization
,
&
erpCompanyInfo
.
EstanlishmentTime
,
&
erpCompanyInfo
.
CustomerProperty
,
&
erpCompanyInfo
.
RegisteredCapital
,
&
erpCompanyInfo
.
LegalRepresentative
,
&
erpCompanyInfo
.
TianyanchaJson
,
&
erpCompanyInfo
.
ComAddress
)
&
erpCompanyInfo
.
CustomerProperty
,
&
erpCompanyInfo
.
RegisteredCapital
,
&
erpCompanyInfo
.
LegalRepresentative
,
&
erpCompanyInfo
.
TianyanchaJson
,
&
erpCompanyInfo
.
ComAddress
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
err
.
Error
())
log
.
Error
(
err
.
Error
())
}
}
jsonArr
:=
strings
.
Split
(
erpCompanyInfo
.
TianyanchaJson
,
"||||"
)
jsonArr
:=
strings
.
Split
(
erpCompanyInfo
.
TianyanchaJson
,
"||||"
)
if
len
(
jsonArr
)
>
1
{
if
len
(
jsonArr
)
>
1
{
err
=
json
.
Unmarshal
([]
byte
(
jsonArr
[
0
]),
&
erpJson
)
err
=
json
.
Unmarshal
([]
byte
(
jsonArr
[
0
]),
&
erpJson
)
erpCompanyInfo
.
TianyanchaInfo
=
erpJson
.
Result
erpCompanyInfo
.
TianyanchaInfo
=
erpJson
.
Result
}
}
erpCompanyInfo
.
TianyanchaJson
=
""
erpCompanyInfo
.
TianyanchaJson
=
""
c
.
JSON
(
erpCompanyInfo
,
nil
)
c
.
JSON
(
erpCompanyInfo
,
nil
)
closedb
()
closedb
()
if
erpCompanyInfo
.
ComName
==
""
{
if
erpCompanyInfo
.
ComName
==
""
{
PushCompanyMq
(
c
,
companyName
)
PushCompanyMq
(
c
,
companyName
)
}
}
}
}
//增加公司,并且推送mq
//增加公司,并且推送mq
func
PushCompanyMq
(
c
*
bm
.
Context
,
companyName
string
)
{
func
PushCompanyMq
(
c
*
bm
.
Context
,
companyName
string
)
{
var
(
var
(
cfg
Rabitmq
cfg
Rabitmq
ct
paladin
.
TOML
ct
paladin
.
TOML
)
)
if
err
:=
paladin
.
Get
(
"rabitmq.toml"
)
.
Unmarshal
(
&
ct
);
err
!=
nil
{
if
err
:=
paladin
.
Get
(
"rabitmq.toml"
)
.
Unmarshal
(
&
ct
);
err
!=
nil
{
...
@@ -94,17 +99,16 @@ func PushCompanyMq(c *bm.Context,companyName string) {
...
@@ -94,17 +99,16 @@ func PushCompanyMq(c *bm.Context,companyName string) {
log
.
Error
(
err
.
Error
())
log
.
Error
(
err
.
Error
())
}
}
db
,
closedb
,
err
:=
dao
.
NewDB
()
db
,
closedb
,
err
:=
dao
.
NewDB
()
currentTime
:=
time
.
Now
()
.
Unix
()
currentTime
:=
time
.
Now
()
.
Unix
()
sqlResult
,
err
:=
db
.
Exec
(
c
,
member
.
INSERTCOMPANY
,
companyName
,
currentTime
,
currentTime
)
sqlResult
,
err
:=
db
.
Exec
(
c
,
member
.
INSERTCOMPANY
,
companyName
,
currentTime
,
currentTime
)
lastid
,
err
:=
sqlResult
.
LastInsertId
()
lastid
,
err
:=
sqlResult
.
LastInsertId
()
//如果添加没问题,就继续添加
//如果添加没问题,就继续添加
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
err
.
Error
())
log
.
Error
(
err
.
Error
())
}
else
{
}
else
{
_
,
err
=
db
.
Exec
(
c
,
member
.
INSERTCOMPANYBASICINFO
,
lastid
,
companyName
,
currentTime
)
_
,
err
=
db
.
Exec
(
c
,
member
.
INSERTCOMPANYBASICINFO
,
lastid
,
companyName
,
currentTime
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
err
.
Error
())
log
.
Error
(
err
.
Error
())
}
}
...
@@ -113,7 +117,7 @@ func PushCompanyMq(c *bm.Context,companyName string) {
...
@@ -113,7 +117,7 @@ func PushCompanyMq(c *bm.Context,companyName string) {
closedb
()
closedb
()
//链接mq
//链接mq
conn
,
err
:=
amqp
.
Dial
(
"amqp://"
+
cfg
.
Dsn
+
"/"
)
conn
,
err
:=
amqp
.
Dial
(
"amqp://"
+
cfg
.
Dsn
+
"/"
)
defer
conn
.
Close
()
defer
conn
.
Close
()
//通道
//通道
...
@@ -123,22 +127,22 @@ func PushCompanyMq(c *bm.Context,companyName string) {
...
@@ -123,22 +127,22 @@ func PushCompanyMq(c *bm.Context,companyName string) {
//设置数据
//设置数据
q
,
err
:=
ch
.
QueueDeclare
(
q
,
err
:=
ch
.
QueueDeclare
(
"fengkong_static_count"
,
// name
"fengkong_static_count"
,
// name
true
,
// durable
true
,
// durable
false
,
// delete when unused
false
,
// delete when unused
false
,
// exclusive
false
,
// exclusive
false
,
// no-wait
false
,
// no-wait
nil
,
// arguments
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
)
fmt
.
Println
(
body
)
err
=
ch
.
Publish
(
err
=
ch
.
Publish
(
"fengkong_exchange"
,
// exchange
"fengkong_exchange"
,
// exchange
q
.
Name
,
// routing key
q
.
Name
,
// routing key
false
,
// mandatory
false
,
// mandatory
false
,
// immediate
false
,
// immediate
amqp
.
Publishing
{
amqp
.
Publishing
{
ContentType
:
"text/plain"
,
ContentType
:
"text/plain"
,
Body
:
[]
byte
(
body
),
Body
:
[]
byte
(
body
),
})
})
}
}
\ No newline at end of file
http/internal/server/http/server.go
View file @
e9a41102
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
pb
"kaopu-server/http/api"
pb
"kaopu-server/http/api"
"kaopu-server/http/internal/model"
"kaopu-server/http/internal/model"
"github.com/go-kratos/kratos/pkg/conf/paladin"
"github.com/go-kratos/kratos/pkg/conf/paladin"
"github.com/go-kratos/kratos/pkg/log"
"github.com/go-kratos/kratos/pkg/log"
bm
"github.com/go-kratos/kratos/pkg/net/http/blademaster"
bm
"github.com/go-kratos/kratos/pkg/net/http/blademaster"
...
@@ -18,7 +19,7 @@ var svc pb.DemoServer
...
@@ -18,7 +19,7 @@ var svc pb.DemoServer
func
New
(
s
pb
.
DemoServer
)
(
engine
*
bm
.
Engine
,
err
error
)
{
func
New
(
s
pb
.
DemoServer
)
(
engine
*
bm
.
Engine
,
err
error
)
{
var
(
var
(
cfg
bm
.
ServerConfig
cfg
bm
.
ServerConfig
ct
paladin
.
TOML
ct
paladin
.
TOML
)
)
if
err
=
paladin
.
Get
(
"http.toml"
)
.
Unmarshal
(
&
ct
);
err
!=
nil
{
if
err
=
paladin
.
Get
(
"http.toml"
)
.
Unmarshal
(
&
ct
);
err
!=
nil
{
return
return
...
@@ -45,6 +46,7 @@ func initRouter(e *bm.Engine) {
...
@@ -45,6 +46,7 @@ func initRouter(e *bm.Engine) {
//会员系统的接口
//会员系统的接口
g
.
GET
(
"/erp/company_info/:company_name"
,
erp
.
GetCompanyInfo
)
g
.
GET
(
"/erp/company_info/:company_name"
,
erp
.
GetCompanyInfo
)
g
.
POST
(
"/erp/company_info"
,
erp
.
GetCompanyInfo
)
}
}
}
}
...
@@ -62,4 +64,4 @@ func howToStart(c *bm.Context) {
...
@@ -62,4 +64,4 @@ func howToStart(c *bm.Context) {
Hello
:
"Golang 大法好 !!!"
,
Hello
:
"Golang 大法好 !!!"
,
}
}
c
.
JSON
(
k
,
nil
)
c
.
JSON
(
k
,
nil
)
}
}
\ 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