Commit dd5937ce by mushishixian

优化速度问题

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