liuxiaolong
2019-07-26 2a9ea1c76b4f493fb974154a130ce682616c5a49
logger
5个文件已修改
245 ■■■■■ 已修改文件
controllers/dbtableperson.go 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/dbtablesCon.go 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/es.go 130 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/fileController.go 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/esSearch.go 27 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/dbtableperson.go
@@ -2,10 +2,10 @@
import (
    "encoding/json"
    "fmt"
    "log"
    "strconv"
    "time"
    "webserver/extend/logger"
    "github.com/gin-gonic/gin"
    "github.com/satori/go.uuid"
@@ -55,10 +55,10 @@
        "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexType + "/" + personId + "?refresh=wait_for"
    personbytes, e := json.Marshal(dbperson)
    if e != nil {
        fmt.Print("Json marshaling failed:%s\n", e)
        logger.Debug("Json marshaling failed:%s\n", e)
    }
    params := string(personbytes)
    fmt.Print("请求url:%s;\n 请求参数params:%s", url, params)
    logger.Debug("请求url:%s;\n 请求参数params:%s", url, params)
    data, _ := esutil.PutEsDataReq(url, params)
    //c.JSON(200, changeEsRespData(data, "添加人员成功"))
    result = changeEsRespData(data, "添加成功")
@@ -89,9 +89,9 @@
    if err != nil {
        log.Fatalf("Json marshaling failed:%s", err)
    }
    //fmt.Printf("%s\n", dbTableByte)
    //logger.Debugf("%s\n", dbTableByte)
    params := "{\"doc\":" + string(dbTableByte) + "}"
    fmt.Print("请求url:%s;\n 请求参数params:%s", url, params)
    logger.Debug("请求url:%s;\n 请求参数params:%s", url, params)
    data := esutil.GetEsDataReq(url, params, false)
    //c.JSON(200,  changeEsRespData(data,"修改成功"))
    result := changeEsRespData(data, "修改成功")
@@ -119,7 +119,7 @@
    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") + "\"}}"
    fmt.Print("删除请求url:%s;\n 请求参数params:%s", url, params)
    logger.Debug("删除请求url:%s;\n 请求参数params:%s", url, params)
    data := esutil.GetEsDataReq(url, params, false)
@@ -152,7 +152,7 @@
        "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/_update_by_query?refresh=wait_for" //   + 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 + "}}}"
    fmt.Print("删除请求url:%s;\n 请求参数params:%s", url, params)
    logger.Debug("删除请求url:%s;\n 请求参数params:%s", url, params)
    data := esutil.GetEsDataReq(url, params, false)
    //c.JSON(200, changeEsRespData(data,"删除成功"))
    //result := changeEsRespData(data, "删除成功")
@@ -224,7 +224,7 @@
    params := "{\"query\":{\"bool\":{\"must_not\":[" +
        "{\"term\":{\"isDelete\":\"1\"}}],\"filter\":[" + syncTerm + "]" + contentParam + "}},\"from\":" + strconv.Itoa(from) + ",\"size\":" + strconv.Itoa(size) + ",\"sort\":{\"" + orderName + "\":{\"order\":\"" + orderType + "\"}}}"
    fmt.Print("请求url:%s;\n 请求参数params:%s", url, params)
    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)
@@ -292,7 +292,7 @@
    //    "{\"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 + "\"}}}"
    fmt.Print("请求url:%s;\n 请求参数params:%s", url, params)
    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
controllers/dbtablesCon.go
@@ -2,13 +2,13 @@
import (
    "encoding/json"
    "fmt"
    "github.com/gin-gonic/gin"
    "github.com/satori/go.uuid"
    "log"
    "webserver/extend/code"
    "webserver/extend/config"
    "webserver/extend/esutil"
    "webserver/extend/logger"
    "webserver/extend/util"
    "webserver/models"
)
@@ -38,7 +38,7 @@
    params := "{\"query\":{\"bool\":{\"must\":[" +
        "{\"term\":{\"isDelete\":\"0\"}}" + syncTerm + "]}}," +
        "\"from\":0,\"size\":100,\"sort\":{\"id\":{\"order\":\"asc\"}}}"
    fmt.Print("请求url:%s;\n 请求参数params:%s", url, params)
    logger.Debug("请求url:%s;\n 请求参数params:%s", url, params)
    data := esutil.GetEsDataReq(url, params, true)
    //c.JSON(200, data)
@@ -49,7 +49,7 @@
func QueryDbTableInfo(tableId string) map[string]interface{} {
    url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
        "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + tableId
    fmt.Print("请求url:%s;", url)
    logger.Debug("请求url:%s;", url)
    data := esutil.GetEsDataInfo(url, true)
    return data
}
@@ -69,7 +69,7 @@
    uuid := c.Params.ByName("id")
    if uuid == "" {
        uuid = dbtable.Id
        fmt.Println("body中获取底库id")
        logger.Debug("body中获取底库id")
    }
    url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
        "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + config.EsInfo.EsIndex.DbTables.IndexType + "/" + uuid + "/_update?refresh=wait_for"
@@ -78,9 +78,9 @@
    if err != nil {
        log.Fatalf("Json marshaling failed:%s", err)
    }
    fmt.Printf("%s\n", dbTableByte)
    logger.Debug("%s\n", dbTableByte)
    params := "{\"doc\":" + string(dbTableByte) + "}"
    fmt.Print("请求url:%s;\n 请求参数params:%s", url, params)
    logger.Debug("请求url:%s;\n 请求参数params:%s", url, params)
    data := esutil.GetEsDataReq(url, params, false)
    //c.JSON(200, changeEsRespData(data, "修改成功"))
    result := changeEsRespData(data, "修改成功")
@@ -114,9 +114,9 @@
    if err != nil {
        log.Fatalf("Json marshaling failed:%s", err)
    }
    //fmt.Printf("%s\n", dbTableByte)
    //logger.Debugf("%s\n", dbTableByte)
    params := string(dbTableByte)
    fmt.Print("请求url:%s;\n 请求参数params:%s", url, params)
    logger.Debug("请求url:%s;\n 请求参数params:%s", url, params)
    data, _ := esutil.PutEsDataReq(url, params)
    //c.JSON(200, changeEsRespData(data, "添加成功"))
    result := changeEsRespData(data, "添加成功")
