Commit 2e1f6f44 by mushishixian

出库同步

parent 98f9e835
......@@ -55,7 +55,6 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
switch message.Type {
case "save":
//先去查询是否存在,不存在才去插入,已经存在即是修改
fmt.Println(goods.ErpId)
if logic.CheckGoodsExist(goods.ErpId) {
operateType = "update"
if err = logic.UpdateGoods(goods); err != nil {
......
......@@ -78,10 +78,7 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
}
inStore.QueueMessage = string(messageData)
//先去查询是否存在,不存在才去插入,已经存在即是修改
if logic.CheckInStoreExist(inStore.BillId) {
err = errors.New("试图新增已存在的入货单,单号为" + message.Data.FSourceBillID)
goto ERR
} else {
if !logic.CheckInStoreExist(inStore.BillId) {
operateType = "insert"
if err = logic.InsertInStore(inStore); err != nil {
fmt.Println(err)
......
......@@ -2,11 +2,11 @@ package main
import (
"encoding/json"
"errors"
"fmt"
"github.com/go-kratos/kratos/pkg/log"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"github.com/imroc/req"
"github.com/pkg/errors"
"scm_server/cmd/queue/sync_status/product"
"scm_server/configs"
"scm_server/internal/common"
......@@ -56,12 +56,12 @@ func init() {
func (t *RecvPro) Consumer(dataByte []byte) error {
var (
message OutStoreMessage
err error
outStore model.OutStore
operateType string
syncLog model.SyncLog
msg []byte
message OutStoreMessage
err error
outStore model.OutStore
operateType string
syncLog model.SyncLog
msg, messageData []byte
)
//先去转换队列消息的json,如果失败,记录起来
if err = json.Unmarshal(dataByte, &message); err != nil {
......@@ -72,20 +72,15 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
switch message.Type {
case "save":
outStore.BillId = message.Data.FSourceBillID
messageData, err := json.Marshal(&message)
messageData, err = json.Marshal(&message)
if err != nil {
goto ERR
}
outStore.QueueMessage = string(messageData)
//先去查询是否存在,不存在才去插入,已经存在即是修改
if logic.CheckOutStoreExist(outStore.BillId) {
err = errors.New("试图新增已存在的出货单,单号为" + message.Data.FSourceBillID)
goto ERR
} else {
if !logic.CheckOutStoreExist(outStore.BillId) {
operateType = "insert"
if err = logic.InsertOutStore(outStore); err != nil {
fmt.Println(err)
//todo:错误原因会消失
goto ERR
}
}
......@@ -110,7 +105,9 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
goto ERR
}
fmt.Println("同步成功,开始发送金蝶状态同步")
product.SyncErpStatus("out_store", outStore.BillId)
if err = product.SyncErpStatus("out_store", outStore.BillId); err != nil {
goto ERR
}
return nil
ERR:
//不存在的billId不去操作对应的数据库
......@@ -160,7 +157,7 @@ func SyncOutStoreData(operate string, message OutStoreMessage) (err error) {
} else {
url = configs.OutStoreApiUrl + ""
}
req.Debug = false
req.Debug = true
billId := message.Data.FSourceBillID
if operate == "insert" {
resp, err = req.Post(url, param)
......@@ -170,9 +167,9 @@ func SyncOutStoreData(operate string, message OutStoreMessage) (err error) {
if err = resp.ToJSON(&respData); err != nil {
return
}
if respData.Errcode != 101100 {
paramJson, _ := json.Marshal(param)
return errors.New(fmt.Sprintf("请求后端接口返回失败,接口链接为%s,请求参数为%s,返回的错误信息为%s", url, string(paramJson), respData.Errmsg))
if respData.Errcode != 0 {
paramJson, _ := json.Marshal(params)
return errors.New(fmt.Sprintf("请求后端接口返回失败,接口链接为%s,请求参数为%s,返回的错误信息为%s", url, string(paramJson), respData.Data))
}
//都没问题,代表后端那边已经成功修改,修改同步表的状态
if err = logic.SyncOutStoreSuccess(billId, false); err != nil {
......@@ -196,15 +193,21 @@ func TransformParams(message OutStoreMessage) (params map[string]interface{}) {
entry OutStoreFEntrys
outStoreDetail []map[string]interface{}
)
var isInsp int
if entry.CFIsInsp {
isInsp = 1
} else {
isInsp = 0
}
params = make(map[string]interface{})
for _, entry = range message.Data.FEntrys {
outStoreDetail = append(outStoreDetail, map[string]interface{}{
"erp_entry_sn": entry.FSourceBillEntryID,
"erp_goods_id": entry.FMaterialID,
"goods_name": entry.FGoods,
"brand_name": entry.FBrand,
"number": entry.FQty,
"goods_unit": entry.FUnit,
"is_insp": entry.CFIsInsp,
"is_insp": isInsp,
})
}
var isApplyCustoms int
......@@ -218,9 +221,10 @@ func TransformParams(message OutStoreMessage) (params map[string]interface{}) {
"receive_user_name": message.Data.FRecPerson,
"receive_tel": message.Data.FRecPersonContact,
//缺一个原始单据id
"erp_in_store_id": message.Data.FSourceBillID,
"erp_client_sn": message.Data.FPrincipalNo,
"remark": message.Data.Remark,
"erp_in_store_id": message.Data.FWarehouseNo,
"erp_store_sn": message.Data.FWarehouseNo,
"warehousing_sn": message.Data.FEntrustBillNo,
"is_apply_customs": isApplyCustoms,
"out_store_detail": outStoreDetail,
......
......@@ -12,9 +12,9 @@ func main() {
"type": "save",
"data": map[string]interface{}{
"FWarehouseNo": "002",
"FEntrustBillNo": "B05364",
"FEntrustBillNo": "B0536495123",
"FErpPurInWorehouseNo": "FKSH202003107482",
"FSourceBillID": "+7fvorsZSAevQCJ7ujsbLMBZJbY=",
"FSourceBillID": "+7fvorsZSAevQCJ7ujsbLMBZJbY=551",
"CFIsInsp": false,
"FPrincipalNo": "WT00268",
"FBizType": "执行采购",
......@@ -26,7 +26,7 @@ func main() {
"FOriginCountry": "502",
"FIsPrint": false,
"CFIsInsp": false,
"FMaterialID": "9l++jtj+RNS2VpdFhzcRE0QJ5/A=",
"FMaterialID": "YscJMHmgT1+Yh6EWN343yEQJ5/A=",
"FBrand": "ON",
"FSourceBillEntryID": "gHw/y6EQRBmCpLGDFkdJCO0oFFw=",
"FModel": "1abaaba",
......
......@@ -136,6 +136,16 @@ func SyncErpDataStatus(syncName, uniqueId string) (err error) {
if err != nil {
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()
if err = doc.ReadFromBytes(res.Body); err != nil {
return
......@@ -147,16 +157,47 @@ func SyncErpDataStatus(syncName, uniqueId string) (err error) {
}
result := root.SelectElement("synRewriteErpBaseDataStatusReturn")
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)
for key, _ := range responseData {
for key, value := range responseData {
//金蝶判断成功的标志
if key == "0000" {
return
}
//金额判断失败的标志
if key == "4444" {
return errors.New("金蝶返回失败")
return errors.New("金蝶返回失败,失败信息为:" + value)
}
}
}
......
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
import "scm_server/cmd/source/goods"
import "scm_server/cmd/source/customer"
func main() {
//forever := make(chan bool)
......@@ -8,6 +8,6 @@ func main() {
//go supplier.Import()
//supplier.Import()
//<-forever
//customer.Import()
goods.Import()
customer.Import()
//goods.Import()
}
......@@ -6,17 +6,17 @@ import (
"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 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 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) {
......
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