123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- package main
- import (
- "fmt"
- util "jygit.jydev.jianyu360.cn/data_processing/common_utils"
- es "jygit.jydev.jianyu360.cn/data_processing/common_utils/elastic"
- "jygit.jydev.jianyu360.cn/data_processing/common_utils/mongodb"
- "log"
- "testing"
- )
- func TestGetAreaInfo(t *testing.T) {
- data := map[string]interface{}{
- "detail": "北京鑫台华科技有限公司",
- }
- res := GetAreaInfo(data)
- log.Println(res)
- }
- // TestProject 更新测试环境项目字段
- func TestProject(t *testing.T) {
- // 测试环境
- MgoB := &mongodb.MongodbSim{
- MongodbAddr: "192.168.3.206:27002",
- Size: 10,
- DbName: "qfw_data",
- UserName: "root",
- Password: "root",
- //Direct: true,
- }
- MgoB.InitPool()
- //mongodb 163
- //Mgo := &mongodb.MongodbSim{
- // //MongodbAddr: "172.17.189.140:27080",
- // MongodbAddr: "127.0.0.1:27083",
- // DbName: "qfw",
- // Size: 10,
- // UserName: "SJZY_RWbid_ES",
- // Password: "SJZY@B4i4D5e6S",
- // Direct: true,
- //}
- //Mgo.InitPool()
- // 项目数据
- MgoP := &mongodb.MongodbSim{
- //MongodbAddr: "172.17.4.85:27080",
- MongodbAddr: "127.0.0.1:27080",
- Size: 10,
- DbName: "qfw",
- Direct: true,
- }
- MgoP.InitPool()
- //测试环境
- Es := &es.Elastic{
- S_esurl: "http://192.168.3.149:9201",
- I_size: 5,
- Username: "",
- Password: "",
- }
- Es.InitElasticSize()
- defer util.Catch()
- sess := MgoB.GetMgoConn()
- defer MgoB.DestoryMongoConn(sess)
- it := sess.DB("qfw_data").C("projectset").Find(nil).Select(nil).Iter()
- count := 0
- log.Println("开始")
- for tmp := make(map[string]interface{}); it.Next(&tmp); count++ {
- if count%5000 == 0 {
- log.Println("current:", count, tmp["projectname"])
- }
- projectID := mongodb.BsonIdToSId(tmp["_id"])
- project, _ := MgoP.FindById("projectset_20230904", projectID, nil)
- if project != nil && len(*project) > 0 {
- if tag_top, ok := (*project)["tag_topinformation"]; ok {
- update := map[string]interface{}{
- "tag_topinformation": tag_top,
- }
- Es.UpdateDocument("projectset", projectID, update)
- }
- }
- }
- }
- func TestTimeStr(T *testing.T) {
- // Test cases
- fmt.Println(getTTMethod("2024")) // Expected: 20240000
- fmt.Println(getTTMethod("202409")) // Expected: 20240900
- fmt.Println(getTTMethod("20240929")) // Expected: 20240929
- fmt.Println(getTTMethod("2024/4/11")) // Expected: 20240411
- fmt.Println(getTTMethod("2024-01-01")) // Expected: 20240101
- fmt.Println(getTTMethod("2024.02.11")) // Expected: 20240211
- fmt.Println(getTTMethod("2024年")) // Expected: 20240000
- fmt.Println(getTTMethod("2024年09月")) // Expected: 20240900
- fmt.Println(getTTMethod("2024年09月29日")) // Expected: 20240929
- fmt.Println(getTTMethod("2024/9/9")) // Expected: 20240909
- fmt.Println(getTTMethod("2024-9-9")) // Expected: 20240909
- fmt.Println(getTTMethod("2024.9.9")) // Expected: 20240909
- fmt.Println(getTTMethod("2024年9月9日")) // Expected: 20240909
- }
|