liuxiaolong
2020-06-05 7c811247ecf143e08c576986a884bedadc57dd66
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"
@@ -50,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"] = "添加成功"
@@ -104,9 +133,9 @@
   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, "")
   }
}
@@ -197,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)
   }
@@ -230,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
@@ -246,7 +275,7 @@
// @Security ApiKeyAuth
// @Summary 更新底库人脸照片
// @Description 更新底库人脸照片
// @Accept  json
// @Accept multipart/form-data
// @Produce json
// @Tags dbperson 底库人员
// @Param id formData string true "人员id"
@@ -297,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"
   //根据人脸坐标扣出人脸小图
   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)
@@ -323,51 +352,6 @@
   //} else {
   //   util.ResponseFormat(c,code.UpdateFail,"更新人脸失败")
   //}
}
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
@@ -520,27 +504,36 @@
      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
         //将这张抓拍的照片下载下来上传到collection=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,"加入失败")