Commit 293610f4 by mushishixian

发货单补全字段

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