Commit e9a41102 by CnChunfeng

增加post数据获取

parent d85da14b
......@@ -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需要获取的公司信息
......@@ -20,24 +21,23 @@ const SELECTERPCOMBASIC = "select " +
" from lie_com_basicinfos where com_name = ?"
type ErpCompanyInfo struct {
ComName string `json:"com_name"` //'公司名称'
ComOrganization string `json:"com_organization"` //'组织结构代码'
EstanlishmentTime int64 `json:"establishment_time"` //'公司成立时间'
RegisteredCapital string `json:"registered_capital"` //'注册资本'
CustomerProperty string `json:"customer_property"` //'客户性质'
LegalRepresentative string `json:"legal_representative"` //'法定代表人'
TianyanchaJson string `json:"tianyancha_json"`
ComAddress string `json:"com_address"` //'公司地址'
TianyanchaInfo ErpTianYanChaCompanyInfo `json:"tyc_info"` //'tycjson'
ComName string `json:"com_name"` //'公司名称'
ComOrganization string `json:"com_organization"` //'组织结构代码'
EstanlishmentTime int64 `json:"establishment_time"` //'公司成立时间'
RegisteredCapital string `json:"registered_capital"` //'注册资本'
CustomerProperty string `json:"customer_property"` //'客户性质'
LegalRepresentative string `json:"legal_representative"` //'法定代表人'
TianyanchaJson string `json:"tianyancha_json"`
ComAddress string `json:"com_address"` //'公司地址'
TianyanchaInfo ErpTianYanChaCompanyInfo `json:"tyc_info"` //'tycjson'
}
type ErpTianYanChaCompanyInfo struct {
RegNumber string `json:"regNumber"`
CreditCode string `json:"creditCode"`
TaxNumber string `json:"taxNumber"`
PhoneNumber string `json:"phoneNumber"`
RegCapitalCurrency string `json:"regCapitalCurrency"`
RegNumber string `json:"regNumber"`
CreditCode string `json:"creditCode"`
TaxNumber string `json:"taxNumber"`
PhoneNumber string `json:"phoneNumber"`
RegCapitalCurrency string `json:"regCapitalCurrency"`
}
type ErpResultStruct struct {
......@@ -45,46 +45,51 @@ type ErpResultStruct 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 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
ct paladin.TOML
)
if err := paladin.Get("rabitmq.toml").Unmarshal(&ct); err != nil {
......@@ -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()
//通道
......@@ -123,22 +127,22 @@ func PushCompanyMq(c *bm.Context,companyName string) {
//设置数据
q, err := ch.QueueDeclare(
"fengkong_static_count", // name
true, // durable
false, // delete when unused
false, // exclusive
false, // no-wait
nil, // arguments
true, // durable
false, // delete when unused
false, // exclusive
false, // no-wait
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 {
"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
}
......@@ -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"
......@@ -18,7 +19,7 @@ var svc pb.DemoServer
func New(s pb.DemoServer) (engine *bm.Engine, err error) {
var (
cfg bm.ServerConfig
ct paladin.TOML
ct paladin.TOML
)
if err = paladin.Get("http.toml").Unmarshal(&ct); err != nil {
return
......@@ -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)
}
}
......@@ -62,4 +64,4 @@ func howToStart(c *bm.Context) {
Hello: "Golang 大法好 !!!",
}
c.JSON(k, nil)
}
\ No newline at end of file
}
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