sunty
2019-11-21 c9296a4e0869aa9b4a98df7d0433ef0d6b9a0b10
EsApi.go
@@ -60,7 +60,7 @@
                     }]
                  }
               },
                "_source":["faceFeature"]
                "_source":["targetInfo.feature"]
            }
        `
   buf, err := EsReq("POST", "http://"+serverIp+":"+serverPort+"/"+indexName+"/_search", []byte(jsonDSL))
@@ -72,8 +72,8 @@
   if err != nil {
      return "", err
   }
   faceFeature := sources[0]["faceFeature"].(string)
   return faceFeature, nil
   feature := sources[0]["targetInfo"].([]interface{})[0].(map[string]interface{})["feature"].(string)
   return feature, nil
}
//根据抓拍人员id更新(videourl)摄像机地址
@@ -175,7 +175,7 @@
   //判断布防等级
   alarmLevelStr := ""
   if alarmLevelTypes != "" {
      alarmLevelStr = "{\"terms\":{\"alarmRules.alarmLevel\":[\"" + alarmLevelTypes + "\"]}},"
      alarmLevelStr = "{\"terms\":{\"alarmRules.alarmLevel.raw\":[\"" + alarmLevelTypes + "\"]}},"
   }
   //使用es底层机制处理分页
@@ -294,34 +294,39 @@
}
//初始化实时抓拍
func InitRealTimeCapture(serverIp string, serverPort string, indexName string, isAlarm bool, quantity int) ([]protomsg.AIOcean, error) {
func InitRealTimeCapture(serverIp string, serverPort string, indexName string, isAlarm bool, category string, quantity int) ([]protomsg.AIOcean, error) {
   var aIOceanInfo []protomsg.AIOcean
   url := "http://" + serverIp + ":" + serverPort +
      "/" + indexName + "/_search"
   queryStr := ""
   if isAlarm == true {
      queryStr = `"query":{
      "match_all":{}
   },`
   } else {
      queryStr = `"query":{
   categoryStr := ""
   if category != "" {
      categoryStr = `            {
               "term":{
                  "targetInfo.targetType":"` + category + `"
               }
            },`
   }
   queryStr := `"query":{
      "bool":{
         "filter":[
            ` + categoryStr + `
            {
               "term":{
                  "isAlarm":true
                  "isAlarm":` + strconv.FormatBool(isAlarm) + `
               }
            }
         ]
      }
   },`
   }
   DSLJson := `{
   "size":` + strconv.Itoa(quantity) + `,
   ` + queryStr + `
   "sort":[{"picDate":{"order":"desc"}}],
   "_source": {"includes":[],"excludes":["*.feature"]}
   }`
   fmt.Println(DSLJson)
   buf, err := EsReq("POST", url, []byte(DSLJson))
   if err != nil {
      return aIOceanInfo, err
@@ -342,18 +347,6 @@
   var aIOceanInfo []protomsg.AIOcean
   url := "http://" + serverIp + ":" + serverPort +
      "/" + indexName + "/_search"
   queryStr := ""
   if isAlarm == true {
      fmt.Println("continue")
   } else {
      queryStr = `
            {
               "term":{
                  "isAlarm":1
               }
            }
               `
   }
   DSLJson := `{
   "size":20,
   "query":{
@@ -367,11 +360,15 @@
                  }      
               }
            },
         ` + queryStr + `
            {
               "term":{
                  "isAlarm":` + strconv.FormatBool(isAlarm) + `
               }
            }
         ]
      }
   },
   "_source": ["baseInfo", "alarmRules", "sex", "analyServerName", "sdkName", "ageDescription", "content", "id", "cameraAddr", "picMaxUrl", "picDate", "race", "videoUrl", "picSmUrl", "taskName", "personIsHub", "isAlarm", "analyServerIp", "cameraId", "isAckAlarm"]
   "_source": {"includes":[],"excludes":["*.feature"]}
   }`
   buf, err := EsReq("POST", url, []byte(DSLJson))
@@ -391,10 +388,6 @@
//综合统计
func StatisticsComprehensive(serverIp string, serverPort string, indexName string, isAlarm bool) (total int, err error) {
   isAlarmStr := ""
   if isAlarm == true {
      isAlarmStr = `,{"term":{"isAlarm":true}}`
   }
   url := "http://" + serverIp + ":" + serverPort +
      "/" + indexName + "/_search"
   DSLJson := `{
@@ -407,8 +400,12 @@
                  "gte":"now+8h/d"
                  }
               }
            },
            {
               "term":{
                  "isAlarm":` + strconv.FormatBool(isAlarm) + `
               }
            }
            ` + isAlarmStr + `
            ]
         }
      }