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
b325966d
authored
Mar 11, 2021
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
同步代码
parent
e02431c5
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
107 additions
and
22 deletions
.idea/dictionaries/HUNT.xml
app/dao/supplier_sync.go
app/model/supplier.go
app/model/supplier_merger_mapping.go
app/model/supplier_sync.go
app/queue/supplier.go
app/service/supplier_sync.go
go.mod
go.sum
.idea/dictionaries/HUNT.xml
View file @
b325966d
<component
name=
"ProjectDictionaryState"
>
<dictionary
name=
"HUNT"
>
<words>
<w>
ptid
</w>
<w>
xorm
</w>
</words>
</dictionary>
...
...
app/dao/supplier_sync.go
View file @
b325966d
package
dao
import
(
"fmt"
"go-supplier-sync/app/model"
"time"
)
func
AddSupplierSync
()
{
var
supplierSync
model
.
SupplierSync
Dao
.
GetDb
(
"supplier"
)
.
Table
(
"supplier_sync"
)
.
Where
(
"id"
,
1
)
.
Get
(
&
supplierSync
)
fmt
.
Println
(
supplierSync
)
//添加erp同步记录
func
AddSupplierSync
(
supplierCode
,
erpSupplierCode
,
erpSupplierName
string
)
(
err
error
)
{
supplierDao
:=
Dao
.
GetDb
(
"supplier"
)
supplierSync
:=
new
(
model
.
SupplierSync
)
supplier
:=
new
(
model
.
Supplier
)
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
)
.
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
)
if
err
!=
nil
{
return
err
}
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
supplierMapping
.
OldSupplierName
=
erpSupplierName
supplierMapping
.
SupplierId
=
supplier
.
SupplierId
supplierMapping
.
SupplierCode
=
supplier
.
SupplierCode
supplierMapping
.
SupplierName
=
supplier
.
SupplierName
supplierMapping
.
Source
=
1
supplierMapping
.
CreateTime
=
int
(
time
.
Now
()
.
Unix
())
_
,
err
=
supplierDao
.
Table
(
"lie_supplier_merger_mapping"
)
.
Insert
(
supplierMapping
)
if
err
!=
nil
{
return
err
}
}
else
{
supplierMapping
.
OldSupplierName
=
erpSupplierName
supplierMapping
.
UpdateTime
=
int
(
time
.
Now
()
.
Unix
())
_
,
err
=
supplierDao
.
Table
(
"lie_supplier_merger_mapping"
)
.
Where
(
"old_supplier_code = ?"
,
erpSupplierCode
)
.
Update
(
supplierMapping
)
if
err
!=
nil
{
return
err
}
}
return
}
app/model/supplier.go
0 → 100644
View file @
b325966d
package
model
type
Supplier
struct
{
SupplierId
int
SupplierCode
string
SupplierName
string
}
app/model/supplier_merger_mapping.go
0 → 100644
View file @
b325966d
package
model
type
SupplierMergeMapping
struct
{
Id
int
OldSupplierCode
string
SupplierCode
string
SupplierId
int
OldSupplierName
string
SupplierName
string
Source
int
CreateTime
int
UpdateTime
int
}
app/model/supplier_sync.go
View file @
b325966d
...
...
@@ -3,8 +3,9 @@ package model
type
SupplierSync
struct
{
Id
int
SupplierId
int
ErpSync
int
ErpSync
Status
int
ErpSupplierCode
string
ErpSupplierName
string
AddTime
int
UpdateTime
int
}
app/queue/supplier.go
View file @
b325966d
...
...
@@ -4,29 +4,34 @@ import (
"fmt"
"github.com/ichunt2019/cfg/lib"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"go-supplier-sync/app/dao"
"github.com/tidwall/gjson"
"go-supplier-sync/app/service"
)
type
RecvPro
struct
{
}
func
init
()
{
queueExchange
:=
rabbitmq
.
QueueExchange
{
"supplier_erp"
,
""
,
""
,
""
,
"amqp://guest:guest@192.168.2.232:5672/"
,
}
str
:=
`{"supplierNumber":"C0000102","PTID":"L0001","supplierID":"LxYAAAG0CQA3xn38
"}`
//
queueExchange := rabbitmq.QueueExchange{
//
"supplier_erp",
//
"",
//
"",
//
"",
//
"amqp://guest:guest@192.168.2.232:5672/",
//
}
//
//str := `{"supplierNumber":"C0000102","PTID":"L0000002","supplierID":"LxYAAAG0CQA3xn38","supplierName":"TestName
"}`
//str := `{"supplierNumber":"C0000102","PTID":"12324","supplierID":"LxYAAAG0CQA3xn38"}`
rabbitmq
.
Send
(
queueExchange
,
str
)
//
rabbitmq.Send(queueExchange, str)
}
func
(
t
*
RecvPro
)
Consumer
(
dataByte
[]
byte
)
(
err
error
)
{
fmt
.
Println
(
"开始"
)
dao
.
AddSupplierSync
()
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
)
return
nil
}
...
...
app/service/supplier_sync.go
View file @
b325966d
...
...
@@ -2,7 +2,6 @@ package service
import
"go-supplier-sync/app/dao"
func
AddSupplierSync
()
{
dao
.
AddSupplierSync
()
func
AddSupplierSync
(
supplierCode
,
erpSupplierCode
,
erpSupplierName
string
)
(
err
error
)
{
return
dao
.
AddSupplierSync
(
supplierCode
,
erpSupplierCode
,
erpSupplierName
)
}
go.mod
View file @
b325966d
...
...
@@ -14,6 +14,7 @@ require (
github.com/ichunt2019/lxLog v0.0.0-20210226024426-781becb3c042
github.com/mattn/go-sqlite3 v1.14.6 // indirect
github.com/spf13/viper v1.7.1
github.com/tidwall/gjson v1.6.8
google.golang.org/protobuf v1.25.0 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
xorm.io/xorm v1.0.7
...
...
go.sum
View file @
b325966d
...
...
@@ -293,6 +293,12 @@ github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69
github.com/syndtr/goleveldb v1.0.0 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/syyongx/php2go v0.9.4/go.mod h1:meN2eIhhUoxOd2nMxbpe8g6cFPXI5O9/UAAuz7oDdzw=
github.com/tidwall/gjson v1.6.8 h1:CTmXMClGYPAmln7652e69B7OLXfTi5ABcPPwjIWUv7w=
github.com/tidwall/gjson v1.6.8/go.mod h1:zeFuBCIqD4sN/gmqBzZ4j7Jd6UcA2Fc56x7QFsv+8fI=
github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE=
github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
github.com/tidwall/pretty v1.0.2 h1:Z7S3cePv9Jwm1KwS0513MRaoUe3S01WPbLNV40pwWZU=
github.com/tidwall/pretty v1.0.2/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 h1:LnC5Kc/wtumK+WB441p7ynQJzVuNRJiqddSIE3IlSEQ=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
...
...
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