Browse Source

修复导出数据量 错误

wcc 2 years ago
parent
commit
6faf58382f
2 changed files with 22 additions and 13 deletions
  1. 3 3
      exportContact/config.toml
  2. 19 10
      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 = "20230616HP_1"  ## 数据表名
+    coll = "zlm-111111"  ## 数据表名
     username = ""
     username = ""
     password = ""
     password = ""
     size = 15
     size = 15
 
 
 [env]
 [env]
 
 
-    winner  = 1           ## 1表示 导出中标单位信息;0 表示不导出
-    buyer = 0
+    winner  = 0          ## 1表示 导出中标单位信息;0 表示不导出
+    buyer = 1
     agency = 0
     agency = 0

+ 19 - 10
exportContact/main.go

@@ -70,6 +70,7 @@ func InitLog() {
 		os.Exit(1)
 		os.Exit(1)
 	}
 	}
 }
 }
+
 func main() {
 func main() {
 	Init()
 	Init()
 
 
@@ -103,16 +104,31 @@ func export() {
 		},
 		},
 	)
 	)
 
 
+	if GF.Env.Buyer > 0 {
+		xlsx.NewSheet("采购单位")
+		xlsx.SetSheetRow("采购单位", fmt.Sprintf("%s%d", "A", 1), &[]interface{}{"采购单位", "联系人", "联系电话", "发布时间"})
+
+	}
+
+	if GF.Env.Winner > 0 {
+		xlsx.NewSheet("中标单位")
+		xlsx.SetSheetRow("中标单位", fmt.Sprintf("%s%d", "A", 1), &[]interface{}{"中标单位", "联系人", "联系电话", "发布时间"})
+
+	}
+	if GF.Env.Agency > 0 {
+		xlsx.NewSheet("代理机关")
+		xlsx.SetSheetRow("代理机关", fmt.Sprintf("%s%d", "A", 1), &[]interface{}{"代理机关", "联系人", "联系电话", "发布时间"})
+	}
+
 	sess := MgoS.GetMgoConn()
 	sess := MgoS.GetMgoConn()
 	defer MgoS.DestoryMongoConn(sess)
 	defer MgoS.DestoryMongoConn(sess)
 	count := 0
 	count := 0
-
+	line := 1
 	query := sess.DB(MgoS.DbName).C(GF.MongoS.Coll).Find(nil).Select(nil).Iter()
 	query := sess.DB(MgoS.DbName).C(GF.MongoS.Coll).Find(nil).Select(nil).Iter()
 	for tmp := make(map[string]interface{}); query.Next(tmp); count++ {
 	for tmp := make(map[string]interface{}); query.Next(tmp); count++ {
-		if count%1000 == 0 {
+		if count%100 == 0 {
 			fmt.Println(fmt.Sprintf("dealTmp current --- %d", count))
 			fmt.Println(fmt.Sprintf("dealTmp current --- %d", count))
 		}
 		}
-
 		var winner interface{}
 		var winner interface{}
 		if tmp["company_name"] != nil {
 		if tmp["company_name"] != nil {
 			winner = tmp["company_name"]
 			winner = tmp["company_name"]
@@ -120,12 +136,9 @@ func export() {
 
 
 		//1.采购单位数据
 		//1.采购单位数据
 		if GF.Env.Buyer > 0 {
 		if GF.Env.Buyer > 0 {
-			line := 1
 			if tmp["buyer_contacts"] != nil {
 			if tmp["buyer_contacts"] != nil {
 				if contacts, ok := tmp["buyer_contacts"].([]interface{}); ok {
 				if contacts, ok := tmp["buyer_contacts"].([]interface{}); ok {
 					log.Info("export", zap.Any("开始导采购单位", winner))
 					log.Info("export", zap.Any("开始导采购单位", winner))
-					xlsx.NewSheet("采购单位")
-					xlsx.SetSheetRow("采购单位", fmt.Sprintf("%s%d", "A", line), &[]interface{}{"采购单位", "联系人", "联系电话", "发布时间"})
 					for _, v := range contacts {
 					for _, v := range contacts {
 						line++
 						line++
 						if data, ok := v.(map[string]interface{}); ok {
 						if data, ok := v.(map[string]interface{}); ok {
@@ -146,8 +159,6 @@ func export() {
 			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))
-					xlsx.NewSheet("中标单位")
-					xlsx.SetSheetRow("中标单位", fmt.Sprintf("%s%d", "A", line), &[]interface{}{"中标单位", "联系人", "联系电话", "发布时间"})
 					for _, v := range contacts {
 					for _, v := range contacts {
 						line++
 						line++
 						if data, ok := v.(map[string]interface{}); ok {
 						if data, ok := v.(map[string]interface{}); ok {
@@ -168,8 +179,6 @@ func export() {
 			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))
-					xlsx.NewSheet("代理机关")
-					xlsx.SetSheetRow("代理机关", fmt.Sprintf("%s%d", "A", line), &[]interface{}{"代理机关", "联系人", "联系电话", "发布时间"})
 					for _, v := range contacts {
 					for _, v := range contacts {
 						line++
 						line++
 						if data, ok := v.(map[string]interface{}); ok {
 						if data, ok := v.(map[string]interface{}); ok {