Commit 30b2e198 by mushishixian

导入初始数据修改成异步

parent 82d7e9c2
......@@ -8,6 +8,7 @@ import (
"scm_server/configs"
"scm_server/internal/logic"
"scm_server/internal/model"
"sync"
)
var Exchange rabbitmq.QueueExchange
......@@ -22,7 +23,8 @@ func init() {
configs.RABBITMQDSN,
}
}
func Import() {
func Import(wg *sync.WaitGroup) {
defer wg.Done()
var (
excelFileName string
xlFile *xlsx.File
......@@ -49,8 +51,6 @@ func Import() {
//去数据库检测是否已经同步过了
if exist := logic.CheckCustomerExist(customer.ErpId); exist {
i++
fmt.Println("已存在,跳过")
fmt.Println(i)
continue
}
message := make(map[string]interface{})
......@@ -67,8 +67,8 @@ func Import() {
fmt.Println(err)
}
body := string(data)
fmt.Println(message)
rabbitmq.Send(Exchange, body)
}
}
fmt.Println("已完成客户导入")
}
......@@ -8,6 +8,7 @@ import (
"scm_server/configs"
"scm_server/internal/logic"
"scm_server/internal/model"
"sync"
)
var Exchange rabbitmq.QueueExchange
......@@ -24,7 +25,8 @@ func init() {
}
//导入委托方的信息(excel导入)
func Import() {
func Import(wg *sync.WaitGroup) {
defer wg.Done()
var (
excelFileName string
xlFile *xlsx.File
......@@ -71,4 +73,5 @@ func Import() {
rabbitmq.Send(Exchange, body)
}
}
fmt.Println("已完成物料导入")
}
package main
import "scm_server/cmd/source/goods"
import (
"scm_server/cmd/source/customer"
"scm_server/cmd/source/goods"
"scm_server/cmd/source/supplier"
"sync"
)
func main() {
//forever := make(chan bool)
//go supplier.Import()
//supplier.Import()
//<-forever
//customer.Import()
goods.Import()
var wg sync.WaitGroup
wg.Add(3)
go supplier.Import(&wg)
go customer.Import(&wg)
go goods.Import(&wg)
wg.Wait()
}
......@@ -8,6 +8,7 @@ import (
"scm_server/configs"
"scm_server/internal/logic"
"scm_server/internal/model"
"sync"
)
var Exchange rabbitmq.QueueExchange
......@@ -24,7 +25,8 @@ func init() {
}
//导入委托方的信息(excel导入)
func Import() {
func Import(wg *sync.WaitGroup) {
defer wg.Done()
var (
excelFileName string
xlFile *xlsx.File
......@@ -61,9 +63,9 @@ func Import() {
fmt.Println(err)
}
body := string(data)
fmt.Println(message)
rabbitmq.Send(Exchange, body)
}
}
}
fmt.Println("已完成供应商导入")
}
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