xiamen.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. package main
  2. import (
  3. "go.mongodb.org/mongo-driver/bson"
  4. util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  5. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  6. "log"
  7. "strings"
  8. "sync"
  9. "time"
  10. "unicode/utf8"
  11. )
  12. // dealXmData 处理中标企业注册地为厦门的数据;陈伟铭 需求
  13. /**
  14. 中标方企业注册地为厦门的企业数量一共是多少,可以分别看下22年度,23年度的两个数据总量
  15. */
  16. func dealXmData() {
  17. Mgo := &mongodb.MongodbSim{
  18. MongodbAddr: "172.17.189.140:27080",
  19. //MongodbAddr: "127.0.0.1:27083",
  20. DbName: "qfw",
  21. Size: 10,
  22. UserName: "SJZY_RWbid_ES",
  23. Password: "SJZY@B4i4D5e6S",
  24. //Direct: true,
  25. }
  26. Mgo.InitPool()
  27. MgoC := &mongodb.MongodbSim{
  28. MongodbAddr: "172.17.189.140:27080",
  29. //MongodbAddr: "127.0.0.1:27083",
  30. DbName: "mixdata",
  31. Size: 10,
  32. UserName: "SJZY_RWbid_ES",
  33. Password: "SJZY@B4i4D5e6S",
  34. //Direct: true,
  35. }
  36. MgoC.InitPool()
  37. defer util.Catch()
  38. sess := Mgo.GetMgoConn()
  39. defer Mgo.DestoryMongoConn(sess)
  40. pool := make(chan bool, 10) //处理协程
  41. wg := &sync.WaitGroup{}
  42. // 设置查询条件
  43. filter := bson.D{
  44. {"publishtime", bson.M{"$gte": 1640966400, "$lt": 1704038400}},
  45. {"subtype", bson.M{"$in": []string{"中标", "单一", "成交", "合同"}}},
  46. }
  47. selected := map[string]interface{}{
  48. "contenthtml": 0, // 0表示不返回该字段
  49. "attach_text": 0, // 0表示不返回该字段
  50. "detail": 0, // 0表示不返回该字段
  51. "purchasingsource": 0, // 0表示不返回该字段
  52. "jsondata": 0, // 0表示不返回该字段
  53. "package": 0, // 0表示不返回该字段
  54. }
  55. it := sess.DB("qfw").C("bidding").Find(&filter).Select(&selected).Iter()
  56. count := 0
  57. for tmp := make(map[string]interface{}); it.Next(&tmp); count++ {
  58. if count%10000 == 0 {
  59. log.Println("current :", count)
  60. }
  61. pool <- true
  62. wg.Add(1)
  63. go func(tmp map[string]interface{}) {
  64. defer func() {
  65. <-pool
  66. wg.Done()
  67. }()
  68. if sensitive := util.ObjToString(tmp["sensitive"]); sensitive == "测试" { //bidding中有敏感词,不生索引
  69. tmp = make(map[string]interface{})
  70. return
  71. }
  72. // 针对存量数据,重复数据不进索引
  73. if util.IntAll(tmp["extracttype"]) == -1 {
  74. return
  75. }
  76. swinner := util.ObjToString(tmp["s_winner"])
  77. if swinner == "" {
  78. return
  79. }
  80. if utf8.RuneCountInString(swinner) < 4 {
  81. return
  82. }
  83. publishtime := util.Int64All(tmp["publishtime"])
  84. projectName := util.ObjToString(tmp["projectname"])
  85. if strings.Contains(swinner, ",") {
  86. winners := strings.Split(swinner, ",")
  87. for _, v := range winners {
  88. if utf8.RuneCountInString(v) < 4 {
  89. continue
  90. } else {
  91. da, _ := MgoC.FindOne("qyxy_std", map[string]interface{}{"company_name": v})
  92. if da == nil || (*da)["credit_no"] == nil || util.ObjToString((*da)["credit_no"]) == "" {
  93. continue
  94. }
  95. city := util.ObjToString((*da)["company_city"])
  96. if city != "厦门市" {
  97. continue
  98. }
  99. insert := map[string]interface{}{
  100. "winner": v,
  101. "credit_no": (*da)["credit_no"],
  102. "bidding_id": mongodb.BsonIdToSId(tmp["_id"]),
  103. "projectname": projectName,
  104. "company_type": (*da)["company_type"],
  105. "company_status": (*da)["company_status"],
  106. "company_area": (*da)["company_area"],
  107. "company_city": (*da)["company_city"],
  108. "year": time.Unix(publishtime, 0).Year(),
  109. }
  110. Mgo.Save("wcc_xiamen_winner", insert)
  111. }
  112. }
  113. } else {
  114. da, _ := MgoC.FindOne("qyxy_std", map[string]interface{}{"company_name": swinner})
  115. if da == nil || (*da)["credit_no"] == nil || util.ObjToString((*da)["credit_no"]) == "" {
  116. return
  117. }
  118. city := util.ObjToString((*da)["company_city"])
  119. if city != "厦门市" {
  120. return
  121. }
  122. insert := map[string]interface{}{
  123. "winner": swinner,
  124. "credit_no": (*da)["credit_no"],
  125. "bidding_id": mongodb.BsonIdToSId(tmp["_id"]),
  126. "projectname": projectName,
  127. "company_type": (*da)["company_type"],
  128. "company_status": (*da)["company_status"],
  129. "company_area": (*da)["company_area"],
  130. "company_city": (*da)["company_city"],
  131. "year": time.Unix(publishtime, 0).Year(),
  132. }
  133. Mgo.Save("wcc_xiamen_winner", insert)
  134. }
  135. }(tmp)
  136. tmp = make(map[string]interface{})
  137. }
  138. wg.Wait()
  139. log.Println("结束")
  140. }
  141. // CountBidamount 统计厦门中标单位,中标金额总数
  142. func CountBidamount() {
  143. Mgo := &mongodb.MongodbSim{
  144. MongodbAddr: "172.17.189.140:27080",
  145. //MongodbAddr: "127.0.0.1:27083",
  146. DbName: "qfw",
  147. Size: 10,
  148. UserName: "SJZY_RWbid_ES",
  149. Password: "SJZY@B4i4D5e6S",
  150. //Direct: true,
  151. }
  152. Mgo.InitPool()
  153. defer util.Catch()
  154. sess := Mgo.GetMgoConn()
  155. defer Mgo.DestoryMongoConn(sess)
  156. var BidMap = make(map[string]bool)
  157. it := sess.DB("qfw").C("wcc_xiamen_winner").Find(nil).Select(nil).Iter()
  158. count := 0
  159. var total = float64(0)
  160. for tmp := make(map[string]interface{}); it.Next(&tmp); count++ {
  161. biddingID := util.ObjToString(tmp["bidding_id"])
  162. if BidMap[biddingID] {
  163. continue
  164. }
  165. data, _ := Mgo.FindById("bidding", biddingID, nil)
  166. BidMap[biddingID] = true
  167. bid := util.Float64All((*data)["bidamount"])
  168. total += bid
  169. tmp = make(map[string]interface{})
  170. }
  171. log.Println("total", total)
  172. }