Commit 2e1f6f44 by mushishixian

出库同步

parent 98f9e835
...@@ -55,7 +55,6 @@ func (t *RecvPro) Consumer(dataByte []byte) error { ...@@ -55,7 +55,6 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
switch message.Type { switch message.Type {
case "save": case "save":
//先去查询是否存在,不存在才去插入,已经存在即是修改 //先去查询是否存在,不存在才去插入,已经存在即是修改
fmt.Println(goods.ErpId)
if logic.CheckGoodsExist(goods.ErpId) { if logic.CheckGoodsExist(goods.ErpId) {
operateType = "update" operateType = "update"
if err = logic.UpdateGoods(goods); err != nil { if err = logic.UpdateGoods(goods); err != nil {
......
...@@ -78,10 +78,7 @@ func (t *RecvPro) Consumer(dataByte []byte) error { ...@@ -78,10 +78,7 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
} }
inStore.QueueMessage = string(messageData) inStore.QueueMessage = string(messageData)
//先去查询是否存在,不存在才去插入,已经存在即是修改 //先去查询是否存在,不存在才去插入,已经存在即是修改
if logic.CheckInStoreExist(inStore.BillId) { if !logic.CheckInStoreExist(inStore.BillId) {
err = errors.New("试图新增已存在的入货单,单号为" + message.Data.FSourceBillID)
goto ERR
} else {
operateType = "insert" operateType = "insert"
if err = logic.InsertInStore(inStore); err != nil { if err = logic.InsertInStore(inStore); err != nil {
fmt.Println(err) fmt.Println(err)
......
...@@ -2,11 +2,11 @@ package main ...@@ -2,11 +2,11 @@ package main
import ( import (
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"github.com/go-kratos/kratos/pkg/log" "github.com/go-kratos/kratos/pkg/log"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq" "github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"github.com/imroc/req" "github.com/imroc/req"
"github.com/pkg/errors"
"scm_server/cmd/queue/sync_status/product" "scm_server/cmd/queue/sync_status/product"
"scm_server/configs" "scm_server/configs"
"scm_server/internal/common" "scm_server/internal/common"
...@@ -56,12 +56,12 @@ func init() { ...@@ -56,12 +56,12 @@ func init() {
func (t *RecvPro) Consumer(dataByte []byte) error { func (t *RecvPro) Consumer(dataByte []byte) error {
var ( var (
message OutStoreMessage message OutStoreMessage
err error err error
outStore model.OutStore outStore model.OutStore
operateType string operateType string
syncLog model.SyncLog syncLog model.SyncLog
msg []byte msg, messageData []byte
) )
//先去转换队列消息的json,如果失败,记录起来 //先去转换队列消息的json,如果失败,记录起来
if err = json.Unmarshal(dataByte, &message); err != nil { if err = json.Unmarshal(dataByte, &message); err != nil {
...@@ -72,20 +72,15 @@ func (t *RecvPro) Consumer(dataByte []byte) error { ...@@ -72,20 +72,15 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
switch message.Type { switch message.Type {
case "save": case "save":
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 {
goto ERR goto ERR
} }
outStore.QueueMessage = string(messageData) outStore.QueueMessage = string(messageData)
//先去查询是否存在,不存在才去插入,已经存在即是修改 //先去查询是否存在,不存在才去插入,已经存在即是修改
if logic.CheckOutStoreExist(outStore.BillId) { if !logic.CheckOutStoreExist(outStore.BillId) {
err = errors.New("试图新增已存在的出货单,单号为" + message.Data.FSourceBillID)
goto ERR
} else {
operateType = "insert" operateType = "insert"
if err = logic.InsertOutStore(outStore); err != nil { if err = logic.InsertOutStore(outStore); err != nil {
fmt.Println(err)
//todo:错误原因会消失
goto ERR goto ERR
} }
} }
...@@ -110,7 +105,9 @@ func (t *RecvPro) Consumer(dataByte []byte) error { ...@@ -110,7 +105,9 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
goto ERR goto ERR
} }
fmt.Println("同步成功,开始发送金蝶状态同步") fmt.Println("同步成功,开始发送金蝶状态同步")
product.SyncErpStatus("out_store", outStore.BillId) if err = product.SyncErpStatus("out_store", outStore.BillId); err != nil {
goto ERR
}
return nil return nil
ERR: ERR:
//不存在的billId不去操作对应的数据库 //不存在的billId不去操作对应的数据库
...@@ -160,7 +157,7 @@ func SyncOutStoreData(operate string, message OutStoreMessage) (err error) { ...@@ -160,7 +157,7 @@ func SyncOutStoreData(operate string, message OutStoreMessage) (err error) {
} else { } else {
url = configs.OutStoreApiUrl + "" url = configs.OutStoreApiUrl + ""
} }
req.Debug = false req.Debug = true
billId := message.Data.FSourceBillID billId := message.Data.FSourceBillID
if operate == "insert" { if operate == "insert" {
resp, err = req.Post(url, param) resp, err = req.Post(url, param)
...@@ -170,9 +167,9 @@ func SyncOutStoreData(operate string, message OutStoreMessage) (err error) { ...@@ -170,9 +167,9 @@ func SyncOutStoreData(operate string, message OutStoreMessage) (err error) {
if err = resp.ToJSON(&respData); err != nil { if err = resp.ToJSON(&respData); err != nil {
return return
} }
if respData.Errcode != 101100 { if respData.Errcode != 0 {
paramJson, _ := json.Marshal(param) paramJson, _ := json.Marshal(params)
return errors.New(fmt.Sprintf("请求后端接口返回失败,接口链接为%s,请求参数为%s,返回的错误信息为%s", url, string(paramJson), respData.Errmsg)) return errors.New(fmt.Sprintf("请求后端接口返回失败,接口链接为%s,请求参数为%s,返回的错误信息为%s", url, string(paramJson), respData.Data))
} }
//都没问题,代表后端那边已经成功修改,修改同步表的状态 //都没问题,代表后端那边已经成功修改,修改同步表的状态
if err = logic.SyncOutStoreSuccess(billId, false); err != nil { if err = logic.SyncOutStoreSuccess(billId, false); err != nil {
...@@ -196,15 +193,21 @@ func TransformParams(message OutStoreMessage) (params map[string]interface{}) { ...@@ -196,15 +193,21 @@ func TransformParams(message OutStoreMessage) (params map[string]interface{}) {
entry OutStoreFEntrys entry OutStoreFEntrys
outStoreDetail []map[string]interface{} outStoreDetail []map[string]interface{}
) )
var isInsp int
if entry.CFIsInsp {
isInsp = 1
} else {
isInsp = 0
}
params = make(map[string]interface{}) params = make(map[string]interface{})
for _, entry = range message.Data.FEntrys { for _, entry = range message.Data.FEntrys {
outStoreDetail = append(outStoreDetail, map[string]interface{}{ outStoreDetail = append(outStoreDetail, map[string]interface{}{
"erp_entry_sn": entry.FSourceBillEntryID, "erp_goods_id": entry.FMaterialID,
"goods_name": entry.FGoods, "goods_name": entry.FGoods,
"brand_name": entry.FBrand, "brand_name": entry.FBrand,
"number": entry.FQty, "number": entry.FQty,
"goods_unit": entry.FUnit, "goods_unit": entry.FUnit,
"is_insp": entry.CFIsInsp, "is_insp": isInsp,
}) })
} }
var isApplyCustoms int var isApplyCustoms int
...@@ -218,9 +221,10 @@ func TransformParams(message OutStoreMessage) (params map[string]interface{}) { ...@@ -218,9 +221,10 @@ func TransformParams(message OutStoreMessage) (params map[string]interface{}) {
"receive_user_name": message.Data.FRecPerson, "receive_user_name": message.Data.FRecPerson,
"receive_tel": message.Data.FRecPersonContact, "receive_tel": message.Data.FRecPersonContact,
//缺一个原始单据id //缺一个原始单据id
"erp_in_store_id": message.Data.FSourceBillID,
"erp_client_sn": message.Data.FPrincipalNo, "erp_client_sn": message.Data.FPrincipalNo,
"remark": message.Data.Remark, "remark": message.Data.Remark,
"erp_in_store_id": message.Data.FWarehouseNo, "erp_store_sn": message.Data.FWarehouseNo,
"warehousing_sn": message.Data.FEntrustBillNo, "warehousing_sn": message.Data.FEntrustBillNo,
"is_apply_customs": isApplyCustoms, "is_apply_customs": isApplyCustoms,
"out_store_detail": outStoreDetail, "out_store_detail": outStoreDetail,
......
...@@ -12,9 +12,9 @@ func main() { ...@@ -12,9 +12,9 @@ func main() {
"type": "save", "type": "save",
"data": map[string]interface{}{ "data": map[string]interface{}{
"FWarehouseNo": "002", "FWarehouseNo": "002",
"FEntrustBillNo": "B05364", "FEntrustBillNo": "B0536495123",
"FErpPurInWorehouseNo": "FKSH202003107482", "FErpPurInWorehouseNo": "FKSH202003107482",
"FSourceBillID": "+7fvorsZSAevQCJ7ujsbLMBZJbY=", "FSourceBillID": "+7fvorsZSAevQCJ7ujsbLMBZJbY=551",
"CFIsInsp": false, "CFIsInsp": false,
"FPrincipalNo": "WT00268", "FPrincipalNo": "WT00268",
"FBizType": "执行采购", "FBizType": "执行采购",
...@@ -26,7 +26,7 @@ func main() { ...@@ -26,7 +26,7 @@ func main() {
"FOriginCountry": "502", "FOriginCountry": "502",
"FIsPrint": false, "FIsPrint": false,
"CFIsInsp": false, "CFIsInsp": false,
"FMaterialID": "9l++jtj+RNS2VpdFhzcRE0QJ5/A=", "FMaterialID": "YscJMHmgT1+Yh6EWN343yEQJ5/A=",
"FBrand": "ON", "FBrand": "ON",
"FSourceBillEntryID": "gHw/y6EQRBmCpLGDFkdJCO0oFFw=", "FSourceBillEntryID": "gHw/y6EQRBmCpLGDFkdJCO0oFFw=",
"FModel": "1abaaba", "FModel": "1abaaba",
......
...@@ -136,6 +136,16 @@ func SyncErpDataStatus(syncName, uniqueId string) (err error) { ...@@ -136,6 +136,16 @@ func SyncErpDataStatus(syncName, uniqueId string) (err error) {
if err != nil { if err != nil {
return return
} }
if apiMethod == "synRewriteErpBaseDataStatus" {
return CheckBaseDataRequest(res)
} else if apiMethod == "synErpInventoryStatus" {
return CheckBillDataRequest(res)
}
return
}
//坚持基础物料的修改状态情况
func CheckBaseDataRequest(res *gosoap.Response) (err error) {
doc := etree.NewDocument() doc := etree.NewDocument()
if err = doc.ReadFromBytes(res.Body); err != nil { if err = doc.ReadFromBytes(res.Body); err != nil {
return return
...@@ -147,16 +157,47 @@ func SyncErpDataStatus(syncName, uniqueId string) (err error) { ...@@ -147,16 +157,47 @@ func SyncErpDataStatus(syncName, uniqueId string) (err error) {
} }
result := root.SelectElement("synRewriteErpBaseDataStatusReturn") result := root.SelectElement("synRewriteErpBaseDataStatusReturn")
if result != nil { if result != nil {
var responseData map[string]interface{} var responseData map[string]string
json.Unmarshal([]byte(result.Text()), &responseData)
for key, value := range responseData {
//金蝶判断成功的标志
if key == "0000" {
return
}
//金额判断失败的标志
if key == "4444" {
return errors.New("金蝶返回失败,失败信息为:" + value)
}
}
}
return errors.New("金蝶返回响应格式无法识别")
}
//检查出入库单的情况
func CheckBillDataRequest(res *gosoap.Response) (err error) {
fmt.Println("checkBillStatus")
doc := etree.NewDocument()
if err = doc.ReadFromBytes(res.Body); err != nil {
return
}
//没有这个xml节点代表金蝶报错了
root := doc.SelectElement("ns1:synErpInventoryStatusResponse")
fmt.Println(root)
if root == nil {
return errors.New(string(res.Body))
}
result := root.SelectElement("synErpInventoryStatusReturn")
if result != nil {
var responseData map[string]string
json.Unmarshal([]byte(result.Text()), &responseData) json.Unmarshal([]byte(result.Text()), &responseData)
for key, _ := range responseData { for key, value := range responseData {
//金蝶判断成功的标志 //金蝶判断成功的标志
if key == "0000" { if key == "0000" {
return return
} }
//金额判断失败的标志 //金额判断失败的标志
if key == "4444" { if key == "4444" {
return errors.New("金蝶返回失败") return errors.New("金蝶返回失败,失败信息为:" + value)
} }
} }
} }
......
package main package main
import (
"encoding/json"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
)
func main(){
//{"FType":"out_store", "FID":"+7fvorsZSAevQCJ7ujsbLMBZJbY=121"}
message := make(map[string]interface{})
message = map[string]interface{}{
"SyncName": "out_store",
"Status": 1,
"ErpId": "+7fvorsZSAevQCJ7ujsbLMBZJbY=121",
}
data, err := json.Marshal(message)
if err != nil {
return
}
body := string(data)
queueExchange := rabbitmq.QueueExchange{
"store_sync_status",
"store_sync_status",
"store",
"direct",
"amqp://huntadmin:jy2y2900@192.168.1.237:5672/",
}
rabbitmq.Send(queueExchange, body)
}
\ No newline at end of file
package main package main
import "scm_server/cmd/source/goods" import "scm_server/cmd/source/customer"
func main() { func main() {
//forever := make(chan bool) //forever := make(chan bool)
...@@ -8,6 +8,6 @@ func main() { ...@@ -8,6 +8,6 @@ func main() {
//go supplier.Import() //go supplier.Import()
//supplier.Import() //supplier.Import()
//<-forever //<-forever
//customer.Import() customer.Import()
goods.Import() //goods.Import()
} }
...@@ -6,17 +6,17 @@ import ( ...@@ -6,17 +6,17 @@ import (
"time" "time"
) )
const CheckOutStoreExistSql = "SELECT goods_id FROM lie_out_store WHERE erp_id = ? AND sync_status = 1" const CheckOutStoreExistSql = "SELECT out_store_id FROM lie_out_store WHERE bill_id = ?"
const InsertOutStoreSql = "INSERT INTO `lie_out_store` (`queue_message`,`bill_id`,`add_time`) VALUES (?,?,?)" 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 DeleteOutStoreSql = "UPDATE `lie_out_store` SET `status` = ? , `update_time` = ? WHERE `bill_id` = ?"
const WriteOutStoreSyncErrorSql = "UPDATE `lie_out_store` SET sync_error = ? WHERE bill_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 SyncOutStoreSuccessSql = "UPDATE `lie_out_store` SET sync_status = 1 , sync_time = ? WHERE bill_id = ?"
const SyncOutStoreSuccessSqlWithStatus = "UPDATE `lie_out_store` SET sync_status = 1 , sync_time = ? , status = ? WHERE erp_id = ?" const SyncOutStoreSuccessSqlWithStatus = "UPDATE `lie_out_store` SET sync_status = 1 , sync_time = ? , status = ? WHERE bill_id = ?"
//检查出库是否存在 //检查出库是否存在
func CheckOutStoreExist(erpId string) (exist bool) { func CheckOutStoreExist(erpId string) (exist bool) {
......
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