Commit db55cfbb by mushishixian

回调金蝶同步服务:

parent 4f689a67
package main
import (
"encoding/xml"
"github.com/hooklift/gowsdl/example/gen"
"github.com/hooklift/gowsdl/soap"
"encoding/json"
"errors"
"fmt"
"github.com/beevik/etree"
"github.com/mushishixian/gosoap"
"log"
)
// GetIPLocationResponse will hold the Soap response
type GetIPLocationResponse struct {
GetIPLocationResult string `xml:"GetIpLocationResult"`
func main() {
fmt.Println(SyncBaseDataStatus())
}
// GetIPLocationResult will
type GetIPLocationResult struct {
XMLName xml.Name `xml:"GeoIP"`
Country string `xml:"Country"`
State string `xml:"State"`
func LoginErp() bool {
soap, err := gosoap.SoapClient("http://192.168.2.253:6888/ormrpc/services/EASLogin?wsdl")
if err != nil {
log.Fatalf("SoapClient error: %s", err)
}
params := gosoap.ArrayParams{
{"userName", "WBYH"},
{"password", "123456"},
{"slnName", "eas"},
{"dcName", "demo"},
{"language", "L2"},
{"dbType", "1"},
{"authPattern", "BaseDB"},
}
res, err := soap.Call("login", params)
if err != nil {
log.Fatalf("Call error: %s", err)
}
doc := etree.NewDocument()
if err := doc.ReadFromBytes(res.Body); err != nil {
fmt.Println(err)
}
root := doc.SelectElement("multiRef")
sessionId := root.SelectElement("sessionId").Text()
if sessionId != "" {
return true
}
return false
}
var (
r GetIPLocationResponse
)
func SyncBaseDataStatus() (err error) {
soap, err := gosoap.SoapClient("http://192.168.2.253:6888/ormrpc/services/WSInventoryManagementFacade?wsdl")
if err != nil {
return
}
params := gosoap.ArrayParams{
{"json", `{"FType":"material", "FID":"++Mhf5K+T9KTEE+bJhM9PEQJ5/A="}`},
//{"json", `{"FType":"material", "FID":"ET9WHFzYagYZf0="}`},
}
func main() {
client := soap.NewClient("http://192.168.2.253:6888/ormrpc/services/EASLogin?wsdl")
service := gen.NewStockQuotePortType(client)
reply, err := service.GetLastTradePrice(&gen.TradePriceRequest{})
res, err := soap.Call("synRewriteErpBaseDataStatus", params)
if err != nil {
log.Fatalf("could't get trade prices: %v", err)
return
}
log.Println(reply)
//
//soap, err := gosoap.SoapClient("http://192.168.2.253:6888/ormrpc/services/EASLogin?wsdl")
//if err != nil {
// log.Fatalf("SoapClient error: %s", err)
//}
////
//params := gosoap.Params{
// "userName": "WBYH",
// "password": "123456",
// "slnName": "eas",
// "dcName": "demo",
// "language": "L2",
// "authPattern": "BaseDB",
// "dbType": 1,
//}
//
//
////params := gosoap.Params{
//// "json": `{"FType":"material", "FID":"ET9WHFzYagYZf0="}`,
////}
//
//res, err := soap.Call("login", params)
//if err != nil {
// log.Fatalf("Call error: %s", err)
//}
//fmt.Println(string(res.Body))
//return
//res.Unmarshal(&r)
//
//// GetIpLocationResult will be a string. We need to parse it to XML
//result := GetIPLocationResult{}
//err = xml.Unmarshal([]byte(r.GetIPLocationResult), &result)
//if err != nil {
// log.Fatalf("xml.Unmarshal error: %s", err)
//}
//
//if result.Country != "US" {
// log.Fatalf("error: %+v", r)
//}
//
//log.Println("Country: ", result.Country)
//log.Println("State: ", result.State)
doc := etree.NewDocument()
if err = doc.ReadFromBytes(res.Body); err != nil {
return
}
//没有这个xml节点代表金蝶报错了
root := doc.SelectElement("synRewriteErpBaseDataStatusResponse")
if root == nil {
return errors.New(string(res.Body))
}
result := root.SelectElement("synRewriteErpBaseDataStatusReturn")
if result != nil {
var responseData map[string]interface{}
json.Unmarshal([]byte(result.Text()), &responseData)
for key, _ := range responseData {
//金蝶判断成功的标志
if key == "0000" {
return
}
//金额判断失败的标志
if key == "4444" {
return errors.New("金蝶返回失败")
}
}
}
return errors.New("金蝶返回响应格式无法识别")
}
......@@ -7,6 +7,7 @@ import (
"github.com/go-kratos/kratos/pkg/log"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"github.com/imroc/req"
"scm_server/cmd/queue/sync_status/product"
"scm_server/configs"
"scm_server/internal/common"
"scm_server/internal/logic"
......@@ -84,7 +85,10 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
if err = SyncCustomerData(operateType, customer); err != nil {
goto ERR
}
fmt.Println("同步成功")
fmt.Println("同步成功,开始发送金蝶状态同步")
if err = product.SyncErpStatus("customer", customer.ErpId); err != nil {
goto ERR
}
return nil
ERR:
//不存在的erp_id不去操作对应的数据库
......@@ -150,7 +154,8 @@ func SyncCustomerData(operate string, customer model.Customer) (err error) {
return
}
if respData.Errcode != 101100 {
return errors.New(respData.Errmsg)
paramJson, _ := json.Marshal(param)
return errors.New(fmt.Sprintf("请求后端接口返回失败,接口链接为%s,请求参数为%s,返回的错误信息为%s", url, string(paramJson), respData.Errmsg))
}
//都没问题,代表后端那边已经成功修改,修改同步表的状态
if err = logic.SyncCustomerSuccess(customer.ErpId); err != nil {
......@@ -172,14 +177,14 @@ func SyncCustomerData(operate string, customer model.Customer) (err error) {
return
}
if respData.Errcode != 101100 {
return errors.New(respData.Errmsg)
paramJson, _ := json.Marshal(param)
return errors.New(fmt.Sprintf("请求后端接口返回失败,接口链接为%s,请求参数为%s,返回的错误信息为%s", url, string(paramJson), respData.Errmsg))
}
//都没问题,代表后端那边已经成功修改,修改同步表的状态
if err = logic.SyncCustomerSuccess(customer.ErpId); err != nil {
return
}
}
return
}
......
......@@ -17,11 +17,11 @@ func main() {
// },
//}
message = map[string]interface{}{
"type": "delete",
"type": "save",
"data": map[string]string{
"FID": "c4HiJbe4TRmrdwM+Gbrn8agYZf0=",
"FNUMBER": "WT0050333",
"CFNAME": "深圳市鼎驰达电子有限公司TEST",
"FID": "Bg/8bD0XRdayeQFMFsSgY6gYZf0=",
"FNUMBER": "WT00013",
"CFNAME": "深圳市肯特尔科技有限公司",
},
}
data,err := json.Marshal(message)
......
......@@ -88,7 +88,9 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
goto ERR
}
fmt.Println("同步成功,开始发送金蝶状态同步")
product.SyncErpStatus("goods", goods.ErpId)
if err = product.SyncErpStatus("goods", goods.ErpId); err != nil {
goto ERR
}
return nil
ERR:
//不存在的erp_id不去操作对应的数据库
......@@ -155,7 +157,8 @@ func SyncGoodsData(operate string, goods model.Goods) (err error) {
return
}
if respData.Errcode != 101100 {
return errors.New(respData.Errmsg)
paramJson, _ := json.Marshal(param)
return errors.New(fmt.Sprintf("请求后端接口返回失败,接口链接为%s,请求参数为%s,返回的错误信息为%s", url, string(paramJson), respData.Errmsg))
}
//都没问题,代表后端那边已经成功修改,修改同步表的状态
if err = logic.SyncGoodsSuccess(goods.ErpId, false); err != nil {
......@@ -177,7 +180,8 @@ func SyncGoodsData(operate string, goods model.Goods) (err error) {
return
}
if respData.Errcode != 101100 {
return errors.New(respData.Errmsg)
paramJson, _ := json.Marshal(param)
return errors.New(fmt.Sprintf("请求后端接口返回失败,接口链接为%s,请求参数为%s,返回的错误信息为%s", url, string(paramJson), respData.Errmsg))
}
//都没问题,代表后端那边已经成功修改,修改同步表的状态
if err = logic.SyncGoodsSuccess(goods.ErpId, true); err != nil {
......
......@@ -9,12 +9,12 @@ import (
func main() {
message := make(map[string]interface{})
message = map[string]interface{}{
"type": "delete",
"type": "save",
"data": map[string]string{
"FID": "Z8eVSzSLRXKa7ET9WHFzYagYZf01721=",
"FGoods": "WT0050333",
"FBrand": "深圳市鼎驰达电子有限公司",
"FModel": "XXX",
"FID": "BUqVwVoBTRm/BY9kIKL7fEQJ5/A=",
"FGoods": "光电耦合器",
"FBrand": "VISHAY",
"FModel": "LH1512BB",
},
}
data, err := json.Marshal(message)
......
......@@ -18,21 +18,21 @@ import (
type RecvPro struct {
}
type OutStoreMessage struct {
type InStoreMessage struct {
Type string
Data struct {
FSourceBillID string //原始单据id
FWarehouseNo string //
FEntrustBillNo string
FErpPurInWorehouseNo string
FSourceBillID string //原始单据id
CFIsInsp bool
FPrincipalNo string
FBizType string
FEntrys FEntrys
FEntrys InStoreFEntry
}
}
type FEntrys struct {
type InStoreFEntry struct {
FQty int
FIsRecordLotAndDC bool
FOriginCountry string
......@@ -44,6 +44,7 @@ type FEntrys struct {
FModel string
FGoods string
FUnit string
FRemark string
}
func init() {
......@@ -51,10 +52,8 @@ func init() {
}
func (t *RecvPro) Consumer(dataByte []byte) error {
fmt.Println(string(dataByte))
return errors.New("test")
var (
message SupplierQueueMessage
message InStoreMessage
err error
supplier model.Supplier
operateType string
......@@ -169,7 +168,8 @@ func SyncSupplierData(operate string, supplier model.Supplier) (err error) {
return
}
if respData.Errcode != 101100 {
return errors.New(respData.Errmsg)
paramJson, _ := json.Marshal(param)
return errors.New(fmt.Sprintf("请求后端接口返回失败,接口链接为%s,请求参数为%s,返回的错误信息为%s", url, string(paramJson), respData.Errmsg))
}
//都没问题,代表后端那边已经成功修改,修改同步表的状态
if err = logic.SyncSupplierSuccess(supplier.ErpId); err != nil {
......@@ -191,7 +191,8 @@ func SyncSupplierData(operate string, supplier model.Supplier) (err error) {
return
}
if respData.Errcode != 101100 {
return errors.New(respData.Errmsg)
paramJson, _ := json.Marshal(param)
return errors.New(fmt.Sprintf("请求后端接口返回失败,接口链接为%s,请求参数为%s,返回的错误信息为%s", url, string(paramJson), respData.Errmsg))
}
//都没问题,代表后端那边已经成功修改,修改同步表的状态
if err = logic.SyncCustomerSuccess(supplier.ErpId); err != nil {
......
......@@ -7,6 +7,7 @@ import (
"github.com/go-kratos/kratos/pkg/log"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"github.com/imroc/req"
"scm_server/cmd/queue/sync_status/product"
"scm_server/configs"
"scm_server/internal/common"
"scm_server/internal/logic"
......@@ -28,7 +29,9 @@ type OutStoreMessage struct {
FRecPerson string
FRecPersonContact string
FRecPersonAddress string
FEntrys OutStoreFEntrys
Remark string
FEntrustBillNo string
FEntrys []OutStoreFEntrys
}
}
......@@ -41,6 +44,9 @@ type OutStoreFEntrys struct {
FModel string
FGoods string
FUnit string
CFIsInsp bool
Fremark string
FOriginCountry string
}
func init() {
......@@ -48,13 +54,13 @@ func init() {
}
func (t *RecvPro) Consumer(dataByte []byte) error {
fmt.Println(string(dataByte))
var (
message OutStoreMessage
err error
outStore model.OutStore
operateType string
syncLog model.SyncLog
msg []byte
)
//先去转换队列消息的json,如果失败,记录起来
if err = json.Unmarshal(dataByte, &message); err != nil {
......@@ -64,41 +70,51 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
//判断操作类型
switch message.Type {
case "save":
outStore.BillId = message.Data.FSourceBillID
messageData, err := json.Marshal(&message)
if err != nil {
goto ERR
}
outStore.QueueMessage = string(messageData)
//先去查询是否存在,不存在才去插入,已经存在即是修改
if logic.CheckSupplierExist(supplier.ErpId) {
if logic.CheckOutStoreExist(outStore.BillId) {
err = errors.New("试图新增已存在的出货单,单号为" + message.Data.FSourceBillID)
goto ERR
} else {
operateType = "insert"
if err = logic.InsertSupplier(supplier); err != nil {
if err = logic.InsertOutStore(outStore); err != nil {
fmt.Println(err)
//todo:错误原因会消失
goto ERR
}
}
case "delete":
operateType = "delete"
supplier.Status = 0
if logic.CheckSupplierExist(supplier.ErpId) {
outStore.Status = 0
if logic.CheckOutStoreExist(outStore.BillId) {
//如果存在,才进行删除
if err = logic.DeleteSupplier(supplier); err != nil {
if err = logic.DeleteOutStore(outStore); err != nil {
goto ERR
}
} else {
err = errors.New("试图删除不存在的供应商")
err = errors.New("试图删除不存在的出货单")
goto ERR
}
default:
err = errors.New("同步供应商出现不存在的操作类型")
err = errors.New("同步出货单出现不存在的操作类型")
goto ERR
}
//操作成功后还要去请求后端接口同步数据
if err = SyncSupplierData(operateType, supplier); err != nil {
if err = SyncOutStoreData(operateType, message); err != nil {
goto ERR
}
fmt.Println("同步成功")
fmt.Println("同步成功,开始发送金蝶状态同步")
product.SyncErpStatus("out_store", outStore.BillId)
return nil
ERR:
//不存在的erp_id不去操作对应的数据库
if supplier.ErpId != "" {
logSyncErrorToSupplier(supplier.ErpId, err.Error())
//不存在的billId不去操作对应的数据库
if outStore.BillId != "" {
logSyncErrorToOutStore(outStore.BillId, err.Error())
}
//还要存到一个统一错误表
......@@ -106,13 +122,13 @@ ERR:
AddTime: time.Now().Unix(),
SyncTime: time.Now().Unix(),
QueueMessage: string(dataByte),
UniqueId: supplier.ErpId, //有可能为
UniqueId: outStore.BillId, //有可能为
SyncError: err.Error(),
SyncName: "supplier",
SyncName: "outStore",
}
logic.InsertSyncLog(syncLog)
//发送钉钉错误消息
msg, _ := json.Marshal(syncLog)
msg, _ = json.Marshal(syncLog)
service.SendMessage(common.ErrorSendPhone, string(msg))
//保存日志
......@@ -126,52 +142,26 @@ func (t *RecvPro) FailAction(dataByte []byte) error {
}
//同步数据
func SyncSupplierData(operate string, supplier model.Supplier) (err error) {
func SyncOutStoreData(operate string, message OutStoreMessage) (err error) {
var (
resp *req.Resp
url string
respData common.Response
params map[string]interface{}
)
param := req.Param{
"erp_supplier_sn": supplier.ErpSupplierCode,
"supplier_name": supplier.Name,
"erp_supplier_id": supplier.ErpId,
"admin_name": "系统",
"admin_id": 1,
}
params = TransformParams(message)
//构建请求数据
param := req.BodyJSON(&params)
//更新和插入接口不同
if operate == "update" {
url = configs.BasicApiUrl + "/basic/api/ApiUpdateSupplierInfo"
} else if operate == "insert" {
url = configs.BasicApiUrl + "/basic/api/ApiInsertSupplierInfo"
if operate == "insert" {
url = configs.OutStoreApiUrl + "/out_store/createOutStore"
} else {
url = configs.BasicApiUrl + "/basic/api/ApiUpdateSupplierStatus"
url = configs.OutStoreApiUrl + ""
}
req.Debug = false
if operate == "update" || operate == "insert" {
resp, err = req.Post(url, param)
if err != nil {
return
}
if err = resp.ToJSON(&respData); err != nil {
return
}
if respData.Errcode != 101100 {
return errors.New(respData.Errmsg)
}
//都没问题,代表后端那边已经成功修改,修改同步表的状态
if err = logic.SyncSupplierSuccess(supplier.ErpId); err != nil {
return
}
} else {
param = req.Param{
"erp_supplier_id": supplier.ErpId,
"admin_name": "系统",
"admin_id": 1,
"status": 0,
}
//删除
billId := message.Data.FSourceBillID
if operate == "insert" {
resp, err = req.Post(url, param)
if err != nil {
return
......@@ -180,25 +170,62 @@ func SyncSupplierData(operate string, supplier model.Supplier) (err error) {
return
}
if respData.Errcode != 101100 {
return errors.New(respData.Errmsg)
paramJson, _ := json.Marshal(param)
return errors.New(fmt.Sprintf("请求后端接口返回失败,接口链接为%s,请求参数为%s,返回的错误信息为%s", url, string(paramJson), respData.Errmsg))
}
//都没问题,代表后端那边已经成功修改,修改同步表的状态
if err = logic.SyncCustomerSuccess(supplier.ErpId); err != nil {
if err = logic.SyncOutStoreSuccess(billId, false); err != nil {
return
}
}
return
}
func logSyncErrorToSupplier(erpId, syncError string) {
func logSyncErrorToOutStore(erpId, syncError string) {
var err error
//请求失败的话,将原因存起来
if err = logic.WriteSupplierSyncError(erpId, syncError); err != nil {
if err = logic.WriteOutStoreSyncError(erpId, syncError); err != nil {
//数据库错误,发送警告
service.SendMessage(common.ErrorSendPhone, err.Error())
}
}
func TransformParams(message OutStoreMessage) (params map[string]interface{}) {
var (
entry OutStoreFEntrys
outStoreDetail []map[string]interface{}
)
params = make(map[string]interface{})
for _, entry = range message.Data.FEntrys {
outStoreDetail = append(outStoreDetail, map[string]interface{}{
"erp_entry_sn": entry.FMaterialID,
"goods_name": entry.FGoods,
"brand_name": entry.FBrand,
"number": entry.FQty,
"goods_unit": entry.FUnit,
"is_insp": entry.CFIsInsp,
})
}
var isApplyCustoms int
if message.Data.FIsCustoms {
isApplyCustoms = 1
} else {
isApplyCustoms = 0
}
params = map[string]interface{}{
"receive_address": message.Data.FRecPersonAddress,
"receive_user_name": message.Data.FRecPerson,
"receive_tel": message.Data.FRecPersonContact,
//缺一个原始单据id
"remark": message.Data.Remark,
"store_id": message.Data.FWarehouseNo,
"warehousing_sn": message.Data.FEntrustBillNo,
"is_apply_customs": isApplyCustoms,
"out_store_detail": outStoreDetail,
}
return
}
func main() {
t := &RecvPro{}
rabbitmq.Recv(rabbitmq.QueueExchange{
......
......@@ -18,6 +18,7 @@ func main() {
"CFIsInsp": false,
"FPrincipalNo": "WT00268",
"FBizType": "执行采购",
"Remark": "测试",
"FEntrys": []map[string]interface{}{
{
"FQty": 9,
......
......@@ -3,8 +3,12 @@ package main
import (
"encoding/json"
"fmt"
"github.com/beevik/etree"
"github.com/go-kratos/kratos/pkg/log"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"github.com/mushishixian/gosoap"
"github.com/pkg/errors"
"scm_server/configs"
"scm_server/internal/logic"
)
......@@ -21,10 +25,9 @@ func init() {
log.Init(nil)
}
func (t *RecvPro) Consumer(dataByte []byte) error {
func (t *RecvPro) Consumer(dataByte []byte) (err error) {
fmt.Println(string(dataByte))
var (
err error
message QueueStatus
)
//先去转换队列消息的json
......@@ -33,11 +36,14 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
}
//得到message以后,去请求金蝶的接口
fmt.Println("请求金蝶接口")
if err = SyncErpDataStatus(message.SyncName, message.ErpId); err != nil {
goto ERR
}
return nil
//如果失败了,记录到表,并且发送钉钉消息
ERR:
//如果失败了,记录到表,并且发送钉钉消息
fmt.Println(err)
if err = logic.InsertSyncStatusLog(message.SyncName, message.ErpId, "err.Error()"); err != nil {
if err = logic.InsertSyncStatusLog(message.SyncName, message.ErpId, err.Error()); err != nil {
fmt.Println(err)
}
return nil
......@@ -48,6 +54,103 @@ func (t *RecvPro) FailAction(dataByte []byte) error {
return nil
}
func LoginErp() (err error) {
soap, err := gosoap.SoapClient(configs.ErpLoginStatusApi)
if err != nil {
return
}
params := gosoap.ArrayParams{
{"userName", "WBYH"},
{"password", "123456"},
{"slnName", "eas"},
{"dcName", "demo"},
{"language", "L2"},
{"dbType", "1"},
{"authPattern", "BaseDB"},
}
res, err := soap.Call("login", params)
if err != nil {
return
}
doc := etree.NewDocument()
if err := doc.ReadFromBytes(res.Body); err != nil {
return err
}
root := doc.SelectElement("multiRef")
sessionId := root.SelectElement("sessionId").Text()
if sessionId != "" {
return
}
return errors.New(string(res.Body))
}
func SyncErpDataStatus(syncName, uniqueId string) (err error) {
if err = LoginErp(); err != nil {
return
}
var (
soap *gosoap.Client
params gosoap.ArrayParams
res *gosoap.Response
apiUrl string
apiMethod string
)
switch syncName {
case "goods":
case "supplier":
case "customer":
apiUrl = configs.ErpSyncBaseDataStatusApi
apiMethod = "synRewriteErpBaseDataStatus"
break
case "in_store":
case "out_store":
apiUrl = configs.ErpSyncBillStatusApi
apiMethod = "synErpInventoryStatus"
break
}
soap, err = gosoap.SoapClient(apiUrl)
if err != nil {
return
}
//uniqueId = "++Mhf5K+T9KTEE+bJhM9PEQJ5/A="
//syncName = "material"
fmt.Println(fmt.Sprintf(`{"FType":"%s", "FID":"%s"}`, syncName, uniqueId))
params = gosoap.ArrayParams{
{"json", fmt.Sprintf(`{"FType":"%s", "FID":"%s"}`, syncName, uniqueId)},
}
res, err = soap.Call(apiMethod, params)
if err != nil {
return
}
doc := etree.NewDocument()
if err = doc.ReadFromBytes(res.Body); err != nil {
return
}
//没有这个xml节点代表金蝶报错了
root := doc.SelectElement("synRewriteErpBaseDataStatusResponse")
if root == nil {
return errors.New(string(res.Body))
}
result := root.SelectElement("synRewriteErpBaseDataStatusReturn")
if result != nil {
var responseData map[string]interface{}
json.Unmarshal([]byte(result.Text()), &responseData)
for key, _ := range responseData {
//金蝶判断成功的标志
if key == "0000" {
return
}
//金额判断失败的标志
if key == "4444" {
return errors.New("金蝶返回失败")
}
}
}
return errors.New("金蝶返回响应格式无法识别")
}
func main() {
t := &RecvPro{}
rabbitmq.Recv(rabbitmq.QueueExchange{
......
......@@ -2,11 +2,10 @@ package product
import (
"encoding/json"
"fmt"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
)
func SyncErpStatus(syncName string, ErpId string) {
func SyncErpStatus(syncName string, ErpId string) (err error) {
message := make(map[string]interface{})
message = map[string]interface{}{
"SyncName": syncName,
......@@ -15,7 +14,7 @@ func SyncErpStatus(syncName string, ErpId string) {
}
data, err := json.Marshal(message)
if err != nil {
fmt.Println(err)
return
}
body := string(data)
queueExchange := rabbitmq.QueueExchange{
......@@ -27,4 +26,5 @@ func SyncErpStatus(syncName string, ErpId string) {
}
rabbitmq.Send(queueExchange, body)
return
}
......@@ -7,6 +7,7 @@ import (
"github.com/go-kratos/kratos/pkg/log"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"github.com/imroc/req"
"scm_server/cmd/queue/sync_status/product"
"scm_server/configs"
"scm_server/internal/common"
"scm_server/internal/logic"
......@@ -83,7 +84,10 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
if err = SyncSupplierData(operateType, supplier); err != nil {
goto ERR
}
fmt.Println("同步成功")
fmt.Println("同步成功,开始发送金蝶状态同步")
if err = product.SyncErpStatus("supplier", supplier.ErpId); err != nil {
goto ERR
}
return nil
ERR:
//不存在的erp_id不去操作对应的数据库
......@@ -148,7 +152,8 @@ func SyncSupplierData(operate string, supplier model.Supplier) (err error) {
return
}
if respData.Errcode != 101100 {
return errors.New(respData.Errmsg)
paramJson, _ := json.Marshal(param)
return errors.New(fmt.Sprintf("请求后端接口返回失败,接口链接为%s,请求参数为%s,返回的错误信息为%s", url, string(paramJson), respData.Errmsg))
}
//都没问题,代表后端那边已经成功修改,修改同步表的状态
if err = logic.SyncSupplierSuccess(supplier.ErpId); err != nil {
......@@ -170,7 +175,8 @@ func SyncSupplierData(operate string, supplier model.Supplier) (err error) {
return
}
if respData.Errcode != 101100 {
return errors.New(respData.Errmsg)
paramJson, _ := json.Marshal(param)
return errors.New(fmt.Sprintf("请求后端接口返回失败,接口链接为%s,请求参数为%s,返回的错误信息为%s", url, string(paramJson), respData.Errmsg))
}
//都没问题,代表后端那边已经成功修改,修改同步表的状态
if err = logic.SyncCustomerSuccess(supplier.ErpId); err != nil {
......
......@@ -9,11 +9,11 @@ import (
func main() {
message := make(map[string]interface{})
message = map[string]interface{}{
"type": "delete",
"type": "save",
"data": map[string]string{
"FID": "Z8eVSzSLRXKa7ET9WHFzYagYZf017ff=",
"FNUMBER": "WT0050333",
"CFNAME": "深圳市鼎驰达电子有限公司11",
"FID": "LxYAAAABVic3xn38",
"FNUMBER": "M0000009",
"CFNAME": "深圳市永盛微电子有限公司",
},
}
data,err := json.Marshal(message)
......
package main
import (
"encoding/xml"
"fmt"
"log"
"github.com/mushishixian/gosoap"
)
// GetIPLocationResponse will hold the Soap response
type GetIPLocationResponse struct {
GetIPLocationResult string `xml:"GetIpLocationResult"`
}
// GetIPLocationResult will
type GetIPLocationResult struct {
XMLName xml.Name `xml:"GeoIP"`
Country string `xml:"Country"`
State string `xml:"State"`
}
var (
r GetIPLocationResponse
)
func main() {
soap, err := gosoap.SoapClient("http://wsgeoip.lavasoft.com/ipservice.asmx?WSDL")
if err != nil {
log.Fatalf("SoapClient error: %s", err)
}
params := gosoap.Params{
"sIp": "8.8.8.8",
}
res, err := soap.Call("GetIpLocation", params)
if err != nil {
log.Fatalf("Call error: %s", err)
}
fmt.Println(string(res.Body))
res.Unmarshal(&r)
// GetIpLocationResult will be a string. We need to parse it to XML
result := GetIPLocationResult{}
err = xml.Unmarshal([]byte(r.GetIPLocationResult), &result)
if err != nil {
log.Fatalf("xml.Unmarshal error: %s", err)
}
if result.Country != "US" {
log.Fatalf("error: %+v", r)
}
log.Println("Country: ", result.Country)
log.Println("State: ", result.State)
}
\ No newline at end of file
......@@ -3,11 +3,14 @@ module scm_server
go 1.13
require (
github.com/beevik/etree v1.1.0
github.com/go-kratos/kratos v0.4.2
github.com/hooklift/gowsdl v0.3.2-0.20200216020636-7a3e6bce010b
github.com/ichunt2019/go-rabbitmq v1.0.1
github.com/imroc/req v0.3.0
github.com/jmoiron/sqlx v1.2.0
github.com/mushishixian/gosoap v1.2.1-0.20200424081802-b11347c911bc
github.com/pkg/errors v0.9.1
github.com/tealeg/xlsx v1.0.5
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd // indirect
)
......@@ -13,6 +13,8 @@ github.com/aristanetworks/glog v0.0.0-20180419172825-c15b03b3054f/go.mod h1:KASm
github.com/aristanetworks/goarista v0.0.0-20190912214011-b54698eaaca6/go.mod h1:Z4RTxGAuYhPzcq8+EdRM+R8M48Ssle2TsWtwRKa+vns=
github.com/aristanetworks/splunk-hec-go v0.3.3/go.mod h1:1VHO9r17b0K7WmOlLb9nTk/2YanvOEnLMUgsFrxBROc=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/beevik/etree v1.1.0 h1:T0xke/WvNtMoCqgzPhkX2r4rjY3GDZFi+FjpRZY2Jbs=
github.com/beevik/etree v1.1.0/go.mod h1:r8Aw8JqVegEf0w2fDnATrX9VpkMcyFeM0FhwO62wh+A=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
......@@ -156,6 +158,8 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/montanaflynn/stats v0.5.0/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
github.com/mushishixian/gosoap v1.2.1-0.20200424081802-b11347c911bc h1:XH26AiSFBgMk+/Pldb8SIEhe53zBK7ZqpOMMq7LqKYQ=
github.com/mushishixian/gosoap v1.2.1-0.20200424081802-b11347c911bc/go.mod h1:AZDF6hjSYtYYTGLpjI/EN1/hHl1VTXO6nsPhR1IcLQ4=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/olekukonko/tablewriter v0.0.0-20170122224234-a0225b3f23b5/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
......@@ -271,6 +275,7 @@ golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
......@@ -281,6 +286,8 @@ golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20190912160710-24e19bdeb0f2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20191011234655-491137f69257 h1:ry8e2D+cwaV6hk7lb3aRTjjZo24shrbK0e11QEOkTIg=
golang.org/x/net v0.0.0-20191011234655-491137f69257/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd h1:QPwSajcTUrFriMF1nJ3XzgoqakqQEsnZf9LdXdi2nkI=
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
......@@ -306,6 +313,8 @@ golang.org/x/sys v0.0.0-20190912141932-bc967efca4b8/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191105231009-c1f44814a5cd h1:3x5uuvBgE6oaXJjCOvpCC1IpgJogqQ+PqGGU3ZxAgII=
golang.org/x/sys v0.0.0-20191105231009-c1f44814a5cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
......
package logic
import (
"scm_server/internal/dao"
"scm_server/internal/model"
"time"
)
const CheckInStoreExistSql = "SELECT goods_id FROM lie_in_store WHERE erp_id = ? AND sync_status = 1"
const InsertInStoreSql = "INSERT INTO `lie_in_store` (`queue_message`,`bill_id`,`add_time`) VALUES (?,?,?)"
const DeleteInStoreSql = "UPDATE `lie_in_store` SET `status` = ? , `update_time` = ? WHERE `erp_id` = ?"
const WriteInStoreSyncErrorSql = "UPDATE `lie_in_store` SET sync_error = ? WHERE bill_id = ?"
const SyncInStoreSuccessSql = "UPDATE `lie_in_store` SET sync_status = 1 , sync_time = ? WHERE erp_id = ?"
const SyncInStoreSuccessSqlWithStatus = "UPDATE `lie_in_store` SET sync_status = 1 , sync_time = ? , status = ? WHERE erp_id = ?"
//检查出库是否存在
func CheckInStoreExist(erpId string) (exist bool) {
var goodsId int
dao.GetDb().QueryRowx(CheckInStoreExistSql, erpId).Scan(&goodsId)
return goodsId > 0
}
//插入出库
func InsertInStore(outStore model.InStore) (err error) {
_, err = dao.GetDb().Exec(InsertInStoreSql, outStore.QueueMessage, outStore.BillId, time.Now().Unix())
return
}
//删除出库
func DeleteInStore(outStore model.InStore) (err error) {
_, err = dao.GetDb().Exec(DeleteInStoreSql, outStore.Status, time.Now().Unix(), outStore.BillId)
return
}
//写入同步失败的原因
func WriteInStoreSyncError(erpId string, syncError string) (err error) {
_, err = dao.GetDb().Exec(WriteInStoreSyncErrorSql, syncError, erpId)
return
}
//修改成功的同步状态
func SyncInStoreSuccess(erpId string, isDelete bool) (err error) {
//不是删除,不需要修改状态
if !isDelete {
_, err = dao.GetDb().Exec(SyncInStoreSuccessSql, time.Now().Unix(), erpId)
} else {
_, err = dao.GetDb().Exec(SyncInStoreSuccessSqlWithStatus, time.Now().Unix(), 0, erpId)
}
return
}
package logic
import (
"scm_server/internal/dao"
"scm_server/internal/model"
"time"
)
const CheckOutStoreExistSql = "SELECT goods_id FROM lie_out_store WHERE erp_id = ? AND sync_status = 1"
const InsertOutStoreSql = "INSERT INTO `lie_out_store` (`queue_message`,`bill_id`,`add_time`) VALUES (?,?,?)"
const DeleteOutStoreSql = "UPDATE `lie_out_store` SET `status` = ? , `update_time` = ? WHERE `erp_id` = ?"
const WriteOutStoreSyncErrorSql = "UPDATE `lie_out_store` SET sync_error = ? WHERE bill_id = ?"
const SyncOutStoreSuccessSql = "UPDATE `lie_out_store` SET sync_status = 1 , sync_time = ? WHERE erp_id = ?"
const SyncOutStoreSuccessSqlWithStatus = "UPDATE `lie_out_store` SET sync_status = 1 , sync_time = ? , status = ? WHERE erp_id = ?"
//检查出库是否存在
func CheckOutStoreExist(erpId string) (exist bool) {
var goodsId int
dao.GetDb().QueryRowx(CheckOutStoreExistSql, erpId).Scan(&goodsId)
return goodsId > 0
}
//插入出库
func InsertOutStore(outStore model.OutStore) (err error) {
_, err = dao.GetDb().Exec(InsertOutStoreSql, outStore.QueueMessage, outStore.BillId, time.Now().Unix())
return
}
//删除出库
func DeleteOutStore(outStore model.OutStore) (err error) {
_, err = dao.GetDb().Exec(DeleteOutStoreSql, outStore.Status, time.Now().Unix(), outStore.BillId)
return
}
//写入同步失败的原因
func WriteOutStoreSyncError(erpId string, syncError string) (err error) {
_, err = dao.GetDb().Exec(WriteOutStoreSyncErrorSql, syncError, erpId)
return
}
//修改成功的同步状态
func SyncOutStoreSuccess(erpId string, isDelete bool) (err error) {
//不是删除,不需要修改状态
if !isDelete {
_, err = dao.GetDb().Exec(SyncOutStoreSuccessSql, time.Now().Unix(), erpId)
} else {
_, err = dao.GetDb().Exec(SyncOutStoreSuccessSqlWithStatus, time.Now().Unix(), 0, erpId)
}
return
}
package model
//{
// "receive_address": "万科星火online",
// "receive_user_name": "张三",
// "receive_tel": "13555556666",
// "unique": "ce0bdf3c0a3fc32843a20c2ad09f499e",
// "remark": "加糖",
// "store_id": "12",
// "customer_id": "213",
// "warehousing_sn": "1232131231",
// "is_apply_customs": "1",
// "is_insp": "1",
// "out_store_detail": [
// {
// "erp_entry_sn": "123",
// "is_apply_customs": "1",
// "goods_id": 13113,
// "goods_name": 2131,
// "brand_name": 213,
// "batch": "13",
// "dc": "dccc",
// "number": 100,
// "goods_unit": "美元",
// "is_insp": 1
// }
// ]
//}
type InStore struct {
QueueMessage string
BillId string
AddTime int
SyncTime int
SyncStatus int
SyncErpStatus int
Status int
SyncError string
}
......@@ -50,7 +50,7 @@ func NewEASLoginProxy(client *soap.Client) EASLoginProxy {
func (service *eASLoginProxy) Login(request *RequestData) (*WSContext, error) {
response := new(WSContext)
err := service.client.Call("", request, response)
err := service.client.Call("login", request, response)
if err != nil {
return nil, err
}
......
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