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
a6aa2bb2
authored
Apr 30, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
完善修复客户导入逻辑
parent
474a76e6
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
14 additions
and
125 deletions
back/customer_back.go
cmd/queue/sync_audit_status/main.go
cmd/queue/sync_customer/main.go
cmd/queue/sync_customer/product.go
internal/logic/customer.go
internal/logic/goods.go
internal/service/dingding.go
back/customer_back.go
deleted
100644 → 0
View file @
474a76e6
package
customer
import
(
"fmt"
"github.com/imroc/req"
"github.com/tealeg/xlsx"
"scm_server/configs"
"scm_server/internal/common"
"scm_server/internal/logic"
"scm_server/internal/model"
)
//导入委托方的信息(excel导入)
func
Imports
()
{
var
(
excelFileName
string
xlFile
*
xlsx
.
File
err
error
customer
model
.
Customer
)
excelFileName
=
"./cmd/source/data/customer.xlsx"
xlFile
,
err
=
xlsx
.
OpenFile
(
excelFileName
)
if
err
!=
nil
{
fmt
.
Printf
(
"open failed: %s
\n
"
,
err
)
}
//循环遍历数据
for
_
,
sheet
:=
range
xlFile
.
Sheets
{
for
key
,
row
:=
range
sheet
.
Rows
{
if
key
==
0
{
continue
}
customer
.
ErpId
=
row
.
Cells
[
0
]
.
String
()
customer
.
ErpClientCode
=
row
.
Cells
[
1
]
.
String
()
customer
.
Name
=
row
.
Cells
[
2
]
.
String
()
//存在的记录跳过
if
logic
.
CheckCustomerExist
(
customer
.
ErpId
)
{
continue
}
if
err
=
logic
.
InsertCustomer
(
customer
);
err
!=
nil
{
fmt
.
Println
(
err
)
break
}
//插入成功后还要去请求后端接口同步数据
SyncCustomerData
(
customer
)
}
}
}
//同步数据
func
SyncCustomerData
(
customer
model
.
Customer
)
bool
{
var
(
resp
*
req
.
Resp
url
string
respData
common
.
Response
err
error
)
param
:=
req
.
Param
{
"erp_client_sn"
:
customer
.
ErpClientCode
,
"customer_name"
:
customer
.
Name
,
"erp_customer_id"
:
customer
.
ErpId
,
"admin_name"
:
"系统"
,
"admin_id"
:
1
,
}
url
=
configs
.
BasicApiUrl
+
"/basic/api/ApiInsertCustomerInfo"
req
.
Debug
=
true
resp
,
err
=
req
.
Post
(
url
,
param
)
if
err
!=
nil
{
logSyncErrorToDataBase
(
customer
.
ErpId
,
err
.
Error
())
return
false
}
if
err
=
resp
.
ToJSON
(
&
respData
);
err
!=
nil
{
logSyncErrorToDataBase
(
customer
.
ErpId
,
err
.
Error
())
return
false
}
if
respData
.
Errcode
!=
101100
{
logSyncErrorToDataBase
(
customer
.
ErpId
,
respData
.
Errmsg
)
return
false
}
//都没问题,代表后端那边已经成功修改,修改同步表的状态
if
err
=
logic
.
SyncCustomerSuccess
(
customer
.
ErpId
);
err
!=
nil
{
fmt
.
Println
(
err
)
}
}
func
logSyncErrorToDataBase
(
erpId
,
syncError
string
)
{
var
err
error
//请求失败的话,将原因存起来
if
err
=
logic
.
WriteCustomerSyncError
(
erpId
,
syncError
);
err
!=
nil
{
//写数据失败,记录到日志
fmt
.
Println
(
err
)
}
}
cmd/queue/sync_audit_status/main.go
View file @
a6aa2bb2
...
...
@@ -8,7 +8,6 @@ import (
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"github.com/mushishixian/gosoap"
"github.com/pkg/errors"
"scm_server/cmd/queue/sync_audit_status/product"
"scm_server/configs"
"scm_server/internal/logic"
"scm_server/internal/model"
...
...
@@ -26,7 +25,7 @@ type QueueAuditStatus struct {
}
func
init
()
{
product
.
SyncErpStatus
(
"in_store"
,
"+7fvorsZSAevQCJ7ujsbLMBZJbY="
)
//
product.SyncErpStatus("in_store", "+7fvorsZSAevQCJ7ujsbLMBZJbY=")
log
.
Init
(
nil
)
}
...
...
cmd/queue/sync_customer/main.go
View file @
a6aa2bb2
...
...
@@ -51,8 +51,8 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
//判断操作类型
switch
message
.
Type
{
case
"save"
:
//先去查询是否存在
,不存在才去插入,已经存在即是修改
if
logic
.
CheckCustomer
Exist
(
customer
.
ErpId
)
{
//先去查询是否存在
已经同步完成的记录
if
logic
.
CheckCustomer
SyncStatus
(
customer
.
ErpId
)
{
operateType
=
"update"
if
err
=
logic
.
UpdateCustomer
(
customer
);
err
!=
nil
{
goto
ERR
...
...
@@ -76,7 +76,7 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
goto
ERR
}
default
:
err
=
errors
.
New
(
"同步客户出现不存在的操作类型"
+
operateType
)
err
=
errors
.
New
(
"同步客户出现不存在的操作类型
:
"
+
operateType
)
goto
ERR
}
//操作成功后还要去请求后端接口同步数据
...
...
cmd/queue/sync_customer/product.go
View file @
a6aa2bb2
...
...
@@ -18,11 +18,11 @@ func main() {
// },
//}
message
=
map
[
string
]
interface
{}{
"type"
:
"
sav
e"
,
"type"
:
"
delet
e"
,
"data"
:
map
[
string
]
string
{
"FID"
:
"
Bg/8bD0XRdayeQFMFsSgY6gYZf0=111
"
,
"FNUMBER"
:
"WT000
13
"
,
"CFNAME"
:
"深圳市
肯特尔科技
有限公司"
,
"FID"
:
"
Dd3D2Z6NRHClK+vLy4+g8qgYZf0=
"
,
"FNUMBER"
:
"WT000
21
"
,
"CFNAME"
:
"深圳市
深之和电子
有限公司"
,
},
}
data
,
err
:=
json
.
Marshal
(
message
)
...
...
internal/logic/customer.go
View file @
a6aa2bb2
...
...
@@ -8,7 +8,7 @@ import (
const
CheckCustomerExistSql
=
"SELECT customer_id FROM lie_customer WHERE erp_id = ?"
const
CheckCustomerSyncStatusSql
=
"SELECT status FROM lie_customer WHERE erp_id = ?"
const
CheckCustomerSyncStatusSql
=
"SELECT s
ync_s
tatus FROM lie_customer WHERE erp_id = ?"
const
InsertCustomerSql
=
"Insert INTO `lie_customer` (`erp_client_code`,`name`,`erp_id`,`add_time`,`sync_status`) VALUES (?,?,?,?,?)"
...
...
@@ -16,8 +16,6 @@ const UpdateCustomerSql = "UPDATE `lie_customer` SET `erp_client_code` = ? , `na
const
DeleteCustomerSql
=
"UPDATE `lie_customer` SET `status` = ? , `update_time` = ? WHERE `erp_id` = ?"
const
WriteCustomerSyncErrorSql
=
"UPDATE `lie_customer` SET sync_error = ? WHERE erp_id = ?"
const
SyncCustomerSuccessSql
=
"UPDATE `lie_customer` SET sync_status = 1 , sync_time = ? WHERE erp_id = ?"
//检查用户是否存在
...
...
@@ -30,17 +28,16 @@ func CheckCustomerExist(erpId string) (exist bool) {
//获取后端同步状态
func
CheckCustomerSyncStatus
(
erpId
string
)
(
status
bool
)
{
var
statusInt
int
dao
.
GetDb
()
.
QueryRow
(
CheckCustomerSyncStatusSql
,
erpId
)
.
Scan
(
&
statusInt
)
dao
.
GetDb
()
.
QueryRow
x
(
CheckCustomerSyncStatusSql
,
erpId
)
.
Scan
(
&
statusInt
)
return
statusInt
>
0
}
//插入用户
func
InsertCustomer
(
customer
model
.
Customer
)
(
err
error
)
{
if
!
CheckCustomerExist
(
customer
.
ErpId
)
{
_
,
err
=
dao
.
GetDb
()
.
Exec
(
InsertCustomerSql
,
customer
.
ErpClientCode
,
customer
.
Name
,
customer
.
ErpId
,
time
.
Now
()
.
Unix
(),
0
)
if
err
!=
nil
{
return
}
return
nil
return
}
//更新供应商
...
...
@@ -58,12 +55,6 @@ func DeleteCustomer(customer model.Customer) (err error) {
return
}
//写入同步失败的原因
func
WriteCustomerSyncError
(
erpId
,
syncError
string
)
(
err
error
)
{
_
,
err
=
dao
.
GetDb
()
.
Exec
(
WriteCustomerSyncErrorSql
,
syncError
,
erpId
)
return
}
//修改成功的同步状态
func
SyncCustomerSuccess
(
erpId
string
)
(
err
error
)
{
_
,
err
=
dao
.
GetDb
()
.
Exec
(
SyncCustomerSuccessSql
,
time
.
Now
()
.
Unix
(),
erpId
)
...
...
internal/logic/goods.go
View file @
a6aa2bb2
...
...
@@ -14,8 +14,6 @@ const UpdateGoodsSql = "UPDATE `lie_goods` SET `goods_name` = ? , `goods_cn_name
const
DeleteGoodsSql
=
"UPDATE `lie_goods` SET `status` = ? , `update_time` = ? WHERE `erp_id` = ?"
const
WriteGoodsSyncErrorSql
=
"UPDATE `lie_goods` SET sync_error = ? WHERE goods_id = ?"
const
SyncGoodsSuccessSql
=
"UPDATE `lie_goods` SET sync_status = 1 , sync_time = ? WHERE erp_id = ?"
const
SyncGoodsSuccessWithStatusSql
=
"UPDATE `lie_goods` SET sync_status = 1 , sync_time = ? , status = ? WHERE erp_id = ?"
...
...
@@ -49,12 +47,6 @@ func DeleteGoods(goods model.Goods) (err error) {
return
}
//写入同步失败的原因
func
WriteGoodsSyncError
(
erpId
string
,
syncError
string
)
(
err
error
)
{
_
,
err
=
dao
.
GetDb
()
.
Exec
(
WriteGoodsSyncErrorSql
,
syncError
,
erpId
)
return
}
//修改成功的同步状态
func
SyncGoodsSuccess
(
erpId
string
,
isDelete
bool
)
(
err
error
)
{
//不是删除,不需要修改状态
...
...
internal/service/dingding.go
View file @
a6aa2bb2
...
...
@@ -55,7 +55,7 @@ func SendDingTalkRobotToApi(content string) {
var
(
requestData
DingDingRequest
apiUrl
,
token
string
resp
*
req
.
Resp
//
resp *req.Resp
err
error
)
content
=
"仓储同步告警 : "
+
content
...
...
@@ -68,9 +68,8 @@ func SendDingTalkRobotToApi(content string) {
token
=
"3c048caba514a5252aa8bdbb3e10994def6409a2f0d5212e5626c1a071152ec3"
apiUrl
=
"https://api.ichunt.com/public/dingtalkrobot?access_token="
+
token
params
:=
req
.
BodyJSON
(
requestData
)
resp
,
err
=
req
.
Post
(
apiUrl
,
params
)
_
,
err
=
req
.
Post
(
apiUrl
,
params
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
fmt
.
Println
(
resp
)
}
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