From 1fac78f3b6e21aff0946a151dda83f4530b6d1c7 Mon Sep 17 00:00:00 2001
From: panlei <2799247126@qq.com>
Date: 星期二, 19 十一月 2019 09:45:02 +0800
Subject: [PATCH] ---

---
 insertdata/insertDataToEs.go | 1202 +++++++++++++++++++++++++++++++--------------------------
 1 files changed, 654 insertions(+), 548 deletions(-)

diff --git a/insertdata/insertDataToEs.go b/insertdata/insertDataToEs.go
index 4b57f9a..9daabd6 100644
--- a/insertdata/insertDataToEs.go
+++ b/insertdata/insertDataToEs.go
@@ -1,19 +1,17 @@
 package insertdata
 
 import (
+	"basic.com/valib/logger.git"
 	"encoding/base64"
 	"encoding/json"
 	"errors"
-	"fmt"
-	"io/ioutil"
 	"net"
 	"ruleprocess/cache"
-	"ruleprocess/logger"
+	"ruleprocess/structure"
 	"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,244 +29,240 @@
 	DbTablePersons string `yaml:"dbTablePersons"`
 }
 
-func init() {
-	data, err := ioutil.ReadFile("./config/conf.yml")
-	if err != nil {
-		fmt.Println("璇诲彇閰嶇疆鏂囦欢鍑洪敊--", err)
-		logger.Error("璇诲彇閰嶇疆鏂囦欢鍑洪敊--", err)
-	}
-	c := conf{}
-	//鎶妝aml褰㈠紡鐨勫瓧绗︿覆瑙f瀽鎴恠truct绫诲瀷
-	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 {
-	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"`
-	LinkId          string                 `json:"linkId"`
-	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"`
+	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"`
+	ShowLabels      string                `json:"showLabels"`
+	OtherLabels     string                `json:"otherLabels"`
+	VideoUrl        string                `json:"videoUrl"`
+	AnalyServerId   string                `json:"analyServerId"`
+	AnalyServerName string                `json:"analyServerName"`
+	AnalyServerIp   string                `json:"analyServerIp"`
+	ClusterId       string                `json:"clusterId"`
+	IsAlarm         bool                  `json:"isAlarm"`
+	IsAckAlarm      bool                  `json:"isAckAlarm"`
+	IsCollect       bool                  `json:"isCollect"`
+	IsDelete        bool                  `json:"isDelete"`
+	BaseInfo        []*structure.BaseInfo `json:"baseInfo"`
+	TargetInfo      []Target              `json:"targetInfo"`
+	LinkTag         string                `json:"linkTag"`
+	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"`
+	ShowLabels      string                `json:"showLabels"`
+	OtherLabels     string                `json:"otherLabels"`
+	VideoUrl        string                `json:"videoUrl"`
+	AnalyServerId   string                `json:"analyServerId"`
+	AnalyServerName string                `json:"analyServerName"`
+	AnalyServerIp   string                `json:"analyServerIp"`
+	ClusterId       string                `json:"clusterId"`
+	IsAlarm         bool                  `json:"isAlarm"`
+	IsAckAlarm      bool                  `json:"isAckAlarm"`
+	IsCollect       bool                  `json:"isCollect"`
+	IsDelete        bool                  `json:"isDelete"`
+	BaseInfo        []*structure.BaseInfo `json:"baseInfo"`
+	TargetInfo      []Target              `json:"targetInfo"`
+}
+
+type Target struct {
+	TargetId       string  `json:"targetId"`
+	TargetScore    float64 `json:"targetScore"`
+	FaceFeature    string  `json:"feature"`
+	PicSmUrl       string  `json:"picSmUrl"`
+	TargetLocation Points  `json:"targetLocation"`
+}
+
+type Points struct {
+	TopLeft     Point `json:"topLeft"`
+	BottomRight Point `json:"bottomRight"`
+}
+
+type Point struct {
+	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"`
-	LinkId          string      `json:"linkId"`
-	VideoUrl        string      `json:"videoUrl"`
-	IsAlarm         int         `json:"isAlarm"`
-	IsAckAlarm      int         `json:"isAckAlarm"`
-	IsCollect       int         `json:"isCollect"`
-	IsDelete        int         `json:"isDelete"`
-}
+//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     []*LinkInfo `json:"linkTagInfo"`
+//}
 
 type AlarmRule struct {
 	GroupId      string `json:"groupId"`
 	AlarmLevel   string `json:"alarmLevel"`
 	RuleText     string `json:"ruleText"`
 	DefenceState bool   `json:"defenceState"`
-	IsLink		 bool	`json:"isLink"`
-	LinkInfo	 string `json:"linkInfo"`
+	LinkInfo     string `json:"linkInfo"`
 }
 
-// 涓�涓猣ace瀵瑰涓鍒欑粍鐨勫綊缃汉鑴哥殑缁撴瀯浣�
-type FaceAndRules struct {
-	ruleserver.Arg
-	rules []ruleserver.Result
+// 涓�涓猳bj瀵瑰涓鍒欑粍鐨勫綊缃汉鑴哥殑缁撴瀯浣� 鍙敤浜庝汉鑴� 鍙敤浜庤溅鐗�
+type ObjAndRules struct {
+	structure.Arg
+	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 ruleserver.ResultMsg) {
-	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, "")
-		}
+func InsertToEs(msg structure.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.AIOcean.IndexName + "/" + EsInfo.EsIndex.AIOcean.IndexType
+	InsertFace(msg)
+	InsertYolo(msg)
+	InsertTarget(msg)
 }
 
-// 寰�es涓彃鍏ヤ汉鑴告暟鎹�
-func InsertFace(msg ruleserver.ResultMsg, linkId string) {
-	if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]ruleserver.FaceResult)) > 0 {
-		logger.Info("寰�ES鎻掍汉鑴告暟鎹�")
-		faces := []*FaceAndRules{}
-		faces = PutFace(faces,msg)
-		//logger.Info("鏁寸悊鍚庣殑鏁版嵁锛�",faces)
-		if faces != nil {
-			for _,face := range faces {
-				// 涓婁紶澶у浘
-				// 瑙e帇缂╁苟涓婁紶鍥剧墖
-				bdata, err := util.UnCompress(msg.Data)
-				if err != nil {
-					panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
-				}
-				alarmRules := []AlarmRule{}
-				logger.Warn("浜鸿劯id涓猴細",face.Id,"浜鸿劯鐨勮鍒欓暱搴︿负锛�",len(face.rules))
-				//os.Exit(1)
-				for _,faceResult := range face.rules {
-					alarm := ChangeToString(faceResult.DefenceState, faceResult.AlarmLevel)
-					alarmRules = append(alarmRules, AlarmRule{faceResult.RuleGroupId, alarm, faceResult.RuleText, faceResult.DefenceState,faceResult.IsLink,""})
-				}
-				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 := ""
-				logger.Info(sex)
-				if face.ThftRes.Gender == 1 {
-					sex = "鐢�"
-				} else {
-					sex = "濂�"
-				}
-				race := getRaceString(face.ThftRes.Race)
-				ageDescription := getDescription(face.ThftRes.Age)
-				logger.Info(ageDescription)
-				esDataId := uuid.NewV4().String()
-				linksId := ""
-				if linkId != "" {
-					linksId = linkId
-				}
-				logger.Info("浜鸿劯鐨刬d:",strconv.FormatUint(face.Id, 10))
-				logger.Info("浜鸿劯鐨勫垎鍊硷細",face.Score)
-				pervideo := PerVideoPicture{
-					esDataId,
-					msg.Cid,
-					camera.Addr,
-					i.Timestamp,
-					bigPhotoUrl["fileUrl"].(string),
-					msg.Tasklab.Taskid,
-					msg.Tasklab.Taskname,
-					"浜鸿劯",
-					"",
-					alarmRules,
-					time.Now().Format("2006-01-02 15:04:05"), // 鍙娴嬶紝娌℃湁姣斿鏃堕棿
-					strconv.FormatUint(face.Id, 10),            //鏆傛敼涓轰汉鑴竔d
-					face.ThftRes.Age,
-					 fmt.Sprintf("%.2f",face.Score), // 鏆傛敼涓哄垎鍊�
-					race,
-					face.ThftRes.Smile,
-					face.ThftRes.Beauty,
-					base64.StdEncoding.EncodeToString(face.Feature),
-					[]string{resp["fileUrl"].(string)},
-					"鏆傛棤闆嗙兢",
-					localConfig.ServerId,
-					localConfig.ServerName,
-					serverIp,
-					"",
-					linksId,
-					face.Score,
-					1,
-					0,
-					0,
-					0,
-					face.Liker,
-				}
-				requstbody, err := json.Marshal(pervideo)
+// 寰�es涓彃鍏ヤ汉鑴哥被鍨嬫暟鎹�
+func InsertFace(msg structure.ResultMsg) {
+	if (msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]structure.Result)) > 0) || (msg.RuleResult["plate"] != nil && len(msg.RuleResult["plate"].([]structure.Result)) > 0) {
+		for key, results := range msg.RuleResult {
+			if key == "face" || key == "plate" {
+				logger.Info("寰�ES鎻掍汉鑴告暟鎹�(鎴栬溅鐗屾暟鎹�)")
+				faces := []*ObjAndRules{}
+				faces = PutFace(faces, results.([]structure.Result))
+				//logger.Info("鏁寸悊鍚庣殑鏁版嵁锛�",faces)
+				if faces != nil {
+					var imgMaxUrl []string = []string{}
+					var picTime string = ""
+					for _, face := range faces {
+						// 涓婁紶澶у浘
+						// 瑙e帇缂╁苟涓婁紶鍥剧墖
+						bdata, err := util.UnCompress(msg.Data)
+						if err != nil {
+							panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
+						}
+						alarmRules := []AlarmRule{}
+						for _, faceResult := range face.rules {
+							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)
+						// 鍏堜紶灏忓浘锛屽啀浼犲ぇ鍥撅紝闃叉鑴镐笂鏈夌嚎
+						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 len(imgMaxUrl) == 0 {
+							bigPhotoUrl := make(map[string]interface{})
+							bigPhotoUrl, err = util.DrawPolygonOnImageForFace(msg.Cid, i, msg.RuleResult["face"].([]structure.Result), weedfsUrl)
+							logger.Debug("========澶у浘璺緞锛�", bigPhotoUrl)
+							imgMaxUrl = append(imgMaxUrl, bigPhotoUrl["fileUrl"].(string))
+							picTime = i.Timestamp
+						}
+						lable, lableAttach := Feature2Jsonstr(*face)
+						var target = new(Target)
+						target.TargetId = face.Id
+						target.TargetScore = face.Score
+						target.FaceFeature = base64.StdEncoding.EncodeToString(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}}
+						var targetInfos []Target
+						targetInfos = append(targetInfos, *target)
+						pervideo := PerVideoPicture{
+							face.Uuid,
+							msg.Cid,
+							msg.Push.Cam.Addr,
+							msg.Push.Cam.Name,
+							picTime,
+							imgMaxUrl,
+							msg.Tasklab.Taskid,
+							msg.Tasklab.Taskname,
+							"浜鸿劯",
+							time.Now().Format("2006-01-02 15:04:05"),
+							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 := 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 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: face.Uuid, CameraId: msg.Cid, TaskId: msg.Tasklab.Taskid, VideoUrl: msg.Push.VideoUrl, ImgId: i.Id, SdkIds: []string{"-1"}, Type: 1})
+						}
+					}
 				}
 			}
 		}
