liuxiaolong
2019-07-26 2a9ea1c76b4f493fb974154a130ce682616c5a49
controllers/es.go
@@ -2,7 +2,6 @@
import (
   "basic.com/dbapi.git"
   "encoding/json"
   "fmt"
   "github.com/gin-gonic/gin"
   "math/rand"
@@ -24,57 +23,33 @@
// @Produce json
// @Tags es
// @Param reqMap body models.EsSearch true "collection 为空"
// @Success 200 {string} json "{"code":200, msg:"目录结构数据", success:true}"
// @Failure 500 {string} json "{"code":500,  msg:"返回错误信息", success:false}"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
// @Router /data/api-v/es/queryEsCompareData [POST]
func PostEsCompareData(c *gin.Context) {
   searchBody := new(models.EsSearch)
   c.BindJSON(&searchBody)
   isEsSource := true
   err := c.BindJSON(&searchBody)
   if err != nil || searchBody.PicUrl == "" || len(searchBody.DataBases) == 0 {
      util.ResponseFormat(c, code.RequestParamError, "参数有误")
      return
   }
   databases := searchBody.DataBases
   page := searchBody.Page
   if page <= 0 {
      page = 1
   }
   size := searchBody.Size
   if size <= 0 {
      size = 8
   }
   from := (page - 1) * size
   to := page * size
   threshold := searchBody.Threshold
   if threshold < 0 || threshold > 100 {
      threshold = 60
   }
   picUrl := searchBody.PicUrl
   /*feature := searchBody.Feature*/
   var featByte []byte
   if len(picUrl) > 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
   }
   from := 0
   to := 0
   data := make(map[string]interface{})
   searchBody.Page = 1
   searchBody.Size = 15000
   //searchMap := Struct2Map(*searchBody)
   if len(databases) == 1 && databases[0] == "esData" {
      searchBody.IsAggs = false
      data = searchEsData(*searchBody)
   } else {
      isEsSource = false
      data = service.QueryDbPersonsForCompare(*searchBody)
   }
   sources := data["datalist"].([]interface{})
   if len(sources) > 0 {
      //进行比对
      sources = sourceCompare(sources, isEsSource, featByte, threshold)
   } else {
      fmt.Println("查询条件下无数据 source 数据为空:" + string(len(sources)))
   }
@@ -86,79 +61,13 @@
   if to > dataLen {
      to = dataLen
   }
   sources = sources[from:to] // 数据 部分获取
   if !isEsSource {           //  人员数据要加底库名称
      for _, sou := range sources {
         tableId := sou.(map[string]interface{})["tableId"]
         if tableId != nil {
            info := QueryDbTableInfo(tableId.(string))
            if info["tableName"] != nil {
               sou.(map[string]interface{})["tableName"] = info["tableName"]
            } else {
               sou.(map[string]interface{})["tableName"] = "其他"
            }
            if info["bwType"] != nil {
               sou.(map[string]interface{})["bwType"] = info["bwType"]
            } else {
               sou.(map[string]interface{})["bwType"] = "4"
            }
         }
      }
   }
   dmap := make(map[string]interface{}, 2)
   dmap["datalist"] = sources
   dmap["total"] = dataLen
   util.ResponseFormat(c, code.Success, dmap)
}
// @Summary 查询摄像机以及启算法
// @Description 关联查询摄像机以及启算法
// @Produce json
// @Tags camera
// @Success 200 {string} json "{"code":200, success:true,  msg:"请求处理成功", data:"摄像机信息"}"
// @Failure 500 {string} json "{"code":500, success:false   msg:"",data:"错误信息内容"}"
// @Router /data/api-v/camera/queryCameraAndTaskInfo [get]
//func (ac *CameraController) QueryCameraAndTaskInfo(c *gin.Context) {
//   var cam models.Camera
//   rows := cam.FindAllCamTask()
//
//   if len(rows) == 0 {
//      util.ResponseFormat(c, code.ComError, "没有记录")
//      return
//   }
//   camList := make([]map[string]interface{}, 0, 5)
//   for _, cam := range rows {
//      newCam := make(map[string]interface{})
//      newCam["cameraid"] = cam.Id
//      newCam["rtspUrl"] = cam.Rtsp
//      tasks := cam.CamTask
//      taskList := make([]map[string]interface{}, 0)
//      if tasks != nil {
//         taskmap := make(map[string]interface{})
//         for _, task := range tasks {
//            taskId := taskmap[task.Taskid]
//            if taskId != nil {
//               cameraTasks := taskmap[task.Taskid].([]models.CameraTask)
//               cameraTasks = append(cameraTasks, task)
//               taskmap[task.Taskid] = cameraTasks
//            } else {
//               cameraTasks := make([]models.CameraTask, 0)
//               taskmap[task.Taskid] = append(cameraTasks, task)
//            }
//         }
//         for key, value := range taskmap {
//            i := make(map[string]interface{})
//            i["taskid"] = key
//            i["sdklist"] = value
//            taskList = append(taskList, i)
//         }
//      }
//      newCam["tasklist"] = taskList
//      camList = append(camList, newCam)
//   }
//   c.JSON(200, camList)
//
//}
}
func searchEsData(searchBody models.EsSearch) map[string]interface{} {
   //请求索引
@@ -251,17 +160,4 @@
      }
   }
   return dataSource
}
// type  转 map
func Struct2Map(obj interface{}) map[string]interface{} {
   var data = make(map[string]interface{})
   bytes, _ := json.Marshal(obj)
   json.Unmarshal(bytes, &data)
   /*t := reflect.TypeOf(obj)
   v := reflect.ValueOf(obj)
   for i := 0; i < t.NumField(); i++ {
      data[t.Field(i).Name] = v.Field(i).Interface()
   }*/
   return data
}