From b0500fee9c01e17c81b9293b244c8ed88dc9ca29 Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期五, 11 十月 2019 15:12:25 +0800
Subject: [PATCH] add swagger

---
 controllers/fileController.go |  110 +++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 78 insertions(+), 32 deletions(-)

diff --git a/controllers/fileController.go b/controllers/fileController.go
index fab536f..7bfc13a 100644
--- a/controllers/fileController.go
+++ b/controllers/fileController.go
@@ -129,6 +129,7 @@
 		return
 	}
 	var weedfsUri = "http://"+localConf.WebPicIp+":"+strconv.Itoa(int(localConf.WebPicPort))+"/submit"
+	logger.Debug("weedfsUri:",weedfsUri)
 	resultMap :=make(map[string]interface{},0)
 	//灏嗕笂浼犵殑鍥剧墖浜や汉鑴告娴嬪拰浜鸿劯鎻愬彇锛岃幏寰楃壒寰�
 	fileBytes, _ := ioutil.ReadAll(file)
@@ -275,10 +276,11 @@
 	}
 	if len(captureIds) >0 {
 		localConf, err2 := cache.GetServerInfo()
-		if err2 !=nil || localConf.AlarmIp == "" {
+		if err2 !=nil || localConf.AlarmIp == "" || localConf.ServerId == "" {
 			logger.Debug("localConfig is wrong!!!")
 			return nil
 		}
+		logger.Debug("captureIds:",strings.Join(captureIds,","))
 		videopersons, _ := esApi.Videopersonsinfosbyid(captureIds, config.EsInfo.EsIndex.VideoPersons.IndexName, localConf.AlarmIp, strconv.Itoa(int(localConf.AlarmPort)))
 		logger.Debug("comp videoPersons.len:",len(videopersons))
 		for _,vp :=range videopersons {
@@ -336,6 +338,36 @@
 	return level
 }
 
+func GetFeaFromOneFaceImg(fileBytes []byte) (faceB []byte,oriImg string,smImgs []string, err error){
+	localConf, err2 := cache.GetServerInfo()
+	if err2 !=nil || localConf.WebPicIp == "" {
+		logger.Debug("localConfig is wrong!!!")
+		return nil,"",nil,errors.New("localConf err")
+	}
+	var weedfsUri = "http://"+localConf.WebPicIp+":"+strconv.Itoa(int(localConf.WebPicPort))+"/submit"
+	logger.Debug("weedfsUri:",weedfsUri)
+	faceArr, err, pI := service.GetFaceFeaFromSdk(fileBytes, time.Second*60)
+	if err ==nil && len(faceArr) ==1 {
+		rcFace := faceArr[0].Pos.RcFace
+		cutFaceImgData := util.SubImg(*pI, int(rcFace.Left), int(rcFace.Top), int(rcFace.Right), int(rcFace.Bottom))
+		weedFilePath, e := WeedFSClient.UploadFile(weedfsUri, "FaceUrl", cutFaceImgData)
+		if e == nil{
+			faceExtractedMap[weedFilePath] = FaceExtract{
+				Url:weedFilePath,
+				FaceBytes:faceArr[0].Feats,
+			}
+			smImgs = append(smImgs, weedFilePath)
+		}
+		//2.澶у浘鐢绘,鏍囪瘑浜鸿劯浣嶇疆
+		drawedB, _ := drawPolygonOnImg(pI, &faceArr)
+
+		originFilePath, _ := WeedFSClient.UploadFile(weedfsUri, "FaceUrl", *drawedB)
+		return faceArr[0].Feats,originFilePath,smImgs,nil
+	} else {
+		return nil,"",nil,errors.New("no face")
+	}
+}
+
 // @Summary 浠ュ浘鎼滃浘
 // @Description  浠ュ浘鎼滃浘
 // @Accept json
@@ -345,55 +377,69 @@
 // @Success 200 {string} json "{"code":200, msg:"", data:"", success:true}"
 // @Failure 500 {string} json "{"code":500, msg:"", data:"", success:false}"
 // @Router /data/api-v/dbperson/searchByPhoto [POST]
-func (controller FileController) SearchByPhoto(c *gin.Context) {
+func (fc FileController) SearchByPhoto(c *gin.Context) {
 	var searchBody models.EsSearch
 	err := c.BindJSON(&searchBody)
 	if err !=nil{
 		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎")
 		return
 	}
+	localConf, err2 := cache.GetServerInfo()
+	if err2 !=nil || localConf.AlarmIp == "" || localConf.ServerId == "" {
+		logger.Debug("localConfig is wrong!!!")
+		util.ResponseFormat(c,code.ComError,"localConf wrong")
+		return
+	}
 	var faceB []byte
-	if searchBody.CaptureId != "" {//鍋氭煡鎵炬浜�,鎼滄墍鏈夋姄鎷嶅拰搴曞簱
-		localConf, err2 := cache.GetServerInfo()
-		if err2 !=nil || localConf.AlarmIp == "" {
-			logger.Debug("localConfig is wrong!!!")
-			util.ResponseFormat(c,code.ComError,"localConf wrong")
-			return
-		}
-		searchBase64Fea, err := esApi.GetVideoPersonFaceFeatureById(searchBody.CaptureId, config.EsInfo.EsIndex.VideoPersons.IndexName, localConf.AlarmIp, strconv.Itoa(int(localConf.AlarmPort)))
-		if err !=nil {
-			util.ResponseFormat(c, code.ComError, "鎶撴媿鏁版嵁涓嶅瓨鍦紝璇锋鏌�")
-			return
-		}
-		if searchBase64Fea !=""{
-			decodeF, err := base64.StdEncoding.DecodeString(searchBase64Fea)
-			if err !=nil {
-				util.ResponseFormat(c, code.ComError, "鏈潯鎶撴�曠壒寰佷笉鏄痓ase64锛岃妫�鏌�")
+
+	if searchBody.CompTargetId != "" {//鍋氭煡鎵炬浜�,鎸夋姄鎷嶇殑浜鸿劯鎴栬�呭簳搴撶殑浜鸿劯浠ュ浘鎼滃浘
+		if searchBody.CompTargetType == 0 {//鏈紶浜鸿劯鏄簳搴撲汉鑴�
+			var dbpApi dbapi.DbPersonApi
+			dbPersons, e := dbpApi.Dbpersoninfosbyid([]string{searchBody.CompTargetId})
+			if e ==nil && dbPersons !=nil && len(dbPersons) ==1 {
+				searchBase64Fea := dbPersons[0].FaceFeature
+				if searchBase64Fea != "" {
+					decodeF, err := base64.StdEncoding.DecodeString(dbPersons[0].FaceFeature)
+					if err !=nil {
+						util.ResponseFormat(c, code.ComError, "鏈潯搴曞簱浜哄憳鐗瑰緛涓嶆槸base64锛岃妫�鏌�")
+						return
+					}
+					faceB = decodeF
+				} else {
+					util.ResponseFormat(c, code.ComError, "鏈潯搴曞簱浜哄憳鐗瑰緛涓虹┖锛岃妫�鏌�")
+					return
+				}
+			} else {
+				util.ResponseFormat(c, code.ComError, "搴曞簱浜哄憳鏌ヨ澶辫触锛岃妫�鏌�")
 				return
 			}
-			faceB = decodeF
+		} else {
+			searchBase64Fea, err := esApi.GetVideoPersonFaceFeatureById(searchBody.CompTargetId, config.EsInfo.EsIndex.VideoPersons.IndexName, localConf.AlarmIp, strconv.Itoa(int(localConf.AlarmPort)))
+			if err !=nil {
+				util.ResponseFormat(c, code.ComError, "鎶撴媿鏁版嵁涓嶅瓨鍦紝璇锋鏌�")
+				return
+			}
+			if searchBase64Fea !=""{
+				decodeF, err := base64.StdEncoding.DecodeString(searchBase64Fea)
+				if err !=nil {
+					util.ResponseFormat(c, code.ComError, "鏈潯鎶撴�曠壒寰佷笉鏄痓ase64锛岃妫�鏌�")
+					return
+				}
+				faceB = decodeF
+			}
 		}
+
 	} else {//鍋氫互鍥炬悳鍥�
 		if searchBody.PicUrl == "" || len(searchBody.DataBases) == 0 {
-			util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎")
+			util.ResponseFormat(c, code.RequestParamError, "浠ュ浘鎼滃浘PicUrl涓嶈兘涓虹┖")
 			return
 		}
 		if face,ok := faceExtractedMap[searchBody.PicUrl];!ok{
-			util.ResponseFormat(c, code.RequestParamError, "璇烽噸鏂颁笂浼犲浘鐗�")
+			util.ResponseFormat(c, code.RequestParamError, "浜鸿劯鐗瑰緛鏈娴嬶紝璇烽噸鏂颁笂浼犲浘鐗�")
 			return
 		} else {
 			faceB = face.FaceBytes
 		}
-	}
-
-	var sysSetApi dbapi.SysSetApi
-	analyServerId := ""
-	flag, sysconf := sysSetApi.GetServerInfo()
-	if flag {
-		analyServerId = sysconf.ServerId
-	} else {
-		util.ResponseFormat(c, code.ComError, "analyServerId涓虹┖锛岄厤缃湁璇�")
-		return
 	}
 
 	if faceB == nil {
@@ -426,7 +472,7 @@
 	arg.SearchTime = searchBody.SearchTime
 	arg.InputValue = searchBody.InputValue
 	arg.Collection = searchBody.Collection
-	arg.AnalyServerId = analyServerId
+	arg.AnalyServerId = localConf.ServerId
 
 	logger.Debug("arg.TableIds:", arg.TableIds, ",alarmLevel:",arg.AlarmLevel,",treeNodes:",arg.TreeNodes,",searchTime:",arg.SearchTime,
 		",inputValue:",arg.InputValue,",tasks:",arg.Tasks,",compThreshold:",arg.CompareThreshold)

--
Gitblit v1.8.0