From 789d38603d73dabe8ae5f79c1a35a8d84c130b00 Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期三, 04 三月 2020 18:20:47 +0800
Subject: [PATCH] update protomsg
---
controllers/dbtableperson.go | 258 +++++++++++++++++++++++++++++++++++---------------
1 files changed, 179 insertions(+), 79 deletions(-)
diff --git a/controllers/dbtableperson.go b/controllers/dbtableperson.go
index 88766f3..6112be3 100644
--- a/controllers/dbtableperson.go
+++ b/controllers/dbtableperson.go
@@ -4,27 +4,29 @@
"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"
- "webserver/extend/logger"
+ "webserver/cache"
"webserver/service"
"github.com/gin-gonic/gin"
"github.com/satori/go.uuid"
"webserver/extend/code"
"webserver/extend/config"
- "webserver/extend/esutil"
"webserver/extend/util"
"webserver/models"
+
+ esApi "basic.com/pubsub/esutil.git"
)
type DbPersonController struct {
}
+// @Security ApiKeyAuth
// @Summary 娣诲姞搴曞簱浜哄憳
// @Description 娣诲姞搴曞簱浜哄憳
// @Accept json
@@ -78,6 +80,7 @@
return result
}
+// @Security ApiKeyAuth
// @Summary 淇敼搴曞簱浜哄憳
// @Description 淇敼搴曞簱浜哄憳
// @Accept json
@@ -105,6 +108,7 @@
}
}
+// @Security ApiKeyAuth
// @Summary 搴曞簱浜哄憳浠ュ浘鎼滃浘
// @Description 搴曞簱浜哄憳浠ュ浘鎼滃浘
// @Accept json
@@ -128,18 +132,19 @@
} else {
faceB = face.FaceBytes
}
- var sysSetApi dbapi.SysSetApi
+
analyServerId := ""
- flag, sysconf := sysSetApi.GetServerInfo()
- if flag {
- analyServerId = sysconf.ServerId
+ conf, e := cache.GetServerInfo()
+ if e ==nil && conf.ServerId != "" {
+ analyServerId = conf.ServerId
} else {
util.ResponseFormat(c, code.ComError, "analyServerId涓虹┖锛岄厤缃湁璇�")
return
}
+
arg := protomsg.CompareArgs{
FaceFeature: faceB,
- CompareThreshold: 0.6,
+ CompareThreshold: searchBody.Threshold,
}
arg.TableIds = searchBody.DataBases
arg.AnalyServerId = analyServerId
@@ -181,16 +186,16 @@
}
//濉厖鍚戝墠绔繑鍥炵殑鏁版嵁
-func FillDbPersonDataToCompareResult(compResult *protomsg.SdkCompareResult) []DbPersonVo {
+func FillDbPersonDataToCompareResult(compResult *protomsg.SdkCompareResult) []models.DbPersonsCompVo {
- var resultList = make([]DbPersonVo, len(compResult.CompareResult))
+ var resultList = make([]models.DbPersonsCompVo, len(compResult.CompareResult))
dbPersonM := make(map[string]ScoreIndex, 0)
personIds := make([]string,0)
for idx,v :=range compResult.CompareResult{
dbPersonM[v.Id] = ScoreIndex{
Index: idx,
- CompareScore: v.CompareScore,
+ CompareScore: float64(v.CompareScore),
}
personIds = append(personIds,v.Id)
}
@@ -203,25 +208,32 @@
}
if len(dbpersons) >0 {
- var dtApi dbapi.DbTableApi
+ //var dtApi dbapi.DbTableApi
for _,p :=range dbpersons {
- var dbP = DbPersonVo {
- PersonId: p.Id,
- IdCard: p.IdCard,
- CompareScore: util.ParseScore(dbPersonM[p.Id].CompareScore),
- MonitorLevel: p.MonitorLevel,
- PersonName: p.PersonName,
- PersonPicUrl: p.PersonPicUrl,
- PhoneNum: p.PhoneNum,
- Sex: p.Sex,
- TableId: p.TableId,
- Enable: p.Enable,
- }
- dbTableInfos, _ := dtApi.DbtablesById([]string{ p.TableId })
- if dbTableInfos !=nil{
- dbP.BwType = dbTableInfos[0].BwType
- dbP.TableName = dbTableInfos[0].TableName
- }
+ var dbP models.DbPersonsCompVo
+
+ dbP.Id = p.Id
+ dbP.TableId = p.TableId
+ dbP.FaceFeature = p.FaceFeature
+ dbP.PersonPicUrl = p.PersonPicUrl
+ dbP.PersonName = p.PersonName
+ dbP.Age = p.Age
+ dbP.Sex = p.Sex
+ dbP.IdCard = p.IdCard
+ dbP.PhoneNum = p.PhoneNum
+ dbP.MonitorLevel = p.MonitorLevel
+ dbP.Reserved = p.Reserved
+ dbP.IsDelete = int(p.IsDelete)
+ dbP.Enable = int(p.Enable)
+ dbP.CreateTime = p.CreateTime
+ dbP.UpdateTime = p.UpdateTime
+ dbP.CreateBy = p.CreateBy
+ dbP.CompareScore = dbPersonM[p.Id].CompareScore
+ //dbTableInfos, _ := dtApi.DbtablesById([]string{ p.TableId })
+ //if dbTableInfos !=nil{
+ // dbP.BwType = dbTableInfos[0].BwType
+ // dbP.TableName = dbTableInfos[0].TableName
+ //}
resultList[dbPersonM[p.Id].Index] = dbP
}
}
@@ -229,11 +241,12 @@
return resultList
}
+// @Security ApiKeyAuth
// @Summary 鏇存柊搴曞簱浜鸿劯鐓х墖
// @Description 鏇存柊搴曞簱浜鸿劯鐓х墖
-// @Accept json
+// @Accept multipart/form-data
// @Produce json
-// @Tags 搴曞簱浜哄憳
+// @Tags dbperson 搴曞簱浜哄憳
// @Param id formData string true "浜哄憳id"
// @Param file formData file true "浜鸿劯鍥剧墖"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
@@ -277,7 +290,12 @@
break
}
}
- var weedfsUri = "http://"+config.WeedFs.Ip+":"+strconv.Itoa(config.WeedFs.UploadPort)+"/submit"
+ localConf, err2 := cache.GetServerInfo()
+ if err2 !=nil || localConf.WebPicIp == "" {
+ logger.Debug("localConfig is wrong!!!")
+ return
+ }
+ 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))
@@ -305,46 +323,7 @@
//}
}
-func UpdateDbPersonsOfDbTable(id string) (message string) {
- url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
- "/" + 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
// @Summary 鍒犻櫎搴曞簱浜哄憳
// @Description 鍒犻櫎搴撲汉鍛�
// @Accept x-www-form-urlencoded
@@ -372,6 +351,7 @@
type DelMultiPerson []string
+// @Security ApiKeyAuth
// @Summary 鍒犻櫎搴曞簱浜哄憳
// @Description 鍒犻櫎搴撲汉鍛�
// @Accept json
@@ -401,6 +381,7 @@
}
}
+// @Security ApiKeyAuth
// @Summary 鏌ヨ搴曞簱浜哄憳鍒楄〃
// @Description 鏌ヨ搴撲汉鍛樺垪琛�
// @Accept json
@@ -465,11 +446,130 @@
}
}
-type DbtSearch struct {
- TableId string `json:"tableId"`
- OrderName string `json:"orderName"`
- OrderType string `json:"orderType"`
- ContentValue string `json:"contentValue"`
- Page int `json:"page"`
- Size int `json:"size"`
+type JoinDbTVo struct {
+ CaptureId string `json:"captureId"`
+ TableIds []string `json:"tableIds"`
}
+
+// @Security ApiKeyAuth
+// @Summary 鎶撴媿浜哄憳鍔犲叆搴曞簱
+// @Description 鎶撴媿浜哄憳鍔犲叆搴曞簱
+// @Accept json
+// @Produce json
+// @Tags dbperson 搴曞簱浜哄憳
+// @Param obj body controllers.JoinDbTVo true "搴曞簱鏁版嵁"
+// @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}"
+// @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}"
+// @Router /data/api-v/dbperson/joinDbTable [POST]
+func (dbc *DbPersonController) JoinDbTable(c *gin.Context) {
+ var reqBody JoinDbTVo
+ c.BindJSON(&reqBody)
+ if reqBody.CaptureId == "" || len(reqBody.TableIds) ==0 {
+ util.ResponseFormat(c,code.RequestParamError, "鍙傛暟鏈夎")
+ return
+ }
+ localConf, err := cache.GetServerInfo()
+ if err !=nil || localConf.AlarmIp == "" || localConf.AlarmPort <=0 {
+ util.ResponseFormat(c,code.ComError,"鎶ヨ璁剧疆鏈夎")
+ return
+ }
+ 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 aiOceans[0].TargetInfo !=nil && len(aiOceans[0].TargetInfo) >0 {
+ personPicUrl = aiOceans[0].TargetInfo[0].PicSmUrl
+ }
+ 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 != "" {
+ //灏嗚繖寮犳姄鎷嶇殑鐓х墖涓嬭浇涓嬫潵涓婁紶鍒癱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,"鍔犲叆澶辫触")
+}
+
+type DbtSearch struct {
+ TableId string `json:"tableId"`
+ OrderName string `json:"orderName"`
+ OrderType string `json:"orderType"`
+ ContentValue string `json:"contentValue"`
+ Page int `json:"page"`
+ Size int `json:"size"`
+}
+
+type DbPersonMove struct {
+ PersonId string `json:"personId"`
+ TableIds []string `json:"tableIds"`
+}
+
+// @Security ApiKeyAuth
+// @Summary 浜哄憳绉诲姩
+// @Description 浜哄憳绉诲姩
+// @Accept json
+// @Produce json
+// @Tags dbperson 搴曞簱浜哄憳
+// @Param obj body controllers.DbPersonMove true "绉诲姩鍙傛暟"
+// @Success 200 {string} json "{"code":200, msg:"", success:true}"
+// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
+// @Router /data/api-v/dbperson/move [POST]
+func (dbc *DbPersonController) Move(c *gin.Context) {
+ var reqBody DbPersonMove
+ c.BindJSON(&reqBody)
+ if reqBody.PersonId == "" || len(reqBody.TableIds) == 0 {
+ util.ResponseFormat(c,code.RequestParamError, "鍙傛暟鏈夎")
+ return
+ }
+ var dbpApi dbapi.DbPersonApi
+ b,d := dbpApi.Move(reqBody.PersonId, reqBody.TableIds)
+ if b {
+ util.ResponseFormat(c,code.Success,d)
+ } else {
+ util.ResponseFormat(c,code.ComError,"")
+ }
+}
+
+// @Security ApiKeyAuth
+// @Summary 浜哄憳澶嶅埗
+// @Description 浜哄憳澶嶅埗
+// @Accept json
+// @Produce json
+// @Tags dbperson 搴曞簱浜哄憳
+// @Param obj body controllers.DbPersonMove true "澶嶅埗鍙傛暟"
+// @Success 200 {string} json "{"code":200, msg:"", success:true}"
+// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
+// @Router /data/api-v/dbperson/copy [POST]
+func (dbc *DbPersonController) Copy(c *gin.Context) {
+ var reqBody DbPersonMove
+ c.BindJSON(&reqBody)
+ if reqBody.PersonId == "" || len(reqBody.TableIds) == 0 {
+ util.ResponseFormat(c,code.RequestParamError, "鍙傛暟鏈夎")
+ return
+ }
+ var dbpApi dbapi.DbPersonApi
+ b,d := dbpApi.Copy(reqBody.PersonId, reqBody.TableIds)
+ if b {
+ util.ResponseFormat(c,code.Success,d)
+ } else {
+ util.ResponseFormat(c,code.ComError,"")
+ }
+}
\ No newline at end of file
--
Gitblit v1.8.0