main_test.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. package main
  2. import (
  3. "app.yhyue.com/moapp/jybase/encrypt"
  4. . "app.yhyue.com/moapp/jybase/mongodb"
  5. . "dataIdentify/db"
  6. . "dataIdentify/service"
  7. "github.com/gogf/gf/v2/frame/g"
  8. "github.com/gogf/gf/v2/os/gctx"
  9. "log"
  10. "net/rpc"
  11. "strings"
  12. "sync"
  13. "testing"
  14. )
  15. const (
  16. maxSize = 100
  17. )
  18. // {
  19. // $unset: {
  20. // "bid_commonwealth" : "",
  21. // "quote_mode" : "",
  22. // "model_dataidentify" : ""
  23. // }
  24. // }
  25. func TestAddField(t *testing.T) {
  26. pool := make(chan bool, 5)
  27. wait := &sync.WaitGroup{}
  28. sess := Mgo_Main.GetMgoConn()
  29. defer Mgo_Main.DestoryMongoConn(sess)
  30. it := sess.DB("qfw_data").C("wcj_bidding").Find(map[string]interface{}{}).Select(nil).Sort("-_id").Iter()
  31. index := 0
  32. for tm := make(map[string]interface{}); it.Next(tm); {
  33. index++
  34. if index%100 == 0 {
  35. log.Println("index", index)
  36. }
  37. pool <- true
  38. wait.Add(1)
  39. go func(m map[string]interface{}) {
  40. defer func() {
  41. <-pool
  42. wait.Done()
  43. }()
  44. href := "https://www.jianyu360.com/nologin/content/" + encrypt.CommonEncodeArticle("content", BsonIdToSId(m["_id"])) + ".html"
  45. Mgo_Main.Update("wcj_bidding", map[string]interface{}{
  46. "_id": m["_id"],
  47. }, map[string]interface{}{"$set": map[string]interface{}{
  48. "href": href,
  49. }}, false, false)
  50. }(tm)
  51. tm = make(map[string]interface{})
  52. }
  53. wait.Wait()
  54. log.Println("over...", index)
  55. }
  56. // 示例测试
  57. func TestRule(t *testing.T) {
  58. Start("5b0e1b8da5cb26b9b7b8c9ac")
  59. }
  60. func TestAll(t *testing.T) {
  61. pool := make(chan bool, g.Config().MustGet(gctx.New(), "poolSize").Int())
  62. wait := &sync.WaitGroup{}
  63. sess := Mgo_Main.GetMgoConn()
  64. defer Mgo_Main.DestoryMongoConn(sess)
  65. it := sess.DB("qfw_data").C("wcj_bidding").Find(map[string]interface{}{
  66. "_id": StringTOBsonId("67c123333309c0998b619793"),
  67. }).Select(SelectField).Sort("-_id").Iter()
  68. index := 0
  69. for tm := make(map[string]interface{}); it.Next(tm); {
  70. index++
  71. if index%100 == 0 {
  72. log.Println("index", index)
  73. }
  74. pool <- true
  75. wait.Add(1)
  76. go func(m map[string]interface{}) {
  77. defer func() {
  78. <-pool
  79. wait.Done()
  80. }()
  81. _id := BsonIdToSId(m["_id"])
  82. flag, quoteMode, bidCommonwealth, other := Pretreatment(_id, m)
  83. if !flag {
  84. return
  85. }
  86. set := map[string]interface{}{}
  87. if quoteMode != "" {
  88. set["quote_mode"] = quoteMode
  89. }
  90. if bidCommonwealth != -1 {
  91. set["bid_commonwealth"] = bidCommonwealth
  92. }
  93. if set != nil {
  94. set["model_dataidentify"] = other
  95. }
  96. if len(set) > 0 {
  97. Mgo_Main.UpdateById("wcj_bidding", m["_id"], map[string]interface{}{"$set": set})
  98. }
  99. }(tm)
  100. tm = make(map[string]interface{})
  101. }
  102. wait.Wait()
  103. log.Println("over...", index)
  104. }
  105. func TestExtract(t *testing.T) {
  106. log.Println("start...")
  107. sess := Mgo_Main.GetMgoConn()
  108. defer Mgo_Main.DestoryMongoConn(sess)
  109. it := sess.DB("qfw_data").C("bidding_hasdetail").Find(map[string]interface{}{
  110. "_id": map[string]interface{}{
  111. "$lt": StringTOBsonId("68639706408dd61d6e5d05cd"),
  112. },
  113. }).Select(map[string]interface{}{
  114. "detail": 1,
  115. "_id": 1,
  116. "subtype": 1,
  117. "toptype": 1,
  118. "s_winner": 1,
  119. "bidamount": 1,
  120. }).Sort("-_id").Iter()
  121. types := "邀标、竞谈、单一、招标、中标、成交、合同"
  122. all := map[string]int{}
  123. for _, v := range strings.Split(types, "、") {
  124. all[v] = 0
  125. }
  126. var isOver = func() bool {
  127. for _, v := range all {
  128. if v < maxSize {
  129. return false
  130. }
  131. }
  132. return true
  133. }
  134. index := 0
  135. for m := make(map[string]interface{}); it.Next(m); {
  136. index++
  137. if index%500 == 0 {
  138. log.Println("index", index)
  139. }
  140. subtype, _ := m["subtype"].(string)
  141. if v, ok := all[subtype]; !ok || v >= maxSize {
  142. continue
  143. }
  144. _id := Mgo_Main.SaveByOriID("wcj_bidding", m)
  145. log.Println("save", _id)
  146. all[subtype]++
  147. if isOver() {
  148. break
  149. }
  150. }
  151. log.Println("over...", index)
  152. }
  153. func TestRpc(t *testing.T) {
  154. conn, err := rpc.DialHTTP("tcp", "127.0.0.1:8811")
  155. if err != nil {
  156. log.Println(err)
  157. return
  158. }
  159. defer conn.Close()
  160. var reply map[string]string
  161. err = conn.Call("DataIdentify.Execute", "5b0dfeb4a5cb26b9b79c1330", &reply)
  162. if err != nil {
  163. log.Println(err)
  164. }
  165. log.Println(reply)
  166. }