---
panlei
2019-11-14 855acd05ad59da181e595c6f68b1e5ac8d4bbaa4
insertdata/insertDataToEs.go
@@ -68,15 +68,50 @@
   IsCollect       int                   `json:"isCollect"`
   IsDelete        int                   `json:"isDelete"`
   BaseInfo        []*structure.BaseInfo `json:"baseInfo"`
   TargetInfo      []Target
   LinkTag         string          `json:"linkTag"`
   LinkTagInfo     []*PerVideoPicture `json:"linkTagInfo"`
   TargetInfo      []Target              `json:"targetInfo"`
   LinkTag         string                `json:"linkTag"`
   LinkTagInfo     []*LinkInfo           `json:"linkTagInfo"`
}
type LinkInfo struct {
   Id              string                `json:"id"`
   CameraId        string                `json:"cameraId"`
   CameraAddr      string                `json:"cameraAddr"`
   CameraName      string                `json:"cameraName"`
   PicDate         string                `json:"picDate"`
   PicMaxUrl       string                `json:"picMaxUrl"`
   TaskId          string                `json:"taskId"`
   TaskName        string                `json:"taskName"`
   SdkName         string                `json:"sdkName"`
   Content         string                `json:"content"`
   AlarmRules      []AlarmRule           `json:"alarmRules"`
   LikeDate        string                `json:"likeDate"`
   Sex             string                `json:"sex"`
   Age             int32                 `json:"age"`
   AgeDescription  string                `json:"ageDescription"`
   Race            string                `json:"race"`
   SmileLevel      int32                 `json:"smileLevel"`
   BeautyLevel     int32                 `json:"beautyLevel"`
   FaceFeature     string                `json:"faceFeature"`
   PicSmUrl        []string              `json:"picSmUrl"`
   VideoUrl        string                `json:"videoUrl"`
   AnalyServerId   string                `json:"analyServerId"`
   AnalyServerName string                `json:"analyServerName"`
   AnalyServerIp   string                `json:"analyServerIp"`
   ClusterId       string                `json:"clusterId"`
   DetectScore     float64               `json:"detectScore"`
   IsAlarm         int                   `json:"isAlarm"`
   IsAckAlarm      int                   `json:"isAckAlarm"`
   IsCollect       int                   `json:"isCollect"`
   IsDelete        int                   `json:"isDelete"`
   BaseInfo        []*structure.BaseInfo `json:"baseInfo"`
   TargetInfo      []Target              `json:"targetInfo"`
}
type Target struct {
   TargetId       string  `json:"targetId"`
   TargetScore    float64 `json:"targetScore"`
   TargetLocation Points
   TargetLocation Points  `json:"targetLocation"`
}
type Points struct {
@@ -85,8 +120,8 @@
}
type Point struct {
   Lat float64 `json:"lat"`
   Lon float64 `json:"lon"`
   X float64 `json:"x"`
   Y float64 `json:"y"`
}
//  yolo行为的数据结构
@@ -111,9 +146,9 @@
   IsAckAlarm      int         `json:"isAckAlarm"`
   IsCollect       int         `json:"isCollect"`
   IsDelete        int         `json:"isDelete"`
   TargetInfo      []Target
   LinkTag         string          `json:"linkTag"`
   LinkTagInfo     []*PerVideoPicture `json:"linkTagInfo"`
   TargetInfo      []Target    `json:"targetInfo"`
   LinkTag         string      `json:"linkTag"`
   LinkTagInfo     []*LinkInfo `json:"linkTagInfo"`
}
type AlarmRule struct {
@@ -149,7 +184,7 @@
// 往es中插入人脸数据
func InsertFace(msg structure.ResultMsg) {
   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)
@@ -181,7 +216,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
@@ -202,7 +237,7 @@
            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))
            var targetInfos []Target
            targetInfos = append(targetInfos,*target)
            targetInfos = append(targetInfos, *target)
            pervideo := PerVideoPicture{
               face.Uuid,
               msg.Cid,
@@ -237,7 +272,7 @@
               face.Liker,
               targetInfos,
               "",
               nil,
               []*LinkInfo{},
            }
            requstbody, err := json.Marshal(pervideo)
