liuxiaolong
2020-05-28 27a7f5fb3960b771503597f83e52ec6d687f4a41
EsApi.go
@@ -12,6 +12,16 @@
   "basic.com/pubsub/protomsg.git"
)
var logPrint = func(i ...interface{}) {
   fmt.Println(i)
}
func InitLog(fn func(i ...interface{})) {
   if fn != nil {
      logPrint = fn
   }
}
// 根据抓拍人员id查询抓拍人员信息
func AIOceaninfosbyid(id []string, indexName string, serverIp string, serverPort string) ([]protomsg.AIOcean, error) {
   var aIOceanInfo []protomsg.AIOcean
@@ -123,14 +133,14 @@
    }
  }
}`
   fmt.Println(jsonDSL)
   logPrint(jsonDSL)
   buf, err := EsReq("POST", url, []byte(jsonDSL))
   if err != nil {
      return "", err
   }
   json.Unmarshal(buf, &info)
   out, ok := info.(map[string]interface{})
   fmt.Println(out)
   logPrint(out)
   if !ok {
      return "", errors.New("http response interface can not change map[string]interface{}")
   }
@@ -170,24 +180,24 @@
          }
        }
        `
   //fmt.Println("url: ", url, videoUrlInfo)
   //logPrint("url: ", url, videoUrlInfo)
   buf, err := EsReq("POST", url, []byte(videoUrlInfo))
   if err != nil {
      fmt.Println("http request videoUrlInfo info is err!")
      logPrint("http request videoUrlInfo info is err!")
      statu = 500
      return statu, err
   }
   json.Unmarshal(buf, &info)
   //fmt.Println(info)
   //logPrint(info)
   out, ok := info.(map[string]interface{})
   if !ok {
      fmt.Println("http response interface can not change map[string]interface{}")
      logPrint("http response interface can not change map[string]interface{}")
      statu = 500
      return statu, errors.New("http response interface can not change map[string]interface{}")
   }
   middle, ok := out["updated"].(float64)
   if !ok {
      fmt.Println("first updated change error!")
      logPrint("first updated change error!")
      statu = 500
      return statu, errors.New("first updated change error!")
   }
