Commit b325966d by mushishixian

同步代码

parent e02431c5
<component name="ProjectDictionaryState"> <component name="ProjectDictionaryState">
<dictionary name="HUNT"> <dictionary name="HUNT">
<words> <words>
<w>ptid</w>
<w>xorm</w> <w>xorm</w>
</words> </words>
</dictionary> </dictionary>
......
package dao package dao
import ( import (
"fmt"
"go-supplier-sync/app/model" "go-supplier-sync/app/model"
"time"
) )
func AddSupplierSync() { //添加erp同步记录
var supplierSync model.SupplierSync func AddSupplierSync(supplierCode, erpSupplierCode, erpSupplierName string) (err error) {
Dao.GetDb("supplier").Table("supplier_sync").Where("id", 1).Get(&supplierSync) supplierDao := Dao.GetDb("supplier")
fmt.Println(supplierSync) 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
} }
package model
type Supplier struct {
SupplierId int
SupplierCode string
SupplierName string
}
package model
type SupplierMergeMapping struct {
Id int
OldSupplierCode string
SupplierCode string
SupplierId int
OldSupplierName string
SupplierName string
Source int
CreateTime int
UpdateTime int
}
...@@ -3,8 +3,9 @@ package model ...@@ -3,8 +3,9 @@ package model
type SupplierSync struct { type SupplierSync struct {
Id int Id int
SupplierId int SupplierId int
ErpSync int ErpSyncStatus int
ErpSupplierCode string ErpSupplierCode string
ErpSupplierName string
AddTime int AddTime int
UpdateTime int UpdateTime int
} }
...@@ -4,29 +4,34 @@ import ( ...@@ -4,29 +4,34 @@ import (
"fmt" "fmt"
"github.com/ichunt2019/cfg/lib" "github.com/ichunt2019/cfg/lib"
"github.com/ichunt2019/go-rabbitmq/utils/rabbitmq" "github.com/ichunt2019/go-rabbitmq/utils/rabbitmq"
"go-supplier-sync/app/dao" "github.com/tidwall/gjson"
"go-supplier-sync/app/service"
) )
type RecvPro struct { type RecvPro struct {
} }
func init() { func init() {
queueExchange := rabbitmq.QueueExchange{ //queueExchange := rabbitmq.QueueExchange{
"supplier_erp", // "supplier_erp",
"", // "",
"", // "",
"", // "",
"amqp://guest:guest@192.168.2.232:5672/", // "amqp://guest:guest@192.168.2.232:5672/",
} //}
//
str := `{"supplierNumber":"C0000102","PTID":"L0001","supplierID":"LxYAAAG0CQA3xn38"}` //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) //rabbitmq.Send(queueExchange, str)
} }
func (t *RecvPro) Consumer(dataByte []byte) (err error) { func (t *RecvPro) Consumer(dataByte []byte) (err error) {
fmt.Println("开始") message := string(dataByte)
dao.AddSupplierSync() 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 return nil
} }
......
...@@ -2,7 +2,6 @@ package service ...@@ -2,7 +2,6 @@ package service
import "go-supplier-sync/app/dao" import "go-supplier-sync/app/dao"
func AddSupplierSync(supplierCode, erpSupplierCode, erpSupplierName string) (err error) {
func AddSupplierSync() { return dao.AddSupplierSync(supplierCode, erpSupplierCode, erpSupplierName)
dao.AddSupplierSync()
} }
...@@ -14,6 +14,7 @@ require ( ...@@ -14,6 +14,7 @@ require (
github.com/ichunt2019/lxLog v0.0.0-20210226024426-781becb3c042 github.com/ichunt2019/lxLog v0.0.0-20210226024426-781becb3c042
github.com/mattn/go-sqlite3 v1.14.6 // indirect github.com/mattn/go-sqlite3 v1.14.6 // indirect
github.com/spf13/viper v1.7.1 github.com/spf13/viper v1.7.1
github.com/tidwall/gjson v1.6.8
google.golang.org/protobuf v1.25.0 // indirect google.golang.org/protobuf v1.25.0 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect sigs.k8s.io/yaml v1.2.0 // indirect
xorm.io/xorm v1.0.7 xorm.io/xorm v1.0.7
......
...@@ -293,6 +293,12 @@ github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69 ...@@ -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 h1:fBdIW9lB4Iz0n9khmH8w27SJ3QEJ7+IgjPEwGSZiFdE=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= 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/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 h1:LnC5Kc/wtumK+WB441p7ynQJzVuNRJiqddSIE3IlSEQ=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= 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= github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment