From 317d6f3ebb2437f7f30ef657fafe41a7207ae98e Mon Sep 17 00:00:00 2001
From: panlei <2799247126@qq.com>
Date: 星期四, 01 八月 2019 11:22:39 +0800
Subject: [PATCH] ---

---
 insertdata/insertDataToEs.go |  660 +++++++++++++++++++++++++++++++++++------------------------
 1 files changed, 388 insertions(+), 272 deletions(-)

diff --git a/insertdata/insertDataToEs.go b/insertdata/insertDataToEs.go
index 770fbee..ea8321a 100644
--- a/insertdata/insertDataToEs.go
+++ b/insertdata/insertDataToEs.go
@@ -1,11 +1,13 @@
 package insertdata
 
 import (
+	"encoding/base64"
 	"encoding/json"
 	"errors"
 	"fmt"
 	"io/ioutil"
 	"net"
+	"os"
 	"ruleprocess/cache"
 	"ruleprocess/logger"
 	"strings"
@@ -19,10 +21,15 @@
 	"ruleprocess/util"
 )
 
-var weedfsUrl string
+var weedfsUrl, videoPersonUrl, personAction string
 
 type conf struct {
-	PhotoUrl string `yaml:"photoUrl"`
+	PhotoUrl       string `yaml:"photoUrl"`
+	VideoPersons   string `yaml:"videoPersons"`
+	PersonAction   string `yaml:"personAction"`
+	ServerIp       string `yaml:"serverIp"`
+	ServerPort     string `yaml:"serverPort"`
+	DbTablePersons string `yaml:"dbTablePersons"`
 }
 
 func init() {
@@ -35,39 +42,42 @@
 	//鎶妝aml褰㈠紡鐨勫瓧绗︿覆瑙f瀽鎴恠truct绫诲瀷
 	yaml.Unmarshal(data, &c)
 	weedfsUrl = c.PhotoUrl
+	videoPersonUrl = c.VideoPersons
+	personAction = c.PersonAction
 }
 
 // 浜鸿劯鐨勬暟鎹粨鏋�
 type PerVideoPicture struct {
-	Id              string               `json:"id"`
-	CameraId        string               `json:"cameraId"`
-	CameraAddr      string               `json:"cameraAddr"`
-	PicDate         string               `json:"picDate"`
-	PicMaxUrl       string               `json:"picMaxUrl"`
-	TaskId          string               `json:"taskId"`
-	TaskName        string               `json:"taskName"`
-	SdkName         string               `json:"sdkName"`
-	Content         string               `json:"content"`
-	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        []*protomsg.Baseinfo `json:"baseInfo"`
+	Id              string                 `json:"id"`
+	CameraId        string                 `json:"cameraId"`
+	CameraAddr      string                 `json:"cameraAddr"`
+	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        []*ruleserver.BaseInfo `json:"baseInfo"`
 }
 
 //  yolo琛屼负鐨勬暟鎹粨鏋�
@@ -95,40 +105,294 @@
 }
 
 type AlarmRule struct {
-	GroupId    string `json:"groupId"`
-	AlarmLevel string `json:"alarmLevel"`
-	RuleText   string `json:"ruleText"`
+	GroupId      string `json:"groupId"`
+	AlarmLevel   string `json:"alarmLevel"`
+	RuleText     string `json:"ruleText"`
+	DefenceState bool   `json:"defenceState"`
 }
 
 // 寰�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 ruleserver.ResultMsg) {
-	var timeLabel string
-	// 鐩存帴浠庤鍒欑殑鏍囩鏁版嵁閲屾嬁绗﹀悎瑙勫垯鐨勪汉鑴哥粨鏋�
-	if msg.RuleResult["timeLabel"] != nil {
-		timeLabel = msg.RuleResult["timeLabel"].(string)
-	}
-	logger.Debug("鎻掑叆鏁版嵁鍓嶇湅鐪嬫姤璀︽爣蹇椾綅锛�", timeLabel)
-	if timeLabel == "01" { // 鏃犲畾鏃跺櫒鐘舵�佽鎻掑叆鐨勬姤璀︽暟鎹�
-		InsertFace(msg)
-		InsertYolo(msg)
-	}
-	if timeLabel == "10" { // 瀹氭椂鍣ㄧ姸鎬佽鎻掑叆鐨勯甯ф姤璀︽暟鎹�傝繛甯︾潃瀹氭椂鍣ㄥ紑鍚椂鐨勯偅甯�
-		InsertFace(msg)
-		InsertYolo(msg)
-
-	}
-	if timeLabel == "12" { // 骞堕潪鎶ヨ鏁版嵁锛屽彧鏄姸鎬佹敼鍙樼殑鏁版嵁
-		ChangeStatusFace(msg)
-		ChangeStatusYolo(msg)
-	}
+	InsertFace(msg)
+	//flag := ruleserver.BodyIsSame(msg.SdkMessage)
+	//if !flag {
+	InsertYolo(msg)
+	//}
 }
 
 // 寰�es涓彃鍏ヤ汉鑴告暟鎹�
 func InsertFace(msg ruleserver.ResultMsg) {
-	if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]ruleserver.Arg)) > 0 {
+	if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]ruleserver.FaceResult)) > 0 {
 		logger.Info("寰�ES鎻掍汉鑴告暟鎹�")
-		for _, face := range msg.RuleResult["face"].([]ruleserver.Arg) {
-			// 涓婁紶澶у浘
+		for _, faceResult := range msg.RuleResult["face"].([]ruleserver.FaceResult) {
+			for _, face := range faceResult.Args {
+				// 涓婁紶澶у浘
+				// 瑙e帇缂╁苟涓婁紶鍥剧墖
+				bdata, err := util.UnCompress(msg.Data)
+				if err != nil {
+					panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
+				}
+				alarmRules := []AlarmRule{}
+				alarm := ChangeToString(faceResult.DefenceState, faceResult.AlarmLevel)
+				alarmRules = append(alarmRules, AlarmRule{faceResult.RuleGroupId, alarm, faceResult.RuleText, faceResult.DefenceState})
+				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)
+				// 浜鸿劯妫�娴嬶紝娌℃湁鐩镐技鐨勫簳搴撲汉鍛�
+				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 := ""
+				if face.ThftRes.Gender == 1 {
+					sex = "鐢�"
+				} else {
+					sex = "濂�"
+				}
+				race := getRaceString(face.ThftRes.Race)
+				ageDescription := getDescription(face.ThftRes.Age)
+				esDataId := uuid.NewV4().String()
+				pervideo := PerVideoPicture{
+					esDataId,
+					msg.Cid,
+					camera.Addr,
+					i.Timestamp,
+					strings.Split(bigPhotoUrl["fileUrl"].(string), "/")[1],
+					msg.Tasklab.Taskid,
+					msg.Tasklab.Taskname,
+					"浜鸿劯",
+					"",
+					alarmRules,
+					time.Now().Format("2006-01-02 15:04:05"), // 鍙娴嬶紝娌℃湁姣斿鏃堕棿
+					sex,
+					face.ThftRes.Age,
+					ageDescription,
+					race,
+					face.ThftRes.Smile,
+					face.ThftRes.Beauty,
+					base64.StdEncoding.EncodeToString(face.Feature),
+					[]string{strings.Split(resp["fileUrl"].(string), "/")[1]},
+					"鏆傛棤闆嗙兢",
+					localConfig.ServerId,
+					localConfig.ServerName,
+					serverIp,
+					"",
+					face.Score,
+					1,
+					0,
+					0,
+					0,
+					face.Liker,
+				}
+				requstbody, err := json.Marshal(pervideo)
+
+				if err != nil {
+					logger.Info("json parse error ", err)
+					return
+				}
+				resp1, err1 := EsReq("POST", videoPersonUrl, requstbody)
+				if err1 != nil {
+					logger.Error("涓婁紶ES鍑洪敊锛�---", err1)
+				} 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})
+				}
+			}
+		}
+	}
+}
+func ChangeStatusFace(msg ruleserver.ResultMsg) {
+	logger.Info("寰�ES鎻掑叆浜鸿劯闈炴姤璀︿絾鏄姸鎬佽浆鎹㈡暟鎹�")
+	// 涓婁紶澶у浘
+	// 瑙e帇缂╁苟涓婁紶鍥剧墖
+	bdata, err := util.UnCompress(msg.Data)
+	if err != nil {
+		panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
+	}
+	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)
+	// 浜鸿劯妫�娴嬶紝娌℃湁鐩镐技鐨勫簳搴撲汉鍛�
+	localConfig, err := cache.GetServerInfo()
+	if err != nil {
+		logger.Error("鏌ヨ鏈満淇℃伅澶辫触锛�")
+	}
+	serverIp, err := GetLocalIP()
+	// 鏌ヨcameraName
+	camera, err := cache.GetCameraById(msg.Cid)
+	if err != nil {
+		logger.Error("鏌ヨ鎽勫儚鏈轰俊鎭け璐�")
+	}
+
+	esDataId := uuid.NewV4().String()
+	pervideo := PerVideoPicture{
+		esDataId,
+		msg.Cid,
+		camera.Addr,
+		i.Timestamp,
+		strings.Split(bigPhotoUrl["fileUrl"].(string), "/")[1],
+		msg.Tasklab.Taskid,
+		msg.Tasklab.Taskname,
+		"浜鸿劯",
+		"鐘舵�佽浆鎹㈡暟鎹紝闈炴姤璀︽暟鎹�",
+		[]AlarmRule{},
+		time.Now().Format("2006-01-02 15:04:05"), // 鍙娴嬶紝娌℃湁姣斿鏃堕棿
+		"",
+		0,
+		"",
+		"",
+		0,
+		0,
+		"",
+		[]string{""},
+		"鏆傛棤闆嗙兢",
+		localConfig.ServerId,
+		localConfig.ServerName,
+		serverIp,
+		"",
+		0,
+		1,
+		0,
+		0,
+		0,
+		[]*ruleserver.BaseInfo{},
+	}
+	requstbody, err := json.Marshal(pervideo)
+
+	if err != nil {
+		logger.Info("json parse error ", err)
+		return
+	}
+	resp1, err1 := EsReq("POST", videoPersonUrl, requstbody)
+
+	if err1 != nil {
+		logger.Error("涓婁紶ES鍑洪敊锛�---", err1)
+	} 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})
+	}
+	//if msg.RuleResult["cacheData"] != nil {
+	//	InsertFace(msg.RuleResult["cacheData"].(ruleserver.ResultMsg))
+	//}
+}
+
+// 寰�es涓彃鍏olo鏁版嵁
+func InsertYolo(msg ruleserver.ResultMsg) {
+	if msg.RuleResult["yolo"] != nil && len(msg.RuleResult["yolo"].([]ruleserver.Result)) > 0 {
+		// 鍏堝垽鏂竴涓嬫暟鎹甫鐨勮鍒欐爣绛炬槸鍚︽湁鍙互鎻掑叆鐨�
+		flag := false
+		for _, res := range msg.RuleResult["yolo"].([]ruleserver.Result) {
+			logger.Info("瀹氭椂鍣ㄦ墦鐨勬暟瀛楁爣绛撅細",res.Others["timeLabel"].(string))
+			if res.Others["timeLabel"].(string) == "01" || res.Others["timeLabel"].(string) == "10" {
+				flag = true
+			}
+		}
+		if flag {
+			logger.Info("寰�ES鎻抷olo鏁版嵁")
+			var sdkNames string = ""
+			alarmRules := []AlarmRule{}
+			url := []string{}
+			for _, yoloResult := range msg.RuleResult["yolo"].([]ruleserver.Result) {
+				if yoloResult.Others["timeLabel"].(string) == "01" || yoloResult.Others["timeLabel"].(string) == "10" {
+					// 鎷煎嚭sdkname
+					logger.Info("搴旇杩涙潵鎵嶅鐨�")
+					sdkNames = sdkNames + yoloResult.SdkName
+					alarm := ChangeToString(yoloResult.DefenceState, yoloResult.AlarmLevel)
+					alarmRules = append(alarmRules, AlarmRule{yoloResult.RuleGroupId, alarm, yoloResult.RuleText, yoloResult.DefenceState})
+					// 涓婁紶缂撳瓨鏁版嵁鐨勫浘鐗囨嬁鍒皍rl
+					if yoloResult.Others["cacheData"] != nil {
+						//InsertYolo(msg.RuleResult["cacheData"].(ruleserver.ResultMsg))
+						// 鎶婄紦瀛樼殑鏁版嵁涓婁紶鍚庡緱鍒板湴鍧�瀛樿繘鍘�
+						// 瑙e帇缂╁苟涓婁紶鍥剧墖
+						msgs := yoloResult.Others["cacheData"].([]ruleserver.ResultMsg)
+						for _, msg1 := range msgs {
+							bdata, err := util.UnCompress(msg1.Data)
+							if err != nil {
+								panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
+							}
+							i := protomsg.Image{}
+							err = proto.Unmarshal(bdata, &i)
+							resp1, err1 := util.DrawPolygonOnImage(msg1.Cid, i, msg1.RuleResult["yolo"].([]ruleserver.Result), weedfsUrl)
+							if err1 != nil {
+								logger.Error("缂撳瓨鏁版嵁鐢绘鎴栦笂浼犲浘鐗囨湇鍔″櫒鍑洪敊", err)
+							} else {
+								logger.Info("涓婁紶鐨勫浘鐗囦俊鎭細", resp1)
+							}
+							url = append(url, strings.Split(resp1["fileUrl"].(string), "/")[1])
+						}
+					}
+				}
+			}
+			linkFlag := false
+			for _, yoloResult := range msg.RuleResult["yolo"].([]ruleserver.Result) {
+				if (yoloResult.Others["timeLabel"].(string) == "01" || yoloResult.Others["timeLabel"].(string) == "10") && yoloResult.Others["linkCache"] != nil && len(yoloResult.Others["linkCache"].([]ruleserver.ResultMsg)) > 1{
+					for _, msg2 := range yoloResult.Others["linkCache"].([]ruleserver.ResultMsg) {
+						logger.Warn("鎻掑叆鑱斿姩鏁版嵁")
+						for _,nihao := range msg2.RuleResult["yolo"].([]ruleserver.Result)  {
+							num := 1
+							for k,_ := range nihao.Others {
+								logger.Info("绗�",num,"娆¢敭锛�",k)
+							}
+							num++
+						}
+						//logger.Warn("鍝堝搱鍝堝搱鍝�",[0].Others["linkCache"].([]ruleserver.ResultMsg))
+						InsertYolo(msg2)
+						logger.Warn("鍏勫紵闅鹃亾浣犻櫡鍏ヤ簡姝诲惊鐜悧")
+						linkFlag = true
+						os.Exit(1)
+					}
+				}
+			}
+			if linkFlag {
+				// 鑱斿姩鏁版嵁涓寘鍚湰甯ф暟鎹紝鎻掑叆鑱斿姩鏁版嵁鍚庡氨涓嶉渶瑕佹彃鍏ユ湰甯ф暟鎹簡
+				logger.Warn("鎴愬姛鎻掑叆涓や釜鑱斿姩鍥剧墖")
+				os.Exit(1)
+				return
+			}
+			logger.Info("--------璧板埌杩欏効灏变笉涓�鏍�")
+			isAlarm := 0
+			resp := make(map[string]interface{})
 			// 瑙e帇缂╁苟涓婁紶鍥剧墖
 			bdata, err := util.UnCompress(msg.Data)
 			if err != nil {
@@ -136,234 +400,76 @@
 			}
 			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 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)
+				if err != nil {
+					logger.Error("鐢绘鎴栦笂浼犲浘鐗囨湇鍔″櫒鍑洪敊", err)
+				} else {
+					logger.Info("涓婁紶鐨勫浘鐗囦俊鎭細", resp)
+				}
+			} else {
+				isAlarm = 0
+				// 涓嶆槸鎶ヨ鏁版嵁涓嶅瓨
+				return
+			}
+			// logger.Println("鍥剧墖涓婁紶杩斿洖鍊硷細", resp)
+			// 鏌ヨ鏈満淇℃伅
 			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 := ""
-			if face.ThftRes.Gender == 1 {
-				sex = "鐢�"
-			} else {
-				sex = "濂�"
-			}
-			race := getRaceString(face.ThftRes.Race)
-			ageDescription := getDescription(face.ThftRes.Age)
+			serverIp, err := GetLocalIP()
 
-			pervideo := PerVideoPicture{
-				uuid.NewV4().String(),
+			url = append(url, strings.Split(resp["fileUrl"].(string), "/")[1])
+			esDataId := uuid.NewV4().String()
+			peraction := Personaction{
+				esDataId,
 				msg.Cid,
+				camera.Name,
 				camera.Addr,
-				i.Timestamp,
-				strings.Split(bigPhotoUrl["fileUrl"].(string), "/")[1],
 				msg.Tasklab.Taskid,
 				msg.Tasklab.Taskname,
-				"浜鸿劯",
+				sdkNames,
 				"",
-				time.Now().Format("2006-01-02 15:04:05"), // 鍙娴嬶紝娌℃湁姣斿鏃堕棿
-				sex,
-				face.ThftRes.Age,
-				ageDescription,
-				race,
-				face.ThftRes.Smile,
-				face.ThftRes.Beauty,
-				string(face.Feature),
-				[]string{strings.Split(resp["fileUrl"].(string), "/")[1]},
-				"鏆傛棤闆嗙兢",
+				alarmRules,
 				localConfig.ServerId,
 				localConfig.ServerName,
 				serverIp,
 				"",
-				face.Score,
-				1,
+				url,
+				i.Timestamp,
+				"",
+				isAlarm,
 				0,
 				0,
 				0,
-				face.Liker,
 			}
-			requstbody, err := json.Marshal(pervideo)
+			requstbody, err := json.Marshal(peraction)
 
 			if err != nil {
 				logger.Info("json parse error ", err)
 				return
+
 			}
-			err1 := EsReq("POST", "http://192.168.1.182:9200/videopersons/perVideoPicture", requstbody)
-			if err1 != nil {
-				logger.Error("涓婁紶ES鍑洪敊锛�---", err1)
-			}
-		}
-	}
-}
-func ChangeStatusFace(msg ruleserver.ResultMsg) {
-	logger.Info("寰�ES鎻掗潪鎶ヨ浣嗘槸鐘舵�佽浆鎹㈡暟鎹�")
-		// 涓婁紶澶у浘
-		// 瑙e帇缂╁苟涓婁紶鍥剧墖
-		bdata, err := util.UnCompress(msg.Data)
-		if err != nil {
-			panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
-		}
-		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)
-		// 浜鸿劯妫�娴嬶紝娌℃湁鐩镐技鐨勫簳搴撲汉鍛�
-		localConfig, err := cache.GetServerInfo()
-		if err != nil {
-			logger.Error("鏌ヨ鏈満淇℃伅澶辫触锛�")
-		}
-		serverIp, err := GetLocalIP()
-		// 鏌ヨcameraName
-		camera, err := cache.GetCameraById(msg.Cid)
-		if err != nil {
-			logger.Error("鏌ヨ鎽勫儚鏈轰俊鎭け璐�")
-		}
-
-		pervideo := PerVideoPicture{
-			uuid.NewV4().String(),
-			msg.Cid,
-			camera.Addr,
-			i.Timestamp,
-			strings.Split(bigPhotoUrl["fileUrl"].(string), "/")[1],
-			msg.Tasklab.Taskid,
-			msg.Tasklab.Taskname,
-			"浜鸿劯",
-			"鐘舵�佽浆鎹㈡暟鎹紝闈炴姤璀︽暟鎹�",
-			time.Now().Format("2006-01-02 15:04:05"), // 鍙娴嬶紝娌℃湁姣斿鏃堕棿
-			"",
-			0,
-			"",
-			"",
-			0,
-			0,
-			"",
-			[]string{""},
-			"鏆傛棤闆嗙兢",
-			localConfig.ServerId,
-			localConfig.ServerName,
-			serverIp,
-			"",
-			0,
-			1,
-			0,
-			0,
-			0,
-			[]*protomsg.Baseinfo{},
-		}
-		requstbody, err := json.Marshal(pervideo)
-
-		if err != nil {
-			logger.Info("json parse error ", err)
-			return
-		}
-		err1 := EsReq("POST", "http://192.168.1.182:9200/videopersons/perVideoPicture", requstbody)
-		if err1 != nil {
-			logger.Error("涓婁紶ES鍑洪敊锛�---", err1)
-		}
-		//if msg.RuleResult["cacheData"] != nil {
-		//	InsertFace(msg.RuleResult["cacheData"].(ruleserver.ResultMsg))
-		//}
-}
-
-// 寰�es涓彃鍏olo鏁版嵁
-func InsertYolo(msg ruleserver.ResultMsg) {
-	if msg.RuleResult["yolo"] != nil && len(msg.RuleResult["yolo"].([]ruleserver.Result)) > 0 {
-		logger.Info("寰�ES鎻抷olo鏁版嵁")
-		var sdkNames string = ""
-		alarmRules := []AlarmRule{}
-		for _, yoloResult := range msg.RuleResult["yolo"].([]ruleserver.Result) {
-			sdkNames = sdkNames + yoloResult.SdkName
-			alarm := ChangeToString(yoloResult.AlarmLevel)
-			alarmRules = append(alarmRules, AlarmRule{yoloResult.RuleGroupId, alarm, yoloResult.RuleText})
-		}
-		isAlarm := 0
-		resp := make(map[string]interface{})
-		// 瑙e帇缂╁苟涓婁紶鍥剧墖
-		bdata, err := util.UnCompress(msg.Data)
-		if err != nil {
-			panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
-		}
-		i := protomsg.Image{}
-		err = proto.Unmarshal(bdata, &i)
-		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))
-			if err != nil {
-				logger.Error("鐢绘鎴栦笂浼犲浘鐗囨湇鍔″櫒鍑洪敊", err)
+			resp1, err2 := EsReq("POST", personAction, requstbody)
+			if err2 != nil {
+				logger.Error("寰�ES鎻掑叆鏁版嵁澶辫触", err)
 			} else {
-				logger.Info("涓婁紶鐨勫浘鐗囦俊鎭細", resp)
+				logger.Debug("鎻掑叆es杩斿洖鐨勬暟鎹俊鎭槸锛�", resp1)
+				// 鍙戝嚭褰曞儚淇″彿
+				ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: esDataId, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid, ImgId: i.Id, SdkIds: []string{}, Type: 2})
+				logger.Warn("__________________________________________寰�ES鎻掑叆yolo鏁版嵁鎴愬姛")
+				//os.Exit(1)
 			}
 		} else {
-			isAlarm = 0
-			// 涓嶆槸鎶ヨ鏁版嵁涓嶅瓨
-			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()
-		peraction := Personaction{
-			uuid.NewV4().String(),
-			msg.Cid,
-			camera.Name,
-			camera.Addr,
-			msg.Tasklab.Taskid,
-			msg.Tasklab.Taskname,
-			sdkNames,
-			"",
-			alarmRules,
-			localConfig.ServerId,
-			localConfig.ServerName,
-			serverIp,
-			"",
-			[]string{strings.Split(resp["fileUrl"].(string), "/")[1]},
-			i.Timestamp,
-			"",
-			isAlarm,
-			0,
-			0,
-			0,
-		}
-		requstbody, err := json.Marshal(peraction)
-
-		if err != nil {
-			logger.Info("json parse error ", err)
-			return
-
-		}
-		err = EsReq("POST", "http://192.168.1.182:9200/personaction/perVideoAction", requstbody)
-		if err != nil {
-			logger.Error("寰�ES鎻掑叆鏁版嵁澶辫触", err)
-		} else {
-			logger.Warn("__________________________________________寰�ES鎻掑叆yolo鏁版嵁鎴愬姛")
-			//os.Exit(1)
-		}
-		if msg.RuleResult["cacheData"] != nil {
-			InsertYolo(msg.RuleResult["cacheData"].(ruleserver.ResultMsg))
+			logger.Debug("timeLabel鏉′欢閮戒笉绗﹀悎锛�")
 		}
 	}
 }
