Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
liexin_scm_wms_sync
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
2e1f6f44
authored
Apr 26, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
出库同步
parent
98f9e835
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
106 additions
and
35 deletions
cmd/queue/sync_goods/main.go
cmd/queue/sync_in_store/main.go
cmd/queue/sync_out_store/main.go
cmd/queue/sync_out_store/product.go
cmd/queue/sync_status/main.go
cmd/queue/sync_status/request.go
cmd/source/main.go
internal/logic/out_store.go
cmd/queue/sync_goods/main.go
View file @
2e1f6f44
...
...
@@ -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
{
...
...
cmd/queue/sync_in_store/main.go
View file @
2e1f6f44
...
...
@@ -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
)
...
...
cmd/queue/sync_out_store/main.go
View file @
2e1f6f44
...
...
@@ -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"
...
...
@@ -61,7 +61,7 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
outStore
model
.
OutStore
operateType
string
syncLog
model
.
SyncLog
msg
[]
byte
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
=
fals
e
req
.
Debug
=
tru
e
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
!=
10110
0
{
paramJson
,
_
:=
json
.
Marshal
(
param
)
return
errors
.
New
(
fmt
.
Sprintf
(
"请求后端接口返回失败,接口链接为%s,请求参数为%s,返回的错误信息为%s"
,
url
,
string
(
paramJson
),
respData
.
Errmsg
))
if
respData
.
Errcode
!=
0
{
paramJson
,
_
:=
json
.
Marshal
(
param
s
)
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
.
FSourceBillEntry
ID
,
"erp_
goods_id"
:
entry
.
FMaterial
ID
,
"goods_name"
:
entry
.
FGoods
,
"brand_name"
:
entry
.
FBrand
,
"number"
:
entry
.
FQty
,
"goods_unit"
:
entry
.
FUnit
,
"is_insp"
:
entry
.
CFI
sInsp
,
"is_insp"
:
i
sInsp
,
})
}
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
,
...
...
cmd/queue/sync_out_store/product.go
View file @
2e1f6f44
...
...
@@ -12,9 +12,9 @@ func main() {
"type"
:
"save"
,
"data"
:
map
[
string
]
interface
{}{
"FWarehouseNo"
:
"002"
,
"FEntrustBillNo"
:
"B05364"
,
"FEntrustBillNo"
:
"B05364
95123
"
,
"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+RNS2VpdFhzcRE0
QJ5/A="
,
"FMaterialID"
:
"
YscJMHmgT1+Yh6EWN343yE
QJ5/A="
,
"FBrand"
:
"ON"
,
"FSourceBillEntryID"
:
"gHw/y6EQRBmCpLGDFkdJCO0oFFw="
,
"FModel"
:
"1abaaba"
,
...
...
cmd/queue/sync_status/main.go
View file @
2e1f6f44
...
...
@@ -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
)
}
}
}
...
...
cmd/queue/sync_status/request.go
View file @
2e1f6f44
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
cmd/source/main.go
View file @
2e1f6f44
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()
}
internal/logic/out_store.go
View file @
2e1f6f44
...
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment