|
@@ -11,6 +11,7 @@ import (
|
|
"os"
|
|
"os"
|
|
"path/filepath"
|
|
"path/filepath"
|
|
"strconv"
|
|
"strconv"
|
|
|
|
+ "sync"
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -124,6 +125,10 @@ func export() {
|
|
defer MgoS.DestoryMongoConn(sess)
|
|
defer MgoS.DestoryMongoConn(sess)
|
|
count := 0
|
|
count := 0
|
|
line := 1
|
|
line := 1
|
|
|
|
+
|
|
|
|
+ ch := make(chan bool, 18)
|
|
|
|
+ wg := &sync.WaitGroup{}
|
|
|
|
+
|
|
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%100 == 0 {
|
|
if count%100 == 0 {
|
|
@@ -141,13 +146,18 @@ func export() {
|
|
log.Info("export", zap.Any("开始导采购单位", winner))
|
|
log.Info("export", zap.Any("开始导采购单位", winner))
|
|
for _, v := range contacts {
|
|
for _, v := range contacts {
|
|
line++
|
|
line++
|
|
- if data, ok := v.(map[string]interface{}); ok {
|
|
|
|
- datas := make([]interface{}, 0)
|
|
|
|
- datas = append(datas, winner, data["contact_person"], data["phone"], data["publishtime"])
|
|
|
|
- xlsx.SetSheetRow("采购单位", fmt.Sprintf("%s%d", "A", line), &datas)
|
|
|
|
- _ = xlsx.SetCellStyle("采购单位", fmt.Sprintf("%s%d", "A", line), "H"+strconv.Itoa(line), styleOne)
|
|
|
|
- _ = xlsx.SetColWidth("采购单位", "A", "E", 25)
|
|
|
|
- }
|
|
|
|
|
|
+ ch <- true
|
|
|
|
+ wg.Add(1)
|
|
|
|
+
|
|
|
|
+ go writeToExcel(xlsx, "采购单位", winner, line, v, styleOne, wg, ch)
|
|
|
|
+
|
|
|
|
+ //if data, ok := v.(map[string]interface{}); ok {
|
|
|
|
+ // datas := make([]interface{}, 0)
|
|
|
|
+ // datas = append(datas, winner, data["contact_person"], data["phone"], data["publishtime"])
|
|
|
|
+ // xlsx.SetSheetRow("采购单位", fmt.Sprintf("%s%d", "A", line), &datas)
|
|
|
|
+ // _ = xlsx.SetCellStyle("采购单位", fmt.Sprintf("%s%d", "A", line), "H"+strconv.Itoa(line), styleOne)
|
|
|
|
+ // _ = xlsx.SetColWidth("采购单位", "A", "E", 25)
|
|
|
|
+ //}
|
|
}
|
|
}
|
|
log.Info("export", zap.String("结束 ---", "采购单位数据导出"))
|
|
log.Info("export", zap.String("结束 ---", "采购单位数据导出"))
|
|
}
|
|
}
|
|
@@ -161,13 +171,15 @@ func export() {
|
|
log.Info("export", zap.Any("开始导出中标单位", winner))
|
|
log.Info("export", zap.Any("开始导出中标单位", winner))
|
|
for _, v := range contacts {
|
|
for _, v := range contacts {
|
|
line++
|
|
line++
|
|
- if data, ok := v.(map[string]interface{}); ok {
|
|
|
|
- datas := make([]interface{}, 0)
|
|
|
|
- datas = append(datas, winner, data["contact_person"], data["phone"], data["publishtime"])
|
|
|
|
- xlsx.SetSheetRow("中标单位", fmt.Sprintf("%s%d", "A", line), &datas)
|
|
|
|
- _ = xlsx.SetCellStyle("中标单位", fmt.Sprintf("%s%d", "A", line), "H"+strconv.Itoa(line), styleOne)
|
|
|
|
- _ = xlsx.SetColWidth("中标单位", "A", "E", 25)
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ go writeToExcel(xlsx, "中标单位", winner, line, v, styleOne, wg, ch)
|
|
|
|
+ //if data, ok := v.(map[string]interface{}); ok {
|
|
|
|
+ // datas := make([]interface{}, 0)
|
|
|
|
+ // datas = append(datas, winner, data["contact_person"], data["phone"], data["publishtime"])
|
|
|
|
+ // xlsx.SetSheetRow("中标单位", fmt.Sprintf("%s%d", "A", line), &datas)
|
|
|
|
+ // _ = xlsx.SetCellStyle("中标单位", fmt.Sprintf("%s%d", "A", line), "H"+strconv.Itoa(line), styleOne)
|
|
|
|
+ // _ = xlsx.SetColWidth("中标单位", "A", "E", 25)
|
|
|
|
+ //}
|
|
}
|
|
}
|
|
log.Info("export", zap.String("结束 ---", "中标单位数据导出"))
|
|
log.Info("export", zap.String("结束 ---", "中标单位数据导出"))
|
|
}
|
|
}
|
|
@@ -181,25 +193,49 @@ func export() {
|
|
log.Info("export", zap.Any("开始导出代理机关", winner))
|
|
log.Info("export", zap.Any("开始导出代理机关", winner))
|
|
for _, v := range contacts {
|
|
for _, v := range contacts {
|
|
line++
|
|
line++
|
|
- if data, ok := v.(map[string]interface{}); ok {
|
|
|
|
- datas := make([]interface{}, 0)
|
|
|
|
- datas = append(datas, winner, data["contact_person"], data["phone"], data["publishtime"])
|
|
|
|
- xlsx.SetSheetRow("代理机关", fmt.Sprintf("%s%d", "A", line), &datas)
|
|
|
|
- _ = xlsx.SetCellStyle("代理机关", fmt.Sprintf("%s%d", "A", line), "H"+strconv.Itoa(line), styleOne)
|
|
|
|
- _ = xlsx.SetColWidth("代理机关", "A", "E", 25)
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ go writeToExcel(xlsx, "代理机关", winner, line, v, styleOne, wg, ch)
|
|
|
|
+
|
|
|
|
+ //if data, ok := v.(map[string]interface{}); ok {
|
|
|
|
+ // datas := make([]interface{}, 0)
|
|
|
|
+ // datas = append(datas, winner, data["contact_person"], data["phone"], data["publishtime"])
|
|
|
|
+ // xlsx.SetSheetRow("代理机关", fmt.Sprintf("%s%d", "A", line), &datas)
|
|
|
|
+ // _ = xlsx.SetCellStyle("代理机关", fmt.Sprintf("%s%d", "A", line), "H"+strconv.Itoa(line), styleOne)
|
|
|
|
+ // _ = xlsx.SetColWidth("代理机关", "A", "E", 25)
|
|
|
|
+ //}
|
|
}
|
|
}
|
|
log.Info("export", zap.String("结束 ---", "代理机关数据导出"))
|
|
log.Info("export", zap.String("结束 ---", "代理机关数据导出"))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- xlsx.Path = exportFile
|
|
|
|
- xlsx.DeleteSheet("Sheet1")
|
|
|
|
-
|
|
|
|
- xlsx.Save()
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ wg.Wait()
|
|
|
|
+
|
|
|
|
+ xlsx.Path = exportFile
|
|
|
|
+ xlsx.DeleteSheet("Sheet1")
|
|
|
|
+
|
|
|
|
+ xlsx.Save()
|
|
|
|
+
|
|
log.Info("export", zap.String("所有数据导出", "结束 !!!"))
|
|
log.Info("export", zap.String("所有数据导出", "结束 !!!"))
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+//writeToExcel 写入Excel
|
|
|
|
+func writeToExcel(xlsx *excelize.File, sheetName string, winner interface{}, line int, data interface{}, style int, wg *sync.WaitGroup, ch chan bool) {
|
|
|
|
+
|
|
|
|
+ defer func() {
|
|
|
|
+ <-ch
|
|
|
|
+ wg.Done()
|
|
|
|
+ }()
|
|
|
|
+
|
|
|
|
+ if dataMap, ok := data.(map[string]interface{}); ok {
|
|
|
|
+ datas := make([]interface{}, 0)
|
|
|
|
+ datas = append(datas, winner, dataMap["contact_person"], dataMap["phone"], dataMap["publishtime"])
|
|
|
|
+ xlsx.SetSheetRow(sheetName, fmt.Sprintf("%s%d", "A", line), &datas)
|
|
|
|
+ _ = xlsx.SetCellStyle(sheetName, fmt.Sprintf("%s%d", "A", line), "H"+strconv.Itoa(line), style)
|
|
|
|
+ _ = xlsx.SetColWidth(sheetName, "A", "E", 25)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|