From 1646a48ba47b1f89b156207bf70e5dfdde29b85d Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期四, 25 七月 2019 16:05:40 +0800
Subject: [PATCH] add logger

---
 controllers/fileController.go |  185 ++++++++++++++++++++++++++++++++++++---------
 1 files changed, 146 insertions(+), 39 deletions(-)

diff --git a/controllers/fileController.go b/controllers/fileController.go
index 8f97e3e..8bb9a36 100644
--- a/controllers/fileController.go
+++ b/controllers/fileController.go
@@ -25,6 +25,7 @@
 	"webserver/extend/code"
 	"webserver/extend/config"
 	"webserver/extend/esutil"
+	"webserver/extend/logger"
 	"webserver/extend/util"
 	"webserver/models"
 	"webserver/service"
@@ -105,7 +106,13 @@
 }
 var faceExtractedMap = make(map[string]FaceExtract,0)
 
-// @Description 浜鸿劯鎻愬彇
+// @Summary 浜鸿劯鎻愬彇
+// @Description  浜鸿劯鎻愬彇
+// @Produce json
+// @Tags 浠ュ浘鎼滃浘
+// @Param file formData file true "浜哄憳鍥剧墖"
+// @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/faceExtract [POST]
 func (controller FileController) FaceExtract(c *gin.Context) {
 	file, _, err := c.Request.FormFile("file") //image杩欎釜鏄痷plaodify鍙傛暟瀹氫箟涓殑   'fileObjName':'image'
@@ -114,11 +121,12 @@
 		return
 	}
 	var weedfsUri = "http://"+config.WeedFs.Ip+":"+strconv.Itoa(config.WeedFs.UploadPort)+"/submit"
-
+	resultMap :=make(map[string]interface{},0)
 	//灏嗕笂浼犵殑鍥剧墖浜や汉鑴告娴嬪拰浜鸿劯鎻愬彇锛岃幏寰楃壒寰�
 	fileBytes, _ := ioutil.ReadAll(file)
 	faceArr, err, pI := service.GetFaceFeaFromSdk(fileBytes, time.Second*60)
 	if err ==nil && len(faceArr) >0 {
+		//1.鎻愬彇姣忎竴寮犱汉鑴稿皬鍥�
 		urlArr := make([]string,0)
 		for _,r := range faceArr {
 			rcFace := r.Pos.RcFace
@@ -132,65 +140,164 @@
 				urlArr = append(urlArr, weedFilePath)
 			}
 		}
-		if len(urlArr) == 0{
-			util.ResponseFormat(c,code.ComError,"鏈彁鍙栧埌浜鸿劯")
-		} else {
-			util.ResponseFormat(c,code.Success,urlArr)
-		}
+		//2.澶у浘鐢绘,鏍囪瘑浜鸿劯浣嶇疆
+		originFilePath, _ := WeedFSClient.UploadFile(weedfsUri, "FaceUrl", fileBytes)
+		resultMap["uploadImage"] = originFilePath
+		resultMap["smImage"] = urlArr
+		util.ResponseFormat(c,code.Success, resultMap)
 	} else {
 		util.ResponseFormat(c,code.ComError,"鏈彁鍙栧埌浜鸿劯")
 	}
 }
 
