From f8d06b644c67921ec0729879bc3ac6288931428c Mon Sep 17 00:00:00 2001 From: panlei <2799247126@qq.com> Date: 星期二, 17 十二月 2019 11:26:38 +0800 Subject: [PATCH] --- --- algorithm/middleware/insertDataToEs.go | 147 ++++++++++++++++++++++++++++++------------------ 1 files changed, 91 insertions(+), 56 deletions(-) diff --git a/algorithm/middleware/insertDataToEs.go b/algorithm/middleware/insertDataToEs.go index bb0cfdb..8ef4ffb 100644 --- a/algorithm/middleware/insertDataToEs.go +++ b/algorithm/middleware/insertDataToEs.go @@ -1,7 +1,6 @@ package main import ( - "encoding/base64" "encoding/json" "errors" "net" @@ -9,15 +8,15 @@ "strconv" "time" + "basic.com/valib/logger.git" "github.com/golang/protobuf/proto" "github.com/satori/go.uuid" - "basic.com/valib/logger.git" - "ruleprocess/cache" - "ruleprocess/structure" - "basic.com/pubsub/protomsg.git" "basic.com/pubsub/esutil.git" + "basic.com/pubsub/protomsg.git" + "ruleprocess/cache" "ruleprocess/ruleserver" + "ruleprocess/structure" "ruleprocess/util" ) @@ -134,7 +133,7 @@ faces = PutFace(faces, results.([]structure.Result)) //logger.Info("鏁寸悊鍚庣殑鏁版嵁锛�",faces) if faces != nil { - logger.Warn("face涓嶄负nil") + logger.Warn("鐩爣涓嶄负nil") var imgMaxUrl []string = []string{} var picTime string = "" for _, face := range faces { @@ -171,15 +170,14 @@ target.TargetId = face.Id target.TargetScore = face.Score target.TargetType = face.Type - target.Feature = base64.StdEncoding.EncodeToString(face.Feature) + target.Feature = face.Feature target.PicSmUrl = resp["fileUrl"].(string) 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}} - target.AttachTarget = SourceTarget{face.AttachArg.Id,face.AttachArg.Score,face.AttachArg.Type,base64.StdEncoding.EncodeToString(face.AttachArg.Feature),"",Points{TopLeft: Point{face.AttachArg.Location.X, face.AttachArg.Location.Y}, BottomRight: Point{face.AttachArg.Location.X + face.AttachArg.Location.Width, face.AttachArg.Location.Y + face.AttachArg.Location.Height}}} + target.AttachTarget = SourceTarget{face.AttachArg.Id,face.AttachArg.Score,face.AttachArg.Type,face.AttachArg.Feature,"",Points{TopLeft: Point{face.AttachArg.Location.X, face.AttachArg.Location.Y}, BottomRight: Point{face.AttachArg.Location.X + face.AttachArg.Location.Width, face.AttachArg.Location.Y + face.AttachArg.Location.Height}}} var targetInfos []Target targetInfos = append(targetInfos, *target) sdkname := "" - id := face.Uuid switch key { case "face": sdkname = "浜鸿劯" @@ -187,51 +185,45 @@ sdkname = "杞︾墝璇嗗埆" case "track": sdkname = "璺熻釜" - logger.Info("鏁版嵁鍒颁簡姝ゅ") - if len(face.Liker) == 1{ - id = face.Liker[0].TargetId - } } //logger.Info("浜鸿劯鐩爣target:",targetInfos) - - pervideo := PerVideoPicture{LinkInfo{ - id, - msg.Cid, - msg.Push.Cam.Addr, - msg.Push.Cam.Name, - picTime, - imgMaxUrl, - msg.Tasklab.Taskid, - msg.Tasklab.Taskname, - sdkname, - "", - alarmRules, - time.Now().Format("2006-01-02 15:04:05"), // 鍙娴嬶紝娌℃湁姣斿鏃堕棿 - lable, - lableAttach, - "", - msg.Push.ServerId, - msg.Push.ServerName, - msg.Push.LocalIp, - "", - true, - false, - false, - false, - face.Liker, - targetInfos, - }, - "", - []*LinkInfo{}, - } - requstbody, err := json.Marshal(pervideo) - - if err != nil { - logger.Info("json parse error ", err) - return - } if key == "track" && len(face.Liker) == 1{ + logger.Info("纭杩囩溂绁炴槸瑕佽拷鍔犵殑鏁版嵁") + pervideo1 := LinkInfo{ + face.Liker[0].TargetId, + msg.Cid, + msg.Push.Cam.Addr, + msg.Push.Cam.Name, + picTime, + imgMaxUrl, + msg.Tasklab.Taskid, + msg.Tasklab.Taskname, + sdkname, + "", + alarmRules, + time.Now().Format("2006-01-02 15:04:05"), // 鍙娴嬶紝娌℃湁姣斿鏃堕棿 + lable, + lableAttach, + "", + msg.Push.ServerId, + msg.Push.ServerName, + msg.Push.LocalIp, + "", + true, + false, + false, + false, + face.Liker, + targetInfos, + } + requstbody, err := json.Marshal(pervideo1) + + if err != nil { + logger.Info("json parse error ", err) + return + } esid := face.Liker[0].TargetId + logger.Info("liker淇℃伅锛�",*face.Liker[0]) returnMsg, err1 := esutil.AppendTargetInfo(esid, string(requstbody),structure.EsInfo.EsIndex.AIOcean.IndexName,serverIp,serverPort) if err1 != nil { logger.Error("杩藉姞鏁版嵁鍑洪敊锛�---", err1) @@ -241,13 +233,56 @@ ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: face.Uuid, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid, VideoUrl: msg.Push.VideoUrl, ImgId: i.Id, SdkIds: []string{"-1"}, Type: 1}) } } else { - resp1, err1 := insertdata.EsReq("POST", videoPersonUrl, requstbody) - if err1 != nil { - logger.Error("涓婁紶ES鍑洪敊锛�---", err1) + id := face.Uuid + if id == "" { + // 姣斿埌浜嗙浉浼肩殑浜轰絾鍦ㄦ鎽勫儚鏈轰笅宸茬粡鍑虹幇杩囷紝鏈�鍚庝笉鑳芥彃鍏ユ暟鎹簱 + logger.Info("鍐椾綑鏁版嵁锛屽苟涓嶅叆搴�") } else { - logger.Info("鎻掑叆es杩斿洖鐨勪俊鎭細", resp1) - // 鍙戝嚭褰曞儚淇″彿 - ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: face.Uuid, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid, VideoUrl: msg.Push.VideoUrl, ImgId: i.Id, SdkIds: []string{"-1"}, Type: 1}) + logger.Info("鏂板鏁版嵁") + pervideo := PerVideoPicture{LinkInfo{ + id, + msg.Cid, + msg.Push.Cam.Addr, + msg.Push.Cam.Name, + picTime, + imgMaxUrl, + msg.Tasklab.Taskid, + msg.Tasklab.Taskname, + sdkname, + "", + alarmRules, + time.Now().Format("2006-01-02 15:04:05"), // 鍙娴嬶紝娌℃湁姣斿鏃堕棿 + lable, + lableAttach, + "", + msg.Push.ServerId, + msg.Push.ServerName, + msg.Push.LocalIp, + "", + true, + false, + false, + false, + face.Liker, + targetInfos, + }, + "", + []*LinkInfo{}, + } + requstbody, err := json.Marshal(pervideo) + + if err != nil { + logger.Info("json parse error ", err) + return + } + resp1, err1 := insertdata.EsReq("POST", videoPersonUrl, requstbody) + if err1 != nil { + logger.Error("涓婁紶ES鍑洪敊锛�---", err1) + } else { + logger.Info("鎻掑叆es杩斿洖鐨勪俊鎭細", resp1) + // 鍙戝嚭褰曞儚淇″彿 + ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: face.Uuid, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid, VideoUrl: msg.Push.VideoUrl, ImgId: i.Id, SdkIds: []string{"-1"}, Type: 1}) + } } } } -- Gitblit v1.8.0