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
d62fbed9
authored
Apr 23, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
完善普通的增删改
parent
c034f2e2
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
86 additions
and
47 deletions
cmd/main.go
cmd/queue/sync_goods/main.go
cmd/queue/sync_goods/product.go
cmd/queue/sync_status/main.go
cmd/queue/sync_status/product.go → cmd/queue/sync_status/product/product_status_queue.go
cmd/queue/sync_supplier/main.go
cmd/queue/sync_supplier/product.go
cmd/source/main.go
internal/logic/goods.go
internal/logic/supplier.go
internal/logic/sync_status_log.go
internal/model/goods.go
internal/model/supplier.go
cmd/main.go
View file @
d62fbed9
...
...
@@ -8,28 +8,29 @@ import (
func
main
()
{
//
soap, err := gosoap.SoapClient("http://192.168.2.253:6888/ormrpc/services/EASLogin?wsdl")
soap
,
err
:=
gosoap
.
SoapClient
(
"http://192.168.2.253:6888/ormrpc/services/WSInventoryManagementFacade?wsdl"
)
soap
,
err
:=
gosoap
.
SoapClient
(
"http://192.168.2.253:6888/ormrpc/services/EASLogin?wsdl"
)
//
soap, err := gosoap.SoapClient("http://192.168.2.253:6888/ormrpc/services/WSInventoryManagementFacade?wsdl")
if
err
!=
nil
{
log
.
Fatalf
(
"SoapClient error: %s"
,
err
)
}
//(userName, password, slnName, dcName, language, dbType, authPattern)
//("WBYH", "123456", "eas", "demo", "L2", 1, "BaseDB")
//params := gosoap.Params{
// "userName": "WBYH",
// "password": "123456",
// "slnName": "eas",
// "dcName": "demo",
// "language": "L2",
// "dbType": 1,
// "authPattern": "BaseDB",
//}
params
:=
gosoap
.
Params
{
"json"
:
`{"FType":"material", "FID":"ET9WHFzYagYZf0="}`
,
params
:=
gosoap
.
Params
{
"userName"
:
"WBYH"
,
"password"
:
"123456"
,
"slnName"
:
"eas"
,
"dcName"
:
"demo"
,
"language"
:
"L2"
,
"dbType"
:
1
,
"authPattern"
:
"BaseDB"
,
}
//params:=gosoap.Params{
// "json":`{"FType":"material", "FID":"ET9WHFzYagYZf0="}`,
//}
err
=
soap
.
Call
(
"synRewriteErpBaseDataStatus"
,
params
)
//err = soap.Call("synRewriteErpBaseDataStatus", params)
err
=
soap
.
Call
(
"login"
,
params
)
if
err
!=
nil
{
log
.
Fatalf
(
"Call error: %s"
,
err
)
}
...
...
cmd/queue/sync_goods/main.go
View file @
d62fbed9
...
...
@@ -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"
...
...
@@ -68,9 +69,10 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
}
case
"delete"
:
operateType
=
"delete"
goods
.
Status
=
0
if
logic
.
CheckGoodsExist
(
goods
.
ErpId
)
{
//如果存在,才进行删除
if
err
=
logic
.
DeleteGoods
(
goods
.
ErpId
);
err
!=
nil
{
if
err
=
logic
.
DeleteGoods
(
goods
);
err
!=
nil
{
goto
ERR
}
}
else
{
...
...
@@ -85,7 +87,8 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
if
err
=
SyncGoodsData
(
operateType
,
goods
);
err
!=
nil
{
goto
ERR
}
fmt
.
Println
(
"同步成功"
)
fmt
.
Println
(
"同步成功,开始发送金蝶状态同步"
)
product
.
SyncErpStatus
(
"goods"
,
goods
.
ErpId
)
return
nil
ERR
:
//不存在的erp_id不去操作对应的数据库
...
...
@@ -140,7 +143,7 @@ func SyncGoodsData(operate string, goods model.Goods) (err error) {
}
else
if
operate
==
"insert"
{
url
=
configs
.
BasicApiUrl
+
"/basic/api/ApiInsertGoodsInfo"
}
else
{
url
=
configs
.
BasicApiUrl
+
"/basic/api/Api
DeleteGoodsInfo
"
url
=
configs
.
BasicApiUrl
+
"/basic/api/Api
UpdateGoodsStatus
"
}
req
.
Debug
=
false
if
operate
==
"update"
||
operate
==
"insert"
{
...
...
@@ -159,7 +162,6 @@ func SyncGoodsData(operate string, goods model.Goods) (err error) {
return
}
}
else
{
url
=
configs
.
BasicApiUrl
+
"/basic/api/ApiUpdateGoodsStatus"
//删除,软删除
param
:=
req
.
Param
{
"status"
:
0
,
...
...
cmd/queue/sync_goods/product.go
View file @
d62fbed9
...
...
@@ -9,12 +9,12 @@ import (
func
main
()
{
message
:=
make
(
map
[
string
]
interface
{})
message
=
map
[
string
]
interface
{}{
"type"
:
"
sav
e"
,
"type"
:
"
delet
e"
,
"data"
:
map
[
string
]
string
{
"FID"
:
"Z8eVSzSLRXKa7ET9WHFzYagYZf0171="
,
"FID"
:
"Z8eVSzSLRXKa7ET9WHFzYagYZf017
2
1="
,
"FGoods"
:
"WT0050333"
,
"FBrand"
:
"深圳市鼎驰达电子有限公司"
,
"FModel"
:
""
,
"FModel"
:
"
XXX
"
,
},
}
data
,
err
:=
json
.
Marshal
(
message
)
...
...
cmd/queue/sync_status/main.go
View file @
d62fbed9
...
...
@@ -5,6 +5,7 @@ import (
"fmt"
"github.com/go-kratos/kratos/pkg/log"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"scm_server/internal/logic"
)
type
RecvPro
struct
{
...
...
@@ -21,6 +22,7 @@ func init() {
}
func
(
t
*
RecvPro
)
Consumer
(
dataByte
[]
byte
)
error
{
fmt
.
Println
(
string
(
dataByte
))
var
(
err
error
message
QueueStatus
...
...
@@ -30,10 +32,14 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
goto
ERR
}
//得到message以后,去请求金蝶的接口
fmt
.
Println
(
"请求金蝶接口"
)
return
nil
//如果失败了,记录到表,并且发送钉钉消息
ERR
:
fmt
.
Println
(
err
)
if
err
=
logic
.
InsertSyncStatusLog
(
message
.
SyncName
,
message
.
ErpId
,
"err.Error()"
);
err
!=
nil
{
fmt
.
Println
(
err
)
}
return
nil
}
...
...
cmd/queue/sync_status/product.go
→
cmd/queue/sync_status/product
/product_status_queue
.go
View file @
d62fbed9
package
main
package
product
import
(
"encoding/json"
...
...
@@ -6,15 +6,15 @@ import (
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
)
func
main
(
)
{
func
SyncErpStatus
(
syncName
string
,
ErpId
string
)
{
message
:=
make
(
map
[
string
]
interface
{})
message
=
map
[
string
]
interface
{}{
"SyncName"
:
"supplier"
,
"SyncName"
:
syncName
,
"Status"
:
1
,
"ErpId"
:
"test123456"
,
"ErpId"
:
ErpId
,
}
data
,
err
:=
json
.
Marshal
(
message
)
if
err
!=
nil
{
data
,
err
:=
json
.
Marshal
(
message
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
body
:=
string
(
data
)
...
...
cmd/queue/sync_supplier/main.go
View file @
d62fbed9
...
...
@@ -65,9 +65,10 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
}
case
"delete"
:
operateType
=
"delete"
supplier
.
Status
=
0
if
logic
.
CheckSupplierExist
(
supplier
.
ErpId
)
{
//如果存在,才进行删除
if
err
=
logic
.
DeleteSupplier
(
supplier
.
ErpId
);
err
!=
nil
{
if
err
=
logic
.
DeleteSupplier
(
supplier
);
err
!=
nil
{
goto
ERR
}
}
else
{
...
...
@@ -135,7 +136,7 @@ func SyncSupplierData(operate string, supplier model.Supplier) (err error) {
}
else
if
operate
==
"insert"
{
url
=
configs
.
BasicApiUrl
+
"/basic/api/ApiInsertSupplierInfo"
}
else
{
url
=
configs
.
BasicApiUrl
+
"/basic/api/Api
DeleteSupplierInfo
"
url
=
configs
.
BasicApiUrl
+
"/basic/api/Api
UpdateSupplierStatus
"
}
req
.
Debug
=
false
if
operate
==
"update"
||
operate
==
"insert"
{
...
...
@@ -154,9 +155,28 @@ func SyncSupplierData(operate string, supplier model.Supplier) (err error) {
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
{
return
}
if
err
=
resp
.
ToJSON
(
&
respData
);
err
!=
nil
{
return
}
if
respData
.
Errcode
!=
101100
{
return
errors
.
New
(
respData
.
Errmsg
)
}
//都没问题,代表后端那边已经成功修改,修改同步表的状态
if
err
=
logic
.
SyncCustomerSuccess
(
supplier
.
ErpId
);
err
!=
nil
{
return
}
}
return
}
...
...
cmd/queue/sync_supplier/product.go
View file @
d62fbed9
...
...
@@ -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"
:
"Z8eVSzSLRXKa7ET9WHFzYagYZf017ff="
,
"FNUMBER"
:
"WT0050333"
,
...
...
cmd/source/main.go
View file @
d62fbed9
package
main
import
"scm_server/cmd/source/
supplier
"
import
"scm_server/cmd/source/
goods
"
func
main
()
{
//forever := make(chan bool)
//go supplier.Import()
supplier
.
Import
()
//
supplier.Import()
//<-forever
//customer.Import()
//
goods.Import()
goods
.
Import
()
}
internal/logic/goods.go
View file @
d62fbed9
...
...
@@ -12,7 +12,7 @@ const InsertGoodsSql = "INSERT INTO `lie_goods` (`goods_name`,`goods_cn_name`,`b
const
UpdateGoodsSql
=
"UPDATE `lie_goods` SET `goods_name` = ? , `goods_cn_name` = ? , `brand_name` = ? , `update_time` = ? WHERE `erp_id` = ?"
const
DeleteGoodsSql
=
"
DELETE FROM `lie_goods`
WHERE `erp_id` = ?"
const
DeleteGoodsSql
=
"
UPDATE `lie_goods` SET `status` = ? , `update_time` = ?
WHERE `erp_id` = ?"
const
WriteGoodsSyncErrorSql
=
"UPDATE `lie_goods` SET sync_error = ? WHERE goods_id = ?"
...
...
@@ -44,8 +44,8 @@ func UpdateGoods(goods model.Goods) (err error) {
}
//删除供应商
func
DeleteGoods
(
erpId
string
)
(
err
error
)
{
_
,
err
=
dao
.
GetDb
()
.
Exec
(
DeleteGoodsSql
,
e
rpId
)
func
DeleteGoods
(
goods
model
.
Goods
)
(
err
error
)
{
_
,
err
=
dao
.
GetDb
()
.
Exec
(
DeleteGoodsSql
,
goods
.
Status
,
time
.
Now
()
.
Unix
(),
goods
.
E
rpId
)
return
}
...
...
internal/logic/supplier.go
View file @
d62fbed9
...
...
@@ -12,7 +12,7 @@ const InsertSupplierSql = "Insert INTO `lie_supplier` (`erp_supplier_code`,`name
const
UpdateSupplierSql
=
"UPDATE `lie_supplier` SET `erp_supplier_code` = ? , `name` = ? , `update_time` = ? WHERE `erp_id` = ?"
const
DeleteSupplierSql
=
"
DELETE FROM `lie_supplier`
WHERE `erp_id` = ?"
const
DeleteSupplierSql
=
"
UPDATE `lie_supplier` SET `status` = ? , `update_time` = ?
WHERE `erp_id` = ?"
const
WriteSupplierSyncErrorSql
=
"UPDATE `lie_supplier` SET sync_time = ? , sync_status = ? , sync_error = ? WHERE erp_id = ?"
...
...
@@ -28,24 +28,18 @@ func CheckSupplierExist(erpId string) (exist bool) {
//插入供应商
func
InsertSupplier
(
supplier
model
.
Supplier
)
(
err
error
)
{
_
,
err
=
dao
.
GetDb
()
.
Exec
(
InsertSupplierSql
,
supplier
.
ErpSupplierCode
,
supplier
.
Name
,
supplier
.
ErpId
,
time
.
Now
()
.
Unix
(),
0
)
if
err
!=
nil
{
return
}
return
nil
}
//更新供应商
func
UpdateSupplier
(
supplier
model
.
Supplier
)
(
err
error
)
{
_
,
err
=
dao
.
GetDb
()
.
Exec
(
UpdateSupplierSql
,
supplier
.
ErpSupplierCode
,
supplier
.
Name
,
time
.
Now
()
.
Unix
(),
supplier
.
ErpId
)
if
err
!=
nil
{
return
}
return
nil
}
//删除供应商
func
DeleteSupplier
(
erpId
string
)
(
err
error
)
{
_
,
err
=
dao
.
GetDb
()
.
Exec
(
DeleteSupplierSql
,
e
rpId
)
func
DeleteSupplier
(
supplier
model
.
Supplier
)
(
err
error
)
{
_
,
err
=
dao
.
GetDb
()
.
Exec
(
DeleteSupplierSql
,
supplier
.
Status
,
time
.
Now
()
.
Unix
(),
supplier
.
E
rpId
)
return
}
...
...
internal/logic/sync_status_log.go
0 → 100644
View file @
d62fbed9
package
logic
import
(
"scm_server/internal/dao"
"time"
)
//插入金蝶同步状态错误信息
const
InsertSyncStatusLogSql
=
"Insert Into `lie_sync_status_log` ( `sync_name` , `unique_id` , `error_msg` , `add_time` ) Value (?,?,?,?)"
func
InsertSyncStatusLog
(
syncName
,
uniqueId
,
errMsg
string
)
(
err
error
)
{
_
,
err
=
dao
.
GetDb
()
.
Exec
(
InsertSyncStatusLogSql
,
syncName
,
uniqueId
,
errMsg
,
time
.
Now
()
.
Unix
())
return
}
internal/model/goods.go
View file @
d62fbed9
...
...
@@ -9,4 +9,5 @@ type Goods struct {
SyncTime
int
SyncStatus
int
SyncError
string
Status
int
}
internal/model/supplier.go
View file @
d62fbed9
...
...
@@ -8,4 +8,5 @@ type Supplier struct {
SyncTime
int
SyncStatus
int
SyncError
string
Status
int
}
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