@@ -378,7 +484,7 @@
 	i := protomsg.Image{}
 	err = proto.Unmarshal(bdata, &i)
 	//resp, err = util.PostFormBufferData(weedfsUrl, i, uuid.NewV4().String())
-	resp, err := util.DrawPolygonOnImage(msg.Cid, i, msg.RuleResult["yolo"].([]ruleserver.Result))
+	resp, err := util.DrawPolygonOnImage(msg.Cid, i, msg.RuleResult["yolo"].([]ruleserver.Result), weedfsUrl)
 	if err != nil {
 		logger.Error("鐢绘鎴栦笂浼犲浘鐗囨湇鍔″櫒鍑洪敊", err)
 	} else {
@@ -396,8 +502,9 @@
 		logger.Error("鏌ヨ鎽勫儚鏈轰俊鎭け璐�")
 	}
 	serverIp, err := GetLocalIP()
+	esDataId := uuid.NewV4().String()
 	peraction := Personaction{
-		uuid.NewV4().String(),
+		esDataId,
 		msg.Cid,
 		camera.Name,
 		camera.Addr,
@@ -425,14 +532,18 @@
 		return
 
 	}
-	err = EsReq("POST", "http://192.168.1.182:9200/personaction/perVideoAction", requstbody)
-	if err != nil {
+	resp1, err1 := EsReq("POST", personAction, requstbody)
+	if err1 != nil {
 		logger.Error("寰�ES鎻掑叆鏁版嵁澶辫触", err)
 	} else {
+		logger.Info("鎻掑叆es杩斿洖鐨勪俊鎭細", resp1)
+		// 鍙戝嚭褰曞儚淇″彿
+		ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: esDataId, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid, ImgId: i.Id, SdkIds: []string{}, Type: 2})
 		logger.Warn("__________________________________________寰�ES鎻掑叆yolo鏁版嵁鎴愬姛")
 		//os.Exit(1)
 	}
 }
+
 // 鑾峰彇鏈満ip
 func GetLocalIP() (ipv4 string, err error) {
 	var (
@@ -462,23 +573,28 @@
 }
 
 // 鎶婃姤璀︾瓑绾ц浆鍖栨垚姹夊瓧
-func ChangeToString(i int32) string {
+func ChangeToString(defenceState bool, i int32) string {
 	alarm := ""
-	if i == 1 {
-		alarm = "涓�绾�"
+	if defenceState {
+		if i == 1 {
+			alarm = "涓�绾�"
+		}
+		if i == 2 {
+			alarm = "浜岀骇"
+		}
+		if i == 3 {
+			alarm = "涓夌骇"
+		}
+		if i == 4 {
+			alarm = "鍥涚骇"
+		}
+		if i == 5 {
+			alarm = "浜旂骇"
+		}
+	} else {
+		alarm = "鎾ら槻"
 	}
-	if i == 2 {
-		alarm = "浜岀骇"
-	}
-	if i == 3 {
-		alarm = "涓夌骇"
-	}
-	if i == 4 {
-		alarm = "鍥涚骇"
-	}
-	if i == 5 {
-		alarm = "浜旂骇"
-	}
+
 	return alarm
 }
 

--
Gitblit v1.8.0