From bae7a9a30b89c519460746cfa19cd7e66a0196e2 Mon Sep 17 00:00:00 2001 From: sunty <1172534965@qq.com> Date: 星期日, 19 一月 2020 17:13:07 +0800 Subject: [PATCH] update _source list and struct --- controllers/dbtableperson.go | 92 +++++++++++++-------------------------------- 1 files changed, 27 insertions(+), 65 deletions(-) diff --git a/controllers/dbtableperson.go b/controllers/dbtableperson.go index 91c3550..6112be3 100644 --- a/controllers/dbtableperson.go +++ b/controllers/dbtableperson.go @@ -4,13 +4,12 @@ "basic.com/dbapi.git" "basic.com/fileServer/WeedFSClient.git" "basic.com/pubsub/protomsg.git" + "basic.com/valib/logger.git" "encoding/base64" - "encoding/json" "io/ioutil" "sort" "strconv" "time" - "basic.com/valib/logger.git" "webserver/cache" "webserver/service" @@ -18,7 +17,6 @@ "github.com/satori/go.uuid" "webserver/extend/code" "webserver/extend/config" - "webserver/extend/esutil" "webserver/extend/util" "webserver/models" @@ -197,7 +195,7 @@ for idx,v :=range compResult.CompareResult{ dbPersonM[v.Id] = ScoreIndex{ Index: idx, - CompareScore: v.CompareScore, + CompareScore: float64(v.CompareScore), } personIds = append(personIds,v.Id) } @@ -230,7 +228,7 @@ dbP.CreateTime = p.CreateTime dbP.UpdateTime = p.UpdateTime dbP.CreateBy = p.CreateBy - dbP.CompareScore = util.ParseScore(dbPersonM[p.Id].CompareScore) + dbP.CompareScore = dbPersonM[p.Id].CompareScore //dbTableInfos, _ := dtApi.DbtablesById([]string{ p.TableId }) //if dbTableInfos !=nil{ // dbP.BwType = dbTableInfos[0].BwType @@ -246,7 +244,7 @@ // @Security ApiKeyAuth // @Summary 鏇存柊搴曞簱浜鸿劯鐓х墖 // @Description 鏇存柊搴曞簱浜鸿劯鐓х墖 -// @Accept json +// @Accept multipart/form-data // @Produce json // @Tags dbperson 搴曞簱浜哄憳 // @Param id formData string true "浜哄憳id" @@ -297,7 +295,7 @@ logger.Debug("localConfig is wrong!!!") return } - var weedfsUri = "http://"+localConf.WebPicIp+":"+strconv.Itoa(int(localConf.WebPicPort))+"/submit" + var weedfsUri = "http://"+localConf.WebPicIp+":"+strconv.Itoa(int(localConf.WebPicPort))+"/submit?collection=persistent" //鏍规嵁浜鸿劯鍧愭爣鎵e嚭浜鸿劯灏忓浘 t1 := time.Now() cutFaceImgData := util.SubImg(*pI, int(rcFace.Left), int(rcFace.Top), int(rcFace.Right), int(rcFace.Bottom)) @@ -323,51 +321,6 @@ //} else { // util.ResponseFormat(c,code.UpdateFail,"鏇存柊浜鸿劯澶辫触") //} -} - -func UpdateDbPersonsOfDbTable(id string) (message string) { - localConf, err2 := cache.GetServerInfo() - if err2 !=nil || localConf.AlarmIp == "" || localConf.ServerId == "" { - logger.Debug("localConfig is wrong!!!") - return "淇敼澶辫触" - } - url := "http://" + localConf.AlarmIp + ":" + strconv.Itoa(int(localConf.AlarmPort)) + - "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/_update_by_query?refresh" - jsonDSL := ` - { - "script": { - "lang": "painless", - "inline": "ctx._source.enable = 0" - }, - "query": { - "term": { - "tableId": "` + id + `" - } - } -} -` - buf, err := esutil.EsReq("POST", url, []byte(jsonDSL)) - if err != nil { - logger.Debug("http request info is err!") - message = "淇敼澶辫触" - } - var info interface{} - json.Unmarshal(buf, &info) - out, ok := info.(map[string]interface{}) - if !ok { - logger.Debug("http response interface can not change map[string]interface{}") - message = "淇敼澶辫触" - } - middle, ok := out["updated"].(float64) - if !ok { - logger.Debug("first result change error!") - message = "淇敼澶辫触" - } - if middle >= 0 { - logger.Debug("淇敼鎴愬姛") - message = "淇敼鎴愬姛,鏇存柊鐘舵�佹潯鏁颁负" + strconv.Itoa(int(middle)) - } - return message } // @Security ApiKeyAuth @@ -520,27 +473,36 @@ util.ResponseFormat(c,code.ComError,"鎶ヨ璁剧疆鏈夎") return } - videopersons, e := esApi.Videopersonsinfosbyid([]string{reqBody.CaptureId}, config.EsInfo.EsIndex.VideoPersons.IndexName, localConf.AlarmIp, strconv.Itoa(int(localConf.AlarmPort))) - if e ==nil && videopersons !=nil && len(videopersons) == 1{ + aiOceans, e := esApi.AIOceaninfosbyid([]string{reqBody.CaptureId}, config.EsInfo.EsIndex.AiOcean.IndexName, localConf.AlarmIp, strconv.Itoa(int(localConf.AlarmPort))) + if e ==nil && aiOceans !=nil && len(aiOceans) == 1{ var personPicUrl = ""//浜鸿劯鍥剧墖 var feature = ""//鐗瑰緛 - if videopersons[0].PicSmUrl !=nil && len(videopersons[0].PicSmUrl) >0 { - personPicUrl = videopersons[0].PicSmUrl[0] + if aiOceans[0].TargetInfo !=nil && len(aiOceans[0].TargetInfo) >0 { + personPicUrl = aiOceans[0].TargetInfo[0].PicSmUrl } - fea, e2 := esApi.GetVideoPersonFaceFeatureById(reqBody.CaptureId, config.EsInfo.EsIndex.VideoPersons.IndexName, localConf.AlarmIp, strconv.Itoa(int(localConf.AlarmPort))) + fea, e2 := esApi.GetVideoPersonFaceFeatureById(reqBody.CaptureId, config.EsInfo.EsIndex.AiOcean.IndexName, localConf.AlarmIp, strconv.Itoa(int(localConf.AlarmPort))) if e2 == nil && fea !="" { feature = fea } if personPicUrl != "" && feature != "" { - var dbpApi dbapi.DbPersonApi - b,d := dbpApi.JoinDbTable(reqBody.TableIds, feature, personPicUrl) - if b { - util.ResponseFormat(c,code.Success,d) - return - } else { - util.ResponseFormat(c,code.ComError,"鍔犲叆澶辫触") - return + //灏嗚繖寮犳姄鎷嶇殑鐓х墖涓嬭浇涓嬫潵涓婁紶鍒癱ollection=persistent鐨勯泦鍚堜腑锛岄槻姝㈣娓呯悊鎺� + picB, e3 := util.DownLoad("http://" + personPicUrl) + if e3 == nil { + var weedfsUri = "http://"+localConf.WebPicIp+":"+strconv.Itoa(int(localConf.WebPicPort))+"/submit?collection=persistent" + newPersonPicUrl, e4 := WeedFSClient.UploadFile(weedfsUri, "capturePerson", picB) + if e4 == nil { + var dbpApi dbapi.DbPersonApi + b,d := dbpApi.JoinDbTable(reqBody.TableIds, feature, newPersonPicUrl) + if b { + util.ResponseFormat(c,code.Success,d) + return + } else { + util.ResponseFormat(c,code.ComError,"鍔犲叆澶辫触") + return + } + } } + } } util.ResponseFormat(c,code.ComError,"鍔犲叆澶辫触") -- Gitblit v1.8.0