From 032150859e985bedfb5061320b3aed5984dda476 Mon Sep 17 00:00:00 2001 From: panlei <2799247126@qq.com> Date: 星期三, 18 九月 2019 17:51:02 +0800 Subject: [PATCH] mian函数中加一个异常处理,插入es时大图只插入一次 --- insertdata/insertDataToEs.go | 42 ++++++++++++++++++++---------------------- 1 files changed, 20 insertions(+), 22 deletions(-) diff --git a/insertdata/insertDataToEs.go b/insertdata/insertDataToEs.go index 17f8053..e35ebd2 100644 --- a/insertdata/insertDataToEs.go +++ b/insertdata/insertDataToEs.go @@ -5,7 +5,6 @@ "encoding/json" "errors" "fmt" - "io/ioutil" "net" "ruleprocess/cache" "ruleprocess/logger" @@ -13,7 +12,6 @@ "time" "basic.com/pubsub/protomsg.git" - "github.com/go-yaml/yaml" "github.com/golang/protobuf/proto" "github.com/satori/go.uuid" "ruleprocess/ruleserver" @@ -31,18 +29,10 @@ 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 } // 浜鸿劯鐨勬暟鎹粨鏋� @@ -170,6 +160,8 @@ faces = PutFace(faces,msg) //logger.Info("鏁寸悊鍚庣殑鏁版嵁锛�",faces) if faces != nil { + var imgMaxUrl string = "" + var picTime string = "" for _,face := range faces { // 涓婁紶澶у浘 // 瑙e帇缂╁苟涓婁紶鍥剧墖 @@ -184,11 +176,15 @@ 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) + if imgMaxUrl == "" { + 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) + imgMaxUrl = bigPhotoUrl["fileUrl"].(string) + picTime = i.Timestamp + } // 浜鸿劯妫�娴嬶紝娌℃湁鐩镐技鐨勫簳搴撲汉鍛� localConfig, err := cache.GetServerInfo() if err != nil { @@ -227,8 +223,8 @@ esDataId, msg.Cid, camera.Addr, - i.Timestamp, - bigPhotoUrl["fileUrl"].(string), + picTime, + imgMaxUrl, msg.Tasklab.Taskid, msg.Tasklab.Taskname, "浜鸿劯", @@ -366,7 +362,9 @@ } else { logger.Info("涓婁紶鐨勫浘鐗囦俊鎭細", resp1) } - url = append(url, resp1["fileUrl"].(string)) + if resp1["fileUrl"] != nil { + url = append(url, resp1["fileUrl"].(string)) + } } } } -- Gitblit v1.8.0