From 6a413e1d7d485f506e81c669bc692868c29cefb9 Mon Sep 17 00:00:00 2001
From: sunty <1172534965@qq.com>
Date: 星期四, 18 七月 2019 17:37:25 +0800
Subject: [PATCH] fix sdkcompare

---
 esutil/EsApi.go |  156 +++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 118 insertions(+), 38 deletions(-)

diff --git a/esutil/EsApi.go b/esutil/EsApi.go
index d5510da..0cdc863 100644
--- a/esutil/EsApi.go
+++ b/esutil/EsApi.go
@@ -2,66 +2,146 @@
 
 import (
         "errors"
-        "strconv"
+    "fmt"
+    "strconv"
+    "strings"
 
-        "basic.com/pubsub/protomsg.git"
+    "basic.com/pubsub/protomsg.git"
         )
 
 // 鏌ヨ搴曞簱浜哄憳淇℃伅
-func DbPersoninfos( queryindex int, querynums int ) (dbpersoninfos []*protomsg.Baseinfo, err error){
-            point   := strconv.Itoa(queryindex)
-            number   := strconv.Itoa(querynums)
-
-            var dbinfoRequest =  `  {
+func Personinfos( queryIndex int, queryNums int, indexName string, serverIp string, serverPort string, analyServerId string) ([]*protomsg.Esinfo, error){
+            var dbinfos []*protomsg.Esinfo
+            point   := strconv.Itoa(queryIndex)
+            number   := strconv.Itoa(queryNums)
+            JsonDSL  := ""
+            if indexName == "videopersons" {
+                 JsonDSL =  `  {
+                    "from": ` + point +  `, 
+                    "query": {
+                        "bool": {
+                            "filter": [
+                                {
+                                    "term": {
+                                        "analyServerId": "` + analyServerId + `"
+                                    }
+                                }
+                            ]
+                        }
+                    },
+                    "size":`+ number +`,
+                    "_source": [
+                        "id",
+                        "faceFeature"
+                    ]
+                }`
+            }else {
+                 JsonDSL =  `  {
                     "from": ` + point +  `,        
                     "query": {
                         "match_all": {}
                     },
-                        "size":`+ number +`,
-                        "_source": [
+                     "size":`+ number +`,
+                     "_source": [
+                       "id",
                        "tableId",
-                       "tableName",
-                       "compareScore",
-                       "personId",
-                       "personName",
-                       "personPicUrl",
-                       "phoneNum",
-                       "sex",
-                       "idCard",
-                       "monitorLevel",
-                       "faceFeature",
-                       "content",
-                       "id"
+                       "faceFeature"
                        ]
-                }`
-
-      // 杩斿洖璇锋眰鐨刡uf
-      buf, err := GetDbinfo(dbinfoRequest )
-      if err != nil {
-        return nil ,errors.New("http request get dbperson info is err!")
-      }
+                    }`
+            }
+            fmt.Println("url: "+"http://"+serverIp+":"+serverPort+"/"+indexName+"/_search","body: ",JsonDSL)
+    buf, err := EsReq("POST", "http://"+serverIp+":"+serverPort+"/"+indexName+"/_search",[]byte(JsonDSL))
+    if err != nil {
+        return dbinfos ,errors.New("http request dbtablename info is err!")
+    }
 
       // 杩斿洖 _source 鏁扮粍
       sources, err := Sourcelist(buf)
       if err != nil {
-            return nil,err 
+            return dbinfos,err 
       }
 
       // 杩斿洖鎵�鏈夋煡璇㈢殑鏁版嵁
-      dbpersoninfos =  Parsesources(sources)
+     dbpersoninfos :=  Parsesources(sources)
       return dbpersoninfos, nil
 }
 
-// 鏍规嵁tableid 鏌ヨtablename
+// 鏍规嵁搴曞簱id鏌ヨ搴曞簱淇℃伅
+func Dbtablefosbyid (id []string, indexName string, serverIp string, serverPort string) ([]protomsg.Dbtable, error) {
+    var dbinfo []protomsg.Dbtable
+    dbtableId := strings.Replace(strings.Trim(fmt.Sprint(id), "[]"), " ", "\",\"", -1)
+        var dbinfoRequest = `
+            {
+            	"query": {
+            		"bool": {
+            			"filter": [{
+            				"terms": {
+            					"id": [
+            						"`+ dbtableId +`"
+            					]
+            				}
+            			}]
+            		}
+            	}
+            }
+        `
+    buf, err := EsReq("POST", "http://"+serverIp+":"+serverPort+"/"+indexName+"/_search",[]byte(dbinfoRequest))
+    if err != nil {
+        return dbinfo,  err
+    }
 
-func Dbtablename(tableid string ) (tablename string) {
+    sources, err := Sourcelist(buf)
+    if err != nil {
+        return dbinfo , err
+    }
+
+    dbtable := Dbtablebyid(sources)
+    return dbtable, nil
+}
+
+// 鏍规嵁搴曞簱浜哄憳id鏌ヨ搴曞簱浜哄憳淇℃伅
+func Dbpersoninfosbyid (id []string, indexName string, serverIp string, serverPort string) ([]protomsg.Dbperson, error) {
+    var dbinfo []protomsg.Dbperson
+    dbtablePersonId := strings.Replace(strings.Trim(fmt.Sprint(id), "[]"), " ", "\",\"", -1)
+    var dbinfoRequest = `
+            {
+            	"query": {
+            		"bool": {
+            			"filter": [{
+            				"terms": {
+            					"id": [
+            						"`+ dbtablePersonId +`"
+            					]
+            				}
+            			}]
+            		}
+            	}
+            }
+        `
+    buf, err := EsReq("POST", "http://"+serverIp+":"+serverPort+"/"+indexName+"/_search",[]byte(dbinfoRequest))
+    if err != nil {
+        return dbinfo,  err
+    }
+
+    sources, err := Sourcelist(buf)
+    if err != nil {
+        return dbinfo , err
+    }
+
+    dbperson := Dbpersonbyid(sources)
+    println(dbperson)
+    return dbperson,nil
+}
+
+// 鏍规嵁tableid 鏌ヨtablename
+func Dbtablename(tableid string, indexName string, serverIp string, serverPort string) (tablename string, err error) {
     var dbinfotable =` {
         "query": {
             "bool": {
                 "filter": [
                 {
                     "term": {
-                        "id":`+tableid+`
+                        "id":"`+tableid+`"
                     }
                 }
                 ]
@@ -72,20 +152,20 @@
         ]
     }
     `
-    buf, err := EsReq("POST", "http://192.168.1.182:9200/dbtables/_search",[]byte(dbinfotable))
+    buf, err := EsReq("POST", "http://"+serverIp+":"+serverPort+"/"+indexName+"/_search",[]byte(dbinfotable))
     if err != nil {
-        return nil ,errors.New("http request dbtablename info is err!")
+        return "" ,errors.New("http request dbtablename info is err!")
     }
     sources, err := Sourcelist(buf)
     if err != nil {
-          return nil,err 
+          return "",err 
     }
 
     for _, source := range sources {
-        if name, ok := souce["tableName"].(string); ok {
+        if name, ok := source["tableName"].(string); ok {
             tablename = name
             break
         }
     }
-    return 
+    return tablename, nil 
 }

--
Gitblit v1.8.0