Commit dd5937ce by mushishixian

优化速度问题

parent 6a87045b
......@@ -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
}
......
......@@ -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": "test1231451",
"FBrand": "TEST123145",
"FModel": "test1231451",
"FID": "imqWd01vR7qdD/+CY8FKHkQJ5/A=112",
"FGoods": "11111",
"FBrand": "1111",
"FModel": "1111",
},
}
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)
......
......@@ -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)
......
......@@ -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()
......
......@@ -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)
}
SetUpOne()
SetUpTwo()
SetUpThree()
SetUpEnv()
SetUpErp()
SetUpMQ()
}
func GetConfig(section, name string) string {
......
......@@ -18,7 +18,7 @@ var ErpLoginStatusApi string
var OpenFalconPushUrl string
func SetUpOne() {
func SetUpEnv() {
BasicApiUrl = GetConfig("api", "base")
OutStoreApiUrl = GetConfig("api", "out_store")
InStoreApiUrl = GetConfig("api", "in_store")
......
......@@ -8,7 +8,7 @@ var ErpLanguage string
var ErpDbType string
var ErpAuthPattern string
func SetUpTwo() {
func SetUpErp() {
ErpUserName = GetConfig("erp", "userName")
ErpPassword = GetConfig("erp", "password")
ErpSlnName = GetConfig("erp", "slnName")
......
......@@ -3,6 +3,6 @@ package configs
//const RABBITMQDSN = "amqp://huntadmin:jy2y2900@192.168.1.237:5672/"
var RABBITMQDSN string
func SetUpThree() {
func SetUpMQ() {
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