@@ -276,56 +270,52 @@
 }
 
 // 褰掔疆浜鸿劯
-func PutFace(faces []*FaceAndRules,msg ruleserver.ResultMsg)[]*FaceAndRules{
-	if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]ruleserver.FaceResult)) > 0 {
-		for _, faceResult := range msg.RuleResult["face"].([]ruleserver.FaceResult) {
-			faces = hebingFace(faces, faceResult)
-		}
-		return faces
-	} else {
-		return nil
+func PutFace(objs []*ObjAndRules, resutls []structure.Result) []*ObjAndRules {
+	for _, faceResult := range resutls {
+		objs = hebingFace(objs, faceResult)
 	}
+	return objs
 }
-func hebingFace(faces []*FaceAndRules, faceResult ruleserver.FaceResult) []*FaceAndRules{
-	for _, arg := range faceResult.Args {
+func hebingFace(objs []*ObjAndRules, faceResult structure.Result) []*ObjAndRules {
+	for _, arg := range faceResult.AlarmObj {
 		// 鎷垮埌姣忎竴寮犱汉鑴�
-		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 _, face := range objs {
+			//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)
+				face.rules = append(face.rules, faceResult)
 				// 鐩镐技鑰呭幓閲嶅綊骞�
-				for _,liker := range arg.Liker {
+				for _, liker := range arg.Liker {
 					flag1 := true
-					for _,liker1 := range face.Liker {
-						if liker.PersonId == liker1.PersonId {
+					for _, liker1 := range face.Liker {
+						if liker.TargetId == liker1.TargetId {
 							flag1 = false
 						}
 					}
 					if flag1 {
-						face.Liker = append(face.Liker,liker)
+						face.Liker = append(face.Liker, liker)
 					}
 				}
 				//face.Liker = append(face.Liker,arg.Liker...)
 			}
 		}
 		if !flag {
-			faces = append(faces, &FaceAndRules{arg, []ruleserver.Result{faceResult.Result}})
+			objs = append(objs, &ObjAndRules{*arg, []structure.Result{faceResult}})
 		}
 	}
-	return faces
+	return objs
 }
 
 // 寰�es涓彃鍏olo鏁版嵁
-func InsertYolo(msg ruleserver.ResultMsg, linkId string) {
-	if msg.RuleResult["yolo"] != nil && len(msg.RuleResult["yolo"].([]ruleserver.Result)) > 0 {
+func InsertYolo(msg structure.ResultMsg) {
+	if msg.RuleResult["yolo"] != nil && len(msg.RuleResult["yolo"].([]structure.Result)) > 0 {
 		// 鍏堝垽鏂竴涓嬫暟鎹甫鐨勮鍒欐爣绛炬槸鍚︽湁鍙互鎻掑叆鐨�
 		flag := false
-		for _, res := range msg.RuleResult["yolo"].([]ruleserver.Result) {
+		for _, res := range msg.RuleResult["yolo"].([]structure.Result) {
 			//logger.Info("瀹氭椂鍣ㄦ墦鐨勬暟瀛楁爣绛撅細",res.Others.TimeLabel)
 			if res.Others.TimeLabel == "01" || res.Others.TimeLabel == "10" {
 				flag = true
@@ -335,8 +325,9 @@
 			logger.Info("寰�ES鎻抷olo鏁版嵁")
 			var sdkNames string = ""
 			alarmRules := []AlarmRule{}
+			var targetInfos []Target
 			url := []string{}
-			for _, yoloResult := range msg.RuleResult["yolo"].([]ruleserver.Result) {
+			for _, yoloResult := range msg.RuleResult["yolo"].([]structure.Result) {
 				if yoloResult.Others.TimeLabel == "01" || yoloResult.Others.TimeLabel == "10" {
 					// 鎷煎嚭sdkname
 					//logger.Info("搴旇杩涙潵鎵嶅鐨�")
@@ -346,7 +337,8 @@
 					if yoloResult.IsLink {
 						linkInfo = "鑱斿姩浠诲姟"
 					}
-					alarmRules = append(alarmRules, AlarmRule{yoloResult.RuleGroupId, alarm, yoloResult.RuleText, yoloResult.DefenceState,yoloResult.IsLink,linkInfo})
+					alarmRules = append(alarmRules, AlarmRule{yoloResult.RuleGroupId, alarm, yoloResult.RuleText, yoloResult.DefenceState, linkInfo})
+					logger.Info("鎵撳嵃浠诲姟鍚嶇О锛�", )
 					// 涓婁紶缂撳瓨鏁版嵁鐨勫浘鐗囨嬁鍒皍rl
 					if yoloResult.Others.CacheData != nil {
 						//InsertYolo(msg.RuleResult["cacheData"].(ruleserver.ResultMsg))
@@ -360,36 +352,54 @@
 							}
 							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"].([]structure.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))
+							}
+						}
+					}
+					// 瑁呴厤鐩爣淇℃伅鏁版嵁
+					for _, target := range yoloResult.AlarmObj {
+						// 鍘婚噸娣诲姞
+						var flag = true
+						for _, selectTarget := range targetInfos {
+							if target.Id == selectTarget.TargetId {
+								flag = false
+								break
+							}
+						}
+						if flag {
+							var target1 = new(Target)
+							target1.TargetId = target.Id
+							target1.TargetScore = target.Score
+							target1.TargetLocation = Points{TopLeft: Point{target.Location.X, target.Location.Y}, BottomRight: Point{target.Location.X + target.Location.Width, target.Location.Y + target.Location.Height}}
+							targetInfos = append(targetInfos, *target1)
 						}
 					}
 				}
 			}
-			linkFlag := false
-			for _, yoloResult := range msg.RuleResult["yolo"].([]ruleserver.Result) {
+			// 鑱斿姩鍥惧儚鐨勫鐞�
+			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 {
-					linkId := uuid.NewV4().String()
 					for _, msg2 := range yoloResult.Others.LinkCache {
-						logger.Warn("鎻掑叆鑱斿姩鏁版嵁", "姝ゅ抚鏁版嵁鐨刬d涓�", msg2.Cid)
-						InsertYolo(msg2, linkId)
-						linkFlag = true
+						// 鎶妋sg2鐨勬暟鎹閰嶆垚涓�涓狿erVideoPicture缁撴瀯浣�
+						if msg2.Cid != msg.Cid {
+							linkTagInfos = append(linkTagInfos, msg2PersonVideo(msg2))
+						}
 					}
 				}
 			}
-			if linkFlag {
-				// 鑱斿姩鏁版嵁涓寘鍚湰甯ф暟鎹紝鎻掑叆鑱斿姩鏁版嵁鍚庡氨涓嶉渶瑕佹彃鍏ユ湰甯ф暟鎹簡
-				logger.Warn("鎴愬姛鎻掑叆涓や釜鑱斿姩鍥剧墖")
-				//os.Exit(1)
-				return
+			linkTag := ""
+			if len(linkTagInfos) > 0 {
+				linkTag = "鑱斿姩浠诲姟"
 			}
-			//logger.Info("--------璧板埌杩欏効灏变笉涓�鏍�")
-			isAlarm := 0
+			isAlarm := false
 			resp := make(map[string]interface{})
 			// 瑙e帇缂╁苟涓婁紶鍥剧墖
 			bdata, err := util.UnCompress(msg.Data)
@@ -399,9 +409,9 @@
 			i := protomsg.Image{}
 			err = proto.Unmarshal(bdata, &i)
 			if len(alarmRules) > 0 {
-				isAlarm = 1
+				isAlarm = true
 				//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"].([]structure.Result), weedfsUrl)
 				if err != nil {
 					logger.Error("鐢绘鎴栦笂浼犲浘鐗囨湇鍔″櫒鍑洪敊", err)
 					return
@@ -409,223 +419,232 @@
 					logger.Info("涓婁紶鐨勫浘鐗囦俊鎭細", resp)
 				}
 			} else {
-				isAlarm = 0
+				isAlarm = false
 				// 涓嶆槸鎶ヨ鏁版嵁涓嶅瓨
 				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()
 			if resp["fileUrl"] != nil {
 				url = append(url, resp["fileUrl"].(string))
-				esDataId := uuid.NewV4().String()
-				linksId := ""
-				if linkId != "" {
-					linksId = linkId
-				}
-				peraction := Personaction{
-					esDataId,
+				//esDataId := uuid.NewV4().String()
+				peraction := PerVideoPicture{
+					msg.Push.PushId,
 					msg.Cid,
-					camera.Name,
-					camera.Addr,
+					msg.Push.Cam.Addr,
+					msg.Push.Cam.Name,
+					time.Now().Format("2006-01-02 15:04:05"),
+					url,
 					msg.Tasklab.Taskid,
 					msg.Tasklab.Taskname,
 					sdkNames,
-					"",
+					time.Now().Format("2006-01-02 15:04:05"),
 					alarmRules,
-					localConfig.ServerId,
-					localConfig.ServerName,
-					serverIp,
-					"",
-					url,
 					i.Timestamp,
-					linksId,
+					"",
+					"",
+					"",
+					msg.Push.ServerId,
+					msg.Push.ServerName,
+					msg.Push.LocalIp,
 					"",
 					isAlarm,
-					0,
-					0,
-					0,
+					false,
+					false,
+					false,
+					nil,
+					targetInfos,
+					linkTag,
+					linkTagInfos,
 				}
 				requstbody, err := json.Marshal(peraction)
 
+				if len(linkTagInfos) > 0 {
+					logger.Info("鑱斿姩浠诲姟1111")
+				}
 				if err != nil {
 					logger.Info("json parse error ", err)
 					return
-
 				}
-				resp1, err2 := EsReq("POST", personAction, requstbody)
+				resp1, err2 := EsReq("POST", videoPersonUrl, requstbody)
 				if err2 != nil {
 					logger.Error("寰�ES鎻掑叆鏁版嵁澶辫触", err)
 				} else {
-					logger.Debug("鎻掑叆es杩斿洖鐨勬暟鎹俊鎭槸锛�", resp1)
+					logger.Debug("鎻掑叆es杩斿洖鐨勬暟鎹俊鎭槸锛坹olo锛夛細", 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{"-1"}, Type: 2})
+					for index, link := range linkTagInfos {
+						logger.Info("鑱斿姩浠诲姟鐨勫綍鍍忎俊鍙凤細", index)
+						ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: msg.Push.PushId, CameraId: link.CameraId, TaskId: msg.Tasklab.Taskid, VideoUrl: msg.Push.VideoUrl, ImgId: i.Id, SdkIds: []string{strconv.Itoa(index)}, Type: 2})
+					}
 					logger.Warn("__________________________________________寰�ES鎻掑叆yolo鏁版嵁鎴愬姛")
 					//os.Exit(1)
 				}
 			}
-		} else {
-			logger.Debug("timeLabel鏉′欢閮戒笉绗﹀悎锛�")
+		}
+	} else {
+		logger.Debug("timeLabel鏉′欢閮戒笉绗﹀悎锛�")
+	}
+}
+
+// 鎻掑叆鐩爣鎸佺画鏃堕棿鏁版嵁
+
+func InsertTarget(msg structure.ResultMsg) {
+	if msg.RuleResult["target"] != nil && len(msg.RuleResult["target"].([]structure.Result)) > 0 {
+		// 鍏堝垽鏂竴涓嬫暟鎹甫鐨勮鍒欐爣绛炬槸鍚︽湁鍙互鎻掑叆鐨�
+		logger.Info("鎻掑叆瀹氭椂鐩爣淇℃伅锛�", len(msg.RuleResult["target"].([]structure.Result)))
+		for _, yoloResult := range msg.RuleResult["target"].([]structure.Result) {
+			// 瑁呰浇鐩爣淇℃伅`
+			// 濡傛灉鏈夐娆℃姤璀︾殑鍒欐湰甯ф暟鎹彲浠ユ彃鍏�
+			insertFlag := false
+			alarmNum := 0
+			for _, obj := range yoloResult.AlarmObj {
+				if obj.TimeLable == "10" {
+					insertFlag = true
+					alarmNum++
+				}
+			}
+			if insertFlag {
+				logger.Info("鎶ヨ鐩爣涓暟锛�", alarmNum)
+
+				// 鑾峰彇鐩爣缂撳瓨鍥剧墖
+				url := []string{}
+				//InsertYolo(msg.RuleResult["cacheData"].(ruleserver.ResultMsg))
+				// 鎶婄紦瀛樼殑鏁版嵁涓婁紶鍚庡緱鍒板湴鍧�瀛樿繘鍘�
+				// 瑙e帇缂╁苟涓婁紶鍥剧墖
+				url1 := uploadImg(yoloResult.AlarmObj[0].CacheData)
+				url = append(url, url1)
+				// 娣诲姞鎶ヨ瑙勫垯缁�
+				sdkNames := ""
+				alarmRules := []AlarmRule{}
+				sdkNames = sdkNames + yoloResult.SdkName
+				alarm := ChangeToString(yoloResult.DefenceState, yoloResult.AlarmLevel)
+				linkInfo := ""
+				if yoloResult.IsLink {
+					linkInfo = "鑱斿姩浠诲姟"
+				}
+				alarmRules = append(alarmRules, AlarmRule{yoloResult.RuleGroupId, alarm, yoloResult.RuleText, yoloResult.DefenceState, linkInfo})
+				// 鑱斿姩鍥惧儚鐨勫鐞�
+				linkTagInfos := []*LinkInfo{}
+				for _, yoloResult := range msg.RuleResult["target"].([]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 {
+							// 鎶妋sg2鐨勬暟鎹閰嶆垚涓�涓狿erVideoPicture缁撴瀯浣�
+							if msg2.Cid != msg.Cid {
+								linkTagInfos = append(linkTagInfos, msg2PersonVideo(msg2))
+							}
+						}
+					}
+				}
+				linkTag := ""
+				if len(linkTagInfos) > 0 {
+					linkTag = "鑱斿姩浠诲姟"
+				}
+				isAlarm := false
+				resp := make(map[string]interface{})
+				// 瑙e帇缂╁苟涓婁紶鏈抚鏁版嵁鍥剧墖
+				bdata1, err := util.UnCompress(msg.Data)
+				if err != nil {
+					panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
+				}
+				i := protomsg.Image{}
+				err = proto.Unmarshal(bdata1, &i)
+				if len(alarmRules) > 0 {
+					isAlarm = true
+					//resp, err = util.PostFormBufferData(weedfsUrl, i, uuid.NewV4().String())
+					resp, err = util.DrawPolygonOnImageForYolo(msg.Cid, i, msg.RuleResult["target"].([]structure.Result), weedfsUrl)
+					if err != nil {
+						logger.Error("鐢绘鎴栦笂浼犲浘鐗囨湇鍔″櫒鍑洪敊", err)
+						return
+					} else {
+						logger.Info("涓婁紶鐨勫浘鐗囦俊鎭細", resp)
+					}
+				} else {
+					isAlarm = false
+					// 涓嶆槸鎶ヨ鏁版嵁涓嶅瓨
+					return
+				}
+				// 鏁村悎鐩爣
+				var targetInfos []Target
+				for _, target := range yoloResult.AlarmObj {
+					// 鍘婚噸娣诲姞
+					var flag = true
+					for _, selectTarget := range targetInfos {
+						if target.Id == selectTarget.TargetId {
+							flag = false
+							break
+						}
+					}
+					if flag {
+						var target1 = new(Target)
+						target1.TargetId = target.Id
+						target1.TargetScore = target.Score
+						target1.TargetLocation = Points{TopLeft: Point{target.Location.X, target.Location.Y}, BottomRight: Point{target.Location.X + target.Location.Width, target.Location.Y + target.Location.Height}}
+						targetInfos = append(targetInfos, *target1)
+					}
+				}
+				if resp["fileUrl"] != nil {
+					url = append(url, resp["fileUrl"].(string))
+					if len(url) == 1 {
+						return
+					}
+					//esDataId := uuid.NewV4().String()
+					peraction := PerVideoPicture{
+						msg.Push.PushId,
+						msg.Cid,
+						msg.Push.Cam.Addr,
+						msg.Push.Cam.Name,
+						i.Timestamp,
+						url,
+						msg.Tasklab.Taskid,
+						msg.Tasklab.Taskname,
+						sdkNames,
+						"",
+						alarmRules,
+						time.Now().Format("2006-01-02 15:04:05"),
+						"",
+						"",
+						"",
+						msg.Push.ServerId,
+						msg.Push.ServerName,
+						msg.Push.LocalIp,
+						"",
+						isAlarm,
+						false,
+						false,
+						false,
+						nil,
+						nil,
+						linkTag,
+						linkTagInfos,
+					}
+					requstbody, err := json.Marshal(peraction)
+
+					if len(linkTagInfos) > 0 {
+						logger.Info("鑱斿姩浠诲姟1111")
+					}
+					if err != nil {
+						logger.Info("json parse error ", err)
+						return
+					}
+					resp1, err2 := EsReq("POST", videoPersonUrl, requstbody)
+					if err2 != nil {
+						logger.Error("寰�ES鎻掑叆鏁版嵁澶辫触", err)
+					} else {
+						logger.Debug("鎻掑叆es杩斿洖鐨勬暟鎹俊鎭槸锛坱arget锛夛細", 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{"-1"}, Type: 2})
+						for index, link := range linkTagInfos {
+							logger.Info("鑱斿姩浠诲姟鐨勫綍鍍忎俊鍙凤細", index)
+							ruleserver.AddLxMessage(&protomsg.VideotapeInfo{EsDataId: msg.Push.PushId, CameraId: link.CameraId, TaskId: msg.Tasklab.Taskid, VideoUrl: msg.Push.VideoUrl, ImgId: i.Id, SdkIds: []string{strconv.Itoa(index)}, Type: 2})
+						}
+						logger.Warn("__________________________________________寰�ES鎻掑叆target鏁版嵁鎴愬姛")
+						//os.Exit(1)
+					}
+				}
+			} else {
+				logger.Info("娌℃湁棣栨鎶ヨ鐨勭洰鏍囷紝涓嶆彃鍏�")
+			}
 		}
 	}
-}
-func ChangeStatusYolo(msg ruleserver.ResultMsg) {
-	logger.Info("寰�ES鎻抷olo闈炴姤璀︾姸鎬佹敼鍙樻暟鎹�")
-	var sdkNames string = ""
-	alarmRules := []AlarmRule{}
-	bdata, err := util.UnCompress(msg.Data)
-	if err != nil {
-		panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
-	}
-	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), weedfsUrl)
-	if err != nil {
-		logger.Error("鐢绘鎴栦笂浼犲浘鐗囨湇鍔″櫒鍑洪敊", err)
-	} else {
-		logger.Info("涓婁紶鐨勫浘鐗囦俊鎭細", resp)
-	}
-	// 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()
-	esDataId := uuid.NewV4().String()
-	peraction := Personaction{
-		esDataId,
-		msg.Cid,
-		camera.Name,
-		camera.Addr,
-		msg.Tasklab.Taskid,
-		msg.Tasklab.Taskname,
-		sdkNames,
-		"yolo闈炴姤璀︾姸鎬佹敼鍙樻暟鎹�",
-		alarmRules,
-		localConfig.ServerId,
-		localConfig.ServerName,
-		serverIp,
-		"",
-		[]string{resp["fileUrl"].(string)},
-		i.Timestamp,
-		"",
-		"",
-		0,
-		0,
-		0,
-		0,
-	}
-	requstbody, err := json.Marshal(peraction)
-
-	if err != nil {
-		logger.Info("json parse error ", err)
-		return
-
-	}
-	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)
-	}
-}
-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,
-		bigPhotoUrl["fileUrl"].(string),
-		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))
-	//}
 }
 
 // 鑾峰彇鏈満ip
