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
dd5937ce
authored
May 19, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
优化速度问题
parent
6a87045b
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
28 additions
and
52 deletions
cmd/queue/sync_goods/main.go
cmd/queue/sync_goods/product/product.go
cmd/source/goods/goods.go
cmd/source/main.go
configs/config.go
configs/env.go
configs/erp.go
configs/rabbitmq.go
cmd/queue/sync_goods/main.go
View file @
dd5937ce
...
...
@@ -25,6 +25,7 @@ type GoodsQueueMessage struct {
FGoods
string
FBrand
string
FModel
string
IsInit
bool
//是否是初始化数据
}
}
...
...
@@ -48,40 +49,22 @@ func (t *RecvPro) Consumer(dataByte []byte) error {
//判断操作类型
switch
message
.
Type
{
case
"save"
:
//先去查询是否存在已经同步完成的记录
if
logic
.
CheckGoodsSyncStatus
(
goods
.
ErpId
)
{
operateType
=
"update"
if
err
=
logic
.
UpdateGoods
(
goods
);
err
!=
nil
{
goto
ERR
}
}
else
{
operateType
=
"insert"
if
err
=
logic
.
InsertGoods
(
goods
);
err
!=
nil
{
goto
ERR
}
}
operateType
=
"insert"
case
"delete"
:
operateType
=
"delete"
goods
.
Status
=
0
if
logic
.
CheckGoodsExist
(
goods
.
ErpId
)
{
//如果存在,才进行删除
if
err
=
logic
.
DeleteGoods
(
goods
);
err
!=
nil
{
goto
ERR
}
}
else
{
err
=
errors
.
New
(
"试图删除不存在的供应商"
)
goto
ERR
}
default
:
err
=
errors
.
New
(
"同步
供应商
出现不存在的操作类型"
+
operateType
)
err
=
errors
.
New
(
"同步
商品
出现不存在的操作类型"
+
operateType
)
goto
ERR
}
//操作成功后还要去请求后端接口同步数据
if
err
=
SyncGoodsData
(
operateType
,
goods
);
err
!=
nil
{
goto
ERR
}
if
err
=
product
.
SyncErpStatus
(
"material"
,
goods
.
ErpId
);
err
!=
nil
{
goto
ERR
//不是初始化数据才去请求同步erp
if
!
message
.
Data
.
IsInit
{
if
err
=
product
.
SyncErpStatus
(
"material"
,
goods
.
ErpId
);
err
!=
nil
{
goto
ERR
}
}
return
nil
ERR
:
...
...
@@ -104,16 +87,13 @@ func SyncGoodsData(operate string, goods model.Goods) (err error) {
"admin_id"
:
1
,
}
//更新和插入接口不同
if
operate
==
"update"
{
url
=
configs
.
BasicApiUrl
+
"/basic/api/ApiUpdateGoodsInfo"
}
else
if
operate
==
"insert"
{
if
operate
==
"insert"
{
url
=
configs
.
BasicApiUrl
+
"/basic/api/ApiInsertGoodsInfo"
}
else
{
url
=
configs
.
BasicApiUrl
+
"/basic/api/ApiUpdateGoodsStatus"
}
req
.
Debug
=
false
if
operate
==
"
update"
||
operate
==
"
insert"
{
if
operate
==
"insert"
{
start
:=
time
.
Now
()
resp
,
err
=
req
.
Post
(
url
,
param
)
if
err
!=
nil
{
...
...
@@ -141,6 +121,7 @@ func SyncGoodsData(operate string, goods model.Goods) (err error) {
return
}
if
err
=
resp
.
ToJSON
(
&
respData
);
err
!=
nil
{
err
=
errors
.
New
(
fmt
.
Sprintf
(
"%s,%s"
,
resp
,
err
))
return
}
if
respData
.
Errcode
!=
101100
{
...
...
@@ -148,10 +129,6 @@ func SyncGoodsData(operate string, goods model.Goods) (err error) {
return
errors
.
New
(
fmt
.
Sprintf
(
"请求后端接口返回失败,接口链接为%s,请求参数为%s,返回的错误信息为 : %s"
,
url
,
string
(
paramJson
),
respData
.
Errmsg
))
}
}
//都没问题,代表后端那边已经成功修改,修改同步表的状态
if
err
=
logic
.
SyncGoodsSuccess
(
goods
.
ErpId
,
false
);
err
!=
nil
{
return
}
return
}
...
...
cmd/queue/sync_goods/product/product.go
View file @
dd5937ce
...
...
@@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"scm_server/configs"
)
func
main
()
{
...
...
@@ -12,10 +11,10 @@ func main() {
message
=
map
[
string
]
interface
{}{
"type"
:
"save"
,
"data"
:
map
[
string
]
string
{
"FID"
:
"imqWd01vR7qdD/+CY8FKHkQJ5/A="
,
"FGoods"
:
"
test123145
1"
,
"FBrand"
:
"
TEST123145
"
,
"FModel"
:
"
test123145
1"
,
"FID"
:
"imqWd01vR7qdD/+CY8FKHkQJ5/A=
112
"
,
"FGoods"
:
"
1111
1"
,
"FBrand"
:
"
1111
"
,
"FModel"
:
"
111
1"
,
},
}
data
,
err
:=
json
.
Marshal
(
message
)
...
...
@@ -28,7 +27,7 @@ func main() {
"scm_store_goods"
,
"scm_store"
,
"direct"
,
configs
.
RABBITMQDSN
,
"amqp://huntadmin:jy2y2900@192.168.1.237:5672/"
,
}
rabbitmq
.
Send
(
queueExchange
,
body
)
...
...
cmd/source/goods/goods.go
View file @
dd5937ce
...
...
@@ -34,7 +34,8 @@ func Import(wg *sync.WaitGroup) {
err
error
goods
model
.
Goods
)
excelFileName
=
"../cmd/source/data/goods.xlsx"
//excelFileName = "../cmd/source/data/goods.xlsx"
excelFileName
=
"cmd/source/data/goods.xlsx"
xlFile
,
err
=
xlsx
.
OpenFile
(
excelFileName
)
if
err
!=
nil
{
fmt
.
Printf
(
"open failed: %s
\n
"
,
err
)
...
...
@@ -55,11 +56,12 @@ func Import(wg *sync.WaitGroup) {
message
:=
make
(
map
[
string
]
interface
{})
message
=
map
[
string
]
interface
{}{
"type"
:
"save"
,
"data"
:
map
[
string
]
string
{
"data"
:
map
[
string
]
interface
{}
{
"FID"
:
goods
.
ErpId
,
"FGoods"
:
goods
.
GoodsCnName
,
"FBrand"
:
goods
.
BrandName
,
"FModel"
:
goods
.
GoodsName
,
"IsInit"
:
true
,
},
}
data
,
err
:=
json
.
Marshal
(
message
)
...
...
cmd/source/main.go
View file @
dd5937ce
...
...
@@ -3,7 +3,6 @@ package main
import
(
"flag"
"scm_server/cmd/source/goods"
"scm_server/cmd/source/supplier"
"scm_server/configs"
"sync"
)
...
...
@@ -14,8 +13,8 @@ func main() {
flag
.
Parse
()
configs
.
Setup
(
path
)
var
wg
sync
.
WaitGroup
wg
.
Add
(
2
)
go
supplier
.
Import
(
&
wg
)
wg
.
Add
(
1
)
//
go supplier.Import(&wg)
//go customer.Import(&wg)
go
goods
.
Import
(
&
wg
)
wg
.
Wait
()
...
...
configs/config.go
View file @
dd5937ce
...
...
@@ -11,15 +11,14 @@ var Cfg *ini.File
func
Setup
(
path
string
)
{
var
err
error
//Cfg, err = ini.Load("conf/config.ini")
Cfg
,
err
=
ini
.
Load
(
path
)
if
err
!=
nil
{
fmt
.
Printf
(
"Fail to read file: %v"
,
err
)
os
.
Exit
(
1
)
}
SetUp
One
()
SetUp
Two
()
SetUp
Three
()
SetUp
Env
()
SetUp
Erp
()
SetUp
MQ
()
}
func
GetConfig
(
section
,
name
string
)
string
{
...
...
configs/env.go
View file @
dd5937ce
...
...
@@ -18,7 +18,7 @@ var ErpLoginStatusApi string
var
OpenFalconPushUrl
string
func
SetUp
One
()
{
func
SetUp
Env
()
{
BasicApiUrl
=
GetConfig
(
"api"
,
"base"
)
OutStoreApiUrl
=
GetConfig
(
"api"
,
"out_store"
)
InStoreApiUrl
=
GetConfig
(
"api"
,
"in_store"
)
...
...
configs/erp.go
View file @
dd5937ce
...
...
@@ -8,7 +8,7 @@ var ErpLanguage string
var
ErpDbType
string
var
ErpAuthPattern
string
func
SetUp
Two
()
{
func
SetUp
Erp
()
{
ErpUserName
=
GetConfig
(
"erp"
,
"userName"
)
ErpPassword
=
GetConfig
(
"erp"
,
"password"
)
ErpSlnName
=
GetConfig
(
"erp"
,
"slnName"
)
...
...
configs/rabbitmq.go
View file @
dd5937ce
...
...
@@ -3,6 +3,6 @@ package configs
//const RABBITMQDSN = "amqp://huntadmin:jy2y2900@192.168.1.237:5672/"
var
RABBITMQDSN
string
func
SetUp
Three
()
{
func
SetUp
MQ
()
{
RABBITMQDSN
=
GetConfig
(
"rabbitmq"
,
"url"
)
}
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