check.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package main
  2. import (
  3. "github.com/uuid"
  4. "log"
  5. qu "qfw/util"
  6. "strings"
  7. "sync"
  8. )
  9. // 开始审查数据
  10. func startCheckData(sid, eid string) {
  11. defer qu.Catch()
  12. q := map[string]interface{}{
  13. "_id": map[string]interface{}{
  14. "$gt": StringTOBsonId(sid),
  15. "$lte": StringTOBsonId(eid),
  16. },
  17. }
  18. check_pool := make(chan bool, check_thread)
  19. check_wg := &sync.WaitGroup{}
  20. sess := data_mgo.GetMgoConn()
  21. defer data_mgo.DestoryMongoConn(sess)
  22. it := sess.DB(data_mgo.DbName).C(coll_name).Find(&q).Iter()
  23. total := 0
  24. for tmp := make(map[string]interface{}); it.Next(&tmp); total++ {
  25. if total%10000 == 0 {
  26. log.Println("当前数量:", total, tmp["_id"])
  27. }
  28. update_id := map[string]interface{}{"_id": tmp["_id"]}
  29. check_pool <- true
  30. check_wg.Add(1)
  31. go func(tmp map[string]interface{}, update_id map[string]interface{}) {
  32. defer func() {
  33. <-check_pool
  34. check_wg.Done()
  35. }()
  36. //更新-
  37. update_info := make(map[string]interface{}, 0)
  38. //审查-发布时间
  39. getCheckDataPub(tmp, update_info)
  40. //审查-单位信息
  41. getCheckDataUnit(tmp, update_info)
  42. //是否删除
  43. is_unset := false
  44. if update_ai {
  45. is_unset = ChooseCheckDataAI(tmp, &update_info)
  46. if update_info["com_package"] == nil { //构建单包信息···
  47. com_package := CreatSingleFieldInfo(tmp, update_info)
  48. update_info["com_package"] = com_package
  49. }
  50. }
  51. //最终更新
  52. if len(update_info) > 0 {
  53. UpdateTask.updatePool <- []map[string]interface{}{
  54. update_id,
  55. {"$set": update_info},
  56. }
  57. }
  58. if is_unset {
  59. UpdateTask.updatePool <- []map[string]interface{}{
  60. update_id,
  61. {"$unset": Unset_Check},
  62. }
  63. }
  64. }(tmp, update_id)
  65. tmp = make(map[string]interface{})
  66. }
  67. check_wg.Wait()
  68. log.Println("data_clean is over ", total)
  69. sendNextNode(sid, eid)
  70. }
  71. func CreatSingleFieldInfo(tmp map[string]interface{}, update_info map[string]interface{}) []map[string]interface{} {
  72. pkgArr := []map[string]interface{}{}
  73. com_package := map[string]interface{}{}
  74. package_id := uuid.New().String()
  75. package_id = strings.ReplaceAll(package_id, "-", "")
  76. com_package["package_id"] = package_id
  77. com_package["name"] = qu.ObjToString(tmp["projectname"])
  78. if update_info["budget"] != nil {
  79. com_package["budget"] = update_info["budget"]
  80. } else {
  81. if tmp["budget"] != nil {
  82. com_package["budget"] = tmp["budget"]
  83. }
  84. }
  85. subtype := qu.ObjToString(update_info["subtype"])
  86. if subtype == "" {
  87. subtype = qu.ObjToString(tmp["subtype"])
  88. }
  89. if subtype == "单一" || subtype == "中标" || subtype == "成交" || subtype == "合同" {
  90. if update_info["bidamount"] != nil {
  91. com_package["bidamount"] = update_info["bidamount"]
  92. } else {
  93. if tmp["bidamount"] != nil {
  94. com_package["bidamount"] = tmp["bidamount"]
  95. }
  96. }
  97. if update_info["winner"] != nil {
  98. com_package["winner"] = update_info["winner"]
  99. } else {
  100. if tmp["winner"] != nil {
  101. com_package["winner"] = tmp["winner"]
  102. }
  103. }
  104. }
  105. pkgArr = append(pkgArr, com_package)
  106. return pkgArr
  107. }