Commit 293610f4 by mushishixian

发货单补全字段

parent 81d5112c
...@@ -2,7 +2,6 @@ package main ...@@ -2,7 +2,6 @@ package main
import ( import (
"github.com/imroc/req" "github.com/imroc/req"
"scm_server/cmd/queue/sync_audit_status"
"scm_server/cmd/queue/sync_customer" "scm_server/cmd/queue/sync_customer"
"scm_server/cmd/queue/sync_goods" "scm_server/cmd/queue/sync_goods"
"scm_server/cmd/queue/sync_in_store" "scm_server/cmd/queue/sync_in_store"
...@@ -58,7 +57,7 @@ func main() { ...@@ -58,7 +57,7 @@ func main() {
go sync_in_store.Sync() go sync_in_store.Sync()
go sync_out_store.Sync() go sync_out_store.Sync()
go sync_status.Sync() go sync_status.Sync()
go sync_audit_status.Sync() //go sync_audit_status.Sync()
//定时请求open falcon证明自己没挂 //定时请求open falcon证明自己没挂
for { for {
pushAlive() pushAlive()
......
The file could not be displayed because it is too large.
package sync_audit_status package main
import ( import (
"encoding/json" "encoding/json"
...@@ -18,34 +18,69 @@ import ( ...@@ -18,34 +18,69 @@ import (
type RecvPro struct { type RecvPro struct {
} }
type QueueAuditStatus struct { type QueueAuditData struct {
SyncName string SyncName string `json:"SyncName"`
Status int Data StoreData `json:"Data"`
ErpId string }
type StoreData struct {
ErpStoreId string `json:"erp_store_id"`
BoxNumber int `json:"box_number"`
BoxWeight float64 `json:"box_weight"`
PalletNumber int `json:"pallet_number"`
PalletWeight int `json:"pallet_weight"`
Detail []StoreGoods `json:"detail"`
}
type StoreGoods struct {
ErpEntrySn string `json:"erp_entry_sn"`
Number int `json:"number"`
CountryCode string `json:"country_code"`
} }
func init() { func init() {
//product.SyncErpStatus("in_store", "+7fvorsZSAevQCJ7ujsbLMBZJbY=")
log.Init(nil) log.Init(nil)
} }
func (t *RecvPro) Consumer(dataByte []byte) (err error) { func (t *RecvPro) Consumer(dataByte []byte) (err error) {
var ( var (
message QueueAuditStatus message QueueAuditData
auditStatusLog model.AuditStatusLog auditStatusLog model.AuditStatusLog
storeErpData map[string]interface{}
inStoreErpGoods []map[string]interface{}
jsonByte []byte
) )
//先去转换队列消息的json //先去转换队列消息的json
if err = json.Unmarshal(dataByte, &message); err != nil { if err = json.Unmarshal(dataByte, &message); err != nil {
goto ERR goto ERR
} }
if message.SyncName == "in_store" {
//得到入库数据以后,去组装金蝶需要的数据
storeErpData = map[string]interface{}{
"FSourceBillID": message.Data.ErpStoreId,
"FBoxQty": message.Data.BoxNumber,
"FBoxWeight": message.Data.BoxWeight,
"FCardBoardQty": message.Data.PalletNumber,
"FCardBoardWeight": message.Data.PalletWeight,
}
for _, value := range message.Data.Detail { inStoreErpGoods = append(inStoreErpGoods, map[string]interface{}{
"FSourceBillEntryID": value.ErpEntrySn,
"FQty": value.Number,
"FOriginCountry": value.CountryCode,
})
}
storeErpData["FEntrys"] = inStoreErpGoods
jsonByte, _ = json.Marshal(storeErpData)
}
//得到message以后,去请求金蝶的接口 //得到message以后,去请求金蝶的接口
if err = SyncErpAuditStatus(message.SyncName, message.ErpId); err != nil { if err = SyncErpAuditStatus(message.SyncName, string(jsonByte)); err != nil {
goto ERR goto ERR
} }
return nil return nil
ERR: ERR:
auditStatusLog.SyncName = message.SyncName auditStatusLog.SyncName = message.SyncName
auditStatusLog.UniqueId = message.ErpId //auditStatusLog.UniqueId = message.ErpId
auditStatusLog.SyncError = err.Error() auditStatusLog.SyncError = err.Error()
auditStatusLog.AddTime = time.Now().Unix() auditStatusLog.AddTime = time.Now().Unix()
//如果失败了,记录到表,并且发送钉钉消息 //如果失败了,记录到表,并且发送钉钉消息
...@@ -57,40 +92,8 @@ ERR: ...@@ -57,40 +92,8 @@ ERR:
return nil return nil
} }
func LoginErp() (err error) { func SyncErpAuditStatus(syncName, json string) (err error) {
soap, err := gosoap.SoapClient(configs.ErpLoginStatusApi) if err = service.LoginErp(); err != nil {
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 SyncErpAuditStatus(syncName, uniqueId string) (err error) {
if err = LoginErp(); err != nil {
return return
} }
var ( var (
...@@ -117,8 +120,9 @@ func SyncErpAuditStatus(syncName, uniqueId string) (err error) { ...@@ -117,8 +120,9 @@ func SyncErpAuditStatus(syncName, uniqueId string) (err error) {
return return
} }
params = gosoap.ArrayParams{ params = gosoap.ArrayParams{
{"json", fmt.Sprintf(`{"FSourceBillID":"%s"}`, uniqueId)}, {"json", json},
} }
fmt.Println(json)
res, err = soap.Call(apiMethod, params) res, err = soap.Call(apiMethod, params)
if err != nil { if err != nil {
return return
...@@ -144,6 +148,7 @@ func CheckBillDataRequest(res *gosoap.Response) (err error) { ...@@ -144,6 +148,7 @@ func CheckBillDataRequest(res *gosoap.Response) (err error) {
for key, value := range responseData { for key, value := range responseData {
//金蝶判断成功的标志 //金蝶判断成功的标志
if key == "0000" { if key == "0000" {
fmt.Println("ok")
return return
} }
//金额判断失败的标志 //金额判断失败的标志
...@@ -160,7 +165,7 @@ func (t *RecvPro) FailAction(dataByte []byte) error { ...@@ -160,7 +165,7 @@ func (t *RecvPro) FailAction(dataByte []byte) error {
return nil return nil
} }
func Sync() { func main() {
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
service.SendDingTalkRobotToApi(fmt.Sprintf("%s", err)) service.SendDingTalkRobotToApi(fmt.Sprintf("%s", err))
......
package product package main
import ( import (
"encoding/json" "fmt"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq" "github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"scm_server/configs" "scm_server/configs"
) )
func SyncErpStatus(syncName string, ErpId string) (err error) { func main() () {
message := make(map[string]interface{}) message := `{"SyncName": "in_store",
message = map[string]interface{}{ "Data": {
"SyncName": syncName, "erp_store_id": "9wtJ0cxwTcOCbMSGuBbhfcBZJbY=",
"Status": 1, "box_number": 2,
"ErpId": ErpId, "box_weight": 400,
} "pallet_number": 1,
data, err := json.Marshal(message) "pallet_weight": 600,
if err != nil { "detail": [
return {
} "erp_entry_sn": "RsgAliA2QPGXgJHwk6ntk+0oFFw=",
body := string(data) "number": 55,
"country_code": "502"
}
]
}
}`
fmt.Println(message)
queueExchange := rabbitmq.QueueExchange{ queueExchange := rabbitmq.QueueExchange{
"store_audit_status", "store_audit_status",
"store_audit_status", "store_audit_status",
...@@ -26,6 +32,6 @@ func SyncErpStatus(syncName string, ErpId string) (err error) { ...@@ -26,6 +32,6 @@ func SyncErpStatus(syncName string, ErpId string) (err error) {
configs.RABBITMQDSN, configs.RABBITMQDSN,
} }
rabbitmq.Send(queueExchange, body) rabbitmq.Send(queueExchange, message)
return return
} }
...@@ -26,6 +26,7 @@ type OutStoreMessage struct { ...@@ -26,6 +26,7 @@ type OutStoreMessage struct {
FSourceBillID string //原始单据id FSourceBillID string //原始单据id
FRecPerson string FRecPerson string
FPrincipalNo string FPrincipalNo string
FDeliveryTypeNo string
FRecPersonContact string FRecPersonContact string
FRecPersonAddress string FRecPersonAddress string
Remark string Remark string
...@@ -60,10 +61,10 @@ func (t *RecvPro) Consumer(dataByte []byte) error { ...@@ -60,10 +61,10 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
if err = json.Unmarshal(dataByte, &message); err != nil { if err = json.Unmarshal(dataByte, &message); err != nil {
goto ERR goto ERR
} }
//判断操作类型 //判断操作类型
switch message.Type { switch message.Type {
case "save": case "save":
operateType = "insert"
outStore.BillId = message.Data.FSourceBillID outStore.BillId = message.Data.FSourceBillID
messageData, err = json.Marshal(&message) messageData, err = json.Marshal(&message)
if err != nil { if err != nil {
...@@ -72,7 +73,6 @@ func (t *RecvPro) Consumer(dataByte []byte) error { ...@@ -72,7 +73,6 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
outStore.QueueMessage = string(messageData) outStore.QueueMessage = string(messageData)
//先去查询是否存在,不存在才去插入,已经存在即是修改 //先去查询是否存在,不存在才去插入,已经存在即是修改
if !logic.CheckOutStoreSyncStatus(outStore.BillId) { if !logic.CheckOutStoreSyncStatus(outStore.BillId) {
operateType = "insert"
if err = logic.InsertOutStore(outStore); err != nil { if err = logic.InsertOutStore(outStore); err != nil {
goto ERR goto ERR
} }
...@@ -117,6 +117,7 @@ func SyncOutStoreData(operate string, message OutStoreMessage) (err error) { ...@@ -117,6 +117,7 @@ func SyncOutStoreData(operate string, message OutStoreMessage) (err error) {
params map[string]interface{} params map[string]interface{}
) )
params = TransformParams(message) params = TransformParams(message)
fmt.Println(params)
//构建请求数据 //构建请求数据
param := req.BodyJSON(&params) param := req.BodyJSON(&params)
...@@ -152,7 +153,19 @@ func TransformParams(message OutStoreMessage) (params map[string]interface{}) { ...@@ -152,7 +153,19 @@ func TransformParams(message OutStoreMessage) (params map[string]interface{}) {
var ( var (
entry OutStoreFEntrys entry OutStoreFEntrys
outStoreDetail []map[string]interface{} outStoreDetail []map[string]interface{}
deliveryTypeMap map[string]int
deliveryType int
) )
deliveryTypeMap = map[string]int{
"deliveryTerms0001": 1,
"deliveryTerms0002": 2,
"deliveryTerms0003": 3,
"deliveryTerms0004": 4,
"deliveryTerms0005": 5,
"deliveryTerms0006": 6,
"deliveryTerms0007": 7,
"deliveryTerms0008": 8,
}
var isInsp int var isInsp int
if entry.CFIsInsp { if entry.CFIsInsp {
isInsp = 1 isInsp = 1
...@@ -176,12 +189,21 @@ func TransformParams(message OutStoreMessage) (params map[string]interface{}) { ...@@ -176,12 +189,21 @@ func TransformParams(message OutStoreMessage) (params map[string]interface{}) {
} else { } else {
isApplyCustoms = 0 isApplyCustoms = 0
} }
//获取发货方式
if _, ok := deliveryTypeMap[message.Data.FDeliveryTypeNo]; ok {
deliveryType = deliveryTypeMap[message.Data.FDeliveryTypeNo]
} else {
deliveryType = 0
}
params = map[string]interface{}{ params = map[string]interface{}{
"receive_address": message.Data.FRecPersonAddress, "receive_address": message.Data.FRecPersonAddress,
"receive_user_name": message.Data.FRecPerson, "receive_user_name": message.Data.FRecPerson,
"receive_tel": message.Data.FRecPersonContact, "receive_tel": message.Data.FRecPersonContact,
"erp_out_store_id": message.Data.FSourceBillID, "erp_out_store_id": message.Data.FSourceBillID,
"erp_client_sn": message.Data.FPrincipalNo, "erp_client_sn": message.Data.FPrincipalNo,
"delivery_sn": message.Data.FErpPostRequistionBillNo,
"delivery_type": deliveryType,
"remark": message.Data.Remark, "remark": message.Data.Remark,
"erp_store_sn": message.Data.FWarehouseNo, "erp_store_sn": message.Data.FWarehouseNo,
"warehousing_sn": message.Data.FEntrustBillNo, "warehousing_sn": message.Data.FEntrustBillNo,
......
package sync_out_store package main
import ( import (
"encoding/json" "encoding/json"
...@@ -20,6 +20,8 @@ func main() { ...@@ -20,6 +20,8 @@ func main() {
"FPrincipalNo": "WT00268", "FPrincipalNo": "WT00268",
"FBizType": "执行采购", "FBizType": "执行采购",
"Remark": "测试", "Remark": "测试",
"FErpPostRequistionBillNo" : "536495123",
"FDeliveryTypeNo": "deliveryTerms0001",
"FEntrys": []map[string]interface{}{ "FEntrys": []map[string]interface{}{
{ {
"FQty": 9, "FQty": 9,
......
package service
import (
"errors"
"github.com/beevik/etree"
"github.com/mushishixian/gosoap"
"scm_server/configs"
)
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))
}
package main
import (
"github.com/imroc/req"
"scm_server/cmd/queue/sync_customer"
"scm_server/cmd/queue/sync_goods"
"scm_server/cmd/queue/sync_in_store"
"scm_server/cmd/queue/sync_out_store"
"scm_server/cmd/queue/sync_status"
"scm_server/cmd/queue/sync_supplier"
"scm_server/configs"
"time"
)
type PayloadItem struct {
Endpoint string `json:"endpoint"`
Metric string `json:"metric"`
Timestamp int64 `json:"timestamp"`
Step int `json:"step"`
Value float64 `json:"value"`
CounterType string `json:"counter_type"`
Tags string `json:"tags"`
}
//定时请求open falcon 证明程序没有挂掉
func pushAlive() {
var (
payload []PayloadItem
item PayloadItem
url string
//resp *req.Resp
err error
)
item = PayloadItem{
Endpoint: "store_sync",
Metric: "alive_check",
Timestamp: time.Now().Unix(),
Step: 60,
CounterType: "GAUGE",
Value: float64(time.Now().Unix()),
Tags: "store_sync",
}
payload = append(payload, item)
param := req.BodyJSON(&payload)
req.Debug = false
url = configs.OpenFalconPushUrl
_, err = req.Post(url, param)
if err != nil {
panic("push数据到open_falcon失败,原因是:" + err.Error())
}
}
func main() {
go sync_customer.Sync()
go sync_supplier.Sync()
go sync_goods.Sync()
go sync_in_store.Sync()
go sync_out_store.Sync()
go sync_status.Sync()
//go sync_audit_status.Sync()
//定时请求open falcon证明自己没挂
for {
//pushAlive()
time.Sleep(5 * time.Second)
}
}
The file could not be displayed because it is too large.
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