@@ -249,9 +284,9 @@
            if err1 != nil {
               logger.Error("上传ES出错!---", err1)
            } else {
               logger.Info("插入es返回的信息:", resp1)
               logger.Info("插入es返回的信息(人脸):", resp1)
               // 发出录像信号
               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})
               ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: face.Uuid, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid, VideoUrl: msg.Push.VideoUrl, ImgId: i.Id, SdkIds: []string{}, Type: 1})
            }
         }
      }
@@ -260,8 +295,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
@@ -269,7 +304,7 @@
      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))
@@ -376,12 +411,14 @@
            }
         }
         linkTagInfos := []*PerVideoPicture{}
         linkTagInfos := []*LinkInfo{}
         for _, yoloResult := range msg.RuleResult["yolo"].([]structure.Result) {
            if (yoloResult.Others.TimeLabel == "01" || yoloResult.Others.TimeLabel == "10") && yoloResult.Others.LinkCache != nil && len(yoloResult.Others.LinkCache) > 1 {
               for _, msg2 := range yoloResult.Others.LinkCache {
                  // 把msg2的数据装配成一个PerVideoPicture结构体
                  linkTagInfos = append(linkTagInfos,msg2PersonVideo(msg2))
                  if msg2.Cid != msg.Cid {
                     linkTagInfos = append(linkTagInfos, msg2PersonVideo(msg2))
                  }
               }
            }
         }
@@ -443,6 +480,9 @@
            }
            requstbody, err := json.Marshal(peraction)
            if len(linkTagInfos)>0 {
               logger.Info("联动任务1111")
            }
            if err != nil {
               logger.Info("json parse error ", err)
               return
@@ -451,7 +491,7 @@
            if err2 != nil {
               logger.Error("往ES插入数据失败", err)
            } else {
               logger.Debug("插入es返回的数据信息是:", resp1)
               logger.Debug("插入es返回的数据信息是(yolo):", resp1)
               // 发出录像信号
               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数据成功")
@@ -547,7 +587,7 @@
   return race
}
func msg2PersonVideo (msg structure.ResultMsg) *PerVideoPicture{
func msg2PersonVideo(msg structure.ResultMsg) *LinkInfo {
   if msg.RuleResult["yolo"] != nil && len(msg.RuleResult["yolo"].([]structure.Result)) > 0 {
      // 先判断一下数据带的规则标签是否有可以插入的
      flag := false
@@ -573,7 +613,7 @@
               if yoloResult.IsLink {
                  linkInfo = "联动任务"
               }
               alarmRules = append(alarmRules, AlarmRule{yoloResult.RuleGroupId, alarm, yoloResult.RuleText, yoloResult.DefenceState,linkInfo})
               alarmRules = append(alarmRules, AlarmRule{yoloResult.RuleGroupId, alarm, yoloResult.RuleText, yoloResult.DefenceState, linkInfo})
               // 上传缓存数据的图片拿到url
               if yoloResult.Others.CacheData != nil {
                  //InsertYolo(msg.RuleResult["cacheData"].(ruleserver.ResultMsg))
@@ -645,7 +685,7 @@
         if resp["fileUrl"] != nil {
            url = append(url, resp["fileUrl"].(string))
            //esDataId := uuid.NewV4().String()
            pervideo := &PerVideoPicture{
            pervideo := &LinkInfo{
               msg.Push.PushId + "-" + uuid.NewV4().String(),
               msg.Cid,
               msg.Push.Cam.Addr,
@@ -658,7 +698,7 @@
               "",
               alarmRules,
               time.Now().Format("2006-01-02 15:04:05"), // 只检测,没有比对时间
               "",                                      //暂改为人脸id strconv.FormatUint(face.Id, 10)
               "",                                       //暂改为人脸id strconv.FormatUint(face.Id, 10)
               0,
               "", // 暂改为分值fmt.Sprintf("%.2f",face.Score)
               "",
@@ -678,8 +718,6 @@
               0,
               nil,
               targetInfos,
               "",
               nil,
            }
            return pervideo
         } else {
@@ -692,4 +730,4 @@
   } else {
      return nil
   }
}
}