@@ -288,20 +298,20 @@
      go func(reqParam string) {
         defer wg.Done()
         //fmt.Println(url)
         //fmt.Println(prama)
         //logPrint(url)
         //logPrint(prama)
         buf, err := EsReq("POST", url, []byte(reqParam))
         if err != nil {
            fmt.Println("http request videoUrlInfo info is err!")
            fmt.Println(len(capturetable))
            logPrint("http request videoUrlInfo info is err!")
            logPrint(len(capturetable))
            return
         }
         sources, err := Sourcelistforscroll(buf)
         if err != nil {
            fmt.Println(len(capturetable))
            logPrint(len(capturetable))
            return
         }
         for _, source := range sources["sourcelist"].([]map[string]interface{}) {
@@ -325,12 +335,12 @@
            "scroll": "1m", 
            "scroll_id" : "` + scroll_id + `"
        }`
            //fmt.Println(scroll_url)
            //fmt.Println(jsonDSL)
            //logPrint(scroll_url)
            //logPrint(jsonDSL)
            buf, err := EsReq("POST", scroll_url, []byte(jsonDSL))
            if err != nil {
               fmt.Println("lenth1: ", len(capturetable))
               logPrint("lenth1: ", len(capturetable))
               return
            }
            nextSources, err := Sourcelistforscroll(buf)
@@ -340,16 +350,16 @@
            }
            nextM := nextSources["sourcelist"].([]map[string]interface{})
            //fmt.Println("id",nextSources)
            //logPrint("id",nextSources)
            if nextM == nil || len(nextM) == 0 {
               //fmt.Println("lenth: ", len(capturetable))
               //logPrint("lenth: ", len(capturetable))
               return
            }
            //fmt.Println("id")
            //logPrint("id")
            for _, source := range nextM {
               tmpList = append(tmpList, source["id"].(string))
            }
            //fmt.Println("tmpList: ", len(tmpList))
            //logPrint("tmpList: ", len(tmpList))
            lock.Lock()
            capturetable = append(capturetable, tmpList...)
            lock.Unlock()
@@ -361,8 +371,8 @@
   }
   wg.Wait()
   fmt.Println("lenth_all: ", len(capturetable))
   fmt.Println("耗时:", time.Since(ts))
   logPrint("lenth_all: ", len(capturetable))
   logPrint("耗时:", time.Since(ts))
   return capturetable
}
@@ -403,7 +413,7 @@
   "sort":[{"picDate":{"order":"desc"}}],
   "_source": {"includes":[],"excludes":["*.feature"]}
   }`
   fmt.Println(DSLJson)
   logPrint(DSLJson)
   buf, err := EsReq("POST", url, []byte(DSLJson))
   if err != nil {
      return aIOceanInfo, err
@@ -415,7 +425,7 @@
   }
   aIOcean := AIOceanAnalysis(sources)
   //fmt.Println(len(videoperson))
   //logPrint(len(videoperson))
   return aIOcean, nil
}
@@ -459,7 +469,7 @@
   }
   aIOcean := AIOceanAnalysis(sources)
   fmt.Println(len(aIOcean))
   logPrint(len(aIOcean))
   return aIOcean, nil
}
@@ -493,7 +503,7 @@
         }
      }
   }`
   //fmt.Println(DSLJson)
   //logPrint(DSLJson)
   buf, err := EsReq("POST", url, []byte(DSLJson))
   if err != nil {
      return total, err
@@ -509,7 +519,7 @@
      return total, errors.New("first hits change error!")
   }
   total = int(middle["total"].(float64))
   //fmt.Println(total)
   //logPrint(total)
   return total, nil
}
@@ -561,7 +571,7 @@
      var source = make(map[string]interface{}, 0)
      tmpbuf, ok := in.(map[string]interface{})
      if !ok {
         fmt.Println("change to source error!")
         logPrint("change to source error!")
         continue
      }
      sdkName := tmpbuf["key"].(string)
@@ -570,7 +580,7 @@
      source["value"] = count
      sources = append(sources, source)
   }
   //fmt.Println("tmpSource",sources)
   //logPrint("tmpSource",sources)
   return sources, nil
}
@@ -643,7 +653,7 @@
      var source = make(map[string]interface{}, 0)
      tmpbuf, ok := in.(map[string]interface{})
      if !ok {
         fmt.Println("change to source error!")
         logPrint("change to source error!")
         continue
      }
      task := tmpbuf["key"].(map[string]interface{})
@@ -655,7 +665,7 @@
      source["count"] = count
      sources = append(sources, source)
   }
   //fmt.Println("tmpSource",sources)
   //logPrint("tmpSource",sources)
   return sources, nil
}
@@ -739,7 +749,7 @@
    `
   //logger.Debug(url)
   //logger.Debug(JsonDSL)
   //fmt.Println(JsonDSL)
   //logPrint(JsonDSL)
   buf, err := EsReq("POST", url, []byte(JsonDSL))
   if err != nil {
      return capdbinfo, errors.New("http request dbtablename info is err!")
@@ -750,7 +760,7 @@
   if err != nil {
      return capdbinfo, err
   }
   //fmt.Println(sources)
   //logPrint(sources)
   // 返回所有查询的数据
   capdbinfos := Parsesources(sources)
   return capdbinfos, nil
@@ -787,8 +797,8 @@
                     "_source": ["` + strings.Replace(strings.Trim(fmt.Sprint(source), "[]"), " ", "\",\"", -1) + `"]
                    }`
   
   fmt.Println("url: ",url)
   fmt.Println("url: ",JsonDSL)
   logPrint("url: ",url)
   logPrint("url: ",JsonDSL)
   buf, err := EsReq("POST", url, []byte(JsonDSL))
   if err != nil {
      return dbinfos, err