Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
go_supplier_sever
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
14ecfe48
authored
Mar 23, 2021
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
忽略文件
parent
b325966d
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
8 deletions
.gitignore
app/dao/supplier_sync.go
app/queue/supplier.go
config/dev/db.toml
.gitignore
View file @
14ecfe48
/logs
/.idea
/config/*.toml
app/dao/supplier_sync.go
View file @
14ecfe48
...
...
@@ -13,32 +13,46 @@ func AddSupplierSync(supplierCode, erpSupplierCode, erpSupplierName string) (err
supplierMapping
:=
new
(
model
.
SupplierMergeMapping
)
//先去根据供应商内部编码找出对应的supplierId
_
,
err
=
Dao
.
GetDb
(
"supplier"
)
.
Table
(
"lie_supplier_channel"
)
.
Where
(
"supplier_code = ?"
,
supplierCode
)
.
Get
(
supplier
)
//不存在
直接跳过
//不存在
插入一条数据
if
supplier
.
SupplierId
==
0
{
return
err
}
//再去同步表操作对应的数据
supplierId
:=
supplier
.
SupplierId
_
,
err
=
supplierDao
.
Table
(
"lie_supplier_sync"
)
.
Where
(
"supplier_id = ?"
,
supplierId
)
.
Where
(
"erp_sync_status = ?"
,
0
)
.
_
,
err
=
supplierDao
.
Table
(
"lie_supplier_sync"
)
.
Where
(
"supplier_id = ?"
,
supplierId
)
.
Get
(
supplierSync
)
if
err
!=
nil
{
return
err
}
//还要去写映射表lie_supplier_merger_mapping
_
,
err
=
supplierDao
.
Table
(
"lie_supplier_merger_mapping"
)
.
Where
(
"old_supplier_code = ?"
,
supplierCode
)
.
Get
(
supplierMapping
)
_
,
err
=
supplierDao
.
Table
(
"lie_supplier_merger_mapping"
)
.
Where
(
"old_supplier_code = ?"
,
erpSupplierCode
)
.
Where
(
"source = ?"
,
2
)
.
Get
(
supplierMapping
)
if
err
!=
nil
{
return
err
}
//存在更新,不存在就插入
if
supplierSync
.
SupplierId
==
0
{
supplierSync
.
ErpSyncStatus
=
1
supplierSync
.
SupplierId
=
supplierId
supplierSync
.
ErpSupplierCode
=
erpSupplierCode
supplierSync
.
ErpSupplierName
=
erpSupplierName
supplierSync
.
AddTime
=
int
(
time
.
Now
()
.
Unix
())
_
,
err
=
supplierDao
.
Table
(
"lie_supplier_sync"
)
.
Insert
(
supplierSync
)
if
err
!=
nil
{
return
err
}
}
else
{
supplierSync
.
ErpSyncStatus
=
1
supplierSync
.
SupplierId
=
supplierId
supplierSync
.
ErpSupplierCode
=
erpSupplierCode
supplierSync
.
ErpSupplierName
=
erpSupplierName
//存在更新,不存在就插入
supplierSync
.
UpdateTime
=
int
(
time
.
Now
()
.
Unix
())
_
,
err
=
supplierDao
.
Table
(
"lie_supplier_sync"
)
.
Where
(
"supplier_id = ?"
,
supplierId
)
.
Update
(
supplierSync
)
if
err
!=
nil
{
return
err
}
}
if
supplierMapping
.
SupplierId
==
0
{
supplierMapping
.
OldSupplierCode
=
erpSupplierCode
...
...
@@ -46,7 +60,7 @@ func AddSupplierSync(supplierCode, erpSupplierCode, erpSupplierName string) (err
supplierMapping
.
SupplierId
=
supplier
.
SupplierId
supplierMapping
.
SupplierCode
=
supplier
.
SupplierCode
supplierMapping
.
SupplierName
=
supplier
.
SupplierName
supplierMapping
.
Source
=
1
supplierMapping
.
Source
=
2
supplierMapping
.
CreateTime
=
int
(
time
.
Now
()
.
Unix
())
_
,
err
=
supplierDao
.
Table
(
"lie_supplier_merger_mapping"
)
.
Insert
(
supplierMapping
)
if
err
!=
nil
{
...
...
app/queue/supplier.go
View file @
14ecfe48
...
...
@@ -11,6 +11,8 @@ import (
type
RecvPro
struct
{
}
var
number
int
func
init
()
{
//queueExchange := rabbitmq.QueueExchange{
// "supplier_erp",
...
...
@@ -21,17 +23,20 @@ func init() {
//}
//
//str := `{"supplierNumber":"C0000102","PTID":"L0000002","supplierID":"LxYAAAG0CQA3xn38","supplierName":"TestName"}`
//str := `{"supplierNumber":"C0000102","PTID":"12324","supplierID":"LxYAAAG0CQA3xn38"}`
//
//
str := `{"supplierNumber":"C0000102","PTID":"12324","supplierID":"LxYAAAG0CQA3xn38"}`
//rabbitmq.Send(queueExchange, str)
}
func
(
t
*
RecvPro
)
Consumer
(
dataByte
[]
byte
)
(
err
error
)
{
number
++
message
:=
string
(
dataByte
)
supplierCode
:=
gjson
.
Get
(
message
,
"PTID"
)
.
String
()
erpSupplierCode
:=
gjson
.
Get
(
message
,
"supplierNumber"
)
.
String
()
erpSupplierName
:=
gjson
.
Get
(
message
,
"supplierName"
)
.
String
()
fmt
.
Println
(
supplierCode
,
erpSupplierCode
)
err
=
service
.
AddSupplierSync
(
supplierCode
,
erpSupplierCode
,
erpSupplierName
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
}
return
nil
}
...
...
config/dev/db.toml
View file @
14ecfe48
[xorm]
ShowSQL
=
tru
e
ShowSQL
=
fals
e
[micro]
data_source_name
=
"micro_service:lie_micro_service#zsyM@tcp(192.168.2.232:3306)/lie_micro_service?charset=utf8&parseTime=true&loc=Asia%2FChongqing"
...
...
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