sunty
2020-08-23 a88cd5f3c40d32fb48e80873667455f1424ae1cf
EsApi.go
@@ -159,8 +159,72 @@
}
//根据摄像机列表和时间查询人员浏览轨迹
func GetPersonDataByCameraIdAndTime(cameraId []string, startTime string, endTime string, serverIp string, ServerPort string, indexName string) ([]map[string]interface{}, error) {
   esCameraId := strings.Replace(strings.Trim(fmt.Sprint(cameraId), "[]"), " ", "\",\"", -1)
   personUrl := "http://" + serverIp + ":" + ServerPort + "/" + indexName + "/_search"
   personBody := `{
    "query": {
        "bool": {
            "filter": [
                {
                    "range": {
                        "picDate": {
                            "gte": "` + startTime + `",
                            "lte": "` + endTime + `"
                        }
                    }
                },
                {
                    "term": {
                        "targetInfo.targetType.raw": "Yolo"
                    }
                },
                {
                    "terms": {
                        "cameraId": [
                           "` + esCameraId + `"
                        ]
                    }
                }
            ]
        }
    },
    "size": 2147483647,
    "_source": {
        "includes": [
            "cameraId",
            "cameraName",
            "cameraAddr",
            "targetInfo.targetScore",
            "picDate",
            "updateTime",
            "picMaxUrl",
            "targetInfo.belongsTargetId",
            "targetInfo.targetLocation",
         "picWH"
        ]
    }
}`
   //fmt.Println(personUrl)
   //fmt.Println(personBody)
   buf, err := EsReq("POST", personUrl, []byte(personBody))
   if err != nil {
      return nil, err
   }
   sources, err := Sourcelist(buf)
   if err != nil {
      return nil, err
   }
   resData,err := PerSonAnalysis(sources)
   //println(sources)
   return resData, nil
}
//根据时间范围,摄像机列表,分组聚合人脸列表
func GetfaceDataBucketsBycameraIdAndTime(cameraId []string, startTime string, endTime string, thresholdTime float64, serverIp string, ServerPort string, indexName string) (buckersDate map[string]interface{}, err error) {
func GetFaceDataBucketsByCameraIdAndTime(cameraId []string, startTime string, endTime string, thresholdTime float64, serverIp string, ServerPort string, indexName string) (buckersDate map[string]interface{}, err error) {
   esCameraId := strings.Replace(strings.Trim(fmt.Sprint(cameraId), "[]"), " ", "\",\"", -1)
   var buckersUrl = "http://" + serverIp + ":" + ServerPort + "/" + indexName + "/_search"
   var buckersBody = `{
@@ -207,12 +271,13 @@
                            }
                        }
                    }
                ]
                ],
                "size": 100000000
            },
            "aggs":{
                "top_attention_hits":{
                    "top_hits":{
                        "size": 100,
                        "size": 1000000,
                        "sort": [
                            {
                                "picDate": {
@@ -221,7 +286,7 @@
                            }
                        ],
                        "_source":{
                            "includes":["baseInfo.targetId","cameraId","cameraName","cameraAddr","targetInfo.targetScore","targetInfo.picSmUrl","showLabels","baseInfo.tableId","baseInfo.tableName","baseInfo.bwType","baseInfo.targetName","baseInfo.compareScore","picDate","picMaxUrl"]
                            "includes":["baseInfo.targetId","cameraId","cameraName","cameraAddr","targetInfo.targetScore","targetInfo.picSmUrl","showLabels","baseInfo.tableId","baseInfo.tableName","baseInfo.bwType","baseInfo.targetName","baseInfo.compareScore","picDate","picMaxUrl","picWH"]
                        }
                    }
                }
@@ -229,12 +294,14 @@
        }
    }
}`
   //fmt.Println(buckersUrl)
   //fmt.Println(buckersBody)
   buf, err := EsReq("POST", buckersUrl, []byte(buckersBody))
   if err != nil {
      return nil, err
   }
   sources, err := SourceAggregations(buf,thresholdTime)
   sources, err := SourceAggregations(buf, thresholdTime)
   if err != nil {
      return nil, err
   }
@@ -242,54 +309,68 @@
   return sources, nil
}
//根据抓拍人员id更新(picurl)图片地址---预开发
func UpdatePicUrlById(id string, picurl string, indexName string, serverIp string, serverPort string) (statu int, err error) {
//根据抓拍人员id更新(picurl)图片地址
func UpdatePicUrlById(id string, picUrl string, indexName string, serverIp string, serverPort string) (err error) {
    updateTime := time.Now().Format("2006-01-02 15:04:05")
   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 + `');ctx._source.updateTime='`+updateTime+`'"
`
   if len(picMaxUrls) >= 2 {
      sourceStr = `"source": "ctx._source.picMaxUrl[1]='` + picUrl + `';ctx._source.updateTime='`+updateTime+`'"`
   }
   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)摄像机地址