|
@@ -14,6 +14,7 @@ import (
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"testing"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
func TestEs(T *testing.T) {
|
|
@@ -142,9 +143,9 @@ func removeDuplicates(data []string) []string {
|
|
|
// syncEs 同步es 数据道信集群
|
|
|
func TestSyncEs(T *testing.T) {
|
|
|
//url := "http://172.17.4.184:19805"
|
|
|
- url := "http://127.0.0.1:19805"
|
|
|
- username := "es_all"
|
|
|
- password := "TopJkO2E_d1x"
|
|
|
+ url := "http://127.0.0.1:19905"
|
|
|
+ username := "jybid"
|
|
|
+ password := "Top2023_JEB01i@31"
|
|
|
index := "bidding" //索引名称
|
|
|
// 创建 Elasticsearch 客户端
|
|
|
client, err := elastic.NewClient(
|
|
@@ -156,9 +157,9 @@ func TestSyncEs(T *testing.T) {
|
|
|
log.Fatalf("创建 Elasticsearch 客户端失败:%s", err)
|
|
|
}
|
|
|
|
|
|
- url2 := "http://127.0.0.1:19905"
|
|
|
- username2 := "jybid"
|
|
|
- password2 := "Top2023_JEB01i@31"
|
|
|
+ url2 := "http://192.168.3.149:9201"
|
|
|
+ username2 := ""
|
|
|
+ password2 := ""
|
|
|
// 创建 Elasticsearch 客户端
|
|
|
client2, err := elastic.NewClient(
|
|
|
elastic.SetURL(url2),
|
|
@@ -350,3 +351,167 @@ func TestGetP(T *testing.T) {
|
|
|
fmt.Println("结束~~~~~~~~~~~~~~~")
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+// TestSyncEsDataLimit 同步固定数量es 数据
|
|
|
+func TestSyncEsDataLimit(T *testing.T) {
|
|
|
+ url := "http://192.168.3.149:9201"
|
|
|
+ username := ""
|
|
|
+ //username := "jybid"
|
|
|
+ password := ""
|
|
|
+ //password := "Top2023_JEB01i@31"
|
|
|
+ index := "bidding" //索引名称
|
|
|
+ // 创建 Elasticsearch 客户端
|
|
|
+ client, err := elastic.NewClient(
|
|
|
+ elastic.SetURL(url),
|
|
|
+ elastic.SetBasicAuth(username, password),
|
|
|
+ elastic.SetSniff(false),
|
|
|
+ )
|
|
|
+ if err != nil {
|
|
|
+ log.Fatalf("创建 Elasticsearch 客户端失败:%s", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ //url2 := "http://192.168.3.149:9201"
|
|
|
+ //username2 := ""
|
|
|
+ //password2 := ""
|
|
|
+ // 创建 Elasticsearch 客户端
|
|
|
+ //client2, err := elastic.NewClient(
|
|
|
+ // elastic.SetURL(url2),
|
|
|
+ // elastic.SetBasicAuth(username2, password2),
|
|
|
+ // elastic.SetSniff(false),
|
|
|
+ //)
|
|
|
+ //if err != nil {
|
|
|
+ // log.Fatalf("创建 Elasticsearch 客户端失败:%s", err)
|
|
|
+ //}
|
|
|
+
|
|
|
+ // 构建查询
|
|
|
+ query := elastic.NewBoolQuery().
|
|
|
+ Must(elastic.NewTermQuery("subtype", "采购意向")).
|
|
|
+ Must(elastic.NewMatchQuery("tag_topinformation", "情报_环境采购"))
|
|
|
+ //MustNot(elastic.NewMatchQuery("company_type", "个体工商户"))
|
|
|
+
|
|
|
+ // 执行查询
|
|
|
+ searchResult, err := client.Search().Size(500).
|
|
|
+ Index(index).
|
|
|
+ Query(query).
|
|
|
+ Do(context.Background())
|
|
|
+ if err != nil {
|
|
|
+ log.Fatalf("Error executing search: %s", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ MgoB := &mongodb.MongodbSim{
|
|
|
+ //MongodbAddr: "172.17.189.140:27080",
|
|
|
+ MongodbAddr: "127.0.0.1:27083",
|
|
|
+ Size: 10,
|
|
|
+ DbName: "qfw",
|
|
|
+ UserName: "SJZY_RWbid_ES",
|
|
|
+ Password: "SJZY@B4i4D5e6S",
|
|
|
+ Direct: true,
|
|
|
+ }
|
|
|
+ MgoB.InitPool()
|
|
|
+
|
|
|
+ ////测试环境MongoDB
|
|
|
+ MgoT := &mongodb.MongodbSim{
|
|
|
+ MongodbAddr: "192.168.3.206:27002",
|
|
|
+ DbName: "qfw_data",
|
|
|
+ Size: 10,
|
|
|
+ UserName: "root",
|
|
|
+ Password: "root",
|
|
|
+ }
|
|
|
+ MgoT.InitPool()
|
|
|
+
|
|
|
+ for _, hit := range searchResult.Hits.Hits {
|
|
|
+ var doc map[string]interface{}
|
|
|
+ err := json.Unmarshal(hit.Source, &doc)
|
|
|
+ if err != nil {
|
|
|
+ log.Printf("解析文档失败:%s", err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ id := util.ObjToString(doc["id"])
|
|
|
+ data, _ := MgoB.FindById("bidding", id, nil)
|
|
|
+ //client2.Index().Index(index).Id(id).BodyJson(doc).Do(context.Background())
|
|
|
+ MgoT.SaveByOriID("bidding", *data)
|
|
|
+ }
|
|
|
+
|
|
|
+ fmt.Println("结束~~~~~~~~~~~~~~~")
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// TestGetQyDataLimit 导出企业数据 qyxy
|
|
|
+func TestGetQyDataLimit(T *testing.T) {
|
|
|
+ url := "http://127.0.0.1:19908"
|
|
|
+ username := "jybid"
|
|
|
+ password := "Top2023_JEB01i@31"
|
|
|
+ index := "qyxy" //索引名称
|
|
|
+ // 创建 Elasticsearch 客户端
|
|
|
+ client, err := elastic.NewClient(
|
|
|
+ elastic.SetURL(url),
|
|
|
+ elastic.SetBasicAuth(username, password),
|
|
|
+ elastic.SetSniff(false),
|
|
|
+ )
|
|
|
+ if err != nil {
|
|
|
+ log.Fatalf("创建 Elasticsearch 客户端失败:%s", err)
|
|
|
+ }
|
|
|
+ // 构建查询
|
|
|
+ rangeQuery := elastic.NewRangeQuery("establish_date").Gte("1704038400").Lt("1719763200")
|
|
|
+
|
|
|
+ query := elastic.NewBoolQuery().
|
|
|
+ Must(elastic.NewTermQuery("company_city", "长春市")).
|
|
|
+ Must(elastic.NewMatchQuery("company_type", "个体工商户")).
|
|
|
+ Must(elastic.NewMatchQuery("company_status", "存续")).
|
|
|
+ Must(rangeQuery)
|
|
|
+
|
|
|
+ MgoB := &mongodb.MongodbSim{
|
|
|
+ //MongodbAddr: "172.17.189.140:27080",
|
|
|
+ MongodbAddr: "127.0.0.1:27083",
|
|
|
+ Size: 10,
|
|
|
+ DbName: "qfw",
|
|
|
+ UserName: "SJZY_RWbid_ES",
|
|
|
+ Password: "SJZY@B4i4D5e6S",
|
|
|
+ Direct: true,
|
|
|
+ }
|
|
|
+ MgoB.InitPool()
|
|
|
+
|
|
|
+ // 执行查询
|
|
|
+ searchResult, err := client.Search().Size(200).
|
|
|
+ Index(index).
|
|
|
+ Query(query).
|
|
|
+ Do(context.Background())
|
|
|
+ if err != nil {
|
|
|
+ log.Fatalf("Error executing search: %s", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, hit := range searchResult.Hits.Hits {
|
|
|
+ var doc map[string]interface{}
|
|
|
+ err := json.Unmarshal(hit.Source, &doc)
|
|
|
+ if err != nil {
|
|
|
+ log.Printf("解析文档失败:%s", err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ timeObj := time.Unix(util.Int64All(doc["establish_date"]), 0)
|
|
|
+ insert := map[string]interface{}{
|
|
|
+ "company_name": doc["company_name"],
|
|
|
+ "company_type": doc["company_type"],
|
|
|
+ "company_status": doc["company_status"],
|
|
|
+ "authority": doc["authority"],
|
|
|
+ "company_address": doc["company_address"],
|
|
|
+ "company_code": doc["company_code"],
|
|
|
+ "credit_no": doc["credit_no"],
|
|
|
+ "legal_person": doc["legal_person"],
|
|
|
+ "operation_startdate": doc["operation_startdate"],
|
|
|
+ "operation_enddate": doc["operation_enddate"],
|
|
|
+ "business_scope": doc["business_scope"], //经营范围
|
|
|
+ "establish_date": timeObj.Format("2006-01-02 15:04:05"), // 注册时间,
|
|
|
+ }
|
|
|
+
|
|
|
+ MgoB.Save("wcc_qyxy_changchun_200", insert)
|
|
|
+ //id := util.ObjToString(doc["id"])
|
|
|
+ //data, _ := MgoB.FindById("bidding", id, nil)
|
|
|
+ //client2.Index().Index(index).Id(id).BodyJson(doc).Do(context.Background())
|
|
|
+ //MgoT.SaveByOriID("bidding", *data)
|
|
|
+ }
|
|
|
+
|
|
|
+ fmt.Println("结束~~~~~~~~~~~~~~~")
|
|
|
+
|
|
|
+}
|