bidding.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/wcc4869/common_utils/log"
  5. util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  6. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  7. )
  8. // dealBiddingNiJian 更新bidding ,owner 不为空的赋值给buyer
  9. //if toptype == "拟建"
  10. // if tmp["owner"] != nil
  11. // tmp["buyer"] = tmp["owner"]
  12. func dealBiddingNiJian() {
  13. defer util.Catch()
  14. sess := MgoB.GetMgoConn()
  15. defer MgoB.DestoryMongoConn(sess)
  16. where := map[string]interface{}{
  17. "comeintime": map[string]interface{}{
  18. "$lt": 1735228800,
  19. },
  20. "toptype": "拟建",
  21. }
  22. it := sess.DB("qfw").C("bidding").Find(where).Select(nil).Iter()
  23. fmt.Println("taskRun 开始")
  24. count := 0
  25. for tmp := make(map[string]interface{}); it.Next(&tmp); count++ {
  26. if count%10000 == 0 {
  27. log.Info("current", log.Int("count", count), log.Any("_id", tmp["_id"]))
  28. }
  29. if util.ObjToString(tmp["toptype"]) == "拟建" {
  30. update := map[string]interface{}{}
  31. esUpdate := map[string]interface{}{}
  32. biddingID := mongodb.BsonIdToSId(tmp["_id"])
  33. if tmp["owner"] != nil {
  34. update["buyer"] = tmp["owner"]
  35. esUpdate["buyer"] = tmp["owner"]
  36. }
  37. if len(update) > 0 {
  38. //更新mongo
  39. //MgoT.UpdateById("bidding", biddingID, map[string]interface{}{"$set": update})
  40. //更新MongoDB
  41. updatePool <- []map[string]interface{}{
  42. {"_id": tmp["_id"]},
  43. {"$set": update},
  44. }
  45. //2.es 项目 更新字段
  46. //err := Es.UpdateDocument("bidding", biddingID, update)
  47. //if err != nil && err.Error() != "Document not updated: noop" {
  48. // log.Info("bidding es update err", err, biddingID)
  49. //}
  50. //// 更新es
  51. //updateEsPool <- []map[string]interface{}{
  52. // {"_id": biddingID},
  53. // update,
  54. //}
  55. }
  56. // 更新Es 数据
  57. if len(esUpdate) > 0 {
  58. // 更新es
  59. updateEsPool <- []map[string]interface{}{
  60. {"_id": biddingID},
  61. esUpdate,
  62. }
  63. }
  64. }
  65. }
  66. log.Info("Run Over...Count:", log.Int("count", count))
  67. }
  68. // updateBiddingBidamount 处理bidding 中标金额,预算数据
  69. func updateBiddingBidamount() {
  70. defer util.Catch()
  71. sess := MgoB.GetMgoConn()
  72. defer MgoB.DestoryMongoConn(sess)
  73. it := sess.DB("qfw").C("zktest_repair_0107").Find(nil).Select(nil).Iter()
  74. fmt.Println("taskRun 开始")
  75. count := 0
  76. for tmp := make(map[string]interface{}); it.Next(&tmp); count++ {
  77. if count%10000 == 0 {
  78. log.Info("current", log.Int("count", count), log.Any("_id", tmp["_id"]))
  79. }
  80. update := make(map[string]interface{})
  81. if bidamount, ok := tmp["bidamount"]; ok {
  82. update["bidamount"] = bidamount
  83. } else {
  84. update["bidamount"] = 0.0
  85. }
  86. if _, ok := tmp["budget"]; ok {
  87. update["budget"] = tmp["budget"]
  88. } else {
  89. update["budget"] = 0.0
  90. }
  91. biddingID := mongodb.BsonIdToSId(tmp["_id"])
  92. if len(update) > 0 {
  93. //project := getProject(biddingID)
  94. //if len(project) > 0 {
  95. // //projectID := mongodb.BsonIdToSId(project["_id"])
  96. // //err := Es.UpdateDocument("projectset", projectID, update)
  97. // //err = EsNew.UpdateDocument("projectset", projectID, update)
  98. // //if err != nil && err.Error() != "Document not updated: noop" {
  99. // // log.Info("bidding es update err", err, biddingID)
  100. // //}
  101. //}
  102. // 更新bidding es
  103. err := Es.UpdateDocument("bidding", biddingID, update)
  104. err = EsNew.UpdateDocument("bidding", biddingID, update)
  105. if err != nil && err.Error() != "Document not updated: noop" {
  106. log.Info("bidding es update err", err, biddingID)
  107. }
  108. }
  109. }
  110. log.Info("数据处理完毕", log.Int("total", count))
  111. }