sunty
2019-07-31 d94f80d854d09e89715ca7c2361cd6057f98f396
controllers/fileController.go
@@ -163,6 +163,21 @@
      util.ResponseFormat(c, code.RequestParamError, "参数有误")
      return
   }
   if searchBody.CompareNum !="" {
      //二次搜索,不需要再比对了
      co := service.GetCompResultByNum(searchBody.CompareNum)
      if co != nil {
         //二次搜索和排序
         twiceM := GetCompareDataTwice(co,&searchBody)
         util.ResponseFormat(c,code.Success,twiceM)
      } else {
         m :=make(map[string]interface{},0)
         m["compareNum"] = searchBody.CompareNum
         m["total"] = 0
         m["totalList"] = []service.CompareResult{}
         util.ResponseFormat(c,code.CompareResultGone,m)
      }
   }
   var sysSetApi dbapi.SysSetApi
   analyServerId := ""
   flag, sysconf := sysSetApi.GetServerInfo()
@@ -203,10 +218,15 @@
      logger.Debug("arg.TableIds:", arg.TableIds, ",alarmLevel:",arg.AlarmLevel,",treeNodes:",arg.TreeNodes,",searchTime:",arg.SearchTime,
         ",inputValue:",arg.InputValue,",tasks:",arg.Tasks,",compThreshold:",arg.CompareThreshold)
      timeStart := time.Now()
      compareService := service.NewFaceCompareService(arg)
      compareOnce := compareService.Compare()
      logger.Debug("compareResult:",*compareOnce)
      //logger.Debug("compareResult.len:",*compareOnce)
      dataList := compareOnce.CompareData
      logger.Debug("comp 比对结束,用时:",time.Since(timeStart))
      service.SortByScore(dataList)
      totalList := len(dataList)
      m := make(map[string]interface{},3)
@@ -217,10 +237,84 @@
      } else {
         m["totalList"] = dataList[0:searchBody.Size]
      }
      logger.Debug("comp 比对加排序返回用时:", time.Since(timeStart))
      util.ResponseFormat(c,code.Success,m)
   }
}
func GetCompareDataTwice(co *service.CompareOnce,arg *models.EsSearch) map[string]interface{} {
   camIds := arg.TreeNodes
   tabIds := arg.Tabs
   taskIds := arg.Tasks
   alarmLevels := arg.AlarmLevel
   timeArr := arg.SearchTime
   input := arg.InputValue
   resultList := make([]service.CompareResult,0)
   for _,cr :=range co.CompareData {
      if cr.Id !=""{
         n :=0
         if len(camIds) == 0 || isInArr(cr.CameraId,camIds) {
            n++
         }
         if len(tabIds) == 0 {
            n++
         }
         if len(taskIds) == 0 || isInArr(cr.TaskId, taskIds) {
            n++
         }
         //判断报警等级
         if len(alarmLevels) == 0 {
         }
         n++
         //判断时间
         if len(timeArr) == 0 {
         }
         n++
         if input == ""{
         }
         n++
         if n == 6 {
            resultList = append(resultList,cr)
         }
      } else {
         resultList = append(resultList,cr)
      }
   }
   //logger.Debug("GetCompareDataTwice.data:",resultList)
   service.SortByScore(resultList)
   from := (arg.Page-1)*arg.Size
   to := from + arg.Size
   lenth := len(resultList)
   m := make(map[string]interface{},0)
   m["total"] = lenth
   m["compareNum"] = arg.CompareNum
   if from < len(resultList) {
      if to <= len(resultList) {
         m["totalList"] = resultList[from:to]
      } else {
         lte := len(resultList)
         m["totalList"] = resultList[from:lte]
      }
   } else {
      m["totalList"] = []service.CompareResult{}
   }
   return m
}
func isInArr(id string,arr []string) bool {
   for _,v :=range arr {
      if v == id {
         return true
      }
   }
   return false
}
// @Description 人员照片上传并获取特征值
// @Router /data/api-v/dbperson/fileUploadTest [POST]
func (controller FileController) UploadPersonTest(c *gin.Context) {