|
@@ -155,7 +155,7 @@ func exportTestData() {
|
|
|
sess := MgoP.GetMgoConn()
|
|
|
defer MgoP.DestoryMongoConn(sess)
|
|
|
|
|
|
- queryMgo := sess.DB("qfw").C("wcc_dealXlsxData_0523").Find(nil).Select(nil).Iter()
|
|
|
+ queryMgo := sess.DB("qfw").C("wcc_dealXlsxData_0524").Find(nil).Select(nil).Iter()
|
|
|
count := 0
|
|
|
|
|
|
for tmp := make(map[string]interface{}); queryMgo.Next(tmp); count++ {
|
|
@@ -241,6 +241,141 @@ func exportTestData() {
|
|
|
log.Println("✅ 数据写入完成,共写入行数:", rowIndex-startRow)
|
|
|
}
|
|
|
|
|
|
+// exportTestData1 导出统计局 拟建数据
|
|
|
+func exportTestData1() {
|
|
|
+ // 1. 连接 MongoDB
|
|
|
+ sess := MgoP.GetMgoConn()
|
|
|
+ defer MgoP.DestoryMongoConn(sess)
|
|
|
+
|
|
|
+ // 2. 打开 Excel 模板
|
|
|
+ f, err := excelize.OpenFile("统计局入库项目数据目录树.xlsx")
|
|
|
+ if err != nil {
|
|
|
+ log.Fatalf("无法打开Excel模板: %v", err)
|
|
|
+ }
|
|
|
+ sheet := f.GetSheetName(0)
|
|
|
+ rowIndex := 3 // 假设第一行是表头
|
|
|
+
|
|
|
+ where := map[string]interface{}{
|
|
|
+ "city": "陇南市",
|
|
|
+ }
|
|
|
+ // 3. 查询 Mongo 数据
|
|
|
+ queryMgo := sess.DB("qfw").C("wcc_dealProposed22_0524").Find(where).Iter()
|
|
|
+ count := 0
|
|
|
+
|
|
|
+ for tmp := make(map[string]interface{}); queryMgo.Next(tmp); count++ {
|
|
|
+ if count%1000 == 0 {
|
|
|
+ log.Println("current", count)
|
|
|
+ }
|
|
|
+
|
|
|
+ //projectname := util.ObjToString(tmp["p1_project_name"])
|
|
|
+ //where := map[string]interface{}{"projectname": projectname}
|
|
|
+ //pro_project, _ := MgoP.FindOne("projectset_proposed", where)
|
|
|
+
|
|
|
+ //ppid := ""
|
|
|
+ //if pro_project != nil {
|
|
|
+ // ppid = mongodb.BsonIdToSId((*pro_project)["_id"])
|
|
|
+ //}
|
|
|
+
|
|
|
+ v1 := []interface{}{
|
|
|
+ //ppid,
|
|
|
+ tmp["proposed_id"],
|
|
|
+ tmp["approvecode"],
|
|
|
+ tmp["projectname"],
|
|
|
+ tmp["buyer"],
|
|
|
+ tmp["credit_no"],
|
|
|
+ fmt.Sprintf("%s-%s-%s", tmp["area"], tmp["city"], tmp["district"]),
|
|
|
+ }
|
|
|
+
|
|
|
+ // ----------- 核心容错处理逻辑 ------------
|
|
|
+ if biddingListRaw, ok := tmp["bidding"]; ok {
|
|
|
+ biddingList, ok := biddingListRaw.([]interface{})
|
|
|
+ if !ok || len(biddingList) == 0 {
|
|
|
+ writeEmptyRow(f, sheet, rowIndex, v1)
|
|
|
+ rowIndex++
|
|
|
+ } else {
|
|
|
+ for _, bidItem := range biddingList {
|
|
|
+ bidMap, ok := bidItem.(map[string]interface{})
|
|
|
+ if !ok {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ if util.ObjToString(bidMap["toptype"]) == "拟建" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ // v2
|
|
|
+ v2 := make([]interface{}, 9)
|
|
|
+ for i := range v2 {
|
|
|
+ v2[i] = ""
|
|
|
+ }
|
|
|
+
|
|
|
+ if projRaw, ok := bidMap["project"]; ok {
|
|
|
+ if project, ok := projRaw.(map[string]interface{}); ok {
|
|
|
+ firstTimeStr := ""
|
|
|
+ if val, ok := project["firsttime"]; ok {
|
|
|
+ if t := util.Int64All(val); t > 0 {
|
|
|
+ firstTimeStr = time.Unix(t, 0).In(time.FixedZone("CST", 8*3600)).Format("2006-01-02 15:04:05")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ v2 = []interface{}{
|
|
|
+ project["project_id"],
|
|
|
+ project["projectname"],
|
|
|
+ project["bidamount"],
|
|
|
+ project["area"],
|
|
|
+ project["city"],
|
|
|
+ project["bidstatus"],
|
|
|
+ project["buyer"],
|
|
|
+ firstTimeStr,
|
|
|
+ bidMap["score"],
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ publishTimeStr := ""
|
|
|
+ if val, ok := bidMap["publishtime"]; ok {
|
|
|
+ if t := util.Int64All(val); t > 0 {
|
|
|
+ publishTimeStr = time.Unix(t, 0).In(time.FixedZone("CST", 8*3600)).Format("2006-01-02 15:04:05")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ v3 := []interface{}{
|
|
|
+ bidMap["id"],
|
|
|
+ bidMap["title"],
|
|
|
+ bidMap["subtype"],
|
|
|
+ bidMap["area"],
|
|
|
+ bidMap["city"],
|
|
|
+ bidMap["buyer"],
|
|
|
+ bidMap["budget"],
|
|
|
+ bidMap["buyerperson"],
|
|
|
+ bidMap["buyertel"],
|
|
|
+ bidMap["s_winner"],
|
|
|
+ bidMap["bidamount"],
|
|
|
+ bidMap["winnertel"],
|
|
|
+ bidMap["agency"],
|
|
|
+ publishTimeStr,
|
|
|
+ bidMap["score"],
|
|
|
+ }
|
|
|
+
|
|
|
+ fullRow := append(append(v1, v2...), v3...)
|
|
|
+ cell, _ := excelize.CoordinatesToCellName(1, rowIndex)
|
|
|
+ f.SetSheetRow(sheet, cell, &fullRow)
|
|
|
+ rowIndex++
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // bidding 字段不存在
|
|
|
+ writeEmptyRow(f, sheet, rowIndex, v1)
|
|
|
+ rowIndex++
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 保存结果
|
|
|
+ if err := f.SaveAs("输出结果.xlsx"); err != nil {
|
|
|
+ log.Fatalf("保存文件失败: %v", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ log.Println("导出完成,保存为 输出结果.xlsx")
|
|
|
+}
|
|
|
+
|
|
|
+// exportTestData2 导出 陇南市 拟建数据
|
|
|
func exportTestData2() {
|
|
|
// 1. 连接 MongoDB
|
|
|
sess := MgoP.GetMgoConn()
|
|
@@ -278,12 +413,23 @@ func exportTestData2() {
|
|
|
v1 := []interface{}{
|
|
|
//ppid,
|
|
|
tmp["proposed_id"],
|
|
|
- tmp["proposed_number"],
|
|
|
+ tmp["approvecode"],
|
|
|
tmp["projectname"],
|
|
|
tmp["buyer"],
|
|
|
tmp["credit_no"],
|
|
|
- fmt.Sprintf("%s-%s", tmp["area"], tmp["city"]),
|
|
|
}
|
|
|
+ //fmt.Sprintf("%s-%s-%s", tmp["area"], tmp["city"], tmp["district"]),
|
|
|
+ acd := ""
|
|
|
+ if util.ObjToString(tmp["area"]) != "" {
|
|
|
+ acd = util.ObjToString(tmp["area"])
|
|
|
+ }
|
|
|
+ if util.ObjToString(tmp["city"]) != "" {
|
|
|
+ acd = acd + "-" + util.ObjToString(tmp["city"])
|
|
|
+ }
|
|
|
+ if util.ObjToString(tmp["district"]) != "" {
|
|
|
+ acd = acd + "-" + util.ObjToString(tmp["district"])
|
|
|
+ }
|
|
|
+ v1 = append(v1, acd)
|
|
|
|
|
|
// ----------- 核心容错处理逻辑 ------------
|
|
|
if biddingListRaw, ok := tmp["bidding"]; ok {
|
|
@@ -387,3 +533,30 @@ func writeEmptyRow(f *excelize.File, sheet string, rowIndex int, v1 []interface{
|
|
|
cell, _ := excelize.CoordinatesToCellName(1, rowIndex)
|
|
|
f.SetSheetRow(sheet, cell, &fullRow)
|
|
|
}
|
|
|
+
|
|
|
+// 测试,更新approvecode 字段
|
|
|
+func ddd() {
|
|
|
+ sess := MgoP.GetMgoConn()
|
|
|
+ defer MgoP.DestoryMongoConn(sess)
|
|
|
+
|
|
|
+ // 3. 查询 Mongo 数据
|
|
|
+ queryMgo := sess.DB("qfw").C("wcc_dealProposed22_0524").Find(nil).Iter()
|
|
|
+ count := 0
|
|
|
+
|
|
|
+ for tmp := make(map[string]interface{}); queryMgo.Next(tmp); count++ {
|
|
|
+ if count%1000 == 0 {
|
|
|
+ log.Println("current", count)
|
|
|
+ }
|
|
|
+
|
|
|
+ pro_id := util.ObjToString(tmp["proposed_id"])
|
|
|
+ pro, _ := MgoP.FindById("projectset_proposed", pro_id, nil)
|
|
|
+ if util.ObjToString((*pro)["approvecode"]) != "" {
|
|
|
+ update := map[string]interface{}{
|
|
|
+ "approvecode": (*pro)["approvecode"],
|
|
|
+ }
|
|
|
+
|
|
|
+ id := mongodb.BsonIdToSId(tmp["_id"])
|
|
|
+ MgoP.UpdateById("wcc_dealProposed22_0524", id, map[string]interface{}{"$set": update})
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|