data_test.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package main
  2. import (
  3. "fmt"
  4. util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  5. es "jygit.jydev.jianyu360.cn/data_processing/common_utils/elastic"
  6. "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
  7. "log"
  8. "testing"
  9. )
  10. func TestGetAreaInfo(t *testing.T) {
  11. data := map[string]interface{}{
  12. "detail": "北京鑫台华科技有限公司",
  13. }
  14. res := GetAreaInfo(data)
  15. log.Println(res)
  16. }
  17. // TestProject 更新测试环境项目字段
  18. func TestProject(t *testing.T) {
  19. // 测试环境
  20. MgoB := &mongodb.MongodbSim{
  21. MongodbAddr: "192.168.3.206:27002",
  22. Size: 10,
  23. DbName: "qfw_data",
  24. UserName: "root",
  25. Password: "root",
  26. //Direct: true,
  27. }
  28. MgoB.InitPool()
  29. //mongodb 163
  30. //Mgo := &mongodb.MongodbSim{
  31. // //MongodbAddr: "172.17.189.140:27080",
  32. // MongodbAddr: "127.0.0.1:27083",
  33. // DbName: "qfw",
  34. // Size: 10,
  35. // UserName: "SJZY_RWbid_ES",
  36. // Password: "SJZY@B4i4D5e6S",
  37. // Direct: true,
  38. //}
  39. //Mgo.InitPool()
  40. // 项目数据
  41. MgoP := &mongodb.MongodbSim{
  42. //MongodbAddr: "172.17.4.85:27080",
  43. MongodbAddr: "127.0.0.1:27080",
  44. Size: 10,
  45. DbName: "qfw",
  46. Direct: true,
  47. }
  48. MgoP.InitPool()
  49. //测试环境
  50. Es := &es.Elastic{
  51. S_esurl: "http://192.168.3.149:9201",
  52. I_size: 5,
  53. Username: "",
  54. Password: "",
  55. }
  56. Es.InitElasticSize()
  57. defer util.Catch()
  58. sess := MgoB.GetMgoConn()
  59. defer MgoB.DestoryMongoConn(sess)
  60. it := sess.DB("qfw_data").C("projectset").Find(nil).Select(nil).Iter()
  61. count := 0
  62. log.Println("开始")
  63. for tmp := make(map[string]interface{}); it.Next(&tmp); count++ {
  64. if count%5000 == 0 {
  65. log.Println("current:", count, tmp["projectname"])
  66. }
  67. projectID := mongodb.BsonIdToSId(tmp["_id"])
  68. project, _ := MgoP.FindById("projectset_20230904", projectID, nil)
  69. if project != nil && len(*project) > 0 {
  70. if tag_top, ok := (*project)["tag_topinformation"]; ok {
  71. update := map[string]interface{}{
  72. "tag_topinformation": tag_top,
  73. }
  74. Es.UpdateDocument("projectset", projectID, update)
  75. }
  76. }
  77. }
  78. }
  79. func TestTimeStr(T *testing.T) {
  80. // Test cases
  81. fmt.Println(getTTMethod("2024")) // Expected: 20240000
  82. fmt.Println(getTTMethod("202409")) // Expected: 20240900
  83. fmt.Println(getTTMethod("20240929")) // Expected: 20240929
  84. fmt.Println(getTTMethod("2024/4/11")) // Expected: 20240411
  85. fmt.Println(getTTMethod("2024-01-01")) // Expected: 20240101
  86. fmt.Println(getTTMethod("2024.02.11")) // Expected: 20240211
  87. fmt.Println(getTTMethod("2024年")) // Expected: 20240000
  88. fmt.Println(getTTMethod("2024年09月")) // Expected: 20240900
  89. fmt.Println(getTTMethod("2024年09月29日")) // Expected: 20240929
  90. fmt.Println(getTTMethod("2024/9/9")) // Expected: 20240909
  91. fmt.Println(getTTMethod("2024-9-9")) // Expected: 20240909
  92. fmt.Println(getTTMethod("2024.9.9")) // Expected: 20240909
  93. fmt.Println(getTTMethod("2024年9月9日")) // Expected: 20240909
  94. }