From 52713b8d85e26a984ecaeef926c815e8cf8075b7 Mon Sep 17 00:00:00 2001
From: panlei <2799247126@qq.com>
Date: 星期四, 07 十一月 2019 19:24:17 +0800
Subject: [PATCH] ---

---
 insertdata/insertDataToEs.go |  125 ++++++++++-------------------------------
 1 files changed, 31 insertions(+), 94 deletions(-)

diff --git a/insertdata/insertDataToEs.go b/insertdata/insertDataToEs.go
index 9704795..c857895 100644
--- a/insertdata/insertDataToEs.go
+++ b/insertdata/insertDataToEs.go
@@ -1,7 +1,7 @@
 package insertdata
 
 import (
-	"basic.com/valib/logger.git"
+	"ruleprocess/logger"
 	"encoding/base64"
 	"encoding/json"
 	"errors"
@@ -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 {
@@ -165,20 +141,7 @@
 	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)
-	if fk {
-		InsertYolo(msg, "")
-		//if msg.Cid == "61de081a-7ed9-4970-8432-41d642c35456" {
-		//	logger.Warn("鎹曟崏188鎽勫儚鏈虹殑鎸佺画鏃堕棿浠诲姟.....")
-		//	os.Exit(1)
-		//}
-	} else {
-		flag := ruleserver.BodyIsSame(msg.SdkMessage)
-		if !flag {
-			InsertYolo(msg, "")
-		}
-	}
+	InsertYolo(msg, "")
 }
 
 // 寰�es涓彃鍏ヤ汉鑴告暟鎹�
@@ -199,7 +162,7 @@
 					panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
 				}
 				alarmRules := []AlarmRule{}
-				logger.Warn("浜鸿劯id涓猴細", face.Id, "浜鸿劯鐨勮鍒欓暱搴︿负锛�", len(face.rules))
+				//logger.Warn("浜鸿劯id涓猴細", face.Id, "浜鸿劯鐨勮鍒欓暱搴︿负锛�", len(face.rules))
 				//os.Exit(1)
 				for _, faceResult := range face.rules {
 					alarm := ChangeToString(faceResult.DefenceState, faceResult.AlarmLevel)
@@ -207,6 +170,13 @@
 				}
 				i := protomsg.Image{}
 				err = proto.Unmarshal(bdata, &i)
+				// 鍏堜紶灏忓浘锛屽啀浼犲ぇ鍥撅紝闃叉鑴镐笂鏈夌嚎
+				bytes := util.SubImg(i, int(face.Location.X), int(face.Location.Y), int(face.Location.X+face.Location.Width), int(face.Location.Y+face.Location.Height))
+				resp, err := util.PostFormBufferData1(weedfsUrl, bytes, uuid.NewV4().String())
+				if err != nil {
+					logger.Error("涓婁紶灏忓浘鍑洪敊")
+				}
+				// 涓婁紶澶у浘
 				if imgMaxUrl == "" {
 					bigPhotoUrl := make(map[string]interface{})
 					bigPhotoUrl, err = util.DrawPolygonOnImageForFace(msg.Cid, i, msg.RuleResult["face"].([]structure.FaceResult), weedfsUrl)
@@ -214,23 +184,6 @@
 					imgMaxUrl = bigPhotoUrl["fileUrl"].(string)
 					picTime = i.Timestamp
 				}
