---
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 {
@@ -165,20 +141,7 @@
   videoPersonUrl = "http://" + localConfig1.AlarmIp + ":" + strconv.Itoa(int(localConfig1.AlarmPort)) + "/" + EsInfo.EsIndex.VideoPersons.IndexName + "/" + EsInfo.EsIndex.VideoPersons.IndexType
   personAction = "http://" + localConfig1.AlarmIp + ":" + strconv.Itoa(int(localConfig1.AlarmPort)) + "/" + EsInfo.EsIndex.Personaction.IndexName + "/" + EsInfo.EsIndex.Personaction.IndexType
   InsertFace(msg, "")
   // 如果标签中含有持续时间首次报警的timeLabel的话则不需要过人体追踪,不然就没的插入了
   fk := ruleserver.TrackOrNot(msg.RuleResult)
   if fk {
      InsertYolo(msg, "")
      //if msg.Cid == "61de081a-7ed9-4970-8432-41d642c35456" {
      //   logger.Warn("捕捉188摄像机的持续时间任务.....")
      //   os.Exit(1)
      //}
   } else {
      flag := ruleserver.BodyIsSame(msg.SdkMessage)
      if !flag {
         InsertYolo(msg, "")
      }
   }
   InsertYolo(msg, "")
}
// 往es中插入人脸数据
@@ -199,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)
@@ -207,6 +170,13 @@
            }
            i := protomsg.Image{}
            err = proto.Unmarshal(bdata, &i)
            // 先传小图,再传大图,防止脸上有线
            bytes := util.SubImg(i, int(face.Location.X), int(face.Location.Y), int(face.Location.X+face.Location.Width), int(face.Location.Y+face.Location.Height))
            resp, err := util.PostFormBufferData1(weedfsUrl, bytes, uuid.NewV4().String())
            if err != nil {
               logger.Error("上传小图出错")
            }
            // 上传大图
            if imgMaxUrl == "" {
               bigPhotoUrl := make(map[string]interface{})
               bigPhotoUrl, err = util.DrawPolygonOnImageForFace(msg.Cid, i, msg.RuleResult["face"].([]structure.FaceResult), weedfsUrl)
@@ -214,23 +184,6 @@
               imgMaxUrl = bigPhotoUrl["fileUrl"].(string)
               picTime = i.Timestamp
            }
            // 人脸检测,没有相似的底库人员
            localConfig, err := cache.GetServerInfo()
            if err != nil {
               logger.Error("查询本机信息失败!")
            }
            serverIp, err := GetLocalIP()
            // 查询cameraName
            camera, err := cache.GetCameraById(msg.Cid)
            if err != nil {
               logger.Error("查询摄像机信息失败")
            }
            bytes := util.SubImg(i, int(face.Location.X), int(face.Location.Y), int(face.Location.X+face.Location.Width), int(face.Location.Y+face.Location.Height))
            resp, err := util.PostFormBufferData1(weedfsUrl, bytes, uuid.NewV4().String())
            if err != nil {
               logger.Error("上传小图出错")
            }
            //logger.Info("================小图地址:", resp["fileUrl"].(string))
            sex := ""
            logger.Info(sex)
            if face.ThftRes.Gender == 1 {
@@ -241,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
@@ -251,11 +204,10 @@
            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,
               camera.Addr,
               msg.Push.Cam.Addr,
               picTime,
               imgMaxUrl,
               msg.Tasklab.Taskid,
@@ -272,10 +224,10 @@
               face.ThftRes.Beauty,
               base64.StdEncoding.EncodeToString(face.Feature),
               []string{resp["fileUrl"].(string)},
               "暂无集群",
               localConfig.ServerId,
               localConfig.ServerName,
               serverIp,
               "",
               msg.Push.ServerId,
               msg.Push.ServerName,
               msg.Push.LocalIp,
               "",
               linksId,
               face.Score,
@@ -298,7 +250,7 @@
            } else {
               logger.Info("插入es返回的信息:", resp1)
               // 发出录像信号
               ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: esDataId, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid, 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})
            }
         }
      }
@@ -319,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)
@@ -405,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 {
@@ -465,40 +417,26 @@
            // 不是报警数据不存
            return
         }
         // logger.Println("图片上传返回值:", resp)
         // 查询本机信息
         localConfig, err := cache.GetServerInfo()
         if err != nil {
            logger.Error("查询本机信息失败!")
         }
         // 查询cameraName
         camera, err := cache.GetCameraById(msg.Cid)
         if err != nil {
            logger.Error("查询摄像机信息失败")
         }
         logger.Info("摄像机信息:",camera)
         serverIp, err := GetLocalIP()
         logger.Info("%%%%%%%%%%%%%%%%%yolo的target信息:",targetInfos)
         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,
               camera.Name,
               camera.Addr,
               msg.Push.Cam.Name,
               msg.Push.Cam.Addr,
               msg.Tasklab.Taskid,
               msg.Tasklab.Taskname,
               sdkNames,
               "",
               alarmRules,
               localConfig.ServerId,
               localConfig.ServerName,
               serverIp,
               msg.Push.ServerId,
               msg.Push.ServerName,
               msg.Push.LocalIp,
               "",
               url,
               i.Timestamp,
@@ -515,7 +453,6 @@
            if err != nil {
               logger.Info("json parse error ", err)
               return
            }
            resp1, err2 := EsReq("POST", personAction, requstbody)
            if err2 != nil {
@@ -523,7 +460,7 @@
            } else {
               logger.Debug("插入es返回的数据信息是:", resp1)
               // 发出录像信号
               ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: esDataId, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid, 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)
            }