main.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "mongodb"
  6. "qfw/util"
  7. "strconv"
  8. "strings"
  9. "github.com/shopspring/decimal"
  10. "github.com/tealeg/xlsx"
  11. )
  12. var (
  13. Sysconfig map[string]interface{}
  14. Mgo *mongodb.MongodbSim
  15. Dbname, DbColl string
  16. ExportType, IsMark int
  17. Search map[string]interface{}
  18. Fields map[string]interface{}
  19. FieldsArr []string
  20. FiedlsPurchase []string
  21. SE = util.SimpleEncrypt{Key: "topJYBX2019"}
  22. )
  23. func init() {
  24. util.ReadConfig(&Sysconfig)
  25. // Mgo = &mongodb.MongodbSim{
  26. // MongodbAddr: Sysconfig["mgoAddr"].(string),
  27. // Size: util.IntAllDef(Sysconfig["mgoSize"], 5),
  28. // DbName: Sysconfig["mgoDbName"].(string),
  29. // }
  30. // Mgo.InitPool()
  31. log.Println(Sysconfig)
  32. Mgo = mongodb.NewMgo(Sysconfig["mgoAddr"].(string), Sysconfig["mgoDbName"].(string), 15)
  33. Dbname = Sysconfig["mgoDbName"].(string)
  34. DbColl = Sysconfig["mgoColl"].(string)
  35. ExportType = util.IntAll(Sysconfig["exportType"])
  36. IsMark = util.IntAll(Sysconfig["isMark"])
  37. Search = Sysconfig["search"].(map[string]interface{})
  38. FieldsArr = util.ObjArrToStringArr(Sysconfig["fieldsSort"].([]interface{}))
  39. Fields = Sysconfig["fields"].(map[string]interface{})
  40. FiedlsPurchase = util.ObjArrToStringArr(Sysconfig["fields_purchase"].([]interface{}))
  41. if ExportType == 1 {
  42. FieldsArr[len(FieldsArr)-1] = "itemname"
  43. FieldsArr = append(FieldsArr, "brandname", "model", "unitname", "unitprice", "number", "totalprice", "id")
  44. Fields["itemname"] = "产品名称"
  45. Fields["brandname"] = "品牌"
  46. Fields["model"] = "规格型号"
  47. Fields["unitname"] = "单位"
  48. Fields["unitprice"] = "单价"
  49. Fields["number"] = "数量"
  50. Fields["totalprice"] = "小计"
  51. } else if ExportType == 3 {
  52. FiedlsPurchase[len(FiedlsPurchase)-1] = "projectname_purchase"
  53. FiedlsPurchase = append(FiedlsPurchase, "projectscope_purchase", "item", "buyer_purchase", "remark", "totalprice", "expurasingtime", "cgyxxqhref", "id")
  54. Fields["projectname_purchase"] = "采购意向名称"
  55. Fields["projectscope_purchase"] = "采购内容"
  56. Fields["item"] = "采购品目"
  57. Fields["remark"] = "备注"
  58. Fields["buyer_purchase"] = "采购单位"
  59. Fields["totalprice"] = "预计采购金额(元)"
  60. Fields["expurasingtime"] = "预计采购时间"
  61. Fields["cgyxxqhref"] = "采购意向详情链接"
  62. } else if ExportType == 4 {
  63. FieldsArr[len(FieldsArr)-1] = "itemname"
  64. FieldsArr = append(FieldsArr, "brandname", "madel", "unitname", "unitprice", "number", "totalprice", "id", "departroom")
  65. Fields["itemname"] = "产品名称"
  66. Fields["brandname"] = "品牌"
  67. Fields["madel"] = "规格型号"
  68. Fields["unitname"] = "单位"
  69. Fields["unitprice"] = "单价"
  70. Fields["number"] = "数量"
  71. Fields["totalprice"] = "小计"
  72. Fields["departroom"] = "科室"
  73. }
  74. util.Debug(FieldsArr)
  75. }
  76. func main() {
  77. sess := Mgo.GetMgoConn()
  78. defer Mgo.DestoryMongoConn(sess)
  79. contentMap := map[string]bool{}
  80. file := xlsx.NewFile()
  81. sheet, err := file.AddSheet("sheet1")
  82. if err != nil {
  83. panic(err)
  84. }
  85. row := sheet.AddRow()
  86. if ExportType == 3 {
  87. // 标的物 采购意向
  88. for _, v := range FiedlsPurchase {
  89. row.AddCell().SetValue(Fields[v])
  90. }
  91. } else {
  92. for _, v := range FieldsArr {
  93. row.AddCell().SetValue(Fields[v])
  94. }
  95. }
  96. q := map[string]interface{}{}
  97. if len(Search) > 0 {
  98. q = Search
  99. }
  100. c := Mgo.Count(DbColl, q)
  101. util.Debug("search size result ---", DbColl, q, c)
  102. if c == 0 {
  103. return
  104. }
  105. query := sess.DB(Dbname).C(DbColl).Find(&q).Iter()
  106. count := 0
  107. for tmp := make(map[string]interface{}); query.Next(&tmp); count++ {
  108. if count%500 == 0 {
  109. util.Debug("current ---", count)
  110. }
  111. var baseInfo map[string]interface{}
  112. if tmp["v_baseinfo"] != nil {
  113. baseInfo = tmp["v_baseinfo"].(map[string]interface{})
  114. } else {
  115. baseInfo = tmp
  116. }
  117. tagInfo, _ := tmp["v_taginfo"].(map[string]interface{})
  118. switch ExportType {
  119. case 0:
  120. // 不拆分
  121. row := sheet.AddRow()
  122. for _, v := range FieldsArr {
  123. if v == "publishtime" || v == "bidopentime" || v == "project_startdate" || v == "project_completedate" ||
  124. v == "signaturedate" || v == "comeintime" || v == "createtime" {
  125. str := ""
  126. if baseInfo[v] != nil {
  127. date := util.Int64All(baseInfo[v])
  128. str = util.FormatDateByInt64(&date, util.Date_Short_Layout)
  129. }
  130. row.AddCell().SetValue(str)
  131. } else if v == "id" {
  132. if tmp["id"] != nil {
  133. id := SE.EncodeString(util.ObjToString(tmp["id"]))
  134. row.AddCell().SetValue(id)
  135. } else {
  136. id := SE.EncodeString(mongodb.BsonIdToSId(tmp["_id"]))
  137. row.AddCell().SetValue(id)
  138. }
  139. } else {
  140. row.AddCell().SetValue(baseInfo[v])
  141. }
  142. }
  143. case 1:
  144. // 拆分标的物
  145. if IsMark == 1 {
  146. if tagInfo["purchasinglist"] != nil {
  147. if baseInfo["purchasinglist"] != nil {
  148. plist := baseInfo["purchasinglist"].([]interface{})
  149. for _, p := range plist {
  150. row := sheet.AddRow()
  151. p1 := p.(map[string]interface{})
  152. for _, v := range FieldsArr {
  153. if v == "itemname" || v == "brandname" || v == "model" || v == "unitname" || v == "unitprice" || v == "number" {
  154. row.AddCell().SetValue(p1[v])
  155. } else if v == "totalprice" {
  156. if p1["totalprice"] != nil {
  157. row.AddCell().SetValue(p1[v])
  158. } else {
  159. if p1["unitprice"] != nil && p1["number"] != nil {
  160. d1 := decimal.NewFromFloat(util.Float64All(p1["unitprice"])).Mul(decimal.NewFromInt(int64(util.IntAll(p1["number"]))))
  161. row.AddCell().SetValue(d1)
  162. } else {
  163. row.AddCell().SetValue("")
  164. }
  165. }
  166. } else if v == "publishtime" || v == "bidopentime" || v == "project_startdate" || v == "project_completedate" ||
  167. v == "signaturedate" || v == "comeintime" || v == "createtime" {
  168. str := ""
  169. if baseInfo[v] != nil {
  170. date := util.Int64All(baseInfo[v])
  171. str = util.FormatDateByInt64(&date, util.Date_Short_Layout)
  172. }
  173. row.AddCell().SetValue(str)
  174. } else if v == "id" {
  175. if tmp["id"] != nil {
  176. id := SE.EncodeString(util.ObjToString(tmp["id"]))
  177. row.AddCell().SetValue(id)
  178. } else {
  179. id := SE.EncodeString(mongodb.BsonIdToSId(tmp["_id"]))
  180. row.AddCell().SetValue(id)
  181. }
  182. } else {
  183. row.AddCell().SetValue(baseInfo[v])
  184. }
  185. }
  186. }
  187. } else {
  188. row := sheet.AddRow()
  189. for _, v := range FieldsArr {
  190. if v == "publishtime" || v == "bidopentime" || v == "project_startdate" || v == "project_completedate" ||
  191. v == "signaturedate" || v == "comeintime" || v == "createtime" {
  192. str := ""
  193. if baseInfo[v] != nil {
  194. date := util.Int64All(baseInfo[v])
  195. str = util.FormatDateByInt64(&date, util.Date_Short_Layout)
  196. }
  197. row.AddCell().SetValue(str)
  198. } else if v == "id" {
  199. if tmp["id"] != nil {
  200. id := SE.EncodeString(util.ObjToString(tmp["id"]))
  201. row.AddCell().SetValue(id)
  202. } else {
  203. id := SE.EncodeString(mongodb.BsonIdToSId(tmp["_id"]))
  204. row.AddCell().SetValue(id)
  205. }
  206. } else {
  207. row.AddCell().SetValue(baseInfo[v])
  208. }
  209. }
  210. }
  211. } else {
  212. row := sheet.AddRow()
  213. for _, v := range FieldsArr {
  214. if v == "publishtime" || v == "bidopentime" || v == "project_startdate" || v == "project_completedate" ||
  215. v == "signaturedate" || v == "comeintime" || v == "createtime" {
  216. str := ""
  217. if baseInfo[v] != nil {
  218. date := util.Int64All(baseInfo[v])
  219. str = util.FormatDateByInt64(&date, util.Date_Short_Layout)
  220. }
  221. row.AddCell().SetValue(str)
  222. } else if v == "id" {
  223. if tmp["id"] != nil {
  224. id := SE.EncodeString(util.ObjToString(tmp["id"]))
  225. row.AddCell().SetValue(id)
  226. } else {
  227. id := SE.EncodeString(mongodb.BsonIdToSId(tmp["_id"]))
  228. row.AddCell().SetValue(id)
  229. }
  230. } else {
  231. row.AddCell().SetValue(baseInfo[v])
  232. }
  233. }
  234. }
  235. } else {
  236. if baseInfo["purchasinglist"] != nil {
  237. plist := baseInfo["purchasinglist"].([]interface{})
  238. for _, p := range plist {
  239. row := sheet.AddRow()
  240. p1 := p.(map[string]interface{})
  241. for _, v := range FieldsArr {
  242. if v == "itemname" || v == "brandname" || v == "model" || v == "unitname" || v == "unitprice" || v == "number" {
  243. row.AddCell().SetValue(p1[v])
  244. } else if v == "totalprice" {
  245. if p1["totalprice"] != nil {
  246. row.AddCell().SetValue(p1[v])
  247. } else {
  248. if p1["unitprice"] != nil && p1["number"] != nil {
  249. d1 := decimal.NewFromFloat(util.Float64All(p1["unitprice"])).Mul(decimal.NewFromInt(int64(util.IntAll(p1["number"]))))
  250. row.AddCell().SetValue(d1)
  251. } else {
  252. row.AddCell().SetValue("")
  253. }
  254. }
  255. } else if v == "publishtime" || v == "bidopentime" || v == "project_startdate" || v == "project_completedate" ||
  256. v == "signaturedate" || v == "comeintime" || v == "createtime" {
  257. str := ""
  258. if baseInfo[v] != nil {
  259. date := util.Int64All(baseInfo[v])
  260. str = util.FormatDateByInt64(&date, util.Date_Short_Layout)
  261. }
  262. row.AddCell().SetValue(str)
  263. } else if v == "id" {
  264. if tmp["id"] != nil {
  265. id := SE.EncodeString(util.ObjToString(tmp["id"]))
  266. row.AddCell().SetValue(id)
  267. } else {
  268. id := SE.EncodeString(mongodb.BsonIdToSId(tmp["_id"]))
  269. row.AddCell().SetValue(id)
  270. }
  271. } else {
  272. row.AddCell().SetValue(baseInfo[v])
  273. }
  274. }
  275. }
  276. } else {
  277. row := sheet.AddRow()
  278. for _, v := range FieldsArr {
  279. if v == "publishtime" || v == "bidopentime" || v == "project_startdate" || v == "project_completedate" ||
  280. v == "signaturedate" || v == "comeintime" || v == "createtime" {
  281. str := ""
  282. if baseInfo[v] != nil {
  283. date := util.Int64All(baseInfo[v])
  284. str = util.FormatDateByInt64(&date, util.Date_Short_Layout)
  285. }
  286. row.AddCell().SetValue(str)
  287. } else if v == "id" {
  288. if tmp["id"] != nil {
  289. id := SE.EncodeString(util.ObjToString(tmp["id"]))
  290. row.AddCell().SetValue(id)
  291. } else {
  292. id := SE.EncodeString(mongodb.BsonIdToSId(tmp["_id"]))
  293. row.AddCell().SetValue(id)
  294. }
  295. } else {
  296. row.AddCell().SetValue(baseInfo[v])
  297. }
  298. }
  299. }
  300. break
  301. }
  302. case 2:
  303. // 多包拆分
  304. if baseInfo["package"] != nil {
  305. pkg := baseInfo["package"].(map[string]interface{})
  306. for _, p := range pkg {
  307. row := sheet.AddRow()
  308. p1 := p.(map[string]interface{})
  309. winner := []string{}
  310. bidamount := float64(0)
  311. if p1["winner_all"] != nil {
  312. if all := p1["winner_all"].([]interface{}); all != nil {
  313. if len(all) > 0 {
  314. for _, a := range all {
  315. a1 := a.(map[string]interface{})
  316. if util.ObjToString(a1["winner"]) != "" {
  317. winner = append(winner, util.ObjToString(a1["winner"]))
  318. }
  319. bidamount = util.Float64All(a1["bidamount"])
  320. }
  321. }
  322. }
  323. }
  324. for _, v := range FieldsArr {
  325. if v == "s_winner" && len(winner) > 0 {
  326. row.AddCell().SetValue(strings.Join(winner, ","))
  327. } else if v == "bidamount" {
  328. row.AddCell().SetValue(bidamount)
  329. } else if v == "winnerperson" || v == "winnertel" {
  330. row.AddCell().SetValue("")
  331. } else if v == "publishtime" || v == "bidopentime" || v == "project_startdate" || v == "project_completedate" ||
  332. v == "signaturedate" || v == "comeintime" || v == "createtime" {
  333. str := ""
  334. if baseInfo[v] != nil {
  335. date := util.Int64All(baseInfo[v])
  336. str = util.FormatDateByInt64(&date, util.Date_Short_Layout)
  337. }
  338. row.AddCell().SetValue(str)
  339. } else if v == "id" {
  340. if tmp["id"] != nil {
  341. id := SE.EncodeString(util.ObjToString(tmp["id"]))
  342. row.AddCell().SetValue(id)
  343. } else {
  344. id := SE.EncodeString(mongodb.BsonIdToSId(tmp["_id"]))
  345. row.AddCell().SetValue(id)
  346. }
  347. } else {
  348. row.AddCell().SetValue(baseInfo[v])
  349. }
  350. }
  351. }
  352. } else {
  353. row := sheet.AddRow()
  354. for _, v := range FieldsArr {
  355. if v == "publishtime" || v == "bidopentime" || v == "project_startdate" || v == "project_completedate" ||
  356. v == "signaturedate" || v == "comeintime" || v == "createtime" {
  357. str := ""
  358. if baseInfo[v] != nil {
  359. date := util.Int64All(baseInfo[v])
  360. str = util.FormatDateByInt64(&date, util.Date_Short_Layout)
  361. }
  362. row.AddCell().SetValue(str)
  363. } else if v == "id" {
  364. if tmp["id"] != nil {
  365. id := SE.EncodeString(util.ObjToString(tmp["id"]))
  366. row.AddCell().SetValue(id)
  367. } else {
  368. id := SE.EncodeString(mongodb.BsonIdToSId(tmp["_id"]))
  369. row.AddCell().SetValue(id)
  370. }
  371. } else {
  372. row.AddCell().SetValue(baseInfo[v])
  373. }
  374. }
  375. }
  376. case 3:
  377. // 标的物 采购意向数据拆分
  378. if baseInfo["procurementlist"] != nil {
  379. plist := baseInfo["procurementlist"].([]interface{})
  380. for _, p := range plist {
  381. isOk := false
  382. m := make(map[string]interface{})
  383. p1 := p.(map[string]interface{})
  384. matchkey := util.ObjToString(baseInfo["matchkey"])
  385. projectname_purchase := util.ObjToString(p1["projectname"])
  386. projectscope_purchase := util.ObjToString(p1["projectscope"])
  387. remark := util.ObjToString(p1["remark"])
  388. item := util.ObjToString(p1["item"])
  389. for _, m := range strings.Split(matchkey, ",") {
  390. if strings.Contains(projectname_purchase, m) || strings.Contains(projectscope_purchase, m) || strings.Contains(remark, m) || strings.Contains(item, m) {
  391. isOk = true
  392. }
  393. }
  394. log.Println("matchkey ", matchkey)
  395. log.Println("projectname_purchase ", projectname_purchase)
  396. log.Println("projectscope_purchase ", projectscope_purchase)
  397. log.Println("remark ", remark)
  398. if isOk {
  399. row := sheet.AddRow()
  400. expurasingtime := strconv.Itoa(util.IntAll(p1["expurasingtime"]))
  401. buyer_purchase := util.ObjToString(p1["buyer"])
  402. totalprice := strconv.FormatFloat(util.Float64All(p1["totalprice"]), 'f', -1, 64)
  403. content := projectname_purchase + buyer_purchase + expurasingtime + totalprice
  404. if contentMap[content] {
  405. continue
  406. } else {
  407. contentMap[content] = true
  408. }
  409. for _, v := range FiedlsPurchase {
  410. if v == "projectname_purchase" || v == "projectscope_purchase" || v == "item" || v == "buyer_purchase" ||
  411. v == "totalprice" || v == "expurasingtime" || v == "cgyxxqhref" || v == "remark" {
  412. v1 := strings.ReplaceAll(v, "_purchase", "")
  413. row.AddCell().SetValue(p1[v1])
  414. m[v] = p1[v1]
  415. } else if v == "publishtime" || v == "bidopentime" || v == "project_startdate" || v == "project_completedate" ||
  416. v == "signaturedate" || v == "comeintime" || v == "createtime" {
  417. str := ""
  418. if baseInfo[v] != nil {
  419. date := util.Int64All(baseInfo[v])
  420. str = util.FormatDateByInt64(&date, util.Date_Short_Layout)
  421. }
  422. row.AddCell().SetValue(str)
  423. m[v] = str
  424. } else if v == "id" {
  425. if tmp["id"] != nil {
  426. id := SE.EncodeString(util.ObjToString(tmp["id"]))
  427. row.AddCell().SetValue(id)
  428. m[v] = id
  429. } else {
  430. id := SE.EncodeString(mongodb.BsonIdToSId(tmp["_id"]))
  431. row.AddCell().SetValue(id)
  432. m[v] = id
  433. }
  434. } else {
  435. row.AddCell().SetValue(baseInfo[v])
  436. m[v] = baseInfo[v]
  437. }
  438. }
  439. Mgo.Save("bidding_v1", m)
  440. }
  441. }
  442. } else {
  443. row := sheet.AddRow()
  444. m := make(map[string]interface{})
  445. for _, v := range FiedlsPurchase {
  446. if v == "publishtime" || v == "bidopentime" || v == "project_startdate" || v == "project_completedate" ||
  447. v == "signaturedate" || v == "comeintime" || v == "createtime" {
  448. str := ""
  449. if baseInfo[v] != nil {
  450. date := util.Int64All(baseInfo[v])
  451. str = util.FormatDateByInt64(&date, util.Date_Short_Layout)
  452. }
  453. row.AddCell().SetValue(str)
  454. m[v] = str
  455. } else if v == "id" {
  456. if tmp["id"] != nil {
  457. id := SE.EncodeString(util.ObjToString(tmp["id"]))
  458. row.AddCell().SetValue(id)
  459. m[v] = id
  460. } else {
  461. id := SE.EncodeString(mongodb.BsonIdToSId(tmp["_id"]))
  462. row.AddCell().SetValue(id)
  463. m[v] = id
  464. }
  465. } else {
  466. row.AddCell().SetValue(baseInfo[v])
  467. m[v] = baseInfo[v]
  468. }
  469. }
  470. Mgo.Save(DbColl+"_cf", m)
  471. }
  472. case 4:
  473. // 多包 标的物拆分
  474. if baseInfo["package"] != nil {
  475. pkg := baseInfo["package"].(map[string]interface{})
  476. for _, p := range pkg {
  477. p1 := p.(map[string]interface{})
  478. winner := []string{}
  479. bidamount := float64(0)
  480. if p1["winner_all"] != nil {
  481. if all := p1["winner_all"].([]interface{}); all != nil {
  482. if len(all) > 0 {
  483. for _, a := range all {
  484. a1 := a.(map[string]interface{})
  485. if util.ObjToString(a1["winner"]) != "" {
  486. winner = append(winner, util.ObjToString(a1["winner"]))
  487. }
  488. bidamount = util.Float64All(a1["bidamount"])
  489. }
  490. }
  491. }
  492. }
  493. if len(winner) <= 0 {
  494. continue
  495. }
  496. if plist, ok := p1["purchasinglist"].([]interface{}); ok {
  497. for _, p := range plist {
  498. row := sheet.AddRow()
  499. p1 := p.(map[string]interface{})
  500. for _, v := range FieldsArr {
  501. if v == "itemname" || v == "brandname" || v == "madel" || v == "unitname" || v == "unitprice" || v == "number" || v == "departroom" {
  502. row.AddCell().SetValue(p1[v])
  503. } else if v == "totalprice" {
  504. if p1["totalprice"] != nil {
  505. row.AddCell().SetValue(p1[v])
  506. } else {
  507. if p1["unitprice"] != nil && p1["number"] != nil {
  508. d1 := decimal.NewFromFloat(util.Float64All(p1["unitprice"])).Mul(decimal.NewFromInt(int64(util.IntAll(p1["number"]))))
  509. row.AddCell().SetValue(d1)
  510. } else {
  511. row.AddCell().SetValue("")
  512. }
  513. }
  514. } else if v == "bidamount" {
  515. row.AddCell().SetValue(bidamount)
  516. } else if v == "publishtime" || v == "bidopentime" || v == "project_startdate" || v == "project_completedate" ||
  517. v == "signaturedate" || v == "comeintime" || v == "createtime" {
  518. str := ""
  519. if baseInfo[v] != nil {
  520. date := util.Int64All(baseInfo[v])
  521. str = util.FormatDateByInt64(&date, util.Date_Short_Layout)
  522. }
  523. row.AddCell().SetValue(str)
  524. } else if v == "s_winner" {
  525. row.AddCell().SetValue(strings.Join(winner, ","))
  526. } else if v == "id" {
  527. if tmp["id"] != nil {
  528. id := SE.EncodeString(util.ObjToString(tmp["id"]))
  529. row.AddCell().SetValue(id)
  530. } else {
  531. id := SE.EncodeString(mongodb.BsonIdToSId(tmp["_id"]))
  532. row.AddCell().SetValue(id)
  533. }
  534. } else {
  535. row.AddCell().SetValue(baseInfo[v])
  536. }
  537. }
  538. }
  539. }
  540. }
  541. } else {
  542. row := sheet.AddRow()
  543. for _, v := range FieldsArr {
  544. if v == "publishtime" || v == "bidopentime" || v == "project_startdate" || v == "project_completedate" ||
  545. v == "signaturedate" || v == "comeintime" || v == "createtime" {
  546. str := ""
  547. if baseInfo[v] != nil {
  548. date := util.Int64All(baseInfo[v])
  549. str = util.FormatDateByInt64(&date, util.Date_Short_Layout)
  550. }
  551. row.AddCell().SetValue(str)
  552. } else if v == "id" {
  553. if tmp["id"] != nil {
  554. id := SE.EncodeString(util.ObjToString(tmp["id"]))
  555. row.AddCell().SetValue(id)
  556. } else {
  557. id := SE.EncodeString(mongodb.BsonIdToSId(tmp["_id"]))
  558. row.AddCell().SetValue(id)
  559. }
  560. } else {
  561. row.AddCell().SetValue(baseInfo[v])
  562. }
  563. }
  564. }
  565. }
  566. }
  567. util.Debug("over ---", count)
  568. fname := fmt.Sprintf("./数据导出%s.xlsx", util.NowFormat(util.DATEFORMAT))
  569. err = file.Save(fname)
  570. if err != nil {
  571. panic(err)
  572. }
  573. }