From 7c811247ecf143e08c576986a884bedadc57dd66 Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期五, 05 六月 2020 18:29:41 +0800
Subject: [PATCH] add refresh token to resp

---
 controllers/dbtableperson.go |  220 ++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 139 insertions(+), 81 deletions(-)

diff --git a/controllers/dbtableperson.go b/controllers/dbtableperson.go
index baa0257..c0ed8ac 100644
--- a/controllers/dbtableperson.go
+++ b/controllers/dbtableperson.go
@@ -4,21 +4,18 @@
 	"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"
-	"basic.com/valib/logger.git"
 	"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"
 
@@ -28,6 +25,7 @@
 type DbPersonController struct {
 }
 
+// @Security ApiKeyAuth
 // @Summary 娣诲姞搴曞簱浜哄憳
 // @Description 娣诲姞搴曞簱浜哄憳
 // @Accept  json
@@ -49,26 +47,58 @@
 	paramBody := util.Struct2Map(dbperson)
 	b, data := pApi.AddDbPerson(paramBody)
 	if b {
-		util.ResponseFormat(c, code.Success, data)
+		util.ResponseFormat(c, code.AddSuccess, data)
 	} else {
-		util.ResponseFormat(c, code.ServiceInsideError, "")
+		util.ResponseFormat(c, code.ComError, "")
+	}
+}
+
+
+type MultiCarNo struct {
+	TableId string `json:"tableId" binding:"required"`
+	CarNos []string `json:"carNos" binding:"required"`
+}
+
+// @Security ApiKeyAuth
+// @Summary 鎵归噺娣诲姞搴曞簱杞﹁締
+// @Description 鎵归噺娣诲姞搴曞簱杞﹁締
+// @Accept  json
+// @Produce json
+// @Tags dbperson 搴曞簱浜哄憳
+// @Param reqBody body controllers.MultiCarNo true "鎵归噺杞︾墝鍙�"
+// @Success 200 {string} json "{"code":200, msg:"", success:true}"
+// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
+// @Router /data/api-v/dbperson/multiUploadCarNo [post]
+func (dbc DbPersonController) MultiUploadCarNo(c *gin.Context) {
+	var reqBody  MultiCarNo
+	err := c.BindJSON(&reqBody)
+	if err != nil {
+		util.ResponseFormat(c, code.RequestParamError, "")
+		return
+	}
+	logger.Debug("multiUploadCarNo reqBody:", reqBody)
+	var pApi dbapi.DbPersonApi
+	paramBody := util.Struct2Map(reqBody)
+	if pApi.MultiUploadCarNo(paramBody) {
+		util.ResponseFormat(c,code.UploadSuccess,"涓婁紶鎴愬姛")
+	} else {
+		util.ResponseFormat(c,code.ComError,"")
 	}
 }
 
 func addDbPerson(dbperson *models.Dbtablepersons) (result map[string]interface{}) {
 
-	personId := uuid.NewV4().String()
-	dbperson.Id = personId
 	dbperson.PriInsert()
 
 	var pApi dbapi.DbPersonApi
 	paramBody := util.Struct2Map(dbperson)
-	b, _ := pApi.AddDbPerson(paramBody)
+	b, d := pApi.AddDbPerson(paramBody)
 	result = map[string]interface{}{}
 	if b {
 		result["code"] = 200
+		personMap := util.Struct2Map(d)
 		data := make(map[string]interface{})
-		data["uuid"] = personId
+		data["uuid"] = personMap["id"]
 		result["data"] = data
 		result["success"] = true
 		result["msg"] = "娣诲姞鎴愬姛"
@@ -81,6 +111,7 @@
 	return result
 }
 
+// @Security ApiKeyAuth
 // @Summary 淇敼搴曞簱浜哄憳
 // @Description 淇敼搴曞簱浜哄憳
 // @Accept  json
@@ -102,12 +133,13 @@
 	paramBody := util.Struct2Map(dbperson)
 	b, data := pApi.UpdateDbPerson(paramBody)
 	if b {
-		util.ResponseFormat(c, code.Success, data)
+		util.ResponseFormat(c, code.UpdateSuccess, data)
 	} else {
-		util.ResponseFormat(c, code.ServiceInsideError, "")
+		util.ResponseFormat(c, code.UpdateFail, "")
 	}
 }
 
