Commit b237c424 by mushishixian

格式替换

parent 2e1f6f44
package main
import (
"encoding/json"
"errors"
"fmt"
"github.com/beevik/etree"
"github.com/mushishixian/gosoap"
"log"
"strings"
)
func main() {
fmt.Println(SyncBaseDataStatus())
}
func LoginErp() bool {
soap, err := gosoap.SoapClient("http://192.168.2.253:6888/ormrpc/services/EASLogin?wsdl")
if err != nil {
log.Fatalf("SoapClient error: %s", err)
}
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 {
log.Fatalf("Call error: %s", err)
}
doc := etree.NewDocument()
if err := doc.ReadFromBytes(res.Body); err != nil {
fmt.Println(err)
}
root := doc.SelectElement("multiRef")
sessionId := root.SelectElement("sessionId").Text()
if sessionId != "" {
return true
}
return false
}
func SyncBaseDataStatus() (err error) {
soap, err := gosoap.SoapClient("http://192.168.2.253:6888/ormrpc/services/WSInventoryManagementFacade?wsdl")
if err != nil {
return
}
params := gosoap.ArrayParams{
{"json", `{"FType":"material", "FID":"++Mhf5K+T9KTEE+bJhM9PEQJ5/A="}`},
//{"json", `{"FType":"material", "FID":"ET9WHFzYagYZf0="}`},
}
res, err := soap.Call("synRewriteErpBaseDataStatus", params)
if err != nil {
return
}
doc := etree.NewDocument()
if err = doc.ReadFromBytes(res.Body); err != nil {
return
}
//没有这个xml节点代表金蝶报错了
root := doc.SelectElement("synRewriteErpBaseDataStatusResponse")
if root == nil {
return errors.New(string(res.Body))
}
result := root.SelectElement("synRewriteErpBaseDataStatusReturn")
if result != nil {
var responseData map[string]interface{}
json.Unmarshal([]byte(result.Text()), &responseData)
for key, _ := range responseData {
//金蝶判断成功的标志
if key == "0000" {
temp:=`{\"type\":\"save\",\"date\":{\"FID\":\"UxasZFrOQGC+oCfTmVSNuUQJ5/A=\",\"FBrand\":\"3M\",\"FModel\":\"aabbddcc\",\"FGoods\":\"\u4E8C\u6781\u7BA1\"}}`
temp = strings.ReplaceAll(temp,`\`,"")
fmt.Println(temp)
return
}
//金额判断失败的标志
if key == "4444" {
return errors.New("金蝶返回失败")
}
}
}
return errors.New("金蝶返回响应格式无法识别")
}
......@@ -155,7 +155,7 @@ func SyncCustomerData(operate string, customer model.Customer) (err error) {
}
if respData.Errcode != 101100 {
paramJson, _ := json.Marshal(param)
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(customer.ErpId); err != nil {
......@@ -178,7 +178,7 @@ func SyncCustomerData(operate string, customer model.Customer) (err error) {
}
if respData.Errcode != 101100 {
paramJson, _ := json.Marshal(param)
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(customer.ErpId); err != nil {
......
......@@ -157,7 +157,7 @@ func SyncGoodsData(operate string, goods model.Goods) (err error) {
}
if respData.Errcode != 101100 {
paramJson, _ := json.Marshal(param)
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.SyncGoodsSuccess(goods.ErpId, false); err != nil {
......@@ -180,7 +180,7 @@ func SyncGoodsData(operate string, goods model.Goods) (err error) {
}
if respData.Errcode != 101100 {
paramJson, _ := json.Marshal(param)
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.SyncGoodsSuccess(goods.ErpId, true); err != nil {
......
......@@ -61,7 +61,7 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
inStore model.InStore
operateType string
syncLog model.SyncLog
msg []byte
msg, messageData []byte
)
//先去转换队列消息的json,如果失败,记录起来
if err = json.Unmarshal(dataByte, &message); err != nil {
......@@ -72,17 +72,15 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
switch message.Type {
case "save":
inStore.BillId = message.Data.FSourceBillID
messageData, err := json.Marshal(&message)
messageData, err = json.Marshal(&message)
if err != nil {
goto ERR
}
inStore.QueueMessage = string(messageData)
//先去查询是否存在,不存在才去插入,已经存在即是修改
//先去查询是否存在,不存在才去插入
if !logic.CheckInStoreExist(inStore.BillId) {
operateType = "insert"
if err = logic.InsertInStore(inStore); err != nil {
fmt.Println(err)
//todo:错误原因会消失
goto ERR
}
}
......@@ -107,14 +105,15 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
goto ERR
}
fmt.Println("同步成功,开始发送金蝶状态同步")
product.SyncErpStatus("out_store", inStore.BillId)
if err = product.SyncErpStatus("in_store", inStore.BillId); err != nil {
goto ERR
}
return nil
ERR:
//不存在的billId不去操作对应的数据库
if inStore.BillId != "" {
logSyncErrorToInStore(inStore.BillId, err.Error())
}
//还要存到一个统一错误表
syncLog = model.SyncLog{
AddTime: time.Now().Unix(),
......@@ -145,7 +144,7 @@ func SyncInStoreData(operate string, message InStoreMessage) (err error) {
resp *req.Resp
url string
respData common.Response
params map[string]interface{}
params req.Param
)
params = TransformParams(message)
//更新和插入接口不同
......@@ -164,9 +163,9 @@ func SyncInStoreData(operate string, message InStoreMessage) (err error) {
if err = resp.ToJSON(&respData); err != nil {
return
}
if respData.Errcode != 101100 {
if respData.Errcode != 0 {
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.SyncInStoreSuccess(billId, false); err != nil {
......@@ -185,9 +184,10 @@ func logSyncErrorToInStore(erpId, syncError string) {
}
}
func TransformParams(message InStoreMessage) (params map[string]interface{}) {
func TransformParams(message InStoreMessage) (result req.Param) {
var (
entry InStoreFEntrys
params map[string]interface{}
outStoreDetail map[string]interface{}
key int
detailPrefix string
......@@ -196,6 +196,17 @@ func TransformParams(message InStoreMessage) (params map[string]interface{}) {
params = make(map[string]interface{})
outStoreDetail = make(map[string]interface{})
for key, entry = range message.Data.FEntrys {
var isInsp, isPrint int
if entry.CFIsInsp {
isInsp = 1
} else {
isInsp = 0
}
if entry.FIsPrint {
isPrint = 1
} else {
isPrint = 0
}
detailPrefix = fmt.Sprintf("detail[%d][", key)
detailMap = map[string]interface{}{
detailPrefix + "erp_entry_sn]": entry.FSourceBillEntryID,
......@@ -205,33 +216,40 @@ func TransformParams(message InStoreMessage) (params map[string]interface{}) {
detailPrefix + "number]": entry.FQty,
detailPrefix + "country]": entry.FOriginCountry,
detailPrefix + "goods_unit]": entry.FUnit,
detailPrefix + "is_insp]": entry.CFIsInsp,
detailPrefix + "is_print]": entry.FIsPrint,
detailPrefix + "is_insp]": isInsp,
detailPrefix + "is_print]": isPrint,
}
for k, v := range detailMap {
outStoreDetail[k] = v
}
}
var isInsp int
var isInsp, isApplyCustoms int
if message.Data.CFIsInsp {
isInsp = 1
} else {
isInsp = 0
}
if message.Data.FIsCustoms {
isApplyCustoms = 1
} else {
isApplyCustoms = 0
}
params = map[string]interface{}{
//缺一个原始单据id
"erp_in_store_id": message.Data.FSourceBillID,
"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,
"supplier_erp_id": message.Data.FSupplierNo,
"is_apply_customs": isApplyCustoms,
}
for k, v := range outStoreDetail {
params[k] = v
}
return
result = params
return result
}
func main() {
......
......@@ -13,11 +13,12 @@ func main() {
"data": map[string]interface{}{
"FWarehouseNo": "002",
"FEntrustBillNo": "B05364",
"FErpPurInWorehouseNo": "FKSH202003107482",
"FErpPurInWorehouseNo": "FKSH202003107481",
"FSourceBillID": "+7fvorsZSAevQCJ7ujsbLMBZJbY=",
"CFIsInsp": false,
"FPrincipalNo": "WT00018",
//"FPrincipalNo": "FIZXuVrXRCms51pqby5EVagYZf0=",
"FSupplierNo": "M0000045",
"FBizType": "执行采购",
"FEntrys": []map[string]interface{}{
{
......@@ -26,14 +27,13 @@ func main() {
"FOriginCountry": "502",
"FIsPrint": false,
"CFIsInsp": false,
"FMaterialID": "9l++jtj+RNS2VpdFhzcRE0QJ5/A=",
"FMaterialID": "nlOzVwbKSC2pIOF329QfN0QJ5/A=",
"FBrand": "ON",
"FSourceBillEntryID": "gHw/y6EQRBmCpLGDFkdJCO0oFFw=",
"FModel": "1abaaba",
"FGoods": "集成电路",
"FUnit": "个",
"FIsCustoms": true,
"FSupplierNo": "LxYAAAABgRI3xn38",
},
},
},
......
......@@ -63,6 +63,7 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
syncLog model.SyncLog
msg, messageData []byte
)
fmt.Println(string(dataByte))
//先去转换队列消息的json,如果失败,记录起来
if err = json.Unmarshal(dataByte, &message); err != nil {
goto ERR
......@@ -169,7 +170,7 @@ func SyncOutStoreData(operate string, message OutStoreMessage) (err error) {
}
if respData.Errcode != 0 {
paramJson, _ := json.Marshal(params)
return errors.New(fmt.Sprintf("请求后端接口返回失败,接口链接为%s,请求参数为%s,返回的错误信息为%s", url, string(paramJson), respData.Data))
return errors.New(fmt.Sprintf("请求后端接口返回失败,接口链接为%s,请求参数为%s,返回的错误信息为 : %s", url, string(paramJson), respData.Data))
}
//都没问题,代表后端那边已经成功修改,修改同步表的状态
if err = logic.SyncOutStoreSuccess(billId, false); err != nil {
......
......@@ -153,7 +153,7 @@ func SyncSupplierData(operate string, supplier model.Supplier) (err error) {
}
if respData.Errcode != 101100 {
paramJson, _ := json.Marshal(param)
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.SyncSupplierSuccess(supplier.ErpId); err != nil {
......@@ -176,7 +176,7 @@ func SyncSupplierData(operate string, supplier model.Supplier) (err error) {
}
if respData.Errcode != 101100 {
paramJson, _ := json.Marshal(param)
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 {
......
......@@ -40,6 +40,9 @@ func Import() {
if key == 0 {
continue
}
if key == 100 {
break
}
goods.ErpId = row.Cells[0].String()
goods.GoodsName = row.Cells[1].String()
goods.BrandName = row.Cells[2].String()
......@@ -49,7 +52,6 @@ func Import() {
continue
}
if logic.CheckGoodsExist(goods.ErpId) {
fmt.Println("已存在,跳过")
continue
}
message := make(map[string]interface{})
......
package main
import "scm_server/cmd/source/customer"
import "scm_server/cmd/source/goods"
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,23 +6,23 @@ import (
"time"
)
const CheckInStoreExistSql = "SELECT goods_id FROM lie_in_store WHERE erp_id = ? AND sync_status = 1"
const CheckInStoreExistSql = "SELECT in_store_id FROM lie_in_store WHERE bill_id = ? AND sync_status = 1"
const InsertInStoreSql = "INSERT INTO `lie_in_store` (`queue_message`,`bill_id`,`add_time`) VALUES (?,?,?)"
const DeleteInStoreSql = "UPDATE `lie_in_store` SET `status` = ? , `update_time` = ? WHERE `erp_id` = ?"
const DeleteInStoreSql = "UPDATE `lie_in_store` SET `status` = ? , `update_time` = ? WHERE `bill_id` = ?"
const WriteInStoreSyncErrorSql = "UPDATE `lie_in_store` SET sync_error = ? WHERE bill_id = ?"
const SyncInStoreSuccessSql = "UPDATE `lie_in_store` SET sync_status = 1 , sync_time = ? WHERE erp_id = ?"
const SyncInStoreSuccessSql = "UPDATE `lie_in_store` SET sync_status = 1 , sync_time = ? WHERE bill_id = ?"
const SyncInStoreSuccessSqlWithStatus = "UPDATE `lie_in_store` SET sync_status = 1 , sync_time = ? , status = ? WHERE erp_id = ?"
const SyncInStoreSuccessSqlWithStatus = "UPDATE `lie_in_store` SET sync_status = 1 , sync_time = ? , status = ? WHERE bill_id = ?"
//检查出库是否存在
func CheckInStoreExist(erpId string) (exist bool) {
var goodsId int
dao.GetDb().QueryRowx(CheckInStoreExistSql, erpId).Scan(&goodsId)
return goodsId > 0
func CheckInStoreExist(billId string) (exist bool) {
var inStoreId int
dao.GetDb().QueryRowx(CheckInStoreExistSql, billId).Scan(&inStoreId)
return inStoreId > 0
}
//插入出库
......@@ -38,18 +38,18 @@ func DeleteInStore(outStore model.InStore) (err error) {
}
//写入同步失败的原因
func WriteInStoreSyncError(erpId string, syncError string) (err error) {
_, err = dao.GetDb().Exec(WriteInStoreSyncErrorSql, syncError, erpId)
func WriteInStoreSyncError(billId string, syncError string) (err error) {
_, err = dao.GetDb().Exec(WriteInStoreSyncErrorSql, syncError, billId)
return
}
//修改成功的同步状态
func SyncInStoreSuccess(erpId string, isDelete bool) (err error) {
func SyncInStoreSuccess(billId string, isDelete bool) (err error) {
//不是删除,不需要修改状态
if !isDelete {
_, err = dao.GetDb().Exec(SyncInStoreSuccessSql, time.Now().Unix(), erpId)
_, err = dao.GetDb().Exec(SyncInStoreSuccessSql, time.Now().Unix(), billId)
} else {
_, err = dao.GetDb().Exec(SyncInStoreSuccessSqlWithStatus, time.Now().Unix(), 0, erpId)
_, err = dao.GetDb().Exec(SyncInStoreSuccessSqlWithStatus, time.Now().Unix(), 0, billId)
}
return
}
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