panlei
2019-11-13 33804d4591d5021b4dec1da5f5152422282409c6
insertdata/insertDataToEs.go
@@ -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 {
@@ -170,7 +146,7 @@
// 往es中插入人脸数据
func InsertFace(msg structure.ResultMsg, linkId string) {
   if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]structure.FaceResult)) > 0 {
   if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]structure.TargetResult)) > 0 {
      logger.Info("往ES插人脸数据")
      faces := []*FaceAndRules{}
      faces = PutFace(faces, msg)
@@ -186,7 +162,6 @@
               panic("解压缩图片时出现错误")
            }
            alarmRules := []AlarmRule{}
            logger.Warn("人脸id为:", face.Id, "人脸的规则长度为:", len(face.rules))
            //os.Exit(1)
            for _, faceResult := range face.rules {
               alarm := ChangeToString(faceResult.DefenceState, faceResult.AlarmLevel)
@@ -203,7 +178,7 @@
            // 上传大图
            if imgMaxUrl == "" {
               bigPhotoUrl := make(map[string]interface{})
               bigPhotoUrl, err = util.DrawPolygonOnImageForFace(msg.Cid, i, msg.RuleResult["face"].([]structure.FaceResult), weedfsUrl)
               bigPhotoUrl, err = util.DrawPolygonOnImageForFace(msg.Cid, i, msg.RuleResult["face"].([]structure.TargetResult), weedfsUrl)
               logger.Debug("========大图路径:", bigPhotoUrl)
               imgMaxUrl = bigPhotoUrl["fileUrl"].(string)
               picTime = i.Timestamp
@@ -218,7 +193,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 +203,9 @@
            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.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})
            }
         }
      }
@@ -284,8 +259,8 @@
// 归置人脸
func PutFace(faces []*FaceAndRules, msg structure.ResultMsg) []*FaceAndRules {
   if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]structure.FaceResult)) > 0 {
      for _, faceResult := range msg.RuleResult["face"].([]structure.FaceResult) {
   if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]structure.TargetResult)) > 0 {
      for _, faceResult := range msg.RuleResult["face"].([]structure.TargetResult) {
         faces = hebingFace(faces, faceResult)
      }
      return faces
@@ -293,15 +268,15 @@
      return nil
   }
}
func hebingFace(faces []*FaceAndRules, faceResult structure.FaceResult) []*FaceAndRules {
func hebingFace(faces []*FaceAndRules, faceResult structure.TargetResult) []*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,6 @@
               // 装配目标信息数据
               for _,target := range yoloResult.Location  {
                  // 去重添加
                  logger.Info("装配前的原始数据是:",target)
                  var flag = true
                  for _,selectTarget := range targetInfos  {
                     if strconv.FormatUint(target.TargetId, 10) == selectTarget.TargetId {
@@ -442,16 +416,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,
@@ -479,7 +452,6 @@
            if err != nil {
               logger.Info("json parse error ", err)
               return
            }
            resp1, err2 := EsReq("POST", personAction, requstbody)
            if err2 != nil {
@@ -487,8 +459,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)
            }