@@ -143,7 +143,7 @@
    url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
        "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + config.EsInfo.EsIndex.DbTables.IndexType + "/" + uuid + "/_update?refresh=wait_for"
    params := "{\"doc\":{\"isDelete\":\"1\"}}"
    fmt.Print("删除请求url:%s;\n 请求参数params:%s", url, params)
    logger.Debug("删除请求url:%s;\n 请求参数params:%s", url, params)
    data := esutil.GetEsDataReq(url, params, false)
    //c.JSON(200, changeEsRespData(data, "删除成功"))
    result := changeEsRespData(data, "删除成功")
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
}
controllers/fileController.go
@@ -1,6 +1,7 @@
package controllers
import (
    "basic.com/dbapi.git"
    "basic.com/pubsub/protomsg.git"
    "basic.com/fileServer/WeedFSClient.git"
    "basic.com/valib/deliver.git"
@@ -181,44 +182,61 @@
}
var captureTable = "capturetable" // 抓拍库
type SearchCondition struct {
    PicUrl string `json:"picUrl"`
    Databases []string `json:"databases"`
    Threshold string `json:"threshold"`
}
// @Summary 以图搜图
// @Description  以图搜图
// @Accept json
// @Produce json
// @Tags 以图搜图
// @Param condition body controllers.SearchCondition true "搜索参数"
// @Param condition body models.EsSearch true "搜索参数"
// @Success 200 {string} json "{"code":200, msg:"", data:"", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"", data:"", success:false}"
// @Router /data/api-v/dbperson/searchByPhoto [POST]
func (controller FileController) SearchByPhoto(c *gin.Context) {
    var condition SearchCondition
    err := c.BindJSON(&condition)
    if err !=nil || condition.PicUrl == "" || len(condition.Databases) == 0 {
    var searchBody models.EsSearch
    err := c.BindJSON(&searchBody)
    if err !=nil || searchBody.PicUrl == "" || len(searchBody.DataBases) == 0 {
        util.ResponseFormat(c, code.RequestParamError, "参数有误")
        return
    }
    compThreshold, err := strconv.ParseFloat(condition.Threshold,32)
    if condition.PicUrl == "" || err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数有误")
    var sysSetApi dbapi.SysSetApi
    analyServerId := ""
    flag, sysconf := sysSetApi.GetServerInfo()
    if flag {
        analyServerId = sysconf.ServerId
    } else {
        util.ResponseFormat(c, code.ComError, "analyServerId为空,配置有误")
        return
    }
    if face,ok := faceExtractedMap[condition.PicUrl];!ok{
    if face,ok := faceExtractedMap[searchBody.PicUrl];!ok{
        util.ResponseFormat(c, code.RequestParamError, "请重新上传图片")
        return
    } else {
        arg := protomsg.CompareArgs{
            TableIds: condition.Databases,
            FaceFeature: face.FaceBytes,
            CompareThreshold: float32(compThreshold),
            CompareThreshold: searchBody.Threshold,
        }
        if condition.Databases !=nil {
            arg.TableIds = append(arg.TableIds, condition.Databases...)
        if searchBody.DataBases !=nil {
            for idx,tableId :=range searchBody.DataBases {
                if tableId == captureTable{
                    searchBody.DataBases = append(searchBody.DataBases[:idx], searchBody.DataBases[idx+1:]...)
                    searchBody.DataBases = append(searchBody.DataBases,captureTable)
                    break
                }
            }
            arg.TableIds = searchBody.DataBases
        }
        arg.Source = true // 标识来源是web
        arg.AlarmLevel = searchBody.AlarmLevel
        arg.Tasks = searchBody.Tasks
        arg.TreeNodes = searchBody.TreeNodes
        arg.Tabs = searchBody.Tabs
        arg.SearchTime = searchBody.SearchTime
        arg.InputValue = searchBody.InputValue
        arg.Collection = searchBody.Collection
        arg.AnalyServerId = analyServerId
        logger.Debug("arg.TableIds:", arg.TableIds, ",alarmLevel:",arg.AlarmLevel,",treeNodes:",arg.TreeNodes,",searchTime:",arg.SearchTime,
            ",inputValue:",arg.InputValue,",tasks:",arg.Tasks,",compThreshold:",arg.CompareThreshold)
        b, err := proto.Marshal(&arg)
        if err !=nil{
            util.ResponseFormat(c, code.ComError, "请求marshal失败")
models/esSearch.go
@@ -1,17 +1,18 @@
package models
type EsSearch struct {
    DataBases  []string `json:"databases"`
    Tasks      []string `json:"tasks"`
    TreeNodes  []string `json:"treeNodes"`
    Tabs       []string `json:"tabs"`
    SearchTime []string `json:"searchTime"`
    Page       int      `json:"page"`
    Size       int      `json:"size"`
    Threshold  float32  `json:"threshold"`
    PicUrl     string   `json:"picUrl"`
    Feature    string   `json:"feature"`
    IsAggs     bool     `json:"isAggs"`
    InputValue string   `json:"inputValue"`
    Collection string   `json:"collection"`
    DataBases  []string `json:"databases"`//底库id集合
    Tasks      []string `json:"tasks"`//任务id集合
    TreeNodes  []string `json:"treeNodes"`//摄像机id集合
    Tabs       []string `json:"tabs"`//标签集合
    SearchTime []string `json:"searchTime"`//时间
    Page       int      `json:"page"`//当前页,从1开始
    Size       int      `json:"size"`//每页的数量
    Threshold  float32  `json:"threshold"`//阈值
    PicUrl     string   `json:"picUrl"`//上传的图片
    Feature    string   `json:"feature"`//特征
    IsAggs     bool     `json:"isAggs"`//
    InputValue string   `json:"inputValue"`//输入框
    Collection string   `json:"collection"`//
    AlarmLevel []string `json:"alarmLevel"`//布防等级
}