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需要获取的公司信息
......@@ -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),
})
......
......@@ -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)
}
}
......
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