-// @Description 浠ュ浘鎼滃浘
+type CompareResult struct {
+	Id string `json:"id"`
+	CameraId string `json:"cameraId"`
+	CameraAddr string `json:"cameraAddr"`
+	PicDate string `json:"picDate"`
+	Content string `json:"content"`
+	IsAlarm int `json:"isAlarm"`
+	PicMaxUrl string `json:"picMaxUrl"`
+	PicSmUrl []string `json:"picSmUrl"`
+	Sex string `json:"sex"`
+	AgeDescription string `json:"ageDescription"`
+	Race string `json:"race"`
+	TaskName string `json:"taskName"`
+	BaseInfo []DbPersonVo `json:"baseInfo"`
+	VideoUrl string `json:"videoUrl"`
+}
+type DbPersonVo struct {
+	BwType string `json:"bwType"`
+	CompareScore float32 `json:"compareScore"`
+	IdCard string `json:"idCard"`
+	MonitorLevel string `json:"monitorLevel"`
+	PersonId string `json:"personId"`
+	PersonName string `json:"personName"`
+	PersonPicUrl string `json:"personPicUrl"`
+	PhoneNum string `json:"phoneNum"`
+	Sex string `json:"sex"`
+	TableId string `json:"tableId"`
+	TableName string `json:"tableName"`
+}
+
+var captureTable = "capturetable" // 鎶撴媿搴�
+type SearchCondition struct {
+	PicUrl string `json:"picUrl"`
+	Databases []string `json:"databases"`
+	Threshold string `json:"threshold"`
+}
+// @Summary 浠ュ浘鎼滃浘
+// @Description  浠ュ浘鎼滃浘
+// @Accept json
+// @Produce json
+// @Tags 浠ュ浘鎼滃浘
+// @Param condition body controllers.SearchCondition true "鎼滅储鍙傛暟"
+// @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) {
-	photoUrl := c.Request.FormValue("url")
-	if photoUrl == "" {
+	var condition SearchCondition
+	err := c.BindJSON(&condition)
+	if err !=nil || condition.PicUrl == "" {
 		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎")
 		return
 	}
-	if face,ok := faceExtractedMap[photoUrl];!ok{
+	compThreshold, err := strconv.ParseFloat(condition.Threshold,32)
+	if condition.PicUrl == "" || err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎")
+		return
+	}
+	if face,ok := faceExtractedMap[condition.PicUrl];!ok{
 		util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎")
 		return
 	} else {
-		reqUrl := "tcp://192.168.1.66:40010"
-		reqClient := deliver.NewClient(deliver.ReqRep, reqUrl)
 		arg := protomsg.CompareArgs{
+			TableIds:[]string{ captureTable },
 			FaceFeature:face.FaceBytes,
-			CompareThreshold:0.2,
+			CompareThreshold:float32(compThreshold),
+		}
+		if condition.Databases !=nil {
+			arg.TableIds = append(arg.TableIds, condition.Databases...)
 		}
 		b, err := proto.Marshal(&arg)
 		if err !=nil{
 			util.ResponseFormat(c, code.ComError, "璇锋眰marshal澶辫触")
 			return
 		}
-		err = reqClient.Send(b)
-		if err !=nil{
-			util.ResponseFormat(c, code.ComError, "姣斿鏈嶅姟璇锋眰澶辫触")
-			return
+		compServerList := config.CompServerInfo.Url
+		logger.Debug("compServerList:", compServerList)
+		resultList :=make([]CompareResult,0)
+		for _,str :=range compServerList{
+			reqUrl := "tcp://"+str
+			reqClient := deliver.NewClient(deliver.ReqRep, reqUrl)
+			err = reqClient.Send(b)
+			if err !=nil{
+				logger.Debug("reqClient.Send err:",err)
+				continue
+			}
+			resultB, err := reqClient.Recv()
+			if err !=nil{
+				logger.Debug("reqClient.Recv err:",err)
+				continue
+			}
+			rList :=make([]protomsg.Esinfo,0)
+			err = json.Unmarshal(resultB, &rList)
+			if err !=nil{
+				logger.Debug("recv result Unmarshal err:", err)
+				continue
+			}
+			logger.Debug("rList:", rList)
+
+			dbPersonM := make(map[string]*protomsg.Esinfo,0)
+			captureM := make(map[string]*protomsg.Esinfo,0)
+			personIds :=make([]string,0)
+			captureIds := make([]string,0)
+			for _,v :=range rList{
+				if v.Tableid == captureTable {
+					captureM[v.Id] = &v
+					personIds = append(personIds,v.Id)
+				} else {
+					dbPersonM[v.Id] = &v
+					captureIds = append(captureIds,v.Id)
+				}
+			}
+			logger.Debug("personIds:", personIds)
+			logger.Debug("captureIds:",captureIds)
+			esServerIp := config.EsInfo.Masterip
+			esServerPort := config.EsInfo.Httpport
+			index := config.EsInfo.EsIndex.Dbtablepersons.IndexName
+			dbpersons, e := esApi.Dbpersoninfosbyid(personIds, index, esServerIp, esServerPort)
+			if e !=nil {
+				logger.Debug("Dbpersoninfosbyid.err:",e)
+			}
+			logger.Debug("dbpersons:", dbpersons)
+			if e ==nil && dbpersons !=nil {
+				for _,p :=range dbpersons {
+					var dbP = DbPersonVo {
+						PersonId: p.Id,
+						IdCard: p.IdCard,
+						CompareScore: dbPersonM[p.Id].CompareScore,
+						MonitorLevel: p.MonitorLevel,
+						PersonName: p.PersonName,
+						PersonPicUrl: p.PersonPicUrl,
+						PhoneNum: p.PhoneNum,
+						Sex: p.Sex,
+						TableId: p.TableId,
+					}
+					dbTableInfos, _ := esApi.Dbtablefosbyid([]string{p.TableId}, config.EsInfo.EsIndex.DbTables.IndexName, esServerIp, esServerPort)
+					if dbTableInfos !=nil{
+						dbP.BwType = dbTableInfos[0].BwType
+						dbP.TableName = dbTableInfos[0].TableName
+					}
+					var cr = CompareResult{
+						BaseInfo:[]DbPersonVo{ dbP },
+					}
+					resultList = append(resultList,cr)
+				}
+			}
+			logger.Debug("resultList:",resultList)
 		}
-		resultB, err := reqClient.Recv()
-		if err !=nil{
-			util.ResponseFormat(c, code.ComError, "姣斿鏈嶅姟鍝嶅簲澶辫触")
-			return
-		}
-		m :=make(map[string]float32,0)
-		err = json.Unmarshal(resultB, &m)
-		if err !=nil{
-			util.ResponseFormat(c, code.ComError, "result Unmarshal err")
-			return
-		}
-		personIds := make([]string,len(m))
-		for k,_ :=range m{
-			personIds = append(personIds,k)
-		}
-		dbpeople, e := esApi.Dbpersoninfosbyid(personIds, "dbtablepersons", "192.168.1.182", "9200")
-		if e !=nil{
-			util.ResponseFormat(c, code.ComError, "result es query err")
-		} else {
-			util.ResponseFormat(c,code.Success,dbpeople)
-		}
+		util.ResponseFormat(c,code.Success,resultList)
 	}
 }
 

--
Gitblit v1.8.0