From 4146578720878b47a3d9d9d2833f1893ae80a032 Mon Sep 17 00:00:00 2001
From: panlei <2799247126@qq.com>
Date: 星期五, 27 九月 2019 14:11:12 +0800
Subject: [PATCH] logger改用公共库

---
 insertdata/insertDataToEs.go |  303 +++++--------------------------------------------
 1 files changed, 34 insertions(+), 269 deletions(-)

diff --git a/insertdata/insertDataToEs.go b/insertdata/insertDataToEs.go
index c289e64..9aed57c 100644
--- a/insertdata/insertDataToEs.go
+++ b/insertdata/insertDataToEs.go
@@ -5,15 +5,14 @@
 	"encoding/json"
 	"errors"
 	"fmt"
-	"io/ioutil"
 	"net"
 	"ruleprocess/cache"
+	"basic.com/valib/logger.git"
 	"ruleprocess/logger"
 	"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,19 +30,11 @@
 	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 {
@@ -145,6 +136,18 @@
 //	//}
 //}
 func InsertToEs(msg ruleserver.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.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)
@@ -170,6 +173,8 @@
 		faces = PutFace(faces,msg)
 		//logger.Info("鏁寸悊鍚庣殑鏁版嵁锛�",faces)
 		if faces != nil {
+			var imgMaxUrl string = ""
+			var picTime string = ""
 			for _,face := range faces {
 				// 涓婁紶澶у浘
 				// 瑙e帇缂╁苟涓婁紶鍥剧墖
@@ -186,9 +191,13 @@
 				}
 				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 imgMaxUrl == "" {
+					bigPhotoUrl := make(map[string]interface{})
+					bigPhotoUrl, err = util.PostFormBufferData(weedfsUrl, i, uuid.NewV4().String())
+					logger.Debug("========澶у浘璺緞锛�", bigPhotoUrl)
+					imgMaxUrl = bigPhotoUrl["fileUrl"].(string)
+					picTime = i.Timestamp
+				}
 				// 浜鸿劯妫�娴嬶紝娌℃湁鐩镐技鐨勫簳搴撲汉鍛�
 				localConfig, err := cache.GetServerInfo()
 				if err != nil {
@@ -221,14 +230,14 @@
 				if linkId != "" {
 					linksId = linkId
 				}
-				logger.Info("浜鸿劯鐨刬d:",strconv.FormatUint(face.Id, 10))
-				logger.Info("浜鸿劯鐨勫垎鍊硷細",face.Score)
+				//logger.Info("浜鸿劯鐨刬d:",strconv.FormatUint(face.Id, 10))
+				//logger.Info("浜鸿劯鐨勫垎鍊硷細",face.Score)
 				pervideo := PerVideoPicture{
 					esDataId,
 					msg.Cid,
 					camera.Addr,
-					i.Timestamp,
-					bigPhotoUrl["fileUrl"].(string),
+					picTime,
+					imgMaxUrl,
 					msg.Tasklab.Taskid,
 					msg.Tasklab.Taskname,
 					"浜鸿劯",
@@ -366,7 +375,9 @@
 							} else {
 								logger.Info("涓婁紶鐨勫浘鐗囦俊鎭細", resp1)
 							}
-							url = append(url, resp1["fileUrl"].(string))
+							if resp1["fileUrl"] != nil {
+								url = append(url, resp1["fileUrl"].(string))
+							}
 						}
 					}
 				}
@@ -478,155 +489,6 @@
 		}
 	}
 }
-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
 func GetLocalIP() (ipv4 string, err error) {
@@ -710,100 +572,3 @@
 	}
 	return race
 }
-
-
-//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

--
Gitblit v1.8.0