@@ -682,6 +701,26 @@
 	return alarm
 }
 
+func uploadImg(msg structure.ResultMsg) string {
+	bdata, err := util.UnCompress(msg.Data)
+	if err != nil {
+		panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
+	}
+	i := protomsg.Image{}
+	err = proto.Unmarshal(bdata, &i)
+	resp1, err1 := util.DrawPolygonOnImageForTarget(msg.Cid, i, msg.RuleResult["target"].([]structure.Result), weedfsUrl)
+	if err1 != nil {
+		logger.Error("缂撳瓨鏁版嵁鐢绘鎴栦笂浼犲浘鐗囨湇鍔″櫒鍑洪敊", err)
+	} else {
+		logger.Info("涓婁紶鐨勫浘鐗囦俊鎭細", resp1)
+	}
+	if resp1["fileUrl"] != nil {
+		return resp1["fileUrl"].(string)
+	} else {
+		return ""
+	}
+}
+
 //鑾峰彇骞撮緞鎻忚堪
 func getDescription(age int32) string {
 	ageInfo := "闈掑勾"
@@ -711,99 +750,166 @@
 	return race
 }
 
+func Feature2Jsonstr(obj ObjAndRules) (string, string) {
+	var lable string
+	var lableAttach string
+	switch obj.Type {
+	case "face":
+		sex := ""
+		if obj.ThftRes.Gender == 1 {
+			sex = "鐢�"
+		} else {
+			sex = "濂�"
+		}
+		race := getRaceString(obj.ThftRes.Race)
+		ageDescription := getDescription(obj.ThftRes.Age)
+		lable = sex + "/" + ageDescription + "/" + race + "/"
+		lableAttach = strconv.Itoa(int(obj.ThftRes.Age)) + "宀�" + "/" + "寰瑧鍊硷細" + strconv.Itoa(int(obj.ThftRes.Smile)) + "/" + "棰滃�硷細" + strconv.Itoa(int(obj.ThftRes.Beauty))
 
-//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()
-//		linksId := ""
-//		if linkId != "" {
-//			linksId = linkId
-//		}
-//		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,
-//			"",
-//			linksId,
-//			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})
-//		}
-//	}
-//}
\ No newline at end of file
+	case "plate":
+		// 杞︾墝杩愬姩鏂瑰悜锛�0 unknown, 1 left, 2 right, 3 up, 4 down
+		lable = obj.Car.License + "/" + cache.GetDic("nColor"+strconv.Itoa(int(obj.Car.NColor))) + "杞︾墝" + "/" +
+			cache.GetDic("nCarColor"+strconv.Itoa(int(obj.Car.NCarColor))) + "杞﹁締" + "/" + cache.GetDic("nCarLogo"+strconv.Itoa(int(obj.Car.NCarLogo))) + "/" + cache.GetDic("nCarLogo"+strconv.Itoa(int(obj.Car.NCarType)))
+		lableAttach = cache.GetDic("nDirection"+strconv.Itoa(int(obj.Car.NDirection))) + "/" + "杞︾墝缃俊搴︼細" + strconv.Itoa(int(obj.Car.NConfidence)) + "/" +
+			"杞︾墝浜害锛�" + strconv.Itoa(int(obj.Car.NBright)) + "/" + "杞︾殑浜害锛�" + strconv.Itoa(int(obj.Car.NCarBright)) + "/" + "璇嗗埆鏃堕棿锛�" + strconv.Itoa(int(obj.Car.NTime))
+	}
+	return lable, lableAttach
+}
+
+func msg2PersonVideo(msg structure.ResultMsg) *LinkInfo {
+	if msg.RuleResult["yolo"] != nil && len(msg.RuleResult["yolo"].([]structure.Result)) > 0 {
+		// 鍏堝垽鏂竴涓嬫暟鎹甫鐨勮鍒欐爣绛炬槸鍚︽湁鍙互鎻掑叆鐨�
+		flag := false
+		for _, res := range msg.RuleResult["yolo"].([]structure.Result) {
+			//logger.Info("瀹氭椂鍣ㄦ墦鐨勬暟瀛楁爣绛撅細",res.Others.TimeLabel)
+			if res.Others.TimeLabel == "01" || res.Others.TimeLabel == "10" {
+				flag = true
+			}
+		}
+		if flag {
+			logger.Info("鎻掑叆Yolo缁勮鏁版嵁")
+			var sdkNames string = ""
+			alarmRules := []AlarmRule{}
+			var targetInfos []Target
+			url := []string{}
+			for _, yoloResult := range msg.RuleResult["yolo"].([]structure.Result) {
+				if yoloResult.Others.TimeLabel == "01" || yoloResult.Others.TimeLabel == "10" {
+					// 鎷煎嚭sdkname
+					//logger.Info("搴旇杩涙潵鎵嶅鐨�")
+					sdkNames = sdkNames + yoloResult.SdkName
+					alarm := ChangeToString(yoloResult.DefenceState, yoloResult.AlarmLevel)
+					linkInfo := ""
+					if yoloResult.IsLink {
+						linkInfo = "鑱斿姩浠诲姟"
+					}
+					alarmRules = append(alarmRules, AlarmRule{yoloResult.RuleGroupId, alarm, yoloResult.RuleText, yoloResult.DefenceState, linkInfo})
+					// 涓婁紶缂撳瓨鏁版嵁鐨勫浘鐗囨嬁鍒皍rl
+					if yoloResult.Others.CacheData != nil {
+						//InsertYolo(msg.RuleResult["cacheData"].(ruleserver.ResultMsg))
+						// 鎶婄紦瀛樼殑鏁版嵁涓婁紶鍚庡緱鍒板湴鍧�瀛樿繘鍘�
+						// 瑙e帇缂╁苟涓婁紶鍥剧墖
+						msgs := yoloResult.Others.CacheData
+						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.DrawPolygonOnImageForYolo(msg1.Cid, i, msg1.RuleResult["yolo"].([]structure.Result), weedfsUrl)
+							if err1 != nil {
+								logger.Error("缂撳瓨鏁版嵁鐢绘鎴栦笂浼犲浘鐗囨湇鍔″櫒鍑洪敊", err)
+							} else {
+								logger.Info("涓婁紶鐨勫浘鐗囦俊鎭細", resp1)
+							}
+							if resp1["fileUrl"] != nil {
+								url = append(url, resp1["fileUrl"].(string))
+							}
+						}
+					}
+					// 瑁呴厤鐩爣淇℃伅鏁版嵁
+					for _, target := range yoloResult.AlarmObj {
+						// 鍘婚噸娣诲姞
+						var flag = true
+						for _, selectTarget := range targetInfos {
+							if target.Id == selectTarget.TargetId {
+								flag = false
+								break
+							}
+						}
+						if flag {
+							var target1 = new(Target)
+							target1.TargetId = target.Id
+							target1.TargetScore = target.Score
+							target1.TargetLocation = Points{TopLeft: Point{target.Location.X, target.Location.Y}, BottomRight: Point{target.Location.X + target.Location.Width, target.Location.Y + target.Location.Height}}
+							targetInfos = append(targetInfos, *target1)
+						}
+					}
+				}
+			}
+			isAlarm := false
+			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 = true
+				//resp, err = util.PostFormBufferData(weedfsUrl, i, uuid.NewV4().String())
+				resp, err = util.DrawPolygonOnImageForYolo(msg.Cid, i, msg.RuleResult["yolo"].([]structure.Result), weedfsUrl)
+				if err != nil {
+					logger.Error("鐢绘鎴栦笂浼犲浘鐗囨湇鍔″櫒鍑洪敊", err)
+					return nil
+				} else {
+					logger.Info("涓婁紶鐨勫浘鐗囦俊鎭細", resp)
+				}
+			} else {
+				isAlarm = false
+				// 涓嶆槸鎶ヨ鏁版嵁涓嶅瓨
+				return nil
+			}
+			if resp["fileUrl"] != nil {
+				url = append(url, resp["fileUrl"].(string))
+				//esDataId := uuid.NewV4().String()
+				pervideo := &LinkInfo{
+					msg.Push.PushId + "-" + uuid.NewV4().String(),
+					msg.Cid,
+					msg.Push.Cam.Addr,
+					msg.Push.Cam.Name,
+					i.Timestamp,
+					[]string{resp["fileUrl"].(string)},
+					msg.Tasklab.Taskid,
+					msg.Tasklab.Taskname,
+					"浜鸿劯",
+					"",
+					alarmRules,
+					time.Now().Format("2006-01-02 15:04:05"), // 鍙娴嬶紝娌℃湁姣斿鏃堕棿
+					"",
+					"",
+					"",
+					msg.Push.ServerId,
+					msg.Push.ServerName,
+					msg.Push.LocalIp,
+					"",
+					isAlarm,
+					false,
+					false,
+					false,
+					nil,
+					targetInfos,
+				}
+				return pervideo
+			} else {
+				return nil
+			}
+		} else {
+			logger.Debug("timeLabel鏉′欢閮戒笉绗﹀悎锛�")
+			return nil
+		}
+	} else {
+		return nil
+	}
+}

--
Gitblit v1.8.0