From 9298b8b7228af9c07872b41bffc894a6d9dd4e59 Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期四, 29 八月 2019 14:12:27 +0800
Subject: [PATCH] add UpdateFace
---
extend/code/code.go | 1
controllers/dbtableperson.go | 76 ++++++++++++++++++++++++++++++++++++++
router/router.go | 1
3 files changed, 78 insertions(+), 0 deletions(-)
diff --git a/controllers/dbtableperson.go b/controllers/dbtableperson.go
index 22327b9..966de9d 100644
--- a/controllers/dbtableperson.go
+++ b/controllers/dbtableperson.go
@@ -2,9 +2,15 @@
import (
"basic.com/dbapi.git"
+ "basic.com/fileServer/WeedFSClient.git"
+ "basic.com/pubsub/protomsg.git"
+ "encoding/base64"
"encoding/json"
+ "io/ioutil"
"strconv"
+ "time"
"webserver/extend/logger"
+ "webserver/service"
"github.com/gin-gonic/gin"
"github.com/satori/go.uuid"
@@ -98,6 +104,76 @@
}
}
+// @Summary 鏇存柊搴曞簱浜鸿劯鐓х墖
+// @Description 鏇存柊搴曞簱浜鸿劯鐓х墖
+// @Accept json
+// @Produce json
+// @Tags 搴曞簱浜哄憳
+// @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
+ }
+ }
+ var weedfsUri = "http://"+config.WeedFs.Ip+":"+strconv.Itoa(config.WeedFs.UploadPort)+"/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
+ }
+ 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,"鏇存柊浜鸿劯澶辫触")
+ }
+}
+
func UpdateDbPersonsOfDbTable(id string) (message string) {
url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
"/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/_update_by_query?refresh"
diff --git a/extend/code/code.go b/extend/code/code.go
index 93a4341..e5e79c2 100644
--- a/extend/code/code.go
+++ b/extend/code/code.go
@@ -14,6 +14,7 @@
Success = &Code{http.StatusOK, true, "璇锋眰澶勭悊鎴愬姛"}
AddSuccess = &Code{http.StatusOK,true,"娣诲姞鎴愬姛"}
UpdateSuccess = &Code{http.StatusOK,true,"鏇存柊鎴愬姛"}
+ UpdateFail = &Code{http.StatusBadRequest,false,"鏇存柊澶辫触"}
DelSuccess = &Code{http.StatusOK,true,"鍒犻櫎鎴愬姛"}
// RequestParamError 璇锋眰鍙傛暟閿欒
RequestParamError = &Code{http.StatusBadRequest, false, "璇锋眰鍙傛暟鏈夎"}
diff --git a/router/router.go b/router/router.go
index 365a131..a930b81 100644
--- a/router/router.go
+++ b/router/router.go
@@ -168,6 +168,7 @@
vdbperson.POST("/fileUploadTest", fileController.UploadPersonTest)
vdbperson.POST("/faceExtract",fileController.FaceExtract)
vdbperson.POST("/searchByPhoto",fileController.SearchByPhoto)
+ vdbperson.POST("/updateFace", dbPersonCont.UpdateFace)
}
// 绯荤粺璁剧疆 鎿嶄綔
--
Gitblit v1.8.0