From f26a0cab5bca17b7eab57f6330e576271e17a17f Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期三, 13 十一月 2019 19:12:08 +0800 Subject: [PATCH] update ynSwagger,sync to master --- controllers/dbtableperson.go | 368 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 358 insertions(+), 10 deletions(-) diff --git a/controllers/dbtableperson.go b/controllers/dbtableperson.go index 0cc064d..baac15e 100644 --- a/controllers/dbtableperson.go +++ b/controllers/dbtableperson.go @@ -2,8 +2,14 @@ import ( "basic.com/dbapi.git" + "basic.com/fileServer/WeedFSClient.git" + "basic.com/pubsub/protomsg.git" + "encoding/base64" "encoding/json" + "io/ioutil" + "sort" "strconv" + "time" "webserver/extend/logger" "github.com/gin-gonic/gin" @@ -13,19 +19,24 @@ "webserver/extend/esutil" "webserver/extend/util" "webserver/models" + "webserver/cache" + "webserver/service" + + esApi "basic.com/pubsub/esutil.git" ) type DbPersonController struct { } +// @Security ApiKeyAuth // @Summary 娣诲姞搴曞簱浜哄憳 // @Description 娣诲姞搴曞簱浜哄憳 // @Accept json // @Produce json // @Tags dbperson 搴曞簱浜哄憳 // @Param obj body models.Dbtablepersons true "搴曞簱浜哄憳鏁版嵁" -// @Success 200 {string} json "{"code":200, msg:"", success:true}" -// @Failure 500 {string} json "{"code":500, msg:"", success:false}" +// @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}" +// @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}" // @Router /data/api-v/dbperson/addDbPerson [PUT] func (dbc DbPersonController) AddDbPerson(c *gin.Context) { dbperson := new(models.Dbtablepersons) @@ -71,6 +82,7 @@ return result } +// @Security ApiKeyAuth // @Summary 淇敼搴曞簱浜哄憳 // @Description 淇敼搴曞簱浜哄憳 // @Accept json @@ -99,7 +111,12 @@ } func UpdateDbPersonsOfDbTable(id string) (message string) { - url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + + 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 := ` { @@ -138,6 +155,222 @@ return message } +// @Security ApiKeyAuth +// @Summary 搴曞簱浜哄憳浠ュ浘鎼滃浘 +// @Description 搴曞簱浜哄憳浠ュ浘鎼滃浘 +// @Accept json +// @Produce json +// @Tags dbperson 搴曞簱浜哄憳 +// @Param condition body models.EsSearch true "搴曞簱浠ュ浘鎼滃浘鍙傛暟" +// @Success 200 {string} json "{"code":200, msg:"", success:true}" +// @Failure 500 {string} json "{"code":500, msg:"", success:false}" +// @Router /data/api-v/dbperson/queryDbPersonsByCompare [POST] +func (dbc DbPersonController) QueryDbPersonsByCompare(c *gin.Context) { + var searchBody models.EsSearch + err := c.BindJSON(&searchBody) + if err !=nil || searchBody.PicUrl == "" || len(searchBody.DataBases) == 0{ + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎") + return + } + var faceB []byte + if face,ok := faceExtractedMap[searchBody.PicUrl];!ok{ + util.ResponseFormat(c, code.RequestParamError, "璇烽噸鏂颁笂浼犲浘鐗�") + return + } else { + faceB = face.FaceBytes + } + + analyServerId := "" + 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: searchBody.Threshold, + } + arg.TableIds = searchBody.DataBases + arg.AnalyServerId = analyServerId + compareService := service.NewFaceCompareService(arg) + var totalData service.CompareList + + dbPersonTargets := compareService.CompareDbPersons() + if dbPersonTargets !=nil { + totalData = append(totalData,*dbPersonTargets...) + } + + service.SetCompResultByNum(&service.CompareOnce{ + CompareNum: compareService.CompareNum, + CompareData: &totalData, + }) + + m := make(map[string]interface{},3) + if totalData != nil && totalData.Len() > 0{ + sort.Sort(totalData) + total := totalData.Len() + + m["compareNum"] = compareService.CompareNum + m["total"] = total + var sCompResult protomsg.SdkCompareResult + if total <= searchBody.Size { + sCompResult.CompareResult = totalData + } else { + sCompResult.CompareResult = totalData[0:searchBody.Size] + } + resultList := FillDbPersonDataToCompareResult(&sCompResult) + m["totalList"] = resultList + + } else { + m["total"] = 0 + m["compareNum"] = compareService.CompareNum + m["totalList"] = []CompareResult{} + } + util.ResponseFormat(c,code.Success,m) +} + +//濉厖鍚戝墠绔繑鍥炵殑鏁版嵁 +func FillDbPersonDataToCompareResult(compResult *protomsg.SdkCompareResult) []models.DbPersonsCompVo { + + 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, + } + personIds = append(personIds,v.Id) + } + logger.Debug("comp len(personIds):", len(personIds)) + + var dbpersons []protomsg.Dbperson + if len(personIds) >0 { + var dbpApi dbapi.DbPersonApi + dbpersons, _ = dbpApi.Dbpersoninfosbyid(personIds) + } + + if len(dbpersons) >0 { + //var dtApi dbapi.DbTableApi + for _,p :=range dbpersons { + 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 = util.ParseScore(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 + } + } + + return resultList +} + +// @Security ApiKeyAuth +// @Summary 鏇存柊搴曞簱浜鸿劯鐓х墖 +// @Description 鏇存柊搴曞簱浜鸿劯鐓х墖 +// @Accept multipart/form-data +// @Produce json +// @Tags dbperson 搴曞簱浜哄憳 +// @Param id formData string true "浜哄憳id" +// @Param file formData file true "浜鸿劯鍥剧墖" +// @Success 200 {string} json "{"code":200, msg:"", success:true}" +// @Failure 500 {string} json "{"code":500, msg:"", success:false}" +// @Router /data/api-v/dbperson/updateFace [POST] +func (dbc DbPersonController) UpdateFace(c *gin.Context) { + file, header, err := c.Request.FormFile("file") + id := c.Request.FormValue("id") + if err != nil || id == "" { + util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎") + return + } + //鏂囦欢鐨勫悕绉� + filename := header.Filename + defer file.Close() + // weedfs 涓婁紶 + fileBytes, err := ioutil.ReadAll(file) + if err !=nil { + util.ResponseFormat(c,code.ComError,"鍥剧墖璇诲彇澶辫触") + return + } + + //灏嗕笂浼犵殑鍥剧墖浜や汉鑴告娴嬪拰浜鸿劯鎻愬彇锛岃幏寰楃壒寰� + var faceBase64="" + faceArr, err, pI := service.GetFaceFeaFromSdk(fileBytes, time.Second*5) + if faceArr ==nil { + util.ResponseFormat(c,code.ComError,"鏈埌鎻愬彇浜鸿劯") + return + } + var rcFace *protomsg.Rect + if err ==nil && len(faceArr) >0 { + if len(faceArr) >1 { + util.ResponseFormat(c,code.ComError,"浜鸿劯澶т簬涓�寮狅紝璇锋崲涓�寮犱汉鑴稿浘鐗�") + return + } + for _,r := range faceArr { + //鎷垮埌浜鸿劯鐨勫潗鏍� + rcFace = r.Pos.RcFace + + faceBase64 = base64.StdEncoding.EncodeToString(r.Feats)//鑾峰彇鎻愬彇鍒扮殑绗竴寮犱汉鑴哥壒寰� + break + } + } + 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" + //鏍规嵁浜鸿劯鍧愭爣鎵e嚭浜鸿劯灏忓浘 + t1 := time.Now() + cutFaceImgData := util.SubImg(*pI, int(rcFace.Left), int(rcFace.Top), int(rcFace.Right), int(rcFace.Bottom)) + logger.Debug("SubImg鐢ㄦ椂锛�", time.Since(t1)) + t1 = time.Now() + weedFilePath, e := WeedFSClient.UploadFile(weedfsUri, filename, cutFaceImgData) + logger.Debug("涓婁紶鍒皐eedfs鐢ㄦ椂:", time.Since(t1)) + t1 = time.Now() + if e != nil { + util.ResponseFormat(c,code.ComError,"浜鸿劯涓婁紶澶辫触") + return + } + m := map[string]interface{} { + "faceFeature": faceBase64, + "personPicUrl": weedFilePath, + } + util.ResponseFormat(c,code.Success, m) + + //var dbpApi dbapi.DbPersonApi + //b,d := dbpApi.UpdateFace(id,faceBase64,weedFilePath) + //if b { + // util.ResponseFormat(c,code.UpdateSuccess,d) + //} else { + // util.ResponseFormat(c,code.UpdateFail,"鏇存柊浜鸿劯澶辫触") + //} +} + +// @Security ApiKeyAuth // @Summary 鍒犻櫎搴曞簱浜哄憳 // @Description 鍒犻櫎搴撲汉鍛� // @Accept x-www-form-urlencoded @@ -162,27 +395,31 @@ } } -type multiIds []string +type DelMultiPerson []string -// @Summary 鎵归噺鍒犻櫎搴曞簱浜哄憳 -// @Description 鎵归噺鍒犻櫎搴撲汉鍛� +// @Security ApiKeyAuth +// @Summary 鍒犻櫎搴曞簱浜哄憳 +// @Description 鍒犻櫎搴撲汉鍛� // @Accept json // @Produce json // @Tags dbperson 搴曞簱浜哄憳 -// @Param uuids body controllers.multiIds true "搴曞簱浜哄憳ids" +// @Param uuids body controllers.DelMultiPerson true "搴曞簱浜哄憳ids " // @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}" // @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}" // @Router /data/api-v/dbperson/deleteMoreDbPerson [POST] func (dbc DbPersonController) DeleteMoreDbPerson(c *gin.Context) { - uuids := make([]string, 0, 5) + var uuids DelMultiPerson err := c.BindJSON(&uuids) if err !=nil || len(uuids)==0{ util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎") return } + logger.Debug("DeleteMoreDbPerson len(uuids):",len(uuids)) var pApi dbapi.DbPersonApi - paramBody := util.Struct2Map(uuids) - b, _ := pApi.DeleteMoreDbPerson(paramBody) + m := map[string]interface{}{ + "ids": uuids, + } + b, _ := pApi.DeleteMoreDbPerson(m) if b { util.ResponseFormat(c, code.Success, "鍒犻櫎搴曞簱浜哄憳鎴愬姛") } else { @@ -190,6 +427,7 @@ } } +// @Security ApiKeyAuth // @Summary 鏌ヨ搴曞簱浜哄憳鍒楄〃 // @Description 鏌ヨ搴撲汉鍛樺垪琛� // @Accept json @@ -253,6 +491,59 @@ } } +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 + } + 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{ + var personPicUrl = ""//浜鸿劯鍥剧墖 + var feature = ""//鐗瑰緛 + if videopersons[0].PicSmUrl !=nil && len(videopersons[0].PicSmUrl) >0 { + personPicUrl = videopersons[0].PicSmUrl[0] + } + fea, e2 := esApi.GetVideoPersonFaceFeatureById(reqBody.CaptureId, config.EsInfo.EsIndex.VideoPersons.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 + } + } + } + util.ResponseFormat(c,code.ComError,"鍔犲叆澶辫触") +} + type DbtSearch struct { TableId string `json:"tableId"` OrderName string `json:"orderName"` @@ -262,6 +553,63 @@ 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,"") + } +} + /* // @Summary 鏌ヨ搴曞簱浜哄憳鍒楄〃 // @Description 鏌ヨ搴撲汉鍛樺垪琛� -- Gitblit v1.8.0