From e320f5c14d9833ba2c7f6bdcc62ffda866ad7fdc Mon Sep 17 00:00:00 2001 From: panlei <2799247126@qq.com> Date: 星期四, 18 七月 2019 16:40:54 +0800 Subject: [PATCH] --- --- insertdata/insertDataToEs.go | 212 +++++++++++++++++++++++++++------------------------- 1 files changed, 111 insertions(+), 101 deletions(-) diff --git a/insertdata/insertDataToEs.go b/insertdata/insertDataToEs.go index 0134a6d..e0b081d 100644 --- a/insertdata/insertDataToEs.go +++ b/insertdata/insertDataToEs.go @@ -19,10 +19,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 +40,41 @@ //鎶妝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"` + 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琛屼负鐨勬暟鎹粨鏋� @@ -118,7 +125,7 @@ } if timeLabel == "12" { // 骞堕潪鎶ヨ鏁版嵁锛屽彧鏄姸鎬佹敼鍙樼殑鏁版嵁 - ChangeStatusFace(msg) + //ChangeStatusFace(msg) ChangeStatusYolo(msg) } } @@ -202,7 +209,7 @@ logger.Info("json parse error ", err) return } - err1 := EsReq("POST", "http://192.168.1.182:9200/videopersons/perVideoPicture", requstbody) + err1 := EsReq("POST", videoPersonUrl, requstbody) if err1 != nil { logger.Error("涓婁紶ES鍑洪敊锛�---", err1) } @@ -210,72 +217,74 @@ } } 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("鏌ヨ鎽勫儚鏈轰俊鎭け璐�") - } + 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) + 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, + []*ruleserver.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) - } - InsertFace(msg.RuleResult["cacheData"].(ruleserver.ResultMsg)) + if err != nil { + logger.Info("json parse error ", err) + return + } + err1 := EsReq("POST", videoPersonUrl, requstbody) + if err1 != nil { + logger.Error("涓婁紶ES鍑洪敊锛�---", err1) + } + //if msg.RuleResult["cacheData"] != nil { + // InsertFace(msg.RuleResult["cacheData"].(ruleserver.ResultMsg)) + //} } // 寰�es涓彃鍏olo鏁版嵁 @@ -301,7 +310,7 @@ 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)) + resp, err = util.DrawPolygonOnImage(msg.Cid, i, msg.RuleResult["yolo"].([]ruleserver.Result), weedfsUrl) if err != nil { logger.Error("鐢绘鎴栦笂浼犲浘鐗囨湇鍔″櫒鍑洪敊", err) } else { @@ -353,7 +362,7 @@ return } - err = EsReq("POST", "http://192.168.1.182:9200/personaction/perVideoAction", requstbody) + err = EsReq("POST", personAction, requstbody) if err != nil { logger.Error("寰�ES鎻掑叆鏁版嵁澶辫触", err) } else { @@ -376,7 +385,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 { @@ -423,7 +432,7 @@ return } - err = EsReq("POST", "http://192.168.1.182:9200/personaction/perVideoAction", requstbody) + err = EsReq("POST", personAction, requstbody) if err != nil { logger.Error("寰�ES鎻掑叆鏁版嵁澶辫触", err) } else { @@ -431,6 +440,7 @@ //os.Exit(1) } } + // 鑾峰彇鏈満ip func GetLocalIP() (ipv4 string, err error) { var ( -- Gitblit v1.8.0