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 |  743 +++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 486 insertions(+), 257 deletions(-)

diff --git a/controllers/dbtableperson.go b/controllers/dbtableperson.go
index bad1888..c0ed8ac 100644
--- a/controllers/dbtableperson.go
+++ b/controllers/dbtableperson.go
@@ -1,81 +1,117 @@
 package controllers
 
 import (
-	"encoding/json"
-	"log"
+	"basic.com/dbapi.git"
+	"basic.com/fileServer/WeedFSClient.git"
+	"basic.com/pubsub/protomsg.git"
+	"basic.com/valib/logger.git"
+	"encoding/base64"
+	"io/ioutil"
+	"sort"
 	"strconv"
 	"time"
-	"webserver/extend/logger"
+	"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"
+
+	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 {object} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}"
-// @Failure 500 {string} json "{"code":500,  msg:"杩斿洖閿欒淇℃伅", success:false}"
-// @Failure 400 {object} json code.RequestParamError
+// @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)
-	c.BindJSON(&dbperson)
-	if dbperson.TableId == "" {
+	err := c.BindJSON(&dbperson)
+	if err!=nil || dbperson.TableId == "" {
 		// 搴曞簱id涓嶅瓨鍦�
-		c.JSON(401, "TableId 涓嶅瓨鍦�")
+		util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎")
+		return
 	}
-	result := addDbPerson(dbperson)
-	if result["success"].(bool) {
-		//code.Success.Message = "娣诲姞搴曞簱浜哄憳鎴愬姛"
-		util.ResponseFormat(c, code.Success, result["data"])
+	var pApi dbapi.DbPersonApi
+	paramBody := util.Struct2Map(dbperson)
+	b, data := pApi.AddDbPerson(paramBody)
+	if b {
+		util.ResponseFormat(c, code.AddSuccess, data)
 	} else {
-		//code.ServiceInsideError.Message += result["msg"].(string)
-		util.ResponseFormat(c, code.ServiceInsideError, result["data"])
+		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()
-	url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
-		"/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexType + "/" + personId + "?refresh=wait_for"
-	personbytes, e := json.Marshal(dbperson)
-	if e != nil {
-		logger.Debug("Json marshaling failed锛�%s\n", e)
-	}
-	params := string(personbytes)
-	logger.Debug("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params)
-	data, _ := esutil.PutEsDataReq(url, params)
-	//if data["_id"] !=""{
-	//	//閫氱煡姣斿杩涚▼缂撳瓨鏇存柊
-	//	discovery.AddDbMessage(&protomsg.EsPersonCacheChange{
-	//		Type: protomsg.EsCacheChanged_T_DbTablePerson,
-	//		PersonId: personId,
-	//		TableId: []string{ dbperson.TableId },
-	//		Feature: dbperson.FaceFeature,
-	//		Action: protomsg.DbAction_Insert,
-	//	})
-	//}
 
-	//c.JSON(200, changeEsRespData(data, "娣诲姞浜哄憳鎴愬姛"))
-	result = changeEsRespData(data, "娣诲姞鎴愬姛")
+	var pApi dbapi.DbPersonApi
+	paramBody := util.Struct2Map(dbperson)
+	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"] = personMap["id"]
+		result["data"] = data
+		result["success"] = true
+		result["msg"] = "娣诲姞鎴愬姛"
+	} else {
+		result["data"] = nil
+		result["success"] = false
+		result["msg"] = "鏈嶅姟鍣ㄥ紓甯�"
+		result["code"] = 500
+	}
 	return result
 }
 
+// @Security ApiKeyAuth
 // @Summary 淇敼搴曞簱浜哄憳
 // @Description 淇敼搴曞簱浜哄憳
 // @Accept  json
@@ -87,51 +123,238 @@
 // @Router /data/api-v/dbperson/updateDbPerson [POST]
 func (dbc DbPersonController) UpdateDbPerson(c *gin.Context) {
 	var dbperson models.Dbtablepersons
-	c.BindJSON(&dbperson)
-	personid := dbperson.Id
-	if personid == "" {
+	err := c.BindJSON(&dbperson)
+	if err !=nil || dbperson.Id == "" {
 		util.ResponseFormat(c, code.RequestParamError, nil)
 		return
 	}
 	dbperson.PriUpdate()
-	url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
-		"/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexType + "/" + personid + "/_update?refresh=wait_for"
-	dbTableByte, err := json.Marshal(dbperson)
-	if err != nil {
-		log.Fatalf("Json marshaling failed锛�%s", err)
-	}
-	//logger.Debugf("%s\n", dbTableByte)
-	params := "{\"doc\":" + string(dbTableByte) + "}"
-	logger.Debug("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params)
-	data := esutil.GetEsDataReq(url, params, false)
-	//c.JSON(200,  changeEsRespData(data,"淇敼鎴愬姛"))
-	result := changeEsRespData(data, "淇敼鎴愬姛")
-	if result["success"].(bool) {
-		//code.Success.Message = "淇敼搴曞簱浜哄憳鎴愬姛"
-		//if dbperson.Enable == 1 {
-		//	discovery.AddDbMessage(&protomsg.EsPersonCacheChange{
-		//		Type: protomsg.EsCacheChanged_T_DbTablePerson,
-		//		PersonId: dbperson.Id,
-		//		TableId: []string{ dbperson.TableId },
-		//		Feature: "",
-		//		Action: protomsg.DbAction_Insert,
-		//	})
-		//} else {
-		//	discovery.AddDbMessage(&protomsg.EsPersonCacheChange{
-		//		Type: protomsg.EsCacheChanged_T_DbTablePerson,
-		//		PersonId: dbperson.Id,
-		//		TableId: []string{ dbperson.TableId },
-		//		Feature: "",
-		//		Action: protomsg.DbAction_Delete,
-		//	})
-		//}
-		util.ResponseFormat(c, code.Success, result["data"])
+	var pApi dbapi.DbPersonApi
+	paramBody := util.Struct2Map(dbperson)
+	b, data := pApi.UpdateDbPerson(paramBody)
+	if b {
+		util.ResponseFormat(c, code.UpdateSuccess, data)
 	} else {
-		//code.ServiceInsideError.Message += result["msg"].(string)
-		util.ResponseFormat(c, code.ServiceInsideError, result["data"])
+		util.ResponseFormat(c, code.UpdateFail, "")
 	}
 }
 
+// @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: float64(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 = 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?collection=persistent"
+	//鏍规嵁浜鸿劯鍧愭爣鎵e嚭浜鸿劯灏忓浘
+	t1 := time.Now()
+	cutFaceImgData,_ := util.SubCutImg(pI, rcFace, 20)
+	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
@@ -143,235 +366,241 @@
 // @Router /data/api-v/dbperson/deleteDbPersonById/{uuid} [POST]
 
 func (dbc DbPersonController) DeleteDbPerson(c *gin.Context) {
-	uuid := c.Params.ByName("uuid")
-	url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
-		"/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexType + "/" + uuid + "/_update?refresh=wait_for"
-	params := "{\"doc\":{\"isDelete\":\"1\",\"updateTime\":\"" + time.Now().Format("2006-01-02 15:04:05") + "\"}}"
-	logger.Debug("鍒犻櫎璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params)
-
-	data := esutil.GetEsDataReq(url, params, false)
-
-	//c.JSON(200, changeEsRespData(data,"鍒犻櫎鎴愬姛"))
-	result := changeEsRespData(data, "鍒犻櫎鎴愬姛")
-	if result["success"].(bool) {
-		//code.Success.Message = "鍒犻櫎搴曞簱浜哄憳鎴愬姛"
-		//閫氱煡姣斿杩涚▼锛屾浜哄凡鍒犻櫎
-		//dbperArr, e := esApi.Dbpersoninfosbyid([]string{uuid}, config.EsInfo.EsIndex.Dbtablepersons.IndexName, config.EsInfo.Masterip, config.EsInfo.Httpport)
-		//if e ==nil && len(dbperArr) > 0{
-		//	if dbperArr[0].TableId !=""{
-		//		discovery.AddDbMessage(&protomsg.EsPersonCacheChange{
-		//			Type: protomsg.EsCacheChanged_T_DbTablePerson,
-		//			PersonId: uuid,
-		//			TableId: []string{ dbperArr[0].TableId },
-		//			Feature: "",
-		//			Action: protomsg.DbAction_Delete,
-		//		})
-		//	}
-		//}
-
-		util.ResponseFormat(c, code.Success, result["data"])
+	id := c.Params.ByName("uuid")
+	if id == "" {
+		util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎")
+		return
+	}
+	var pApi dbapi.DbPersonApi
+	b, data := pApi.DeleteDbPerson(id)
+	if b {
+		util.ResponseFormat(c, code.Success, data)
 	} else {
-		//code.ServiceInsideError.Message += result["msg"].(string)
-		util.ResponseFormat(c, code.ServiceInsideError, result["data"])
+		util.ResponseFormat(c, code.ServiceInsideError, "鍒犻櫎澶辫触")
 	}
 }
 
+type DelMultiPerson []string
+
+// @Security ApiKeyAuth
 // @Summary 鍒犻櫎搴曞簱浜哄憳
 // @Description 鍒犻櫎搴撲汉鍛�
 // @Accept  json
 // @Produce json
 // @Tags dbperson 搴曞簱浜哄憳
-// @Param uuids body []string 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)
-	c.BindJSON(&uuids)
-	bytes, _ := json.Marshal(uuids)
-	s := string(bytes)
-	url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
-		"/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/_update_by_query?refresh" //   + config.EsInfo.EsIndex.Dbtablepersons.IndexType + "/"  + "/" + s
-	params := "{\"script\":{\"lang\":\"painless\",\"inline\":\"ctx._source.isDelete = \\\"1\\\";" +
-		"ctx._source.updateTime = \\\"" + time.Now().Format("2006-01-02 15:04:05") + "\\\"\"},\"query\":{\"terms\":{\"_id\":" + s + "}}}"
-	logger.Debug("鍒犻櫎璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params)
-	data := esutil.GetEsDataReq(url, params, false)
-	//c.JSON(200, changeEsRespData(data,"鍒犻櫎鎴愬姛"))
-	//result := changeEsRespData(data, "鍒犻櫎鎴愬姛")
-	if data["error"] == nil {
-		//code.Success.Message = "鍒犻櫎搴曞簱浜哄憳鎴愬姛"
-		//dbperArr, e := esApi.Dbpersoninfosbyid(uuids, config.EsInfo.EsIndex.Dbtablepersons.IndexName, config.EsInfo.Masterip, config.EsInfo.Httpport)
-		//if e ==nil && len(dbperArr) > 0{
-		//	for _,esPer :=range dbperArr {
-		//		if esPer.TableId !=""{
-		//			discovery.AddDbMessage(&protomsg.EsPersonCacheChange{
-		//				Type: protomsg.EsCacheChanged_T_DbTablePerson,
-		//				PersonId: esPer.Id,
-		//				TableId: []string{ esPer.TableId },
-		//				Feature: "",
-		//				Action: protomsg.DbAction_Delete,
-		//			})
-		//		}
-		//	}
-		//}
+	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
+	m := map[string]interface{}{
+		"ids": uuids,
+	}
+	b, _ := pApi.DeleteMoreDbPerson(m)
+	if b {
 		util.ResponseFormat(c, code.Success, "鍒犻櫎搴曞簱浜哄憳鎴愬姛")
 	} else {
-		//code.ServiceInsideError.Message += result["msg"].(string)
-		util.ResponseFormat(c, code.ServiceInsideError, data["error"])
+		util.ResponseFormat(c, code.ServiceInsideError, "鍒犻櫎澶辫触")
 	}
 }
 
+// @Security ApiKeyAuth
 // @Summary 鏌ヨ搴曞簱浜哄憳鍒楄〃
 // @Description 鏌ヨ搴撲汉鍛樺垪琛�
 // @Accept  json
 // @Produce json
 // @Tags dbperson 搴曞簱浜哄憳
-// @Param reqMap body map false "{"tableId":"","orderName":"uuid","orderType":"desc","contentValue":"","page":1,"size":8}"
+// @Param reqMap body controllers.DbtSearch false "{"tableId":"","orderName":"id","orderType":"desc","contentValue":"","page":1,"size":8}"
 // @Success 200 {string} json "{"code":200, "msg":"鐩綍缁撴瀯鏁版嵁", "success":true,"data":{}}"
 // @Failure 500 {string} json "{code:500,  msg:"杩斿洖閿欒淇℃伅", success:false,data:{}}"
 // @Router /data/api-v/dbperson/queryDbPersonsByTbId [POST]
 func (dbc DbPersonController) QueryDbPersonsByTbId(c *gin.Context) {
-	url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
-		"/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/_search"
-	reqBody := make(map[string]interface{}, 5)
-	c.BindJSON(&reqBody)
-	tableId := ""
-	if reqBody["tableId"] != nil {
-		tableId = reqBody["tableId"].(string)
+	//reqBody := make(map[string]interface{}, 5)
+	var reqBody DbtSearch
+	err := c.BindJSON(&reqBody)
+	if err !=nil || reqBody.Page <=0 || reqBody.Size <=0 {
+		util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎")
+		return
 	}
-	orderName := "_id"
-	if reqBody["orderName"] != nil {
-		orderName = reqBody["orderName"].(string)
+
+	if reqBody.TableId == "" {
+		util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎锛屽簳搴搃d涓嶈兘涓虹┖")
+		return
+	}
+	orderName := "id"
+	if reqBody.OrderName != "" {
+		orderName = reqBody.OrderName
 	} // 鍒楀悕
 	orderType := "desc"
-	if reqBody["orderType"] != nil {
-		orderType = reqBody["orderType"].(string)
-	} // 鍒楃被鍨�
-	contentValue := ""
-	if reqBody["contentValue"] != nil {
-		contentValue = reqBody["contentValue"].(string)
-	} //杈撳叆妗嗗唴瀹�
+	if reqBody.OrderType != "" {
+		orderType = reqBody.OrderType
+	}
+	//鎼滅储鍐呭
+	contentValue := reqBody.ContentValue
+
 	page := 1
-	if reqBody["page"] != nil {
-		page = int(reqBody["page"].(float64))
+	if reqBody.Page >1 {
+		page = reqBody.Page
 	} // 椤电爜
 	size := 8
-	if reqBody["size"] != nil {
-		size = int(reqBody["size"].(float64))
+	if reqBody.Size >8 {
+		size = reqBody.Size
 	} // 鏉℃暟
-	from := (page - 1) * size
-	syncTerm := ""
-	contentParam := ""
-	if tableId == "all" || tableId == "" {
-		// / 鎵�鏈変汉鍛�
-	} else {
-		syncTerm = "{\"term\":{\"tableId\":\"" + tableId + "\"}}" // 搴曞簱浜哄憳
-	}
-	if contentValue != "" {
-		contentParam = ",\"must\":[{\"multi_match\":{\"query\":\"" + contentValue + "\",\"type\":\"best_fields\"," +
-			"\"fields\":[\"personName\",\"sex\",\"idCard\",\"phoneNum\"],\"tie_breaker\":0.3}}]"
-	}
 
 	if orderType == "desc" {
 		orderType = "desc"
 	} else {
 		orderType = "asc"
 	}
-
-	params := "{\"query\":{\"bool\":{\"must_not\":[" +
-		"{\"term\":{\"isDelete\":\"1\"}}],\"filter\":[" + syncTerm + "]" + contentParam + "}},\"from\":" + strconv.Itoa(from) + ",\"size\":" + strconv.Itoa(size) + ",\"sort\":{\"" + orderName + "\":{\"order\":\"" + orderType + "\"}}}"
-	logger.Debug("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params)
-	data := esutil.GetEsDataReq(url, params, true)
-	//c.JSON(200, data)
-	util.ResponseFormat(c, code.Success, data)
+	var pApi dbapi.DbPersonApi
+	paramBody := map[string]interface{}{
+		"tableId": reqBody.TableId,
+		"orderName":orderName,
+		"orderType":orderType,
+		"contentValue":contentValue,
+		"page":page,
+		"size":size,
+	}
+	b, data := pApi.QueryDbPersonsByTbId(paramBody)
+	if b{
+		util.ResponseFormat(c,code.Success,data)
+	} else {
+		util.ResponseFormat(c,code.ComError,[]interface{}{})
+	}
 }
 
-// @Summary 鏌ヨ搴曞簱浜哄憳鍒楄〃
-// @Description 鏌ヨ搴撲汉鍛樺垪琛�
+type JoinDbTVo struct {
+	CaptureId string 		`json:"captureId"`
+	TableIds  []string 		`json:"tableIds"`
+}
+
+// @Security ApiKeyAuth
+// @Summary 鎶撴媿浜哄憳鍔犲叆搴曞簱
+// @Description 鎶撴媿浜哄憳鍔犲叆搴曞簱
 // @Accept  json
 // @Produce json
 // @Tags dbperson 搴曞簱浜哄憳
-// @Param reqMap body map false "{"tableId":"","orderName":"uuid","orderType":"desc","contentValue":"","page":1,"size":8}"
-// @Success 200 {string} json "{"code":200, "msg":"鐩綍缁撴瀯鏁版嵁", "success":true,"data":{}}"
-// @Failure 500 {string} json "{code:500,  msg:"杩斿洖閿欒淇℃伅", success:false,data:{}}"
-// @Router /data/api-v/dbperson/queryDbPersonsByCampare [POST]
-func (dbc DbPersonController) QueryDbPersonsByCampare(c *gin.Context) {
-	url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
-		"/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/_search" // ?refresh=wait_for
-	reqBody := make(map[string]interface{}, 5)
+// @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)
-	tableId := ""
-	if reqBody["tableId"] != nil {
-		tableId = reqBody["tableId"].(string)
-	}
-	orderName := "_id"
-	if reqBody["orderName"] != nil {
-		orderName = reqBody["orderName"].(string)
-	} // 鍒楀悕
-	orderType := "desc"
-	if reqBody["orderType"] != nil {
-		orderType = reqBody["orderType"].(string)
-	} // 鍒楃被鍨�
-	faceUrl := ""
-	var threshold float32
-	if reqBody["faceUrl"] != nil && reqBody["threshold"] != nil {
-		faceUrl = reqBody["faceUrl"].(string)
-		threshold = float32(reqBody["threshold"].(float64))
-	} else {
-		util.ResponseFormat(c, code.RequestParamError, nil) // 鍥剧墖璺緞鏈夐棶棰�
+	if reqBody.CaptureId == "" || len(reqBody.TableIds) ==0 {
+		util.ResponseFormat(c,code.RequestParamError, "鍙傛暟鏈夎")
 		return
 	}
-	//杈撳叆妗嗗唴瀹�
-	page := 1
-	if reqBody["page"] != nil {
-		page = int(reqBody["page"].(float64))
-	} // 椤电爜
-	size := 8
-	if reqBody["size"] != nil {
-		size = int(reqBody["size"].(float64))
-	} // 鏉℃暟
-	from := (page - 1) * size
-	syncTerm := ""
-	contentParam := ""
-	if tableId == "all" || tableId == "" {
-		// / 鎵�鏈変汉鍛�
-	} else {
-		syncTerm = "{\"term\":{\"tableId\":\"" + tableId + "\"}}" // 搴曞簱浜哄憳
+	localConf, err := cache.GetServerInfo()
+	if err !=nil || localConf.AlarmIp == "" || localConf.AlarmPort <=0 {
+		util.ResponseFormat(c,code.ComError,"鎶ヨ璁剧疆鏈夎")
+		return
 	}
-	if orderType == "desc" {
-		orderType = "desc"
-	} else {
-		orderType = "asc"
-	}
+	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 aiOceans[0].TargetInfo !=nil && len(aiOceans[0].TargetInfo) >0 {
+			personPicUrl = aiOceans[0].TargetInfo[0].PicSmUrl
+		}
+		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 != "" {
+			//灏嗚繖寮犳姄鎷嶇殑鐓х墖涓嬭浇涓嬫潵涓婁紶鍒癱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
+					}
+				}
+			}
 
-	//params := "{\"query\":{\"bool\":{\"filter\":[" +
-	//	"{\"term\":{\"isDelete\":\"0\"}}" + syncTerm + "]" + contentParam + "}},\"from\":" + strconv.Itoa(from) + ",\"size\":" + strconv.Itoa(size) + ",\"sort\":{\"" + orderName + "\":{\"order\":\"" + orderType + "\"}}}"
-	params := "{\"query\":{\"bool\":{\"must_not\":[" +
-		"{\"term\":{\"isDelete\":\"1\"}}],\"filter\":[" + syncTerm + "]" + contentParam + "}},\"from\":" + strconv.Itoa(from) + ",\"size\":" + strconv.Itoa(size) + ",\"sort\":{\"" + orderName + "\":{\"order\":\"" + orderType + "\"}}}"
-	logger.Debug("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params)
-	data := esutil.GetEsDataReq(url, params, true)
-	featByte := make([]byte, 0, 1024)
-	if len(faceUrl) > 3 { //   linux
-		/*fileName := picUrl   // picIp 瀹氫箟鍦� fileController weedfs 鏂囦欢鏈嶅姟鍣� 璁块棶 璺緞 鍓嶇紑
-		detect := gorun.GetSimpleFaceDetect(fileName)
-		if len(detect) != 1 {
-			util.ResponseFormat(c,code.TooManyFeatureFindError,"鍥剧墖鐗瑰緛鍊艰繃澶�")
-			return
-		}else {
-			featByte = detect[0]["feature"].([]byte)
-		}*/ //   linux
+		}
 	}
-	to := page * size
-	datalist := sourceCompare(data["datalist"].([]interface{}), false, featByte, threshold)
-	total := len(datalist)
-	if from > total {
-		from = total
-	}
-	if to > total {
-		to = total
-	}
-	data["datalist"] = datalist[from:to]
-	data["total"] = len(datalist)
-	//c.JSON(200, data)
-	util.ResponseFormat(c, code.Success, data)
+	util.ResponseFormat(c,code.ComError,"鍔犲叆澶辫触")
 }
+
+type DbtSearch struct {
+	TableId string 		`json:"tableId"`
+	OrderName string 	`json:"orderName"`
+	OrderType string 	`json:"orderType"`
+	ContentValue string `json:"contentValue"`
+	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