Browse Source

修复数据数量错误问题

wcc 1 year ago
parent
commit
3e437989a0
2 changed files with 14 additions and 12 deletions
  1. 3 3
      exportContact/config.toml
  2. 11 9
      exportContact/main.go

+ 3 - 3
exportContact/config.toml

@@ -1,13 +1,13 @@
 [mongos]
 [mongos]
     host = "192.168.3.166:27082"
     host = "192.168.3.166:27082"
     db = "fanglei"
     db = "fanglei"
-    coll = "20230630Hp"  ## 数据表名
+    coll = "11111"  ## 数据表名
     username = ""
     username = ""
     password = ""
     password = ""
     size = 15
     size = 15
 
 
 [env]
 [env]
 
 
-    winner  = 0          ## 1表示 导出中标单位信息;0 表示不导出
-    buyer = 1
+    winner  = 1         ## 1表示 导出中标单位信息;0 表示不导出
+    buyer = 0
     agency = 0
     agency = 0

+ 11 - 9
exportContact/main.go

@@ -125,6 +125,8 @@ func export() {
 	defer MgoS.DestoryMongoConn(sess)
 	defer MgoS.DestoryMongoConn(sess)
 	count := 0
 	count := 0
 	line := 1
 	line := 1
+	winnerLine := 1
+	agencyLine := 1
 
 
 	ch := make(chan bool, 18)
 	ch := make(chan bool, 18)
 	wg := &sync.WaitGroup{}
 	wg := &sync.WaitGroup{}
@@ -165,14 +167,14 @@ func export() {
 		}
 		}
 		//2.中标单位
 		//2.中标单位
 		if GF.Env.Winner > 0 {
 		if GF.Env.Winner > 0 {
-			line := 1
 			if tmp["winner_contacts"] != nil {
 			if tmp["winner_contacts"] != nil {
 				if contacts, ok := tmp["winner_contacts"].([]interface{}); ok {
 				if contacts, ok := tmp["winner_contacts"].([]interface{}); ok {
 					log.Info("export", zap.Any("开始导出中标单位", winner))
 					log.Info("export", zap.Any("开始导出中标单位", winner))
 					for _, v := range contacts {
 					for _, v := range contacts {
-						line++
-
-						go writeToExcel(xlsx, "中标单位", winner, line, v, styleOne, wg, ch)
+						winnerLine++
+						ch <- true
+						wg.Add(1)
+						go writeToExcel(xlsx, "中标单位", winner, winnerLine, v, styleOne, wg, ch)
 						//if data, ok := v.(map[string]interface{}); ok {
 						//if data, ok := v.(map[string]interface{}); ok {
 						//	datas := make([]interface{}, 0)
 						//	datas := make([]interface{}, 0)
 						//	datas = append(datas, winner, data["contact_person"], data["phone"], data["publishtime"])
 						//	datas = append(datas, winner, data["contact_person"], data["phone"], data["publishtime"])
@@ -187,14 +189,14 @@ func export() {
 		}
 		}
 		//3.代理机关
 		//3.代理机关
 		if GF.Env.Agency > 0 {
 		if GF.Env.Agency > 0 {
-			line := 1
 			if tmp["agency_contacts"] != nil {
 			if tmp["agency_contacts"] != nil {
 				if contacts, ok := tmp["agency_contacts"].([]interface{}); ok {
 				if contacts, ok := tmp["agency_contacts"].([]interface{}); ok {
 					log.Info("export", zap.Any("开始导出代理机关", winner))
 					log.Info("export", zap.Any("开始导出代理机关", winner))
 					for _, v := range contacts {
 					for _, v := range contacts {
-						line++
-
-						go writeToExcel(xlsx, "代理机关", winner, line, v, styleOne, wg, ch)
+						agencyLine++
+						ch <- true
+						wg.Add(1)
+						writeToExcel(xlsx, "代理机关", winner, agencyLine, v, styleOne, wg, ch)
 
 
 						//if data, ok := v.(map[string]interface{}); ok {
 						//if data, ok := v.(map[string]interface{}); ok {
 						//	datas := make([]interface{}, 0)
 						//	datas := make([]interface{}, 0)
@@ -222,7 +224,7 @@ func export() {
 
 
 }
 }
 
 
-//writeToExcel 写入Excel
+// writeToExcel 写入Excel
 func writeToExcel(xlsx *excelize.File, sheetName string, winner interface{}, line int, data interface{}, style int, wg *sync.WaitGroup, ch chan bool) {
 func writeToExcel(xlsx *excelize.File, sheetName string, winner interface{}, line int, data interface{}, style int, wg *sync.WaitGroup, ch chan bool) {
 
 
 	defer func() {
 	defer func() {