tcp server 用于给andriod 客户端定时发送消息
fix
liuxiaolong
2020-06-17 043acf60de48c730d8e146413ee18a82c4fbfa69
esutil/EsClient.go
@@ -27,7 +27,7 @@
   resp, err := client.Do(req)
   if err != nil {
      return err, nil
        return err, nil
   }
   defer resp.Body.Close()
@@ -47,7 +47,7 @@
   }
   // 是否需要 解析 es 返回的 source
   if isSource {
      dat, ok := dat["hits"].(map[string]interface{})
        dat, ok := dat["hits"].(map[string]interface{})
      if !ok {
         return errors.New("data is not type of  map[string]interface{}"), nil
      }
@@ -63,45 +63,58 @@
         }
         d["id"] = value.(map[string]interface{})["_id"]
         d["picDate"] = source["picDate"]
         pmax, exist := source["picMaxUrl"]
         if !exist {
            continue
         }
         pmArr := pmax.([]string)
         pmArr := pmax.([]interface{})
         if len(pmArr) > 0 {
            d["picMaxUrl"] = pmArr[0]
         } else {
            d["picMaxUrl"] = ""
         }
         tB, err := json.Marshal(source["targetInfo"])
         if err != nil {
            continue
             log.Log.Infoln("err:", err)
                continue
         }
         ti := TargetInfo{}
         err = json.Unmarshal(tB, &ti)
         tiArr := []TargetInfo{}
         err = json.Unmarshal(tB, &tiArr)
         if err !=nil {
             log.Log.Infoln("err:", err)
            continue
         }
         d["picSmUrl"] = ti.PicSmUrl
         if ti.TargetType == "face" {
            sLabelStr, ok := source["showLabels"]
            if ok {
               labelArr := strings.Split(sLabelStr.(string), "/")
               if len(labelArr) == 3 {
                  d["gender"] = labelArr[0]
                  d["ageDescription"] = labelArr[1]
                  d["race"] = labelArr[2]
         if len(tiArr) > 0 {
            ti := tiArr[0]
            d["picSmUrl"] = ti.PicSmUrl
            if ti.TargetType == "face" {
               sLabelStr, ok := source["showLabels"]
               if ok {
                  labelArr := strings.Split(sLabelStr.(string), "/")
                  if len(labelArr) == 3 {
                     d["gender"] = labelArr[0]
                     d["ageDescription"] = labelArr[1]
                     d["race"] = labelArr[2]
                  }
               }
            }
            if bInfos,ok := source["baseInfo"]; ok && bInfos != nil {
               d["baseInfo"] = getSourceBaseInfo(bInfos)
               if bInfos,ok := source["baseInfo"]; ok && bInfos != nil {
                  d["baseInfo"] = getSourceBaseInfo(bInfos)
               } else {
                  d["baseInfo"] = []interface{}{}
               }
               d["sdkType"] = "人脸"
            } else {
               d["baseInfo"] = []interface{}{}
               d["sdkType"] = source["sdkName"]
               d["picSmUrl"] = d["picMaxUrl"]
            }
         } else {
            d["picSmUrl"] = d["picMaxUrl"]
         }
         d["videoNum"] = source["videoUrl"]
@@ -217,7 +230,7 @@
   var filterArr []string
   //是否查报警数据
   if ishub == "hub" {
      filterArr = append(filterArr,"{\"term\":{\"alarmRules.alarmLevel.raw\":\"一级\"}}")
      filterArr = append(filterArr,"{\"term\":{\"alarmRules.alarmLevel.raw\":\"二级\"}}")
   }
   filterArr = append(filterArr, "{\"range\":{\"picDate\":{\"gte\":\"now+8h-"+preSec+"s\",\"lt\":\"now+8h\"}}}")
@@ -226,25 +239,13 @@
   if len(filterArr) >0 {
      filterStr = strings.Join(filterArr, ",")
   }
   sourceArr := []string{
      "baseInfo",
      "targetInfo",
      "content",
      "id",
      "picMaxUrl",
      "picDate",
      "showLabels",
      "taskName",
   }
   sourceStr := strings.Join(sourceArr, ",")
   log.Log.Infoln("filterArr:", filterStr)
   param := "{\"query\":{\"bool\":{\"filter\":["+filterStr+"]}},\"size\":\""+sizeStr+"\",\"sort\":[{\"picDate\":{\"order\":\"desc\"}}]," +
      "\"_source\":{\"includes\":["+sourceStr+"],\"excludes\":[\"*.feature\",\"*.attachTarget\",\"*.targetLocation\",\"alarmRules\"]}" +
      "\"_source\":{\"includes\":[\"baseInfo\",\"targetInfo\",\"content\",\"id\",\"picMaxUrl\",\"picDate\",\"showLabels\",\"taskName\",\"sdkName\"],\"excludes\":[\"*.feature\",\"*.attachTarget\",\"*.targetLocation\",\"alarmRules\"]}" +
      "}"
   err, tokenRes := GetEsDataReq(url, param, true)
   if err != nil {
      log.Log.Errorln(err)
      log.Log.Errorln("GetEsDataReq err:", err)
      return nil
   }
   jsonstring, _ := json.Marshal(tokenRes)