sunty
2020-08-20 f9bf85d9f2f834995d4a485054bf5cb6810ad029
EsApi.go
@@ -234,7 +234,7 @@
      return nil, err
   }
   sources, err := SourceAggregations(buf,thresholdTime)
   sources, err := SourceAggregations(buf, thresholdTime)
   if err != nil {
      return nil, err
   }
@@ -243,53 +243,67 @@
}
//根据抓拍人员id更新(picurl)图片地址---预开发
func UpdatePicUrlById(id string, picurl string, indexName string, serverIp string, serverPort string) (statu int, err error) {
func UpdatePicUrlById(id string, picUrl string, indexName string, serverIp string, serverPort string) (err error) {
   tRes, err := AIOceaninfosbyid([]string{id}, indexName, serverIp, serverPort)
   if err != nil || len(tRes) == 0 {
      return err
   }
   picMaxUrls := tRes[0].PicMaxUrl
   sourceStr := `
        "lang":"painless",
        "inline": "ctx._source.picMaxUrl.add(` + picUrl + `)"
`
   if len(picMaxUrls) >= 2 {
      sourceStr = `"source": "ctx._source.picMaxUrl[1]='` + picUrl + `'"`
   }
   var info interface{}
   url := "http://" + serverIp + ":" + serverPort + "/" + indexName + "/_update_by_query?refresh=true"
   sourceStr := "ctx._source.videoUrl='" + picurl + "'"
   var videoUrlInfo = `
   var picUrlInfo = `
        {
          "script": {
            "source": "` + sourceStr + `"
           ` + sourceStr + `
          },
          "query": {
            "term": {
              "id": "` + id + `"
            }
          }
              "query": {
              "bool": {
                  "filter": [
                      {
                          "term": {
                              "id": "` + id + `"
                          }
                      }
                  ]
              }
          }
        }
        `
   //logPrint("url: ", url, videoUrlInfo)
   buf, err := EsReq("POST", url, []byte(videoUrlInfo))
   //fmt.Println(url, picUrlInfo)
   buf, err := EsReq("POST", url, []byte(picUrlInfo))
   if err != nil {
      logPrint("http request videoUrlInfo info is err!")
      statu = 500
      return statu, err
      return err
   }
   json.Unmarshal(buf, &info)
   //logPrint(info)
   out, ok := info.(map[string]interface{})
   if !ok {
      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{}")
      return errors.New("http response interface can not change map[string]interface{}")
   }
   middle, ok := out["updated"].(float64)
   if !ok {
      logPrint("first updated change error!")
      statu = 500
      return statu, errors.New("first updated change error!")
      return errors.New("first updated change error!")
   }
   if middle == 1 {
      statu = 200
      return statu, nil
      return nil
   }
   if middle == 0 {
      statu = 201
      return statu, errors.New("已经修改")
      return errors.New("已经修改")
   }
   return statu, nil
   return nil
}
//根据抓拍人员id更新(videourl)摄像机地址