bid_test.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package main
  2. import (
  3. "fmt"
  4. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  5. "log"
  6. "strconv"
  7. "strings"
  8. "sync"
  9. "testing"
  10. "time"
  11. )
  12. func TestTime(T *testing.T) {
  13. now := time.Now()
  14. year := strconv.Itoa(now.Year())
  15. month := now.Month()
  16. quarter := strconv.Itoa((int(now.Month())-1)/3 + 1)
  17. monthStringTwoDigits := fmt.Sprintf("%02d", int(now.Month()))
  18. fmt.Println(year, month.String(), quarter)
  19. fmt.Println(monthStringTwoDigits)
  20. }
  21. func TestSendAi(T *testing.T) {
  22. title := "松江南站大型居住社区C18-26-01号地块动迁安置房(智能化工程)"
  23. detail := "<br><ul ><li>招标项目编号:</li><li >e3100000151006395007</li></ul><ul ><li>相关标段(包)编号:</li><li >e3100000151006395007001</li></ul><ul ><li>公示标题:</li><li >松江南站大型居住社区C18-26-01号地块动迁安置房(智能化工程)</li></ul><ul ><li>公示内容:</li><li >第一中标候选人:上海浩臣机电科技有限公司,投标价格:1228.1990,得分/投票:合格;第二中标候选人:上海格瑞特机电系统工程有限公司,投标价格:1230.1015,得分/投票:合格;</li></ul><ul ><li>公示发布时间:</li><li >2024-01-03</li></ul><ul ><li>公示发布媒介:</li><li >http://zjw.sh.gov.cn</li></ul><ul ><li>公示源URL:</li><li ><br>https://ciac.zjw.sh.gov.cn/XMJYPTInterWeb/Tender/PrinttoPdf?zbgcid=65693</li></ul><ul ><li>公示类型:</li><li >正常</li></ul><ul ><li>公示开始时间:</li><li >2024-01-03</li></ul><ul ><li>公示结束时间:</li><li >2024-01-05</li></ul>"
  24. data := map[string]interface{}{
  25. "title": title,
  26. "detail": detail,
  27. }
  28. reqData := map[string]interface{}{
  29. "texts": []interface{}{data},
  30. }
  31. res := SendAi(reqData)
  32. fmt.Println("len res", len(res))
  33. fmt.Println("aaaa")
  34. if len(res) > 0 {
  35. resa := res["result"]
  36. fmt.Println(resa)
  37. if dataa, ok := resa.([]string); ok {
  38. fmt.Println(222)
  39. da := dataa[0]
  40. if len(da) > 0 {
  41. cs := strings.Split(da, "-")
  42. fmt.Println("toptype", cs[0])
  43. fmt.Println("subtype", cs[1])
  44. }
  45. }
  46. }
  47. fmt.Println("res", res)
  48. }
  49. func TestCh(t *testing.T) {
  50. num := 0
  51. var wg sync.WaitGroup
  52. for i := 0; i < 10; i++ {
  53. wg.Add(1)
  54. go func(num *int) {
  55. defer wg.Done()
  56. addNum(num)
  57. }(&num)
  58. }
  59. wg.Wait()
  60. fmt.Println(num)
  61. }
  62. func addNum(num *int) {
  63. *num++
  64. }
  65. func TestUpdateBidding(t *testing.T) {
  66. Mgo := &mongodb.MongodbSim{
  67. //MongodbAddr: "172.17.189.140:27080",
  68. MongodbAddr: "127.0.0.1:27083",
  69. Size: 10,
  70. DbName: "qfw",
  71. UserName: "SJZY_RWbid_ES",
  72. Password: "SJZY@B4i4D5e6S",
  73. Direct: true,
  74. }
  75. Mgo.InitPool()
  76. Mgo2 := &mongodb.MongodbSim{
  77. //MongodbAddr: "172.17.189.140:27080",
  78. MongodbAddr: "127.0.0.1:27017",
  79. Size: 10,
  80. DbName: "wcc",
  81. UserName: "",
  82. Password: "",
  83. //Direct: true,
  84. }
  85. Mgo2.InitPool()
  86. sess := Mgo2.GetMgoConn()
  87. defer Mgo2.DestoryMongoConn(sess)
  88. query := sess.DB("wcc").C("wcc_bidding_20240103_subtype_exists").Find(nil).Select(nil).Iter()
  89. count := 0
  90. for tmp := make(map[string]interface{}); query.Next(tmp); count++ {
  91. if count%10000 == 0 {
  92. log.Println("current:", count)
  93. }
  94. id := mongodb.BsonIdToSId(tmp["_id"])
  95. bidding, _ := Mgo.FindById("bidding", id, nil)
  96. update := map[string]interface{}{
  97. "toptype": (*bidding)["toptype"],
  98. "subtype": (*bidding)["subtype"],
  99. "infoformat": (*bidding)["infoformat"],
  100. }
  101. Mgo2.UpdateById("wcc_bidding_20240103_subtype_exists", id, map[string]interface{}{"$set": update})
  102. tmp = make(map[string]interface{})
  103. }
  104. }