Commit ba0c881f by mushishixian

fix bug

parent 293610f4
......@@ -4,7 +4,6 @@ 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"
......@@ -26,22 +25,18 @@ type QueueAuditData struct {
type StoreData struct {
ErpStoreId string `json:"erp_store_id"`
BoxNumber int `json:"box_number"`
BoxWeight float64 `json:"box_weight"`
BoxWeight string `json:"box_weight"`
PalletNumber int `json:"pallet_number"`
PalletWeight int `json:"pallet_weight"`
PalletWeight string `json:"pallet_weight"`
Detail []StoreGoods `json:"detail"`
}
type StoreGoods struct {
ErpEntrySn string `json:"erp_entry_sn"`
Number int `json:"number"`
Number string `json:"number"`
CountryCode string `json:"country_code"`
}
func init() {
log.Init(nil)
}
func (t *RecvPro) Consumer(dataByte []byte) (err error) {
var (
message QueueAuditData
......@@ -64,7 +59,8 @@ func (t *RecvPro) Consumer(dataByte []byte) (err error) {
"FCardBoardQty": message.Data.PalletNumber,
"FCardBoardWeight": message.Data.PalletWeight,
}
for _, value := range message.Data.Detail { inStoreErpGoods = append(inStoreErpGoods, map[string]interface{}{
for _, value := range message.Data.Detail {
inStoreErpGoods = append(inStoreErpGoods, map[string]interface{}{
"FSourceBillEntryID": value.ErpEntrySn,
"FQty": value.Number,
"FOriginCountry": value.CountryCode,
......@@ -74,25 +70,26 @@ func (t *RecvPro) Consumer(dataByte []byte) (err error) {
jsonByte, _ = json.Marshal(storeErpData)
}
//得到message以后,去请求金蝶的接口
if err = SyncErpAuditStatus(message.SyncName, string(jsonByte)); err != nil {
if err = SyncErpAuditStatus(message.SyncName, message.Data.ErpStoreId, string(jsonByte)); err != nil {
goto ERR
}
return nil
ERR:
auditStatusLog.SyncName = message.SyncName
//auditStatusLog.UniqueId = message.ErpId
auditStatusLog.UniqueId = message.Data.ErpStoreId
auditStatusLog.QueueMessage = string(dataByte)
auditStatusLog.SyncError = err.Error()
auditStatusLog.AddTime = time.Now().Unix()
//如果失败了,记录到表,并且发送钉钉消息
if err = logic.InsertAuditStatusLog(auditStatusLog); err != nil {
log.Error(err.Error())
logic.LogError(err.Error())
service.SendDingTalkRobotToApi(err.Error())
}
service.SendDingTalkRobotToApi(auditStatusLog.SyncError)
return nil
}
func SyncErpAuditStatus(syncName, json string) (err error) {
func SyncErpAuditStatus(syncName, billId, json string) (err error) {
if err = service.LoginErp(); err != nil {
return
}
......@@ -122,16 +119,15 @@ func SyncErpAuditStatus(syncName, json string) (err error) {
params = gosoap.ArrayParams{
{"json", json},
}
fmt.Println(json)
res, err = soap.Call(apiMethod, params)
if err != nil {
return
}
return CheckBillDataRequest(res)
return CheckBillDataRequest(syncName, billId, res)
}
//检查出入库单申请同步请求的情况
func CheckBillDataRequest(res *gosoap.Response) (err error) {
func CheckBillDataRequest(syncName, billId string, res *gosoap.Response) (err error) {
doc := etree.NewDocument()
if err = doc.ReadFromBytes(res.Body); err != nil {
return
......@@ -148,8 +144,11 @@ func CheckBillDataRequest(res *gosoap.Response) (err error) {
for key, value := range responseData {
//金蝶判断成功的标志
if key == "0000" {
fmt.Println("ok")
return
if syncName == "in_store" {
return logic.SyncInStoreErpAuditSuccess(billId)
} else {
return logic.SyncOutStoreErpAuditSuccess(billId)
}
}
//金额判断失败的标志
if key == "4444" {
......
......@@ -7,22 +7,7 @@ import (
)
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"
}
]
}
}`
message := `{"SyncName":"in_store","Data":{"erp_store_id":"FGipxV9OSXGWVCgqefjkesBZJbY=","detail":[{"number":"10.0000","erp_entry_sn":"mJ4W+QdYQoWe0WCnzEOJou0oFFw=","country":""},{"number":"900.0000","erp_entry_sn":"z0ULke\/wRhC5cQFzZZT4WO0oFFw=","country":""}],"pallet_number":1,"pallet_weight":"0.0000","box_number":1,"box_weight":"0.0000"}}`
fmt.Println(message)
queueExchange := rabbitmq.QueueExchange{
"store_audit_status",
......
......@@ -166,14 +166,14 @@ func TransformParams(message OutStoreMessage) (params map[string]interface{}) {
"deliveryTerms0007": 7,
"deliveryTerms0008": 8,
}
var isInsp int
if entry.CFIsInsp {
isInsp = 1
} else {
isInsp = 0
}
params = make(map[string]interface{})
for _, entry = range message.Data.FEntrys {
var isInsp int
if entry.CFIsInsp {
isInsp = 1
} else {
isInsp = 0
}
outStoreDetail = append(outStoreDetail, map[string]interface{}{
"erp_goods_id": entry.FMaterialID,
"goods_name": entry.FModel,
......
......@@ -36,6 +36,19 @@ func main() {
"FGoods": "集成电路",
"FUnit": "个",
},
{
"FQty": 9,
"FIsRecordLotAndDC": false,
"FOriginCountry": "502",
"FIsPrint": false,
"CFIsInsp": true,
"FMaterialID": "YscJMHmgT1+Yh6EWN343yEQJ5/A=",
"FBrand": "ON",
"FSourceBillEntryID": "gHw/y6EQRBmCpLGDFkdJCO0oFFw=",
"FModel": "1abaaba",
"FGoods": "集成电路",
"FUnit": "个",
},
},
},
}
......
......@@ -4,7 +4,6 @@ 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"
......@@ -24,12 +23,9 @@ type QueueStatus struct {
ErpId string
}
func init() {
log.Init(nil)
}
func (t *RecvPro) Consumer(dataByte []byte) (err error) {
func (t *RecvPro) Consumer(dataByte []byte) error {
var (
err error
message QueueStatus
syncStatusLog model.SyncStatusLog
)
......@@ -50,7 +46,9 @@ ERR:
//如果失败了,记录到表,并且发送钉钉消息
if err = logic.InsertSyncStatusLog(syncStatusLog); err != nil {
service.SendDingTalkRobotToApi(err.Error())
logic.LogError(err.Error())
}
logic.LogError(syncStatusLog.SyncError)
service.SendDingTalkRobotToApi(syncStatusLog.SyncError)
return nil
}
......
......@@ -77,7 +77,6 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
if err = SyncSupplierData(operateType, supplier); err != nil {
goto ERR
}
fmt.Println("同步成功,开始发送金蝶状态同步")
if err = product.SyncErpStatus("supplier", supplier.ErpId); err != nil {
goto ERR
}
......@@ -143,7 +142,7 @@ func SyncSupplierData(operate string, supplier model.Supplier) (err error) {
}
}
//都没问题,代表后端那边已经成功修改,修改同步表的状态
if err = logic.SyncCustomerSuccess(supplier.ErpId); err != nil {
if err = logic.SyncSupplierSuccess(supplier.ErpId); err != nil {
return
}
return
......
......@@ -8,9 +8,9 @@ database = lie_scm_sync
url = "amqp://huntadmin:jy2y2900@192.168.1.237:5672/"
[api]
base = http://192.168.2.113:40001
base = http://192.168.2.232:40001
out_store = http://192.168.2.179:40003
in_store = http://192.168.2.239:40004
in_store = http://192.168.2.232:40004
erp_sync_base_data_status = http://192.168.2.253:6888/ormrpc/services/WSInventoryManagementFacade?wsdl
erp_sync_bill_status = http://192.168.2.253:6888/ormrpc/services/WSInventoryManagementFacade?wsdl
erp_login_status = http://192.168.2.253:6888/ormrpc/services/EASLogin?wsdl
......
......@@ -6,9 +6,9 @@ import (
)
//插入金蝶同步状态错误信息
const InsertAuditStatusLogSql = "INSERT INTO `lie_audit_status_log` ( `sync_name` , `unique_id` , `sync_error` , `add_time` ) VALUE (?,?,?,?)"
const InsertAuditStatusLogSql = "INSERT INTO `lie_audit_status_log` ( `sync_name` , `queue_message` , `unique_id` , `sync_error` , `add_time` ) VALUE (?,?,?,?,?)"
func InsertAuditStatusLog(auditStatusLog model.AuditStatusLog) (err error) {
_, err = dao.GetDb().Exec(InsertAuditStatusLogSql, auditStatusLog.SyncName, auditStatusLog.UniqueId, auditStatusLog.SyncError, auditStatusLog.AddTime)
_, err = dao.GetDb().Exec(InsertAuditStatusLogSql, auditStatusLog.SyncName, auditStatusLog.QueueMessage, auditStatusLog.UniqueId, auditStatusLog.SyncError, auditStatusLog.AddTime)
return
}
......@@ -20,12 +20,21 @@ const SyncInStoreSuccessSqlWithStatus = "UPDATE `lie_in_store` SET sync_status =
const SyncInStoreErpSuccessSql = "UPDATE `lie_in_store` SET sync_erp_status = 1 , sync_time = ? WHERE bill_id = ?"
const SyncInStoreErpAuditSuccessSql = "UPDATE `lie_in_store` SET sync_erp_audit_status = 1 , sync_time = ? WHERE bill_id = ?"
//修改同步到erp成功的状态
func SyncInStoreErpSuccess(billId string) (err error) {
_, err = dao.GetDb().Exec(SyncInStoreErpSuccessSql, time.Now().Unix(), billId)
return
}
//修改审核状态同步到erp成功的状态
func SyncInStoreErpAuditSuccess(billId string) (err error) {
_, err = dao.GetDb().Exec(SyncInStoreErpAuditSuccessSql, time.Now().Unix(), billId)
return
}
//检查出库是否存在
func CheckInStoreExist(billId string) (exist bool) {
var inStoreId int
......
......@@ -22,6 +22,8 @@ const SyncOutStoreSuccessSqlWithStatus = "UPDATE `lie_out_store` SET sync_status
const SyncOutStoreErpSuccessSql = "UPDATE `lie_out_store` SET sync_erp_status = 1 , sync_time = ? WHERE bill_id = ?"
const SyncOutStoreErpAuditSuccessSql = "UPDATE `lie_out_store` SET sync_erp_audit_status = 1 , sync_time = ? WHERE bill_id = ?"
//修改同步到erp成功的状态
func SyncOutStoreErpSuccess(billId string) (err error) {
_, err = dao.GetDb().Exec(SyncOutStoreErpSuccessSql, time.Now().Unix(), billId)
......@@ -55,9 +57,9 @@ func DeleteOutStore(outStore model.OutStore) (err error) {
return
}
//写入同步失败的原因
func WriteOutStoreSyncError(erpId string, syncError string) (err error) {
_, err = dao.GetDb().Exec(WriteOutStoreSyncErrorSql, syncError, erpId)
//修改审核状态同步到erp成功的状态
func SyncOutStoreErpAuditSuccess(billId string) (err error) {
_, err = dao.GetDb().Exec(SyncOutStoreErpAuditSuccessSql, time.Now().Unix(), billId)
return
}
......
......@@ -23,6 +23,11 @@ func InsertSyncLog(syncLog model.SyncLog) (err error) {
return err
}
func LogError(msg string) {
//保存日志
logs.Error(fmt.Sprintf("%s", msg))
}
func DealSyncError(dataByte []byte, uniqueId, syncName string, err error) error {
//还要存到一个统一错误表
syncLog := model.SyncLog{
......
......@@ -3,6 +3,7 @@ package model
type AuditStatusLog struct {
SyncName string
SyncError string
QueueMessage string
UniqueId string
AddTime int64
}
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"
......@@ -10,6 +9,8 @@ import (
"scm_server/cmd/queue/sync_supplier"
"scm_server/configs"
"time"
"github.com/imroc/req"
)
type PayloadItem struct {
......@@ -38,7 +39,7 @@ func pushAlive() {
Step: 60,
CounterType: "GAUGE",
Value: float64(time.Now().Unix()),
Tags: "store_sync",
Tags: "service=store_sync",
}
payload = append(payload, item)
param := req.BodyJSON(&payload)
......@@ -57,10 +58,10 @@ 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()
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