liuxiaolong
2019-08-22 f4e8f206a6760bdc31734dfcb1c65916b5b76311
controllers/fileController.go
@@ -214,15 +214,15 @@
   }
   logger.Debug("comp len(personIds):", len(personIds))
   logger.Debug("comp len(captureIds):", len(captureIds))
   esServerIp := config.EsInfo.Masterip
   esServerPort := config.EsInfo.Httpport
   index := config.EsInfo.EsIndex.Dbtablepersons.IndexName
   var dbpersons []protomsg.Dbperson
   if len(personIds) >0 {
      dbpersons, _ = esApi.Dbpersoninfosbyid(personIds, index, esServerIp, esServerPort)
      var dbpApi dbapi.DbPersonApi
      dbpersons, _ = dbpApi.Dbpersoninfosbyid(personIds)
   }
   if len(dbpersons) >0 {
      var dtApi dbapi.DbTableApi
      for _,p :=range dbpersons {
         var dbP = DbPersonVo {
            PersonId: p.Id,
@@ -236,7 +236,7 @@
            TableId: p.TableId,
            Enable: p.Enable,
         }
         dbTableInfos, _ := esApi.Dbtablefosbyid([]string{p.TableId}, config.EsInfo.EsIndex.DbTables.IndexName, esServerIp, esServerPort)
         dbTableInfos, _ := dtApi.DbtablesById([]string{ p.TableId })
         if dbTableInfos !=nil{
            dbP.BwType = dbTableInfos[0].BwType
            dbP.TableName = dbTableInfos[0].TableName
@@ -368,11 +368,12 @@
      CompareThreshold: searchBody.Threshold,
   }
   var hasCompEsPerson = false
   if searchBody.DataBases !=nil {
      for idx,tableId :=range searchBody.DataBases {
         if tableId == "esData" {
            searchBody.DataBases = append(searchBody.DataBases[:idx], searchBody.DataBases[idx+1:]...)
            searchBody.DataBases = append(searchBody.DataBases,service.CaptureTable)
            hasCompEsPerson = true
            break
         }
      }
@@ -395,22 +396,38 @@
   timeStart := time.Now()
   compareService := service.NewFaceCompareService(arg)
   compareOnce := compareService.Compare()
   totalData := compareOnce.CompareData
   var totalData service.CompareList
   if len(arg.TableIds) >0 {//有比对底库
      dbPersonTargets := compareService.CompareDbPersons()
      if dbPersonTargets !=nil {
         totalData = append(totalData,*dbPersonTargets...)
      }
   }
   if hasCompEsPerson {//有比对Es抓拍
      esPersons := compareService.CompareVideoPersons()
      if esPersons !=nil {
         totalData = append(totalData, *esPersons...)
      }
   }
   logger.Debug("comp 比对结束,用时:",time.Since(timeStart))
   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"] = compareOnce.CompareNum
      m["compareNum"] = compareService.CompareNum
      m["total"] = total
      var sCompResult protomsg.SdkCompareResult
      if total <= searchBody.Size {
         sCompResult.CompareResult = *totalData
         sCompResult.CompareResult = totalData
      } else {
         sCompResult.CompareResult = (*totalData)[0:searchBody.Size]
         sCompResult.CompareResult = totalData[0:searchBody.Size]
      }
      resultList := FillDataToCompareResult(&sCompResult)
      m["totalList"] = resultList
@@ -418,7 +435,7 @@
   } else {
      m["total"] = 0
      m["compareNum"] = searchBody.CompareNum
      m["compareNum"] = compareService.CompareNum
      m["totalList"] = []CompareResult{}
   }
   util.ResponseFormat(c,code.Success,m)
@@ -548,7 +565,6 @@
func uploadFileReturnAddr(file multipart.File, filename string, tableId string) (string, map[string]interface{}, error) {
   defer file.Close()
   field := ""
   // weedfs 上传
   fileBytes, err := ioutil.ReadAll(file)
   if err !=nil {
@@ -580,29 +596,22 @@
   cutFaceImgData := util.SubImg(*pI, int(rcFace.Left), int(rcFace.Top), int(rcFace.Right), int(rcFace.Bottom))
   logger.Debug("SubImg用时:", time.Since(t1))
   t1 = time.Now()
   fileInfo, e := esutil.PostFormData(weedfsUri, filename, "file", cutFaceImgData)
   weedFilePath, e := WeedFSClient.UploadFile(weedfsUri, filename, cutFaceImgData)
   logger.Debug("上传到weedfs用时:", time.Since(t1))
   t1 = time.Now()
   if e != nil {
      fmt.Println(e.Error())
      return "", nil, e
   } else {
      field = fileInfo[picUrlField].(string) // 文件路径
   }
   if strings.Contains(field,"/"){
      idx := strings.Index(field, "/")
      field = field[idx+1:]
   }
   ext := path.Ext(filename)
   fileNameOnly := strings.TrimSuffix(filename, ext)
   dbperson := new(models.Dbtablepersons)
   dbperson.PersonPicUrl = field //  图片路经
   dbperson.PersonPicUrl = weedFilePath //  图片路经
   dbperson.TableId = tableId           //
   dbperson.PersonName = fileNameOnly       // 图片名
   dbperson.Enable = 1 //默认有效
   // 演示base64编码
   dbperson.FaceFeature = faceBase64 // 特征值base64 码
   result := addDbPerson(dbperson)