Commit 30b2e198 by mushishixian

导入初始数据修改成异步

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