panlei
2019-09-29 0d08415bcbc5d1b260861365f26b0532771da2c5
insertdata/insertDataToEs.go
@@ -1,19 +1,16 @@
package insertdata
import (
   "basic.com/valib/logger.git"
   "encoding/base64"
   "encoding/json"
   "errors"
   "fmt"
   "io/ioutil"
   "net"
   "ruleprocess/cache"
   "ruleprocess/logger"
   "strconv"
   "time"
   "basic.com/pubsub/protomsg.git"
   "github.com/go-yaml/yaml"
   "github.com/golang/protobuf/proto"
   "github.com/satori/go.uuid"
   "ruleprocess/ruleserver"
@@ -31,19 +28,11 @@
   DbTablePersons string `yaml:"dbTablePersons"`
}
func init() {
   data, err := ioutil.ReadFile("./config/conf.yml")
   if err != nil {
      fmt.Println("读取配置文件出错--", err)
      logger.Error("读取配置文件出错--", err)
   }
   c := conf{}
   //把yaml形式的字符串解析成struct类型
   yaml.Unmarshal(data, &c)
   weedfsUrl = c.PhotoUrl
   videoPersonUrl = c.VideoPersons
   personAction = c.PersonAction
}
//func InitInsertEs() {
//   weedfsUrl = "http://"+WeedFs.Ip+":"+strconv.Itoa(WeedFs.UploadPort)+"/submit"
//   videoPersonUrl = "http://"+EsInfo.Masterip+":"+EsInfo.Httpport+"/"+EsInfo.EsIndex.VideoPersons.IndexName+"/"+EsInfo.EsIndex.VideoPersons.IndexType
//   personAction = "http://"+EsInfo.Masterip+":"+EsInfo.Httpport+"/"+EsInfo.EsIndex.Personaction.IndexName+"/"+EsInfo.EsIndex.Personaction.IndexType
//}
// 人脸的数据结构
type PerVideoPicture struct {
@@ -145,6 +134,18 @@
//   //}
//}
func InsertToEs(msg ruleserver.ResultMsg) {
   defer func() {
      if err := recover(); err != nil {
         logger.Error("es模块儿的异常捕获:",err)
      }
   }()
   localConfig1, err := cache.GetServerInfo()
   if err != nil {
      panic("配置文件不合法")
   }
   weedfsUrl = "http://"+localConfig1.WebPicIp+":"+strconv.Itoa(int(localConfig1.WebPicPort))+"/submit"
   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)
@@ -170,6 +171,8 @@
      faces = PutFace(faces,msg)
      //logger.Info("整理后的数据:",faces)
      if faces != nil {
         var imgMaxUrl string = ""
         var picTime string = ""
         for _,face := range faces {
            // 上传大图
            // 解压缩并上传图片
@@ -186,9 +189,13 @@
            }
            i := protomsg.Image{}
            err = proto.Unmarshal(bdata, &i)
            bigPhotoUrl := make(map[string]interface{})
            bigPhotoUrl, err = util.PostFormBufferData(weedfsUrl, i, uuid.NewV4().String())
            logger.Debug("========大图路径:", bigPhotoUrl)
            if imgMaxUrl == "" {
               bigPhotoUrl := make(map[string]interface{})
               bigPhotoUrl, err = util.DrawPolygonOnImageForFace(msg.Cid, i, msg.RuleResult["face"].([]ruleserver.FaceResult), weedfsUrl)
               logger.Debug("========大图路径:", bigPhotoUrl)
               imgMaxUrl = bigPhotoUrl["fileUrl"].(string)
               picTime = i.Timestamp
            }
            // 人脸检测,没有相似的底库人员
            localConfig, err := cache.GetServerInfo()
            if err != nil {
@@ -221,23 +228,23 @@
            if linkId != "" {
               linksId = linkId
            }
            logger.Info("人脸的id:",strconv.FormatUint(face.Id, 10))
            logger.Info("人脸的分值:",face.Score)
            //logger.Info("人脸的id:",strconv.FormatUint(face.Id, 10))
            //logger.Info("人脸的分值:",face.Score)
            pervideo := PerVideoPicture{
               esDataId,
               msg.Cid,
               camera.Addr,
               i.Timestamp,
               bigPhotoUrl["fileUrl"].(string),
               picTime,
               imgMaxUrl,
               msg.Tasklab.Taskid,
               msg.Tasklab.Taskname,
               "人脸",
               "",
               alarmRules,
               time.Now().Format("2006-01-02 15:04:05"), // 只检测,没有比对时间
               strconv.FormatUint(face.Id, 10),            //暂改为人脸id strconv.FormatUint(face.Id, 10)
               sex,            //暂改为人脸id strconv.FormatUint(face.Id, 10)
               face.ThftRes.Age,
               fmt.Sprintf("%.2f",face.Score), // 暂改为分值fmt.Sprintf("%.2f",face.Score)
               ageDescription, // 暂改为分值fmt.Sprintf("%.2f",face.Score)
               race,
               face.ThftRes.Smile,
               face.ThftRes.Beauty,
@@ -360,13 +367,15 @@
                     }
                     i := protomsg.Image{}
                     err = proto.Unmarshal(bdata, &i)
                     resp1, err1 := util.DrawPolygonOnImage(msg1.Cid, i, msg1.RuleResult["yolo"].([]ruleserver.Result), weedfsUrl)
                     resp1, err1 := util.DrawPolygonOnImageForYolo(msg1.Cid, i, msg1.RuleResult["yolo"].([]ruleserver.Result), weedfsUrl)
                     if err1 != nil {
                        logger.Error("缓存数据画框或上传图片服务器出错", err)
                     } else {
                        logger.Info("上传的图片信息:", resp1)
                     }
                     url = append(url, resp1["fileUrl"].(string))
                     if resp1["fileUrl"] != nil {
                        url = append(url, resp1["fileUrl"].(string))
                     }
                  }
               }
            }
@@ -401,7 +410,7 @@
         if len(alarmRules) > 0 {
            isAlarm = 1
            //resp, err = util.PostFormBufferData(weedfsUrl, i, uuid.NewV4().String())
            resp, err = util.DrawPolygonOnImage(msg.Cid, i, msg.RuleResult["yolo"].([]ruleserver.Result), weedfsUrl)
            resp, err = util.DrawPolygonOnImageForYolo(msg.Cid, i, msg.RuleResult["yolo"].([]ruleserver.Result), weedfsUrl)
            if err != nil {
               logger.Error("画框或上传图片服务器出错", err)
               return