---
panlei
2019-11-14 855acd05ad59da181e595c6f68b1e5ac8d4bbaa4
insertdata/insertDataToEs.go
@@ -70,13 +70,48 @@
   BaseInfo        []*structure.BaseInfo `json:"baseInfo"`
   TargetInfo      []Target              `json:"targetInfo"`
   LinkTag         string                `json:"linkTag"`
   LinkTagInfo     []*PerVideoPicture    `json:"linkTagInfo"`
   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,35 +120,35 @@
}
type Point struct {
   Lat float64 `json:"lat"`
   Lon float64 `json:"lon"`
   X float64 `json:"x"`
   Y float64 `json:"y"`
}
//  yolo行为的数据结构
type Personaction struct {
   Id              string             `json:"id"`
   CameraId        string             `json:"cameraId"`
   CameraName      string             `json:"cameraName"`
   CameraAddr      string             `json:"cameraAddr"`
   TaskId          string             `json:"taskId"`
   TaskName        string             `json:"taskName"`
   SdkName         string             `json:"sdkName"`
   Content         string             `json:"content"`
   AlarmRules      []AlarmRule        `json:"alarmRules"`
   AnalyServerId   string             `json:"analyServerId"`
   AnalyServerName string             `json:"analyServerName"`
   AnalyServerIp   string             `json:"analyServerIp"`
   ClusterId       string             `json:"clusterId"`
   PicSmUrl        []string           `json:"picSmUrl"`
   PicDate         string             `json:"picDate"`
   VideoUrl        string             `json:"videoUrl"`
   IsAlarm         int                `json:"isAlarm"`
   IsAckAlarm      int                `json:"isAckAlarm"`
   IsCollect       int                `json:"isCollect"`
   IsDelete        int                `json:"isDelete"`
   TargetInfo      []Target           `json:"targetInfo"`
   LinkTag         string             `json:"linkTag"`
   LinkTagInfo     []*PerVideoPicture `json:"linkTagInfo"`
   Id              string      `json:"id"`
   CameraId        string      `json:"cameraId"`
   CameraName      string      `json:"cameraName"`
   CameraAddr      string      `json:"cameraAddr"`
   TaskId          string      `json:"taskId"`
   TaskName        string      `json:"taskName"`
   SdkName         string      `json:"sdkName"`
   Content         string      `json:"content"`
   AlarmRules      []AlarmRule `json:"alarmRules"`
   AnalyServerId   string      `json:"analyServerId"`
   AnalyServerName string      `json:"analyServerName"`
   AnalyServerIp   string      `json:"analyServerIp"`
   ClusterId       string      `json:"clusterId"`
   PicSmUrl        []string    `json:"picSmUrl"`
   PicDate         string      `json:"picDate"`
   VideoUrl        string      `json:"videoUrl"`
   IsAlarm         int         `json:"isAlarm"`
   IsAckAlarm      int         `json:"isAckAlarm"`
   IsCollect       int         `json:"isCollect"`
   IsDelete        int         `json:"isDelete"`
   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
@@ -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
@@ -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,
@@ -678,8 +718,6 @@
               0,
               nil,
               targetInfos,
               "",
               nil,
            }
            return pervideo
         } else {