+// @Security ApiKeyAuth
 // @Summary 搴曞簱浜哄憳浠ュ浘鎼滃浘
 // @Description 搴曞簱浜哄憳浠ュ浘鎼滃浘
 // @Accept  json
@@ -194,7 +226,7 @@
 	for idx,v :=range compResult.CompareResult{
 		dbPersonM[v.Id] = ScoreIndex{
 			Index: idx,
-			CompareScore: v.CompareScore,
+			CompareScore: float64(v.CompareScore),
 		}
 		personIds = append(personIds,v.Id)
 	}
@@ -227,7 +259,7 @@
 			dbP.CreateTime = p.CreateTime
 			dbP.UpdateTime = p.UpdateTime
 			dbP.CreateBy = p.CreateBy
-			dbP.CompareScore = util.ParseScore(dbPersonM[p.Id].CompareScore)
+			dbP.CompareScore = dbPersonM[p.Id].CompareScore
 			//dbTableInfos, _ := dtApi.DbtablesById([]string{ p.TableId })
 			//if dbTableInfos !=nil{
 			//	dbP.BwType = dbTableInfos[0].BwType
@@ -240,9 +272,10 @@
 	return  resultList
 }
 
+// @Security ApiKeyAuth
 // @Summary 鏇存柊搴曞簱浜鸿劯鐓х墖
 // @Description 鏇存柊搴曞簱浜鸿劯鐓х墖
-// @Accept  json
+// @Accept multipart/form-data
 // @Produce json
 // @Tags dbperson 搴曞簱浜哄憳
 // @Param id formData string true "浜哄憳id"
@@ -293,10 +326,10 @@
 		logger.Debug("localConfig is wrong!!!")
 		return
 	}
-	var weedfsUri = "http://"+localConf.WebPicIp+":"+strconv.Itoa(int(localConf.WebPicPort))+"/submit"
+	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))
+	cutFaceImgData,_ := util.SubCutImg(pI, rcFace, 20)
 	logger.Debug("SubImg鐢ㄦ椂锛�", time.Since(t1))
 	t1 = time.Now()
 	weedFilePath, e := WeedFSClient.UploadFile(weedfsUri, filename, cutFaceImgData)
@@ -321,51 +354,7 @@
 	//}
 }
 
-func UpdateDbPersonsOfDbTable(id string) (message string) {
-	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 := `
-			{
-	"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
@@ -393,6 +382,7 @@
 
 type DelMultiPerson []string
 
+// @Security ApiKeyAuth
 // @Summary 鍒犻櫎搴曞簱浜哄憳
 // @Description 鍒犻櫎搴撲汉鍛�
 // @Accept  json
@@ -422,6 +412,7 @@
 	}
 }
 
+// @Security ApiKeyAuth
 // @Summary 鏌ヨ搴曞簱浜哄憳鍒楄〃
 // @Description 鏌ヨ搴撲汉鍛樺垪琛�
 // @Accept  json
@@ -491,6 +482,7 @@
 	TableIds  []string 		`json:"tableIds"`
 }
 
+// @Security ApiKeyAuth
 // @Summary 鎶撴媿浜哄憳鍔犲叆搴曞簱
 // @Description 鎶撴媿浜哄憳鍔犲叆搴曞簱
 // @Accept  json
@@ -500,7 +492,7 @@
 // @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 (sc *DbPersonController) JoinDbTable(c *gin.Context) {
+func (dbc *DbPersonController) JoinDbTable(c *gin.Context) {
 	var reqBody JoinDbTVo
 	c.BindJSON(&reqBody)
 	if reqBody.CaptureId == "" || len(reqBody.TableIds) ==0 {
@@ -512,37 +504,103 @@
 		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{
+	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 videopersons[0].PicSmUrl !=nil && len(videopersons[0].PicSmUrl) >0 {
-			personPicUrl = videopersons[0].PicSmUrl[0]
+		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.VideoPersons.IndexName, localConf.AlarmIp, strconv.Itoa(int(localConf.AlarmPort)))
+		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 != "" {
-			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
+			//灏嗚繖寮犳姄鎷嶇殑鐓х墖涓嬭浇涓嬫潵涓婁紶鍒癱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"`
+	TableId string 		`json:"tableId"`
+	OrderName string 	`json:"orderName"`
+	OrderType string 	`json:"orderType"`
 	ContentValue string `json:"contentValue"`
-	Page int `json:"page"`
-	Size int `json:"size"`
+	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