Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
scm_server
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
98f9e835
authored
Apr 26, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
修改逻辑
parent
db55cfbb
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
125 additions
and
105 deletions
cmd/queue/sync_customer/product.go
cmd/queue/sync_goods/main.go
cmd/queue/sync_goods/product.go
cmd/queue/sync_in_store/main.go
cmd/queue/sync_in_store/product.go
cmd/queue/sync_out_store/main.go
cmd/queue/sync_status/main.go
go.mod
go.sum
internal/model/in_store.go
cmd/queue/sync_customer/product.go
View file @
98f9e835
...
...
@@ -19,7 +19,7 @@ func main() {
message
=
map
[
string
]
interface
{}{
"type"
:
"save"
,
"data"
:
map
[
string
]
string
{
"FID"
:
"Bg/8bD0XRdayeQFMFsSgY6gYZf0="
,
"FID"
:
"Bg/8bD0XRdayeQFMFsSgY6gYZf0=
111
"
,
"FNUMBER"
:
"WT00013"
,
"CFNAME"
:
"深圳市肯特尔科技有限公司"
,
},
...
...
cmd/queue/sync_goods/main.go
View file @
98f9e835
...
...
@@ -88,7 +88,7 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
goto
ERR
}
fmt
.
Println
(
"同步成功,开始发送金蝶状态同步"
)
if
err
=
product
.
SyncErpStatus
(
"
goods
"
,
goods
.
ErpId
);
err
!=
nil
{
if
err
=
product
.
SyncErpStatus
(
"
material
"
,
goods
.
ErpId
);
err
!=
nil
{
goto
ERR
}
return
nil
...
...
cmd/queue/sync_goods/product.go
View file @
98f9e835
...
...
@@ -9,7 +9,7 @@ import (
func
main
()
{
message
:=
make
(
map
[
string
]
interface
{})
message
=
map
[
string
]
interface
{}{
"type"
:
"
sav
e"
,
"type"
:
"
delet
e"
,
"data"
:
map
[
string
]
string
{
"FID"
:
"BUqVwVoBTRm/BY9kIKL7fEQJ5/A="
,
"FGoods"
:
"光电耦合器"
,
...
...
cmd/queue/sync_in_store/main.go
View file @
98f9e835
...
...
@@ -7,6 +7,7 @@ import (
"github.com/go-kratos/kratos/pkg/log"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"github.com/imroc/req"
"scm_server/cmd/queue/sync_status/product"
"scm_server/configs"
"scm_server/internal/common"
"scm_server/internal/logic"
...
...
@@ -28,11 +29,13 @@ type InStoreMessage struct {
CFIsInsp
bool
FPrincipalNo
string
FBizType
string
FEntrys
InStoreFEntry
FIsCustoms
bool
FSupplierNo
string
FEntrys
[]
InStoreFEntrys
}
}
type
InStoreFEntry
struct
{
type
InStoreFEntry
s
struct
{
FQty
int
FIsRecordLotAndDC
bool
FOriginCountry
string
...
...
@@ -55,60 +58,64 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
var
(
message
InStoreMessage
err
error
supplier
model
.
Supplier
inStore
model
.
InStore
operateType
string
syncLog
model
.
SyncLog
msg
[]
byte
)
//先去转换队列消息的json,如果失败,记录起来
if
err
=
json
.
Unmarshal
(
dataByte
,
&
message
);
err
!=
nil
{
goto
ERR
}
//转换成supplier数据
supplier
.
ErpId
=
message
.
Data
.
FID
supplier
.
ErpSupplierCode
=
message
.
Data
.
FNUMBER
supplier
.
Name
=
message
.
Data
.
CFNAME
//判断操作类型
switch
message
.
Type
{
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
)
{
operateType
=
"update"
if
err
=
logic
.
UpdateSupplier
(
supplier
);
err
!=
nil
{
goto
ERR
}
if
logic
.
CheckInStoreExist
(
inStore
.
BillId
)
{
err
=
errors
.
New
(
"试图新增已存在的入货单,单号为"
+
message
.
Data
.
FSourceBillID
)
goto
ERR
}
else
{
operateType
=
"insert"
if
err
=
logic
.
InsertSupplier
(
supplier
);
err
!=
nil
{
if
err
=
logic
.
InsertInStore
(
inStore
);
err
!=
nil
{
fmt
.
Println
(
err
)
//todo:错误原因会消失
goto
ERR
}
}
case
"delete"
:
operateType
=
"delete"
supplier
.
Status
=
0
if
logic
.
Check
SupplierExist
(
supplier
.
Erp
Id
)
{
inStore
.
Status
=
0
if
logic
.
Check
InStoreExist
(
inStore
.
Bill
Id
)
{
//如果存在,才进行删除
if
err
=
logic
.
Delete
Supplier
(
supplier
);
err
!=
nil
{
if
err
=
logic
.
Delete
InStore
(
inStore
);
err
!=
nil
{
goto
ERR
}
}
else
{
err
=
errors
.
New
(
"试图删除不存在的
供应商
"
)
err
=
errors
.
New
(
"试图删除不存在的
入货单
"
)
goto
ERR
}
default
:
err
=
errors
.
New
(
"同步
供应商
出现不存在的操作类型"
)
err
=
errors
.
New
(
"同步
入货单
出现不存在的操作类型"
)
goto
ERR
}
//操作成功后还要去请求后端接口同步数据
if
err
=
Sync
SupplierData
(
operateType
,
supplier
);
err
!=
nil
{
if
err
=
Sync
InStoreData
(
operateType
,
message
);
err
!=
nil
{
goto
ERR
}
fmt
.
Println
(
"同步成功"
)
fmt
.
Println
(
"同步成功,开始发送金蝶状态同步"
)
product
.
SyncErpStatus
(
"out_store"
,
inStore
.
BillId
)
return
nil
ERR
:
//不存在的
erp_i
d不去操作对应的数据库
if
supplier
.
Erp
Id
!=
""
{
logSyncErrorTo
Supplier
(
supplier
.
Erp
Id
,
err
.
Error
())
//不存在的
billI
d不去操作对应的数据库
if
inStore
.
Bill
Id
!=
""
{
logSyncErrorTo
InStore
(
inStore
.
Bill
Id
,
err
.
Error
())
}
//还要存到一个统一错误表
...
...
@@ -116,13 +123,13 @@ ERR:
AddTime
:
time
.
Now
()
.
Unix
(),
SyncTime
:
time
.
Now
()
.
Unix
(),
QueueMessage
:
string
(
dataByte
),
UniqueId
:
supplier
.
Erp
Id
,
//有可能为
UniqueId
:
inStore
.
Bill
Id
,
//有可能为
SyncError
:
err
.
Error
(),
SyncName
:
"
supplier
"
,
SyncName
:
"
inStore
"
,
}
logic
.
InsertSyncLog
(
syncLog
)
//发送钉钉错误消息
msg
,
_
:
=
json
.
Marshal
(
syncLog
)
msg
,
_
=
json
.
Marshal
(
syncLog
)
service
.
SendMessage
(
common
.
ErrorSendPhone
,
string
(
msg
))
//保存日志
...
...
@@ -136,54 +143,24 @@ func (t *RecvPro) FailAction(dataByte []byte) error {
}
//同步数据
func
Sync
SupplierData
(
operate
string
,
supplier
model
.
Supplier
)
(
err
error
)
{
func
Sync
InStoreData
(
operate
string
,
message
InStoreMessage
)
(
err
error
)
{
var
(
resp
*
req
.
Resp
url
string
respData
common
.
Response
params
map
[
string
]
interface
{}
)
param
:=
req
.
Param
{
"erp_supplier_sn"
:
supplier
.
ErpSupplierCode
,
"supplier_name"
:
supplier
.
Name
,
"erp_supplier_id"
:
supplier
.
ErpId
,
"admin_name"
:
"系统"
,
"admin_id"
:
1
,
}
params
=
TransformParams
(
message
)
//更新和插入接口不同
if
operate
==
"update"
{
url
=
configs
.
BasicApiUrl
+
"/basic/api/ApiUpdateSupplierInfo"
}
else
if
operate
==
"insert"
{
url
=
configs
.
BasicApiUrl
+
"/basic/api/ApiInsertSupplierInfo"
if
operate
==
"insert"
{
url
=
configs
.
InStoreApiUrl
+
"/in_store/add"
}
else
{
url
=
configs
.
BasicApiUrl
+
"/basic/api/ApiUpdateSupplierStatus
"
url
=
configs
.
InStoreApiUrl
+
"
"
}
req
.
Debug
=
false
if
operate
==
"update"
||
operate
==
"insert"
{
resp
,
err
=
req
.
Post
(
url
,
param
)
if
err
!=
nil
{
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
)
req
.
Debug
=
true
billId
:=
message
.
Data
.
FSourceBillID
if
operate
==
"insert"
{
resp
,
err
=
req
.
Post
(
url
,
params
)
if
err
!=
nil
{
return
}
...
...
@@ -191,26 +168,75 @@ func SyncSupplierData(operate string, supplier model.Supplier) (err error) {
return
}
if
respData
.
Errcode
!=
101100
{
paramJson
,
_
:=
json
.
Marshal
(
param
)
paramJson
,
_
:=
json
.
Marshal
(
param
s
)
return
errors
.
New
(
fmt
.
Sprintf
(
"请求后端接口返回失败,接口链接为%s,请求参数为%s,返回的错误信息为%s"
,
url
,
string
(
paramJson
),
respData
.
Errmsg
))
}
//都没问题,代表后端那边已经成功修改,修改同步表的状态
if
err
=
logic
.
Sync
CustomerSuccess
(
supplier
.
ErpId
);
err
!=
nil
{
if
err
=
logic
.
Sync
InStoreSuccess
(
billId
,
false
);
err
!=
nil
{
return
}
}
return
}
func
logSyncErrorTo
Supplier
(
erpId
,
syncError
string
)
{
func
logSyncErrorTo
InStore
(
erpId
,
syncError
string
)
{
var
err
error
//请求失败的话,将原因存起来
if
err
=
logic
.
Write
Supplier
SyncError
(
erpId
,
syncError
);
err
!=
nil
{
if
err
=
logic
.
Write
InStore
SyncError
(
erpId
,
syncError
);
err
!=
nil
{
//数据库错误,发送警告
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
()
{
t
:=
&
RecvPro
{}
rabbitmq
.
Recv
(
rabbitmq
.
QueueExchange
{
...
...
cmd/queue/sync_in_store/product.go
View file @
98f9e835
...
...
@@ -16,7 +16,8 @@ func main() {
"FErpPurInWorehouseNo"
:
"FKSH202003107482"
,
"FSourceBillID"
:
"+7fvorsZSAevQCJ7ujsbLMBZJbY="
,
"CFIsInsp"
:
false
,
"FPrincipalNo"
:
"WT00268"
,
"FPrincipalNo"
:
"WT00018"
,
//"FPrincipalNo": "FIZXuVrXRCms51pqby5EVagYZf0=",
"FBizType"
:
"执行采购"
,
"FEntrys"
:
[]
map
[
string
]
interface
{}{
{
...
...
@@ -31,6 +32,8 @@ func main() {
"FModel"
:
"1abaaba"
,
"FGoods"
:
"集成电路"
,
"FUnit"
:
"个"
,
"FIsCustoms"
:
true
,
"FSupplierNo"
:
"LxYAAAABgRI3xn38"
,
},
},
},
...
...
cmd/queue/sync_out_store/main.go
View file @
98f9e835
...
...
@@ -27,6 +27,7 @@ type OutStoreMessage struct {
FIsCustoms
bool
FSourceBillID
string
//原始单据id
FRecPerson
string
FPrincipalNo
string
FRecPersonContact
string
FRecPersonAddress
string
Remark
string
...
...
@@ -198,7 +199,7 @@ func TransformParams(message OutStoreMessage) (params map[string]interface{}) {
params
=
make
(
map
[
string
]
interface
{})
for
_
,
entry
=
range
message
.
Data
.
FEntrys
{
outStoreDetail
=
append
(
outStoreDetail
,
map
[
string
]
interface
{}{
"erp_entry_sn"
:
entry
.
F
Material
ID
,
"erp_entry_sn"
:
entry
.
F
SourceBillEntry
ID
,
"goods_name"
:
entry
.
FGoods
,
"brand_name"
:
entry
.
FBrand
,
"number"
:
entry
.
FQty
,
...
...
@@ -217,8 +218,9 @@ func TransformParams(message OutStoreMessage) (params map[string]interface{}) {
"receive_user_name"
:
message
.
Data
.
FRecPerson
,
"receive_tel"
:
message
.
Data
.
FRecPersonContact
,
//缺一个原始单据id
"erp_client_sn"
:
message
.
Data
.
FPrincipalNo
,
"remark"
:
message
.
Data
.
Remark
,
"
store_id"
:
message
.
Data
.
FWarehouseNo
,
"
erp_in_store_id"
:
message
.
Data
.
FWarehouseNo
,
"warehousing_sn"
:
message
.
Data
.
FEntrustBillNo
,
"is_apply_customs"
:
isApplyCustoms
,
"out_store_detail"
:
outStoreDetail
,
...
...
cmd/queue/sync_status/main.go
View file @
98f9e835
...
...
@@ -98,24 +98,36 @@ func SyncErpDataStatus(syncName, uniqueId string) (err error) {
apiMethod
string
)
switch
syncName
{
case
"goods"
:
case
"material"
:
apiUrl
=
configs
.
ErpSyncBaseDataStatusApi
apiMethod
=
"synRewriteErpBaseDataStatus"
break
case
"supplier"
:
apiUrl
=
configs
.
ErpSyncBaseDataStatusApi
apiMethod
=
"synRewriteErpBaseDataStatus"
break
case
"customer"
:
apiUrl
=
configs
.
ErpSyncBaseDataStatusApi
apiMethod
=
"synRewriteErpBaseDataStatus"
break
case
"in_store"
:
apiUrl
=
configs
.
ErpSyncBillStatusApi
apiMethod
=
"synErpInventoryStatus"
break
case
"out_store"
:
apiUrl
=
configs
.
ErpSyncBillStatusApi
apiMethod
=
"synErpInventoryStatus"
break
default
:
return
errors
.
New
(
"同步金蝶状态出现非法的同步类型"
+
syncName
)
}
fmt
.
Println
(
syncName
)
fmt
.
Println
(
apiMethod
)
fmt
.
Println
(
apiUrl
)
soap
,
err
=
gosoap
.
SoapClient
(
apiUrl
)
if
err
!=
nil
{
return
}
//uniqueId = "++Mhf5K+T9KTEE+bJhM9PEQJ5/A="
//syncName = "material"
fmt
.
Println
(
fmt
.
Sprintf
(
`{"FType":"%s", "FID":"%s"}`
,
syncName
,
uniqueId
))
params
=
gosoap
.
ArrayParams
{
{
"json"
,
fmt
.
Sprintf
(
`{"FType":"%s", "FID":"%s"}`
,
syncName
,
uniqueId
)},
...
...
go.mod
View file @
98f9e835
...
...
@@ -11,6 +11,7 @@ require (
github.com/jmoiron/sqlx v1.2.0
github.com/mushishixian/gosoap v1.2.1-0.20200424081802-b11347c911bc
github.com/pkg/errors v0.9.1
github.com/syyongx/php2go v0.9.4
github.com/tealeg/xlsx v1.0.5
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd // indirect
)
go.sum
View file @
98f9e835
...
...
@@ -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.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
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/go.mod h1:btRS8dz54TDnvKNosuAqxrM1QgN1udgk9O34bDCnORM=
github.com/templexxx/cpufeat v0.0.0-20180724012125-cef66df7f161/go.mod h1:wM7WEvslTq+iOEAMDLSzhVuOt5BRZ05WirO+b09GHQU=
...
...
internal/model/in_store.go
View file @
98f9e835
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
{
QueueMessage
string
BillId
string
...
...
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