-				// 浜鸿劯妫�娴嬶紝娌℃湁鐩镐技鐨勫簳搴撲汉鍛�
-				localConfig, err := cache.GetServerInfo()
-				if err != nil {
-					logger.Error("鏌ヨ鏈満淇℃伅澶辫触锛�")
-				}
-				serverIp, err := GetLocalIP()
-				// 鏌ヨcameraName
-				camera, err := cache.GetCameraById(msg.Cid)
-				if err != nil {
-					logger.Error("鏌ヨ鎽勫儚鏈轰俊鎭け璐�")
-				}
-				bytes := util.SubImg(i, int(face.Location.X), int(face.Location.Y), int(face.Location.X+face.Location.Width), int(face.Location.Y+face.Location.Height))
-				resp, err := util.PostFormBufferData1(weedfsUrl, bytes, uuid.NewV4().String())
-				if err != nil {
-					logger.Error("涓婁紶灏忓浘鍑洪敊")
-				}
-				//logger.Info("================灏忓浘鍦板潃:", resp["fileUrl"].(string))
 				sex := ""
 				logger.Info(sex)
 				if face.ThftRes.Gender == 1 {
@@ -241,7 +194,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
@@ -251,11 +204,10 @@
 				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("浜鸿劯鐨刬d:",strconv.FormatUint(face.Id, 10))
-				logger.Info("%%%%%%%%%%%%%%%%%%%%%鐩爣淇℃伅锛�",*target)
 				pervideo := PerVideoPicture{
-					esDataId,
+					msg.Push.PushId,
 					msg.Cid,
-					camera.Addr,
+					msg.Push.Cam.Addr,
 					picTime,
 					imgMaxUrl,
 					msg.Tasklab.Taskid,
@@ -272,10 +224,10 @@
 					face.ThftRes.Beauty,
 					base64.StdEncoding.EncodeToString(face.Feature),
 					[]string{resp["fileUrl"].(string)},
-					"鏆傛棤闆嗙兢",
-					localConfig.ServerId,
-					localConfig.ServerName,
-					serverIp,
+					"",
+					msg.Push.ServerId,
+					msg.Push.ServerName,
+					msg.Push.LocalIp,
 					"",
 					linksId,
 					face.Score,
@@ -298,7 +250,7 @@
 				} else {
 					logger.Info("鎻掑叆es杩斿洖鐨勪俊鎭細", resp1)
 					// 鍙戝嚭褰曞儚淇″彿
-					ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: esDataId, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid, 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})
 				}
 			}
 		}
@@ -319,12 +271,12 @@
 func hebingFace(faces []*FaceAndRules, faceResult structure.FaceResult) []*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)
@@ -405,7 +357,7 @@
 					// 瑁呴厤鐩爣淇℃伅鏁版嵁
 					for _,target := range yoloResult.Location  {
 						// 鍘婚噸娣诲姞
-						logger.Info("瑁呴厤鍓嶇殑鍘熷鏁版嵁鏄細",target)
+						//logger.Info("瑁呴厤鍓嶇殑鍘熷鏁版嵁鏄細",target)
 						var flag = true
 						for _,selectTarget := range targetInfos  {
 							if strconv.FormatUint(target.TargetId, 10) == selectTarget.TargetId {
@@ -465,40 +417,26 @@
 				// 涓嶆槸鎶ヨ鏁版嵁涓嶅瓨
 				return
 			}
-			// logger.Println("鍥剧墖涓婁紶杩斿洖鍊硷細", resp)
-			// 鏌ヨ鏈満淇℃伅
-			localConfig, err := cache.GetServerInfo()
-			if err != nil {
-				logger.Error("鏌ヨ鏈満淇℃伅澶辫触锛�")
-			}
-			// 鏌ヨcameraName
-			camera, err := cache.GetCameraById(msg.Cid)
-			if err != nil {
-				logger.Error("鏌ヨ鎽勫儚鏈轰俊鎭け璐�")
-			}
-
-			serverIp, err := GetLocalIP()
-			logger.Info("%%%%%%%%%%%%%%%%%yolo鐨則arget淇℃伅锛�",targetInfos)
 			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,
-					camera.Name,
-					camera.Addr,
+					msg.Push.Cam.Name,
+					msg.Push.Cam.Addr,
 					msg.Tasklab.Taskid,
 					msg.Tasklab.Taskname,
 					sdkNames,
 					"",
 					alarmRules,
-					localConfig.ServerId,
-					localConfig.ServerName,
-					serverIp,
+					msg.Push.ServerId,
+					msg.Push.ServerName,
+					msg.Push.LocalIp,
 					"",
 					url,
 					i.Timestamp,
@@ -515,7 +453,6 @@
 				if err != nil {
 					logger.Info("json parse error ", err)
 					return
-
 				}
 				resp1, err2 := EsReq("POST", personAction, requstbody)
 				if err2 != nil {
@@ -523,7 +460,7 @@
 				} else {
 					logger.Debug("鎻掑叆es杩斿洖鐨勬暟鎹俊鎭槸锛�", resp1)
 					// 鍙戝嚭褰曞儚淇″彿
-					ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: esDataId, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid, 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)
 				}

--
Gitblit v1.8.0