---
panlei
2019-11-07 52713b8d85e26a984ecaeef926c815e8cf8075b7
insertdata/insertDataToEs.go
@@ -1,7 +1,7 @@
package insertdata
import (
   "basic.com/valib/logger.git"
   "ruleprocess/logger"
   "encoding/base64"
   "encoding/json"
   "errors"
@@ -127,30 +127,6 @@
   rules []structure.Result
}
// 往ES插数据
//func InsertToEs(msg ruleserver.ResultMsg) {
//   var timeLabel string
//   // 直接从规则的标签数据里拿符合规则的人脸结果
//   if msg.RuleResult["timeLabel"] != nil {
//      timeLabel = msg.RuleResult["timeLabel"].(string)
//   }
//   logger.Debug("插入数据前看看报警标志位:", timeLabel)
//   if timeLabel == "01" { // 无定时器状态要插入的报警数据
//      InsertFace(msg)
//      flag := ruleserver.BodyIsSame(msg.SdkMessage)
//      if !flag {
//         InsertYolo(msg)
//      }
//   }
//   if timeLabel == "10" { // 定时器状态要插入的首帧报警数据。连带着定时器开启时的那帧
//      InsertFace(msg)
//      InsertYolo(msg)
//   }
//   //if timeLabel == "12" { // 并非报警数据,只是状态改变的数据
//   //   //ChangeStatusFace(msg)
//   //   ChangeStatusYolo(msg)
//   //}
//}
func InsertToEs(msg structure.ResultMsg) {
   defer func() {
      if err := recover(); err != nil {
@@ -186,7 +162,7 @@
               panic("解压缩图片时出现错误")
            }
            alarmRules := []AlarmRule{}
            logger.Warn("人脸id为:", face.Id, "人脸的规则长度为:", len(face.rules))
            //logger.Warn("人脸id为:", face.Id, "人脸的规则长度为:", len(face.rules))
            //os.Exit(1)
            for _, faceResult := range face.rules {
               alarm := ChangeToString(faceResult.DefenceState, faceResult.AlarmLevel)
@@ -218,7 +194,7 @@
            race := getRaceString(face.ThftRes.Race)
            ageDescription := getDescription(face.ThftRes.Age)
            logger.Info(ageDescription)
            esDataId := uuid.NewV4().String()
            //esDataId := uuid.NewV4().String()
            linksId := ""
            if linkId != "" {
               linksId = linkId
@@ -228,9 +204,8 @@
            target.TargetScore = face.Score
            target.TargetLocation = Points{TopLeft:Point{face.Location.X,face.Location.Y},BottomRight:Point{face.Location.X+face.Location.Width,face.Location.Y+face.Location.Height}}
            //logger.Info("人脸的id:",strconv.FormatUint(face.Id, 10))
            logger.Info("%%%%%%%%%%%%%%%%%%%%%目标信息:",*target)
            pervideo := PerVideoPicture{
               esDataId,
               msg.Push.PushId,
               msg.Cid,
               msg.Push.Cam.Addr,
               picTime,
@@ -249,7 +224,7 @@
               face.ThftRes.Beauty,
               base64.StdEncoding.EncodeToString(face.Feature),
               []string{resp["fileUrl"].(string)},
               msg.Push.VideoUrl,
               "",
               msg.Push.ServerId,
               msg.Push.ServerName,
               msg.Push.LocalIp,
@@ -275,7 +250,7 @@
            } else {
               logger.Info("插入es返回的信息:", resp1)
               // 发出录像信号
               ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: esDataId, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid, VideoUrl:msg.Push.VideoUrl,ImgId: i.Id, SdkIds: []string{}, Type: 1})
               ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: msg.Push.PushId, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid, VideoUrl:msg.Push.VideoUrl,ImgId: i.Id, SdkIds: []string{}, Type: 1})
            }
         }
      }
@@ -296,12 +271,12 @@
func hebingFace(faces []*FaceAndRules, faceResult structure.FaceResult) []*FaceAndRules {
   for _, arg := range faceResult.Args {
      // 拿到每一张人脸
      logger.Info("归置人脸时相似者的数量:", len(arg.Liker))
      //logger.Info("归置人脸时相似者的数量:", len(arg.Liker))
      flag := false
      for _, face := range faces {
         for _, lik := range face.Liker {
            logger.Warn("--------合并人脸时相似者:", lik.PersonId, lik.TableName)
         }
         //for _, lik := range face.Liker {
         //   //logger.Warn("--------合并人脸时相似者:", lik.PersonId, lik.TableName)
         //}
         if arg.Id == face.Id {
            flag = true
            face.rules = append(face.rules, faceResult.Result)
@@ -382,7 +357,7 @@
               // 装配目标信息数据
               for _,target := range yoloResult.Location  {
                  // 去重添加
                  logger.Info("装配前的原始数据是:",target)
                  //logger.Info("装配前的原始数据是:",target)
                  var flag = true
                  for _,selectTarget := range targetInfos  {
                     if strconv.FormatUint(target.TargetId, 10) == selectTarget.TargetId {
@@ -442,16 +417,15 @@
            // 不是报警数据不存
            return
         }
         if resp["fileUrl"] != nil {
            url = append(url, resp["fileUrl"].(string))
            esDataId := uuid.NewV4().String()
            //esDataId := uuid.NewV4().String()
            linksId := ""
            if linkId != "" {
               linksId = linkId
            }
            peraction := Personaction{
               esDataId,
               msg.Push.PushId,
               msg.Cid,
               msg.Push.Cam.Name,
               msg.Push.Cam.Addr,
@@ -467,7 +441,7 @@
               url,
               i.Timestamp,
               linksId,
               msg.Push.VideoUrl,
               "",
               isAlarm,
               0,
               0,
@@ -479,7 +453,6 @@
            if err != nil {
               logger.Info("json parse error ", err)
               return
            }
            resp1, err2 := EsReq("POST", personAction, requstbody)
            if err2 != nil {
@@ -487,8 +460,7 @@
            } else {
               logger.Debug("插入es返回的数据信息是:", resp1)
               // 发出录像信号
               logger.Info("给录像的视频地址:",msg.Push.VideoUrl)
               ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: esDataId, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid,VideoUrl:msg.Push.VideoUrl, ImgId: i.Id, SdkIds: []string{}, Type: 2})
               ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: msg.Push.PushId, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid,VideoUrl:msg.Push.VideoUrl, ImgId: i.Id, SdkIds: []string{}, Type: 2})
               logger.Warn("__________________________________________往ES插入yolo数据成功")
               //os.Exit(1)
            }