Commit 98f9e835 by mushishixian

修改逻辑

parent db55cfbb
...@@ -19,7 +19,7 @@ func main() { ...@@ -19,7 +19,7 @@ func main() {
message = map[string]interface{}{ message = map[string]interface{}{
"type": "save", "type": "save",
"data": map[string]string{ "data": map[string]string{
"FID": "Bg/8bD0XRdayeQFMFsSgY6gYZf0=", "FID": "Bg/8bD0XRdayeQFMFsSgY6gYZf0=111",
"FNUMBER": "WT00013", "FNUMBER": "WT00013",
"CFNAME": "深圳市肯特尔科技有限公司", "CFNAME": "深圳市肯特尔科技有限公司",
}, },
......
...@@ -88,7 +88,7 @@ func (t *RecvPro) Consumer(dataByte []byte) error { ...@@ -88,7 +88,7 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
goto ERR goto ERR
} }
fmt.Println("同步成功,开始发送金蝶状态同步") fmt.Println("同步成功,开始发送金蝶状态同步")
if err = product.SyncErpStatus("goods", goods.ErpId); err != nil { if err = product.SyncErpStatus("material", goods.ErpId); err != nil {
goto ERR goto ERR
} }
return nil return nil
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
func main() { func main() {
message := make(map[string]interface{}) message := make(map[string]interface{})
message = map[string]interface{}{ message = map[string]interface{}{
"type": "save", "type": "delete",
"data": map[string]string{ "data": map[string]string{
"FID": "BUqVwVoBTRm/BY9kIKL7fEQJ5/A=", "FID": "BUqVwVoBTRm/BY9kIKL7fEQJ5/A=",
"FGoods": "光电耦合器", "FGoods": "光电耦合器",
......
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"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"
"scm_server/cmd/queue/sync_status/product"
"scm_server/configs" "scm_server/configs"
"scm_server/internal/common" "scm_server/internal/common"
"scm_server/internal/logic" "scm_server/internal/logic"
...@@ -28,11 +29,13 @@ type InStoreMessage struct { ...@@ -28,11 +29,13 @@ type InStoreMessage struct {
CFIsInsp bool CFIsInsp bool
FPrincipalNo string FPrincipalNo string
FBizType string FBizType string
FEntrys InStoreFEntry FIsCustoms bool
FSupplierNo string
FEntrys []InStoreFEntrys
} }
} }
type InStoreFEntry struct { type InStoreFEntrys struct {
FQty int FQty int
FIsRecordLotAndDC bool FIsRecordLotAndDC bool
FOriginCountry string FOriginCountry string
...@@ -55,60 +58,64 @@ func (t *RecvPro) Consumer(dataByte []byte) error { ...@@ -55,60 +58,64 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
var ( var (
message InStoreMessage message InStoreMessage
err error err error
supplier model.Supplier inStore model.InStore
operateType string operateType string
syncLog model.SyncLog syncLog model.SyncLog
msg []byte
) )
//先去转换队列消息的json,如果失败,记录起来 //先去转换队列消息的json,如果失败,记录起来
if err = json.Unmarshal(dataByte, &message); err != nil { if err = json.Unmarshal(dataByte, &message); err != nil {
goto ERR goto ERR
} }
//转换成supplier数据
supplier.ErpId = message.Data.FID
supplier.ErpSupplierCode = message.Data.FNUMBER
supplier.Name = message.Data.CFNAME
//判断操作类型 //判断操作类型
switch message.Type { switch message.Type {
case "save": case "save":
inStore.BillId = message.Data.FSourceBillID
messageData, err := json.Marshal(&message)
if err != nil {
goto ERR
}
inStore.QueueMessage = string(messageData)
//先去查询是否存在,不存在才去插入,已经存在即是修改 //先去查询是否存在,不存在才去插入,已经存在即是修改
if logic.CheckSupplierExist(supplier.ErpId) { if logic.CheckInStoreExist(inStore.BillId) {
operateType = "update" err = errors.New("试图新增已存在的入货单,单号为" + message.Data.FSourceBillID)
if err = logic.UpdateSupplier(supplier); err != nil { goto ERR
goto ERR
}
} else { } else {
operateType = "insert" operateType = "insert"
if err = logic.InsertSupplier(supplier); err != nil { if err = logic.InsertInStore(inStore); err != nil {
fmt.Println(err)
//todo:错误原因会消失
goto ERR goto ERR
} }
} }
case "delete": case "delete":
operateType = "delete" operateType = "delete"
supplier.Status = 0 inStore.Status = 0
if logic.CheckSupplierExist(supplier.ErpId) { if logic.CheckInStoreExist(inStore.BillId) {
//如果存在,才进行删除 //如果存在,才进行删除
if err = logic.DeleteSupplier(supplier); err != nil { if err = logic.DeleteInStore(inStore); err != nil {
goto ERR goto ERR
} }
} else { } else {
err = errors.New("试图删除不存在的供应商") err = errors.New("试图删除不存在的入货单")
goto ERR goto ERR
} }
default: default:
err = errors.New("同步供应商出现不存在的操作类型") err = errors.New("同步入货单出现不存在的操作类型")
goto ERR goto ERR
} }
//操作成功后还要去请求后端接口同步数据 //操作成功后还要去请求后端接口同步数据
if err = SyncSupplierData(operateType, supplier); err != nil { if err = SyncInStoreData(operateType, message); err != nil {
goto ERR goto ERR
} }
fmt.Println("同步成功") fmt.Println("同步成功,开始发送金蝶状态同步")
product.SyncErpStatus("out_store", inStore.BillId)
return nil return nil
ERR: ERR:
//不存在的erp_id不去操作对应的数据库 //不存在的billId不去操作对应的数据库
if supplier.ErpId != "" { if inStore.BillId != "" {
logSyncErrorToSupplier(supplier.ErpId, err.Error()) logSyncErrorToInStore(inStore.BillId, err.Error())
} }
//还要存到一个统一错误表 //还要存到一个统一错误表
...@@ -116,13 +123,13 @@ ERR: ...@@ -116,13 +123,13 @@ ERR:
AddTime: time.Now().Unix(), AddTime: time.Now().Unix(),
SyncTime: time.Now().Unix(), SyncTime: time.Now().Unix(),
QueueMessage: string(dataByte), QueueMessage: string(dataByte),
UniqueId: supplier.ErpId, //有可能为 UniqueId: inStore.BillId, //有可能为
SyncError: err.Error(), SyncError: err.Error(),
SyncName: "supplier", SyncName: "inStore",
} }
logic.InsertSyncLog(syncLog) logic.InsertSyncLog(syncLog)
//发送钉钉错误消息 //发送钉钉错误消息
msg, _ := json.Marshal(syncLog) msg, _ = json.Marshal(syncLog)
service.SendMessage(common.ErrorSendPhone, string(msg)) service.SendMessage(common.ErrorSendPhone, string(msg))
//保存日志 //保存日志
...@@ -136,54 +143,24 @@ func (t *RecvPro) FailAction(dataByte []byte) error { ...@@ -136,54 +143,24 @@ func (t *RecvPro) FailAction(dataByte []byte) error {
} }
//同步数据 //同步数据
func SyncSupplierData(operate string, supplier model.Supplier) (err error) { func SyncInStoreData(operate string, message InStoreMessage) (err error) {
var ( var (
resp *req.Resp resp *req.Resp
url string url string
respData common.Response respData common.Response
params map[string]interface{}
) )
param := req.Param{ params = TransformParams(message)
"erp_supplier_sn": supplier.ErpSupplierCode,
"supplier_name": supplier.Name,
"erp_supplier_id": supplier.ErpId,
"admin_name": "系统",
"admin_id": 1,
}
//更新和插入接口不同 //更新和插入接口不同
if operate == "update" { if operate == "insert" {
url = configs.BasicApiUrl + "/basic/api/ApiUpdateSupplierInfo" url = configs.InStoreApiUrl + "/in_store/add"
} else if operate == "insert" {
url = configs.BasicApiUrl + "/basic/api/ApiInsertSupplierInfo"
} else { } else {
url = configs.BasicApiUrl + "/basic/api/ApiUpdateSupplierStatus" url = configs.InStoreApiUrl + ""
} }
req.Debug = false req.Debug = true
if operate == "update" || operate == "insert" { billId := message.Data.FSourceBillID
resp, err = req.Post(url, param) if operate == "insert" {
if err != nil { resp, err = req.Post(url, params)
return
}
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 err = logic.SyncSupplierSuccess(supplier.ErpId); err != nil {
return
}
} else {
param = req.Param{
"erp_supplier_id": supplier.ErpId,
"admin_name": "系统",
"admin_id": 1,
"status": 0,
}
//删除
resp, err = req.Post(url, param)
if err != nil { if err != nil {
return return
} }
...@@ -191,26 +168,75 @@ func SyncSupplierData(operate string, supplier model.Supplier) (err error) { ...@@ -191,26 +168,75 @@ func SyncSupplierData(operate string, supplier model.Supplier) (err error) {
return return
} }
if respData.Errcode != 101100 { if respData.Errcode != 101100 {
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.Errmsg))
} }
//都没问题,代表后端那边已经成功修改,修改同步表的状态 //都没问题,代表后端那边已经成功修改,修改同步表的状态
if err = logic.SyncCustomerSuccess(supplier.ErpId); err != nil { if err = logic.SyncInStoreSuccess(billId, false); err != nil {
return return
} }
} }
return return
} }
func logSyncErrorToSupplier(erpId, syncError string) { func logSyncErrorToInStore(erpId, syncError string) {
var err error var err error
//请求失败的话,将原因存起来 //请求失败的话,将原因存起来
if err = logic.WriteSupplierSyncError(erpId, syncError); err != nil { if err = logic.WriteInStoreSyncError(erpId, syncError); err != nil {
//数据库错误,发送警告 //数据库错误,发送警告
service.SendMessage(common.ErrorSendPhone, err.Error()) service.SendMessage(common.ErrorSendPhone, err.Error())
} }
} }
func TransformParams(message InStoreMessage) (params map[string]interface{}) {
var (
entry InStoreFEntrys
outStoreDetail map[string]interface{}
key int
detailPrefix string
detailMap map[string]interface{}
)
params = make(map[string]interface{})
outStoreDetail = make(map[string]interface{})
for key, entry = range message.Data.FEntrys {
detailPrefix = fmt.Sprintf("detail[%d][", key)
detailMap = map[string]interface{}{
detailPrefix + "erp_entry_sn]": entry.FSourceBillEntryID,
detailPrefix + "goods_erp_id]": entry.FMaterialID,
detailPrefix + "goods_name]": entry.FGoods,
detailPrefix + "brand_name]": entry.FBrand,
detailPrefix + "number]": entry.FQty,
detailPrefix + "country]": entry.FOriginCountry,
detailPrefix + "goods_unit]": entry.FUnit,
detailPrefix + "is_insp]": entry.CFIsInsp,
detailPrefix + "is_print]": entry.FIsPrint,
}
for k, v := range detailMap {
outStoreDetail[k] = v
}
}
var isInsp int
if message.Data.CFIsInsp {
isInsp = 1
} else {
isInsp = 0
}
params = map[string]interface{}{
//缺一个原始单据id
"receiving_sn": message.Data.FErpPurInWorehouseNo,
"warehousing_sn": message.Data.FEntrustBillNo,
"is_insp": isInsp,
"store_erp_id": message.Data.FWarehouseNo,
"customer_erp_id": message.Data.FPrincipalNo,
"supplier_erp_id": "LxYAAAABf9I3xn38",
"is_apply_customs": 1,
}
for k, v := range outStoreDetail {
params[k] = v
}
return
}
func main() { func main() {
t := &RecvPro{} t := &RecvPro{}
rabbitmq.Recv(rabbitmq.QueueExchange{ rabbitmq.Recv(rabbitmq.QueueExchange{
......
...@@ -16,7 +16,8 @@ func main() { ...@@ -16,7 +16,8 @@ func main() {
"FErpPurInWorehouseNo": "FKSH202003107482", "FErpPurInWorehouseNo": "FKSH202003107482",
"FSourceBillID": "+7fvorsZSAevQCJ7ujsbLMBZJbY=", "FSourceBillID": "+7fvorsZSAevQCJ7ujsbLMBZJbY=",
"CFIsInsp": false, "CFIsInsp": false,
"FPrincipalNo": "WT00268", "FPrincipalNo": "WT00018",
//"FPrincipalNo": "FIZXuVrXRCms51pqby5EVagYZf0=",
"FBizType": "执行采购", "FBizType": "执行采购",
"FEntrys": []map[string]interface{}{ "FEntrys": []map[string]interface{}{
{ {
...@@ -31,6 +32,8 @@ func main() { ...@@ -31,6 +32,8 @@ func main() {
"FModel": "1abaaba", "FModel": "1abaaba",
"FGoods": "集成电路", "FGoods": "集成电路",
"FUnit": "个", "FUnit": "个",
"FIsCustoms": true,
"FSupplierNo": "LxYAAAABgRI3xn38",
}, },
}, },
}, },
......
...@@ -27,6 +27,7 @@ type OutStoreMessage struct { ...@@ -27,6 +27,7 @@ type OutStoreMessage struct {
FIsCustoms bool FIsCustoms bool
FSourceBillID string //原始单据id FSourceBillID string //原始单据id
FRecPerson string FRecPerson string
FPrincipalNo string
FRecPersonContact string FRecPersonContact string
FRecPersonAddress string FRecPersonAddress string
Remark string Remark string
...@@ -198,7 +199,7 @@ func TransformParams(message OutStoreMessage) (params map[string]interface{}) { ...@@ -198,7 +199,7 @@ func TransformParams(message OutStoreMessage) (params map[string]interface{}) {
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.FMaterialID, "erp_entry_sn": entry.FSourceBillEntryID,
"goods_name": entry.FGoods, "goods_name": entry.FGoods,
"brand_name": entry.FBrand, "brand_name": entry.FBrand,
"number": entry.FQty, "number": entry.FQty,
...@@ -217,8 +218,9 @@ func TransformParams(message OutStoreMessage) (params map[string]interface{}) { ...@@ -217,8 +218,9 @@ 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_client_sn": message.Data.FPrincipalNo,
"remark": message.Data.Remark, "remark": message.Data.Remark,
"store_id": message.Data.FWarehouseNo, "erp_in_store_id": 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,
......
...@@ -98,24 +98,36 @@ func SyncErpDataStatus(syncName, uniqueId string) (err error) { ...@@ -98,24 +98,36 @@ func SyncErpDataStatus(syncName, uniqueId string) (err error) {
apiMethod string apiMethod string
) )
switch syncName { switch syncName {
case "goods": case "material":
apiUrl = configs.ErpSyncBaseDataStatusApi
apiMethod = "synRewriteErpBaseDataStatus"
break
case "supplier": case "supplier":
apiUrl = configs.ErpSyncBaseDataStatusApi
apiMethod = "synRewriteErpBaseDataStatus"
break
case "customer": case "customer":
apiUrl = configs.ErpSyncBaseDataStatusApi apiUrl = configs.ErpSyncBaseDataStatusApi
apiMethod = "synRewriteErpBaseDataStatus" apiMethod = "synRewriteErpBaseDataStatus"
break break
case "in_store": case "in_store":
apiUrl = configs.ErpSyncBillStatusApi
apiMethod = "synErpInventoryStatus"
break
case "out_store": case "out_store":
apiUrl = configs.ErpSyncBillStatusApi apiUrl = configs.ErpSyncBillStatusApi
apiMethod = "synErpInventoryStatus" apiMethod = "synErpInventoryStatus"
break break
default:
return errors.New("同步金蝶状态出现非法的同步类型" + syncName)
} }
fmt.Println(syncName)
fmt.Println(apiMethod)
fmt.Println(apiUrl)
soap, err = gosoap.SoapClient(apiUrl) soap, err = gosoap.SoapClient(apiUrl)
if err != nil { if err != nil {
return return
} }
//uniqueId = "++Mhf5K+T9KTEE+bJhM9PEQJ5/A="
//syncName = "material"
fmt.Println(fmt.Sprintf(`{"FType":"%s", "FID":"%s"}`, syncName, uniqueId)) fmt.Println(fmt.Sprintf(`{"FType":"%s", "FID":"%s"}`, syncName, uniqueId))
params = gosoap.ArrayParams{ params = gosoap.ArrayParams{
{"json", fmt.Sprintf(`{"FType":"%s", "FID":"%s"}`, syncName, uniqueId)}, {"json", fmt.Sprintf(`{"FType":"%s", "FID":"%s"}`, syncName, uniqueId)},
......
...@@ -11,6 +11,7 @@ require ( ...@@ -11,6 +11,7 @@ require (
github.com/jmoiron/sqlx v1.2.0 github.com/jmoiron/sqlx v1.2.0
github.com/mushishixian/gosoap v1.2.1-0.20200424081802-b11347c911bc github.com/mushishixian/gosoap v1.2.1-0.20200424081802-b11347c911bc
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/syyongx/php2go v0.9.4
github.com/tealeg/xlsx v1.0.5 github.com/tealeg/xlsx v1.0.5
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd // indirect golang.org/x/net v0.0.0-20200421231249-e086a090c8fd // indirect
) )
...@@ -235,6 +235,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf ...@@ -235,6 +235,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/syyongx/php2go v0.9.4 h1:qUtETTHzqHzxZK8plkbkb0YawD8bpLpxNsbzHQmb22Y=
github.com/syyongx/php2go v0.9.4/go.mod h1:meN2eIhhUoxOd2nMxbpe8g6cFPXI5O9/UAAuz7oDdzw=
github.com/tealeg/xlsx v1.0.5 h1:+f8oFmvY8Gw1iUXzPk+kz+4GpbDZPK1FhPiQRd+ypgE= github.com/tealeg/xlsx v1.0.5 h1:+f8oFmvY8Gw1iUXzPk+kz+4GpbDZPK1FhPiQRd+ypgE=
github.com/tealeg/xlsx v1.0.5/go.mod h1:btRS8dz54TDnvKNosuAqxrM1QgN1udgk9O34bDCnORM= github.com/tealeg/xlsx v1.0.5/go.mod h1:btRS8dz54TDnvKNosuAqxrM1QgN1udgk9O34bDCnORM=
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161/go.mod h1:wM7WEvslTq+iOEAMDLSzhVuOt5BRZ05WirO+b09GHQU= github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161/go.mod h1:wM7WEvslTq+iOEAMDLSzhVuOt5BRZ05WirO+b09GHQU=
......
package model package model
//{
// "receive_address": "万科星火online",
// "receive_user_name": "张三",
// "receive_tel": "13555556666",
// "unique": "ce0bdf3c0a3fc32843a20c2ad09f499e",
// "remark": "加糖",
// "store_id": "12",
// "customer_id": "213",
// "warehousing_sn": "1232131231",
// "is_apply_customs": "1",
// "is_insp": "1",
// "out_store_detail": [
// {
// "erp_entry_sn": "123",
// "is_apply_customs": "1",
// "goods_id": 13113,
// "goods_name": 2131,
// "brand_name": 213,
// "batch": "13",
// "dc": "dccc",
// "number": 100,
// "goods_unit": "美元",
// "is_insp": 1
// }
// ]
//}
type InStore struct { type InStore struct {
QueueMessage string QueueMessage string
BillId string BillId string
......
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