main_test.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package main
  2. import (
  3. . "app.yhyue.com/moapp/jybase/mongodb"
  4. "dataPrefer/db"
  5. . "dataPrefer/service"
  6. "encoding/json"
  7. "github.com/gogf/gf/v2/util/gconv"
  8. mu "jygit.jydev.jianyu360.cn/data_processing/common_utils/udp"
  9. "log"
  10. "net"
  11. "testing"
  12. )
  13. func TestSendNextNode(t *testing.T) {
  14. uc := mu.UdpClient{Local: ":880", BufSize: 1024}
  15. uc.Listen(ProcessUdpMsg)
  16. by, _ := json.Marshal(map[string]interface{}{
  17. "gtid": "1",
  18. "lteid": "2",
  19. "stype": "bidding",
  20. "key": "1-2-bidding",
  21. })
  22. addr := &net.UDPAddr{
  23. IP: net.ParseIP("127.0.0.1"),
  24. Port: 889,
  25. }
  26. log.Println(uc.WriteUdp(by, mu.OP_TYPE_DATA, addr)) //发送下节点
  27. }
  28. // 370435 201782
  29. func Tj() {
  30. sess := db.Mgo_Main.GetMgoConn()
  31. defer db.Mgo_Main.DestoryMongoConn(sess)
  32. it := sess.DB("qfw").C(Bidding_master).Find(nil).Select(map[string]interface{}{
  33. "old_id": 1,
  34. "id": 1,
  35. "site_toptype": 1,
  36. "old_site_toptype": 1,
  37. }).Iter()
  38. oldMap := map[string]int{}
  39. ooldMap := map[string]int{}
  40. newMap := map[string]int{}
  41. nnewMap := map[string]int{}
  42. update := 0
  43. index := 0
  44. for m := make(map[string]interface{}); it.Next(&m); {
  45. index++
  46. if index%5000 == 0 {
  47. log.Println("index", index)
  48. }
  49. if m["old_site_toptype"] == nil {
  50. m["old_site_toptype"] = m["site_toptype"]
  51. }
  52. if m["old_id"] == nil {
  53. m["old_id"] = m["id"]
  54. }
  55. oldMap[gconv.String(m["old_site_toptype"])] = oldMap[gconv.String(m["old_site_toptype"])] + 1
  56. newMap[gconv.String(m["site_toptype"])] = newMap[gconv.String(m["site_toptype"])] + 1
  57. if gconv.String(m["id"]) != gconv.String(m["old_id"]) {
  58. update++
  59. ooldMap[gconv.String(m["old_site_toptype"])] = ooldMap[gconv.String(m["old_site_toptype"])] + 1
  60. nnewMap[gconv.String(m["site_toptype"])] = nnewMap[gconv.String(m["site_toptype"])] + 1
  61. }
  62. m = make(map[string]interface{})
  63. }
  64. log.Println(oldMap)
  65. log.Println(newMap)
  66. log.Println(update)
  67. log.Println(ooldMap)
  68. log.Println(nnewMap)
  69. log.Println("over...", index)
  70. }
  71. func Hz() {
  72. sess := db.Mgo_Main.GetMgoConn()
  73. defer db.Mgo_Main.DestoryMongoConn(sess)
  74. it := sess.DB("qfw").C(Bidding_master).Find(map[string]interface{}{"mark": 1}).Select(map[string]interface{}{"id": 1}).Iter()
  75. index := 0
  76. for m := make(map[string]interface{}); it.Next(&m); {
  77. index++
  78. id := m["id"].(string)
  79. ids := []interface{}{StringTOBsonId(id)}
  80. data, _ := db.Mgo_Main.FindById(Bidding, id, `{"_id":1,"repeat_id":1}`)
  81. if repeatId, _ := (*data)["repeat_id"].(string); repeatId != "" && repeatId != id {
  82. ids = append(ids, StringTOBsonId(repeatId))
  83. datas, _ := db.Mgo_Extract.Find(Result_20220219, map[string]interface{}{
  84. "repeat_id": repeatId,
  85. }, nil, map[string]interface{}{
  86. "_id": 1,
  87. }, false, -1, -1)
  88. if datas != nil {
  89. for _, v := range *datas {
  90. ids = append(ids, v["_id"])
  91. }
  92. }
  93. datas, _ = db.Mgo_Extract.Find(Result_20220218, map[string]interface{}{
  94. "repeat_id": repeatId,
  95. }, nil, map[string]interface{}{
  96. "_id": 1,
  97. }, false, -1, -1)
  98. if datas != nil {
  99. for _, v := range *datas {
  100. ids = append(ids, v["_id"])
  101. }
  102. }
  103. }
  104. mp := map[string]bool{}
  105. newIds := []interface{}{}
  106. for _, v := range ids {
  107. if mp[BsonIdToSId(v)] {
  108. continue
  109. }
  110. mp[BsonIdToSId(v)] = true
  111. newIds = append(newIds, v)
  112. }
  113. newDatas, _ := db.Mgo_Main.Find(Bidding, map[string]interface{}{
  114. "_id": map[string]interface{}{"$in": newIds},
  115. }, nil, nil, false, -1, -1)
  116. for _, v := range *newDatas {
  117. v["bestid"] = id
  118. if BsonIdToSId(v["_id"]) == id {
  119. v["isbest"] = 1
  120. } else {
  121. v["isbest"] = 0
  122. }
  123. }
  124. db.Mgo_Main.SaveBulk("bidding_master_verify", *newDatas...)
  125. m = make(map[string]interface{})
  126. log.Println("index...", index)
  127. }
  128. }