sunty
2020-01-19 bae7a9a30b89c519460746cfa19cd7e66a0196e2
controllers/esSearch.go
@@ -34,8 +34,8 @@
   var arg models.EsSearch
   err := c.BindJSON(&arg)
   if err !=nil || arg.Page <=0 && arg.Size<=0 {
      util.ResponseFormat(c,code.RequestParamError,"参数有误")
   if err != nil || arg.Page <= 0 && arg.Size <= 0 {
      util.ResponseFormat(c, code.RequestParamError, "参数有误")
      return
   }
   data := findEsData(&arg)
@@ -105,7 +105,7 @@
   //判断数据ID
   idStr := ""
   linkTagInfoIdStr :=""
   linkTagInfoIdStr := ""
   //personId := searchBody.Id
   id := []string{}
   if id != nil && len(id) > 0 {
@@ -158,14 +158,14 @@
   linkTagInfoAlarmLevelStr := ""
   if len(alarmLevelId) > 0 {
      alarmLevelTypes := strings.Replace(strings.Trim(fmt.Sprint(getAlarmLevel(alarmLevelId)), "[]"), " ", "\",\"", -1)
      alarmLevelStr = "{\"terms\":{\"alarmRules.alarmLevel\":[\"" + alarmLevelTypes + "\"]}},"
      linkTagInfoAlarmLevelStr = "{\"terms\":{\"linkTagInfo.alarmRules.alarmLevel\":[\"" + alarmLevelTypes + "\"]}},"
      alarmLevelStr = "{\"terms\":{\"alarmRules.alarmLevel.raw\":[\"" + alarmLevelTypes + "\"]}},"
      linkTagInfoAlarmLevelStr = "{\"terms\":{\"linkTagInfo.alarmRules.alarmLevel.raw\":[\"" + alarmLevelTypes + "\"]}},"
   }
   //使用es底层机制处理分页
   //请求头
   localConf, err2 := cache.GetServerInfo()
   if err2 !=nil || localConf.AlarmIp == "" || localConf.ServerId == "" {
   if err2 != nil || localConf.AlarmIp == "" || localConf.ServerId == "" {
      logger.Debug("localConfig is wrong!!!")
      return nil
   }
@@ -188,7 +188,7 @@
      isCollectStr +
      esTableIdStr +
      analyServerFilterStr +
      "{\"range\":{\"picDate\":{\"from\":\"" + gteDate + "\",\"to\":\"" + lteDate + "\",\"include_lower\":true,\"include_upper\":true,\"boost\":1}}}"+
      "{\"range\":{\"picDate\":{\"from\":\"" + gteDate + "\",\"to\":\"" + lteDate + "\",\"include_lower\":true,\"include_upper\":true,\"boost\":1}}}" +
      "]}}," +
      "{\"bool\":{\"filter\":[" +
      linkTagInfoCameraIdStr +
@@ -198,13 +198,13 @@
      linkTagInfoIsCollectStr +
      linkTagInfoEsTableIdStr +
      linkTagInfoAnalyServerFilterStr +
      "{\"range\":{\"linkTagInfo.picDate\":{\"from\":\"" + gteDate + "\",\"to\":\"" + lteDate + "\",\"include_lower\":true,\"include_upper\":true,\"boost\":1}}}"+
      "{\"range\":{\"linkTagInfo.picDate\":{\"from\":\"" + gteDate + "\",\"to\":\"" + lteDate + "\",\"include_lower\":true,\"include_upper\":true,\"boost\":1}}}" +
      "]}}" +
      "]," +
      "\"sort\":[{\"_score\":{\"order\":\"desc\"}},{\"picDate\":{\"order\":\"desc\"}}]," +
      "],\"minimum_should_match\":1}}," +
      "\"sort\":[{\"_score\":{\"order\":\"desc\"}},{\"updateTime\":{\"order\":\"desc\"}}]," +
      "\"_source\":{\"includes\":[],\"excludes\":[\"*.feature\"]}" +
      "}"
   //logger.Debug("findEsData.param:",prama)
   logger.Debug("findEsData.param:", prama)
   //数据解析
   tokenRes := esutil.GetEsDataReq(url, prama, true)
   //fmt.Println(tokenRes)
@@ -215,30 +215,37 @@
   for _, masterInfoValues := range data.([]interface{}) {
      masterInfo := masterInfoValues.(map[string]interface{})
      sources := make(map[string]interface{}, 0)
      activateInfo := make(map[string]interface{})
      if masterInfo["linkTagInfo"] != nil {
         linkTagInfo := masterInfo["linkTagInfo"].([]interface{})
         delete(masterInfo, "linkTagInfo")
         if len(linkTagInfo) >0 {
         if len(linkTagInfo) > 0 {
            slaveList := make([]interface{}, 0)
            slaveList = append(slaveList, masterInfo)
            slaveList = append(slaveList, linkTagInfo...)
            for i, j := 0, len(slaveList)-1; i < j; i, j = i+1, j-1 {
               slaveList[i], slaveList[j] = slaveList[j], slaveList[i]
            }
            sources["list"] = slaveList
            activateInfo = slaveList[0].(map[string]interface{})
         } else {
            sources["list"] = []interface{}{
               masterInfo,
            }
            activateInfo = masterInfo
         }
      } else {
         if _,ok := masterInfo["linkTagInfo"];ok {
         if _, ok := masterInfo["linkTagInfo"]; ok {
            delete(masterInfo, "linkTagInfo")
         }
         sources["list"] = []interface{}{
            masterInfo,
         }
         activateInfo = masterInfo
      }
      sources["activeObject"] = masterInfo
      sources["activeObject"] = activateInfo
      tmpDate["datalist"] = append(tmpDate["datalist"], sources)
   }