From 6d0833706a3e5ad37ee71cd62e8f9501d2acbc9a Mon Sep 17 00:00:00 2001
From: panlei <2799247126@qq.com>
Date: 星期四, 11 七月 2019 13:26:44 +0800
Subject: [PATCH] ---

---
 insertdata/insertDataToEs.go |  142 +++++++++++++++++++++++++++++++++++++---------
 1 files changed, 113 insertions(+), 29 deletions(-)

diff --git a/insertdata/insertDataToEs.go b/insertdata/insertDataToEs.go
index 4ae4d51..f67c8ed 100644
--- a/insertdata/insertDataToEs.go
+++ b/insertdata/insertDataToEs.go
@@ -1,12 +1,13 @@
 package insertdata
 
 import (
+	"ruleprocess/logger"
 	"encoding/json"
 	"errors"
 	"fmt"
+	"io/ioutil"
 	"net"
 	"ruleprocess/cache"
-	"ruleprocess/logger"
 	"strings"
 	"time"
 
@@ -15,9 +16,24 @@
 	"github.com/satori/go.uuid"
 	"ruleprocess/ruleserver"
 	"ruleprocess/util"
+	"github.com/go-yaml/yaml"
 )
+var weedfsUrl string
+type conf struct {
+	PhotoUrl string `yaml:"photoUrl"`
+}
+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
+}
 
-var weedfsUrl = "http://192.168.1.182:6333/submit"
 // 浜鸿劯鐨勬暟鎹粨鏋�
 type PerVideoPicture struct {
 	Id              string   `json:"id"`
@@ -43,25 +59,12 @@
 	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        []Base   `json:"baseInfo"`
-}
-
-type Base struct {
-	TableId      string  `json:"tableId"`
-	TableName    string  `json:"tableName"`
-	CompareScore float64 `json:"compareScore"`
-	PersonId     string  `json:"personId"`
-	PersonName   string  `json:"personName"`
-	PersonPicUrl string  `json:"personPicUrl"`
-	PhoneNum     string  `json:"phoneNum"`
-	Sex          string  `json:"sex"`
-	IdCard       string  `json:"idCard"`
-	MonitorLevel string  `json:"monitorLevel"`
-	Content      string  `json:"content"`
+	BaseInfo        []*protomsg.Baseinfo   `json:"baseInfo"`
 }
 
 //  yolo琛屼负鐨勬暟鎹粨鏋�
@@ -98,6 +101,7 @@
 func InsertToEs(msg ruleserver.ResultMsg) {
 
 	// 鐩存帴浠庤鍒欑殑鏍囩鏁版嵁閲屾嬁绗﹀悎瑙勫垯鐨勪汉鑴哥粨鏋�
+	//logger.Info("------------------------------------浠庨厤缃枃浠惰鍙栫殑鍊硷細",weedfsUrl)
 	if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]ruleserver.Arg)) > 0 {
 		logger.Info("寰�ES鎻掍汉鑴告暟鎹�")
 		for _, face := range msg.RuleResult["face"].([]ruleserver.Arg) {
@@ -116,7 +120,7 @@
 				// 浜鸿劯妫�娴嬶紝娌℃湁鐩镐技鐨勫簳搴撲汉鍛�
 				localConfig, err := cache.GetServerInfo()
 				if err != nil {
-					logger.Info("鏌ヨ鏈満淇℃伅澶辫触锛�")
+					logger.Error("鏌ヨ鏈満淇℃伅澶辫触锛�")
 				}
 				serverIp, err := GetLocalIP()
 				// 瑙e帇缂╁苟涓婁紶鍥剧墖
@@ -127,16 +131,17 @@
 				// 鏌ヨcameraName
 				camera, err := cache.GetCameraById(msg.Cid)
 				if err != nil {
-					logger.Info("鏌ヨ鎽勫儚鏈轰俊鎭け璐�")
+					logger.Error("鏌ヨ鎽勫儚鏈轰俊鎭け璐�")
 				}
 				i := protomsg.Image{}
 				err = proto.Unmarshal(bdata, &i)
-				logger.Info("-------------------------------------------鐪嬩笅瀹藉拰楂�", i.Width, i.Height)
+				logger.Info("-------------------------------------------鐪嬩笅瀹藉拰楂�", int(face.Location.X),int(face.Location.Y),int(face.Location.X+face.Location.Width),int(face.Location.Y+face.Location.Height))
 				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.Info("涓婁紶灏忓浘鍑洪敊")
+					logger.Error("涓婁紶灏忓浘鍑洪敊")
 				}
+				logger.Info("================灏忓浘鍦板潃:",resp["fileUrl"].(string))
 				sex := ""
 				if face.ThftRes.Gender == 1 {
 					sex = "鐢�"
@@ -163,18 +168,19 @@
 					race,
 					face.ThftRes.Smile,
 					face.ThftRes.Beauty,
-					"涓嶆槸姣忎釜浜鸿劯绠楁硶閮芥湁",
+					string(face.Feature),
 					[]string{strings.Split(resp["fileUrl"].(string), "/")[1]},
 					"鏆傛棤闆嗙兢",
 					localConfig.ServerId,
 					localConfig.ServerName,
 					serverIp,
 					"",
+					face.Score,
 					1,
 					0,
 					0,
 					0,
-					[]Base{},
+					[]*protomsg.Baseinfo{},
 				}
 				requstbody, err := json.Marshal(pervideo)
 
@@ -183,10 +189,87 @@
 					return
 
 				}
