From 2a9ea1c76b4f493fb974154a130ce682616c5a49 Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期五, 26 七月 2019 13:48:11 +0800
Subject: [PATCH] logger
---
controllers/dbtablesCon.go | 18 +-
controllers/fileController.go | 52 +++++++---
controllers/es.go | 130 ++-----------------------
models/esSearch.go | 27 ++--
controllers/dbtableperson.go | 18 +-
5 files changed, 80 insertions(+), 165 deletions(-)
diff --git a/controllers/dbtableperson.go b/controllers/dbtableperson.go
index 0e9e2fa..bce4198 100644
--- a/controllers/dbtableperson.go
+++ b/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
diff --git a/controllers/dbtablesCon.go b/controllers/dbtablesCon.go
index e74d046..9a3cf28 100644
--- a/controllers/dbtablesCon.go
+++ b/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涓幏鍙栧簳搴搃d")
+ logger.Debug("body涓幏鍙栧簳搴搃d")
}
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, "鍒犻櫎鎴愬姛")
diff --git a/controllers/es.go b/controllers/es.go
index 0753d32..fe2afbc 100644
--- a/controllers/es.go
+++ b/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
}
diff --git a/controllers/fileController.go b/controllers/fileController.go
index 74d1b25..0f6e41f 100644
--- a/controllers/fileController.go
+++ b/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 // 鏍囪瘑鏉ユ簮鏄痺eb
+ 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澶辫触")
diff --git a/models/esSearch.go b/models/esSearch.go
index 8b542cc..81e4c76 100644
--- a/models/esSearch.go
+++ b/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"`//鎽勫儚鏈篿d闆嗗悎
+ 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"`//甯冮槻绛夌骇
}
--
Gitblit v1.8.0