-				err = EsReq("POST", "http://192.168.1.182:9200/videopersons/perVideoPicture", requstbody)
+				err1 := EsReq("POST", "http://192.168.1.182:9200/videopersons/perVideoPicture", requstbody)
+				if err1 != nil {
+					logger.Error("涓婁紶ES鍑洪敊锛�---",err1)
+				}
 				//logger.Info(err.Error())
 			} else {
+				// 浜鸿劯姣斿
+				logger.Warn("___________________________________________杩欐槸鏈塨aseinfo鐨�")
+				localConfig, err := cache.GetServerInfo()
+				if err != nil {
+					logger.Info("鏌ヨ鏈満淇℃伅澶辫触锛�")
+				}
+				serverIp, err := GetLocalIP()
+				// 瑙e帇缂╁苟涓婁紶鍥剧墖
+				bdata, err := util.UnCompress(msg.Data)
+				if err != nil {
+					panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
+				}
+				// 鏌ヨcameraName
+				camera, err := cache.GetCameraById(msg.Cid)
+				if err != nil {
+					logger.Error("鏌ヨ鎽勫儚鏈轰俊鎭け璐�")
+				}
+				i := protomsg.Image{}
+				err = proto.Unmarshal(bdata, &i)
+				//logger.Info("-------------------------------------------鐪嬩笅瀹藉拰楂�", i.Width, i.Height)
+				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)
+				pervideo := PerVideoPicture{
+					uuid.NewV4().String(),
+					msg.Cid,
+					camera.Addr,
+					time.Now().Format("2006-01-02 15:04:05"),
+					strings.Split(bigPhotoUrl["fileUrl"].(string), "/")[1],
+					msg.Tasklab.Taskid,
+					msg.Tasklab.Taskname,
+					"浜鸿劯",
+					"",
+					time.Now().Format("2006-01-02 15:04:05"), // 鍙娴嬶紝娌℃湁姣斿鏃堕棿
+					sex,
+					face.ThftRes.Age,
+					ageDescription,
+					race,
+					face.ThftRes.Smile,
+					face.ThftRes.Beauty,
+					"",
+					[]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.Error("json parse error ", err)
+					return
+
+				}
+				err = EsReq("POST", "http://192.168.1.182:9200/videopersons/perVideoPicture", requstbody)
 				logger.Info("璺熷簳搴撶殑鐩镐技鏁版嵁---------锛�", face.Liker)
+
 				fmt.Println("------------------------------------------鍝堝搱鍝堝搱锛屽簳搴撴湁浜�")
 
 			}
@@ -215,7 +298,7 @@
 			//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.Info("鐢绘鎴栦笂浼犲浘鐗囨湇鍔″櫒鍑洪敊", err)
+				logger.Error("鐢绘鎴栦笂浼犲浘鐗囨湇鍔″櫒鍑洪敊", err)
 			} else {
 				logger.Info("宸叉姤璀﹀苟涓婁紶鏀瑰抚鍥剧墖鍒版湇鍔″櫒")
 			}
@@ -228,12 +311,12 @@
 		// 鏌ヨ鏈満淇℃伅
 		localConfig, err := cache.GetServerInfo()
 		if err != nil {
-			logger.Info("鏌ヨ鏈満淇℃伅澶辫触锛�")
+			logger.Error("鏌ヨ鏈満淇℃伅澶辫触锛�")
 		}
 		// 鏌ヨcameraName
 		camera, err := cache.GetCameraById(msg.Cid)
 		if err != nil {
-			logger.Info("鏌ヨ鎽勫儚鏈轰俊鎭け璐�")
+			logger.Error("鏌ヨ鎽勫儚鏈轰俊鎭け璐�")
 		}
 		serverIp, err := GetLocalIP()
 		peraction := Personaction{
@@ -267,9 +350,10 @@
 		}
 		err = EsReq("POST", "http://192.168.1.182:9200/personaction/perVideoAction", requstbody)
 		if err != nil {
-			logger.Info("寰�ES鎻掑叆鏁版嵁澶辫触", err)
+			logger.Error("寰�ES鎻掑叆鏁版嵁澶辫触", err)
 		} else {
-			logger.Info("__________________________________________寰�ES鎻掑叆yolo鏁版嵁鎴愬姛")
+			logger.Warn("__________________________________________寰�ES鎻掑叆yolo鏁版嵁鎴愬姛")
+			//os.Exit(1)
 		}
 	}
 }

--
Gitblit v1.8.0