From e9d0ba14154d623898803a294a25db634a9ceec7 Mon Sep 17 00:00:00 2001
From: panlei <2799247126@qq.com>
Date: 星期五, 23 八月 2019 11:14:30 +0800
Subject: [PATCH] add download so
---
controllers/cluster.go | 240 +++++++++++++++
extend/code/code.go | 1
middlewares/auth/auth.go | 32 -
service/CamraUpdatesnashot.go | 16
config/dev.yaml | 8
service/FaceCompareService.go | 53 ++
controllers/dbtableperson.go | 179 ++++------
controllers/task.go | 13
controllers/sdk.go | 2
router/router.go | 15
controllers/dbtablesCon.go | 169 +++------
controllers/fileController.go | 55 ++-
config/test.yaml | 63 ++-
controllers/taglist.go | 88 +---
extend/config/config.go | 13
15 files changed, 578 insertions(+), 369 deletions(-)
diff --git a/config/dev.yaml b/config/dev.yaml
index 00b6c79..0a5ece6 100644
--- a/config/dev.yaml
+++ b/config/dev.yaml
@@ -4,11 +4,13 @@
jwtExpire: 24
url: http://127.0.0.1:8080
imageUrl: http://192.168.1.203:6080
- publicDomain: bsic.asuscomm.com
+ publicDomain: http://bsic.asuscomm.com
networkAdapter: enp8s0
-compare:
+dbpersoncompare:
+ url: 127.0.0.1:40010
+espersoncompare:
url:
- - 127.0.0.1:40010
+ - 127.0.0.1:40011
weedfs:
ip: 192.168.1.203
uploadport: 6333
diff --git a/config/test.yaml b/config/test.yaml
index a2d7be2..cd8dca9 100644
--- a/config/test.yaml
+++ b/config/test.yaml
@@ -1,24 +1,49 @@
-runmode: test
-timezone: Asia/Chongqing
-dbLogMode: true
-addr: :8080
-name: albedo
-url: http://127.0.0.1:8080
+server:
+ runmode: debug
+ jwtSecret: BASIC
+ jwtExpire: 24
+ url: http://127.0.0.1:8080
+ imageUrl: http://192.168.1.203:6080
+ publicDomain: http://192.168.1.203
+ networkAdapter: enp8s0
+dbpersoncompare:
+ url: 127.0.0.1:40010
+espersoncompare:
+ url:
+ - 127.0.0.1:40011
+weedfs:
+ ip: 192.168.1.203
+ uploadport: 6333
+ visitport: 6080
redis:
host: 127.0.0.1
port: 6379
password: password
db: 1
-db:
-# 鍙�夊�硷細mysql銆乻qlite
- driver: mysql
- name: db_apiserver
- addr: 127.0.0.1:3306
- username: root
- password: root
-docker_db:
- driver: mysql
- name: db_apiserver
- addr: 127.0.0.1:3306
- username: root
- password: root
+database:
+ driver: sqlite
+ name: sqlite3
+ filepath: config/testdb
+# es 鏁版嵁 绱㈠紩 浠ュ強 ip 绔彛 閰嶇疆
+es:
+ masterip: 192.168.1.182
+ httpport: 9200
+ index:
+ # 浜鸿劯鎶撴媿璁板綍
+ videopersons:
+ index: videopersons
+ type: perVideoPicture
+ # 搴曞簱 鍒楄〃
+ dbtables:
+ index: dbtables
+ type: dbpersontables
+ # 搴曞簱浜哄憳搴�
+ dbtablepersons:
+ index: dbtablepersons
+ type: dbpersons
+ # 琛屼负鎶撴媿璁板綍*
+ personaction:
+ index: personaction
+ type: perVideoAction
+
+
diff --git a/controllers/cluster.go b/controllers/cluster.go
new file mode 100644
index 0000000..7ac903d
--- /dev/null
+++ b/controllers/cluster.go
@@ -0,0 +1,240 @@
+package controllers
+
+import (
+ "basic.com/dbapi.git"
+ "fmt"
+ "github.com/gin-gonic/gin"
+ "math/rand"
+ "time"
+ "webserver/extend/code"
+ "webserver/extend/util"
+)
+
+type ClusterController struct {
+
+}
+
+type Cluster struct {
+ ClusterId string `json:"cluster_id"`
+ ClusterName string `json:"cluster_name"`
+ Password string `json:"password"`
+ VirtualIp string `json:"virtual_ip"`
+}
+
+type Node struct {
+ Id string `json:"id"`
+ ClusterId string `json:"cluster_id"`
+ NodeName string `json:"node_name"`
+ NodeId string `json:"node_id"`
+ NodeIp string `json:"node_ip"`
+ CreateTime string `json:"create_time"`
+ IsAlive int
+}
+
+type ClusterVo struct {
+ ClusterInfo Cluster `json:"clusterInfo"`
+ Nodes []Node `json:"nodes"`
+}
+
+type ClusterCreateVo struct {
+ Password string `json:"password"`
+ ClusterName string `json:"clusterName"`
+ ClusterId string `json:"clusterId"`
+}
+
+type ClusterSearchVo struct {
+ Password string `json:"password"`
+ SearchNum string `json:"searchNum"`
+}
+
+type ClusterJoinVo struct {
+ ClusterId string `json:"clusterId"`
+ Password string `json:"password"`
+ NodeIps []string `json:"nodeIps"`
+}
+
+// @Summary 鍒涘缓闆嗙兢
+// @Description 鍒涘缓闆嗙兢
+// @Accept json
+// @Produce json
+// @Tags cluster
+// @Param clusterArg body controllers.ClusterCreateVo true "闆嗙兢鍒涘缓鍙傛暟"
+// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
+// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
+// @Router /data/api-v/cluster/create [post]
+func (cc ClusterController) Create(c *gin.Context) {
+ var clusterVo ClusterCreateVo
+ err := c.BindJSON(&clusterVo)
+ if err !=nil || clusterVo.Password == "" || clusterVo.ClusterName == "" {
+ util.ResponseFormat(c,code.RequestParamError, "鍙傛暟鏈夎")
+ return
+ }
+ var api dbapi.ClusterApi
+ b, d := api.Create(clusterVo.ClusterName, clusterVo.Password)
+ if b {
+ util.ResponseFormat(c,code.Success, d)
+ } else {
+ util.ResponseFormat(c,code.ComError,"鍒涘缓澶辫触")
+ }
+}
+
+// @Summary 鐢熸垚闆嗙兢6浣嶉殢鏈哄瘑鐮�
+// @Description 鐢熸垚闆嗙兢6浣嶉殢鏈哄瘑鐮�
+// @Produce json
+// @Tags cluster
+// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
+// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
+// @Router /data/api-v/cluster/randomPwd [get]
+func (cc ClusterController) RandomPwd(c *gin.Context) {
+ pwd := fmt.Sprintf("%06v", rand.New(rand.NewSource(time.Now().UnixNano())).Int31n(1000000))
+ util.ResponseFormat(c,code.Success,pwd)
+}
+
+// @Summary 鏌ヨ鏈湴闆嗙兢
+// @Description 鏌ヨ鏈湴闆嗙兢
+// @Produce json
+// @Tags cluster
+// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
+// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
+// @Router /data/api-v/cluster/findCluster [get]
+func (cc ClusterController) FindCluster(c *gin.Context) {
+ var clusterApi dbapi.ClusterApi
+ b, d := clusterApi.FindCluster()
+ if b {
+ util.ResponseFormat(c,code.Success, d)
+ } else {
+ util.ResponseFormat(c,code.ComError,"闆嗙兢鏌ヨ澶辫触")
+ }
+}
+
+// @Summary 鎼滅储闆嗙兢
+// @Description 鎼滅储闆嗙兢
+// @Accept json
+// @Produce json
+// @Tags cluster
+// @Param searchArg body controllers.ClusterSearchVo true "闆嗙兢鎼滅储鍙傛暟"
+// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
+// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
+// @Router /data/api-v/cluster/search [post]
+func (cc ClusterController) Search(c *gin.Context) {
+ var csv ClusterSearchVo
+ err := c.BindJSON(&csv)
+ if err !=nil || csv.Password == ""{
+ util.ResponseFormat(c,code.RequestParamError, "鍙傛暟鏈夎")
+ return
+ }
+ var api dbapi.ClusterApi
+ b,d := api.Search(csv.SearchNum, csv.Password)
+ if b {
+ util.ResponseFormat(c,code.Success, d)
+ } else {
+ util.ResponseFormat(c,code.ComError,"鎼滅储澶辫触")
+ }
+}
+
+// @Summary 閫氳繃searchNum寮傛鑾峰彇闆嗙兢鑺傜偣淇℃伅
+// @Description 閫氳繃searchNum寮傛鑾峰彇闆嗙兢鑺傜偣淇℃伅
+// @Accept json
+// @Produce json
+// @Tags cluster
+// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
+// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
+// @Router /data/api-v/cluster/getNodesByNum [get]
+func (cc ClusterController) GetSearchNodes(c *gin.Context) {
+ var api dbapi.ClusterApi
+ b, d := api.GetSearchNodes()
+ if b {
+ util.ResponseFormat(c,code.Success,d)
+ } else {
+ util.ResponseFormat(c,code.ClusterNodesEmpty,[]interface{}{})
+ }
+}
+
+// @Summary 閫氳繃searchNum鍋滄鎼滅储
+// @Description 閫氳繃searchNum鍋滄鎼滅储
+// @Produce json
+// @Tags cluster
+// @Param searchNum query string true "鎼滅储缂栧彿"
+// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
+// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
+// @Router /data/api-v/cluster/stopSearching [post]
+func (cc ClusterController) StopSearching(c *gin.Context) {
+ searchNum := c.Query("searchNum")
+ if searchNum == "" {
+ util.ResponseFormat(c,code.RequestParamError, "鍙傛暟鏈夎")
+ return
+ }
+ var api dbapi.ClusterApi
+ b, d := api.StopSearching(searchNum)
+ if b {
+ util.ResponseFormat(c,code.Success, d)
+ } else {
+ util.ResponseFormat(c,code.ComError,"鍋滄澶辫触")
+ }
+}
+
+
+// @Summary 鍔犲叆闆嗙兢
+// @Description 鍔犲叆闆嗙兢
+// @Accept json
+// @Produce json
+// @Tags cluster
+// @Param clusterArg body controllers.ClusterCreateVo true "闆嗙兢鍒涘缓鍙傛暟"
+// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
+// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
+// @Router /data/api-v/cluster/joinCluster [post]
+func (cc ClusterController) JoinCluster(c *gin.Context) {
+ var arg ClusterJoinVo
+ err := c.BindJSON(&arg)
+ if err!=nil || arg.ClusterId == "" || arg.Password == "" || len(arg.NodeIps) == 0{
+ util.ResponseFormat(c,code.RequestParamError, "鍙傛暟鏈夎")
+ return
+ }
+ var api dbapi.ClusterApi
+ paramBody := util.Struct2Map(arg)
+ b, d := api.JoinCluster(paramBody)
+ if b {
+ util.ResponseFormat(c,code.Success,d)
+ } else {
+ util.ResponseFormat(c,code.ComError,"鍔犲叆澶辫触")
+ }
+}
+
+// @Summary 淇濆瓨闆嗙兢鍚嶇О
+// @Description 淇濆瓨闆嗙兢鍚嶇О
+// @Produce json
+// @Tags cluster
+// @Param clusterName query string true "闆嗙兢鍚嶇О"
+// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
+// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
+// @Router /data/api-v/cluster/updateClusterName [post]
+func (cc ClusterController) UpdateClusterName(c *gin.Context) {
+ clusterName := c.PostForm("clusterName")
+ if clusterName == "" {
+ util.ResponseFormat(c,code.RequestParamError, "鍙傛暟鏈夎")
+ return
+ }
+ var api dbapi.ClusterApi
+ b,_ := api.UpdateClusterName(clusterName)
+ if b {
+ util.ResponseFormat(c,code.UpdateSuccess,"鏇存柊鎴愬姛")
+ } else {
+ util.ResponseFormat(c,code.ComError, "鏇存柊澶辫触")
+ }
+}
+
+// @Summary 閫�鍑洪泦缇�
+// @Description 閫�鍑洪泦缇�
+// @Produce json
+// @Tags cluster
+// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
+// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
+// @Router /data/api-v/cluster/leave [post]
+func (cc ClusterController) Leave(c *gin.Context) {
+ var api dbapi.ClusterApi
+ if b,_:= api.Leave();b {
+ util.ResponseFormat(c,code.Success,"閫�鍑烘垚鍔�")
+ } else {
+ util.ResponseFormat(c,code.ComError,"閫�鍑哄け璐�")
+ }
+}
\ No newline at end of file
diff --git a/controllers/dbtableperson.go b/controllers/dbtableperson.go
index ca4a0d9..9afabe9 100644
--- a/controllers/dbtableperson.go
+++ b/controllers/dbtableperson.go
@@ -1,10 +1,9 @@
package controllers
import (
+ "basic.com/dbapi.git"
"encoding/json"
- "log"
"strconv"
- "time"
"webserver/extend/logger"
"github.com/gin-gonic/gin"
@@ -31,38 +30,45 @@
// @Router /data/api-v/dbperson/addDbPerson [PUT]
func (dbc DbPersonController) AddDbPerson(c *gin.Context) {
dbperson := new(models.Dbtablepersons)
- c.BindJSON(&dbperson)
- if dbperson.TableId == "" {
+ err := c.BindJSON(&dbperson)
+ if err!=nil || dbperson.TableId == "" {
// 搴曞簱id涓嶅瓨鍦�
- c.JSON(401, "TableId 涓嶅瓨鍦�")
+ util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎")
return
}
- result := addDbPerson(dbperson)
- if result["success"].(bool) {
- //code.Success.Message = "娣诲姞搴曞簱浜哄憳鎴愬姛"
- util.ResponseFormat(c, code.Success, result["data"])
+ var pApi dbapi.DbPersonApi
+ paramBody := util.Struct2Map(dbperson)
+ b, data := pApi.AddDbPerson(paramBody)
+ if b {
+ util.ResponseFormat(c, code.Success, data)
} else {
- //code.ServiceInsideError.Message += result["msg"].(string)
- util.ResponseFormat(c, code.ServiceInsideError, result["data"])
+ util.ResponseFormat(c, code.ServiceInsideError, "")
}
}
func addDbPerson(dbperson *models.Dbtablepersons) (result map[string]interface{}) {
- personId := uuid.NewV4().String() // 浠ュ悗鏇夸唬 渚濇嵁鐢熸垚瑙勫垯
+ personId := uuid.NewV4().String()
dbperson.Id = personId
dbperson.PriInsert()
- url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
- "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexType + "/" + personId + "?refresh=wait_for"
- personbytes, e := json.Marshal(dbperson)
- if e != nil {
- logger.Debug("Json marshaling failed锛�%s\n", e)
- }
- params := string(personbytes)
- data, _ := esutil.PutEsDataReq(url, params)
- //c.JSON(200, changeEsRespData(data, "娣诲姞浜哄憳鎴愬姛"))
- result = changeEsRespData(data, "娣诲姞鎴愬姛")
+ var pApi dbapi.DbPersonApi
+ paramBody := util.Struct2Map(dbperson)
+ b, _ := pApi.AddDbPerson(paramBody)
+ result = map[string]interface{}{}
+ if b {
+ result["code"] = 200
+ data := make(map[string]interface{})
+ data["uuid"] = personId
+ result["data"] = data
+ result["success"] = true
+ result["msg"] = "娣诲姞鎴愬姛"
+ } else {
+ result["data"] = nil
+ result["success"] = false
+ result["msg"] = "鏈嶅姟鍣ㄥ紓甯�"
+ result["code"] = 500
+ }
return result
}
@@ -77,30 +83,19 @@
// @Router /data/api-v/dbperson/updateDbPerson [POST]
func (dbc DbPersonController) UpdateDbPerson(c *gin.Context) {
var dbperson models.Dbtablepersons
- c.BindJSON(&dbperson)
- personid := dbperson.Id
- if personid == "" {
+ err := c.BindJSON(&dbperson)
+ if err !=nil || dbperson.Id == "" {
util.ResponseFormat(c, code.RequestParamError, nil)
return
}
dbperson.PriUpdate()
- url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
- "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexType + "/" + personid + "/_update?refresh=wait_for"
- dbTableByte, err := json.Marshal(dbperson)
- if err != nil {
- log.Fatalf("Json marshaling failed锛�%s", err)
- }
- //logger.Debugf("%s\n", dbTableByte)
- params := "{\"doc\":" + string(dbTableByte) + "}"
- logger.Debug("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params)
- data := esutil.GetEsDataReq(url, params, false)
- //c.JSON(200, changeEsRespData(data,"淇敼鎴愬姛"))
- result := changeEsRespData(data, "淇敼鎴愬姛")
- if result["success"].(bool) {
- util.ResponseFormat(c, code.Success, result["data"])
+ var pApi dbapi.DbPersonApi
+ paramBody := util.Struct2Map(dbperson)
+ b, data := pApi.UpdateDbPerson(paramBody)
+ if b {
+ util.ResponseFormat(c, code.Success, data)
} else {
- //code.ServiceInsideError.Message += result["msg"].(string)
- util.ResponseFormat(c, code.ServiceInsideError, result["data"])
+ util.ResponseFormat(c, code.ServiceInsideError, "")
}
}
@@ -155,21 +150,17 @@
// @Router /data/api-v/dbperson/deleteDbPersonById/{uuid} [POST]
func (dbc DbPersonController) DeleteDbPerson(c *gin.Context) {
- uuid := c.Params.ByName("uuid")
- 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") + "\"}}"
- logger.Debug("鍒犻櫎璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params)
-
- data := esutil.GetEsDataReq(url, params, false)
-
- //c.JSON(200, changeEsRespData(data,"鍒犻櫎鎴愬姛"))
- result := changeEsRespData(data, "鍒犻櫎鎴愬姛")
- if result["success"].(bool) {
- util.ResponseFormat(c, code.Success, result["data"])
+ id := c.Params.ByName("uuid")
+ if id == "" {
+ util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎")
+ return
+ }
+ var pApi dbapi.DbPersonApi
+ b, data := pApi.DeleteDbPerson(id)
+ if b {
+ util.ResponseFormat(c, code.Success, data)
} else {
- //code.ServiceInsideError.Message += result["msg"].(string)
- util.ResponseFormat(c, code.ServiceInsideError, result["data"])
+ util.ResponseFormat(c, code.ServiceInsideError, "鍒犻櫎澶辫触")
}
}
@@ -184,37 +175,18 @@
// @Router /data/api-v/dbperson/deleteMoreDbPerson [POST]
func (dbc DbPersonController) DeleteMoreDbPerson(c *gin.Context) {
uuids := make([]string, 0, 5)
- c.BindJSON(&uuids)
- bytes, _ := json.Marshal(uuids)
- s := string(bytes)
- url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
- "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/_update_by_query?refresh" // + 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 + "}}}"
- logger.Debug("鍒犻櫎璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params)
- data := esutil.GetEsDataReq(url, params, false)
- //c.JSON(200, changeEsRespData(data,"鍒犻櫎鎴愬姛"))
- //result := changeEsRespData(data, "鍒犻櫎鎴愬姛")
- if data["error"] == nil {
- //code.Success.Message = "鍒犻櫎搴曞簱浜哄憳鎴愬姛"
- //dbperArr, e := esApi.Dbpersoninfosbyid(uuids, config.EsInfo.EsIndex.Dbtablepersons.IndexName, config.EsInfo.Masterip, config.EsInfo.Httpport)
- //if e ==nil && len(dbperArr) > 0{
- // for _,esPer :=range dbperArr {
- // if esPer.TableId !=""{
- // discovery.AddDbMessage(&protomsg.EsPersonCacheChange{
- // Type: protomsg.EsCacheChanged_T_DbTablePerson,
- // PersonId: esPer.Id,
- // TableId: []string{ esPer.TableId },
- // Feature: "",
- // Action: protomsg.DbAction_Delete,
- // })
- // }
- // }
- //}
+ err := c.BindJSON(&uuids)
+ if err !=nil || len(uuids)==0{
+ util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎")
+ return
+ }
+ var pApi dbapi.DbPersonApi
+ paramBody := util.Struct2Map(uuids)
+ b, _ := pApi.DeleteMoreDbPerson(paramBody)
+ if b {
util.ResponseFormat(c, code.Success, "鍒犻櫎搴曞簱浜哄憳鎴愬姛")
} else {
- //code.ServiceInsideError.Message += result["msg"].(string)
- util.ResponseFormat(c, code.ServiceInsideError, data["error"])
+ util.ResponseFormat(c, code.ServiceInsideError, "鍒犻櫎澶辫触")
}
}
@@ -228,15 +200,17 @@
// @Failure 500 {string} json "{code:500, msg:"杩斿洖閿欒淇℃伅", success:false,data:{}}"
// @Router /data/api-v/dbperson/queryDbPersonsByTbId [POST]
func (dbc DbPersonController) QueryDbPersonsByTbId(c *gin.Context) {
- url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
- "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/_search"
reqBody := make(map[string]interface{}, 5)
c.BindJSON(&reqBody)
tableId := ""
if reqBody["tableId"] != nil {
tableId = reqBody["tableId"].(string)
}
- orderName := "_id"
+ if tableId == "" {
+ util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎锛屽簳搴搃d涓嶈兘涓虹┖")
+ return
+ }
+ orderName := "id"
if reqBody["orderName"] != nil {
orderName = reqBody["orderName"].(string)
} // 鍒楀悕
@@ -256,17 +230,9 @@
if reqBody["size"] != nil {
size = int(reqBody["size"].(float64))
} // 鏉℃暟
- from := (page - 1) * size
- syncTerm := ""
- contentParam := ""
+
if tableId == "all" || tableId == "" {
// / 鎵�鏈変汉鍛�
- } else {
- syncTerm = "{\"term\":{\"tableId\":\"" + tableId + "\"}}" // 搴曞簱浜哄憳
- }
- if contentValue != "" {
- contentParam = ",\"must\":[{\"multi_match\":{\"query\":\"" + contentValue + "\",\"type\":\"best_fields\"," +
- "\"fields\":[\"personName\",\"sex\",\"idCard\",\"phoneNum\"],\"tie_breaker\":0.3}}]"
}
if orderType == "desc" {
@@ -274,12 +240,21 @@
} else {
orderType = "asc"
}
-
- params := "{\"query\":{\"bool\":{\"must_not\":[" +
- "{\"term\":{\"isDelete\":\"1\"}}],\"filter\":[" + syncTerm + "]" + contentParam + "}},\"from\":" + strconv.Itoa(from) + ",\"size\":" + strconv.Itoa(size) + ",\"sort\":{\"" + orderName + "\":{\"order\":\"" + orderType + "\"}}}"
- data := esutil.GetEsDataReq(url, params, true)
- //c.JSON(200, data)
- util.ResponseFormat(c, code.Success, data)
+ var pApi dbapi.DbPersonApi
+ paramBody := map[string]interface{}{
+ "tableId":tableId,
+ "orderName":orderName,
+ "orderType":orderType,
+ "contentValue":contentValue,
+ "page":page,
+ "size":size,
+ }
+ b, data := pApi.QueryDbPersonsByTbId(paramBody)
+ if b{
+ util.ResponseFormat(c,code.Success,data)
+ } else {
+ util.ResponseFormat(c,code.ComError,[]interface{}{})
+ }
}
// @Summary 鏌ヨ搴曞簱浜哄憳鍒楄〃
diff --git a/controllers/dbtablesCon.go b/controllers/dbtablesCon.go
index 82daabe..fd8ddd0 100644
--- a/controllers/dbtablesCon.go
+++ b/controllers/dbtablesCon.go
@@ -6,7 +6,6 @@
"fmt"
"github.com/gin-gonic/gin"
"github.com/satori/go.uuid"
- "log"
"time"
"webserver/extend/code"
"webserver/extend/config"
@@ -29,28 +28,14 @@
// @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}"
// @Router /data/api-v/dbtable/queryDbTables/{isSync} [POST]
func (dbt DbTableController) QueryDbTables(c *gin.Context) {
- url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
- "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/_search"
isSync := c.Params.ByName("isSync")
- var setApi dbapi.SysSetApi
- _, sysconf := setApi.GetServerInfo()
- analyServerFilterStr := ""
- if isSync == "1" {
- analyServerFilterStr = "{\"term\":{\"analyServerId\":\"\"}}" // / 鍚屾搴�
- } else if isSync == "2" {
- analyServerFilterStr = "{\"term\":{\"analyServerId\":\"" + sysconf.ServerId + "\"}}" // 鏈湴搴�
+ var tApi dbapi.DbTableApi
+ b, data := tApi.QueryDbTables(isSync)
+ if b{
+ util.ResponseFormat(c, code.Success, data)
+ } else {
+ util.ResponseFormat(c,code.ComError,[]interface{}{})
}
- if analyServerFilterStr != "" {
- analyServerFilterStr = "," + analyServerFilterStr
- }
- params := "{\"query\":{\"bool\":{\"must\":[" +
- "{\"term\":{\"isDelete\":\"0\"}}" + analyServerFilterStr + "]}}," +
- "\"from\":0,\"size\":1000,\"sort\":{\"id\":{\"order\":\"asc\"}}}"
- 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)
}
// 渚濇嵁搴曞簱id 鏌ヨ鏁版嵁
@@ -73,60 +58,35 @@
// @Router /data/api-v/dbtable/updateDbTables [POST]
func (dbt DbTableController) UpdateDbTables(c *gin.Context) {
dbtable := new(models.Dbtables)
- c.BindJSON(&dbtable)
- uuid := c.Params.ByName("id")
- if uuid == "" {
- uuid = dbtable.Id
- logger.Debug("body涓幏鍙栧簳搴搃d")
+ err := c.BindJSON(&dbtable)
+ if err !=nil || dbtable.Id == "" || dbtable.TableName == "" {
+ util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎")
+ return
}
- if dbtable.EndTime == "" {
- flag := UpdateEndTime(dbtable.Id)
- if flag == false {
- util.ResponseFormat(c, code.ServiceInsideError, "淇敼澶辫触")
- }
- }
- url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
- "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + config.EsInfo.EsIndex.DbTables.IndexType + "/" + uuid + "/_update?refresh=wait_for"
- dbtable.PriUpdate()
- dbTableByte, err := json.Marshal(dbtable)
- if err != nil {
- log.Fatalf("Json marshaling failed锛�%s", err)
- }
- logger.Debug("%s\n", dbTableByte)
- params := "{\"doc\":" + string(dbTableByte) + "}"
- logger.Debug("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params)
- data := esutil.GetEsDataReq(url, params, false)
- //c.JSON(200, changeEsRespData(data, "淇敼鎴愬姛"))
- result := changeEsRespData(data, "淇敼鎴愬姛")
- if dbtable.Enable == 0 {
- res := UpdateDbPersonsOfDbTable(dbtable.Id)
- //fmt.Println("鍚屾淇敼浜哄憳鐘舵�佹垚鍔�----",res)
- logger.Debug("鍚屾淇敼浜哄憳鐘舵�佹垚鍔�----", res)
- }
- if result["success"].(bool) {
- //code.Success.Message = "淇敼搴曞簱鎴愬姛"
- //if dbtable.Enable ==1 {
- // discovery.AddDbMessage(&protomsg.EsPersonCacheChange{
- // Type: protomsg.EsCacheChanged_T_DbTable,
- // PersonId: "",
- // TableId: []string{ dbtable.Id },
- // Feature: "",
- // Action: protomsg.DbAction_Insert,
- // })
- //} else {
- // discovery.AddDbMessage(&protomsg.EsPersonCacheChange{
- // Type: protomsg.EsCacheChanged_T_DbTable,
- // PersonId: "",
- // TableId: []string{ dbtable.Id },
- // Feature: "",
- // Action: protomsg.DbAction_Delete,
- // })
- //}
- util.ResponseFormat(c, code.Success, result["data"])
+ paramBody := util.Struct2Map(dbtable)
+ var tApi dbapi.DbTableApi
+ b, data := tApi.UpdateDbTables(paramBody)
+ if b{
+ util.ResponseFormat(c,code.UpdateSuccess,data)
} else {
- //code.ServiceInsideError.Message += result["msg"].(string)
- util.ResponseFormat(c, code.ServiceInsideError, result["data"])
+ util.ResponseFormat(c,code.ComError,"鏇存柊澶辫触")
}
+
+ //if dbtable.EndTime == "" {
+ // flag := UpdateEndTime(dbtable.Id)
+ // if flag == false {
+ // util.ResponseFormat(c, code.ServiceInsideError, "淇敼澶辫触")
+ // }
+ //}
+ //
+ //if dbtable.Enable == 0 {
+ // res := UpdateDbPersonsOfDbTable(dbtable.Id)
+ //}
+ //if result["success"].(bool) {
+ // util.ResponseFormat(c, code.Success, result["data"])
+ //} else {
+ // util.ResponseFormat(c, code.ServiceInsideError, result["data"])
+ //}
}
func UpdateEndTime(id string) (flag bool) {
@@ -168,19 +128,25 @@
// @Router /data/api-v/dbtable/addDbTableInfo [PUT]
func (dbt DbTableController) AddDbTableInfo(c *gin.Context) {
dbtable := new(models.Dbtables)
- c.BindJSON(&dbtable)
- tableId := uuid.NewV4().String()
- dbtable.Id = tableId
+ err := c.BindJSON(&dbtable)
+ if err!=nil || dbtable.TableName==""{
+ util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎")
+ return
+ }
+ dbtable.Id = uuid.NewV4().String()
if dbtable.AnalyServerId == "sync" {
dbtable.AnalyServerId = ""
}
if dbtable.AnalyServerId == "local" {
var setApi dbapi.SysSetApi
- _, sysconf := setApi.GetServerInfo()
+ flag, sysconf := setApi.GetServerInfo()
+ if !flag {
+ util.ResponseFormat(c,code.ComError,"鏈嶅姟鍣ㄥ熀鏈厤缃湁璇�,璇锋鏌�")
+ return
+ }
dbtable.AnalyServerId = sysconf.ServerId
}
- url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
- "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/" + config.EsInfo.EsIndex.DbTables.IndexType + "/" + tableId + "?refresh=wait_for"
+
dbtable.PriInsert() // 娣诲姞鏃堕棿鍜屽垱寤轰汉
currentTime := time.Now()
@@ -202,22 +168,14 @@
} else {
dbtable.Enable = 0
}
- dbTableByte, err := json.Marshal(dbtable)
- if err != nil {
- log.Fatalf("Json marshaling failed锛�%s", err)
- }
- //logger.Debugf("%s\n", dbTableByte)
- params := string(dbTableByte)
- logger.Debug("璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params)
- data, _ := esutil.PutEsDataReq(url, params)
- //c.JSON(200, changeEsRespData(data, "娣诲姞鎴愬姛"))
- result := changeEsRespData(data, "娣诲姞鎴愬姛")
- if result["success"].(bool) {
- //code.Success.Message = "娣诲姞搴曞簱鎴愬姛"
- util.ResponseFormat(c, code.Success, result["data"])
+
+ paramBody := util.Struct2Map(dbtable)
+ var tApi dbapi.DbTableApi
+ b, data := tApi.AddDbTableInfo(paramBody)
+ if b {
+ util.ResponseFormat(c,code.AddSuccess, data)
} else {
- //code.ServiceInsideError.Message += result["msg"].(string)
- util.ResponseFormat(c, code.ServiceInsideError, result["data"])
+ util.ResponseFormat(c,code.ComError,"鏂板澶辫触")
}
}
@@ -226,25 +184,22 @@
// @Accept x-www-form-urlencoded
// @Produce json
// @Tags dbtable
-// @Param uuid path string true "搴曞簱id "
+// @Param id path string true "搴曞簱id "
// @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false}"
// @Router /data/api-v/dbtable/deleteDBtablesById/{id} [POST]
func (dbt DbTableController) DeleteDbTables(c *gin.Context) {
- uuid := c.Params.ByName("id")
- 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}}"
- logger.Debug("鍒犻櫎璇锋眰url:%s;\n 璇锋眰鍙傛暟params:%s", url, params)
- data := esutil.GetEsDataReq(url, params, false)
- //c.JSON(200, changeEsRespData(data, "鍒犻櫎鎴愬姛"))
- result := changeEsRespData(data, "鍒犻櫎鎴愬姛")
- if result["success"].(bool) {
- //code.Success.Message = "鍒犻櫎搴曞簱鎴愬姛"
- util.ResponseFormat(c, code.Success, result["data"])
+ id := c.Params.ByName("id")
+ if id == "" {
+ util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎")
+ return
+ }
+ var tApi dbapi.DbTableApi
+ b, data := tApi.DeleteById(id)
+ if b {
+ util.ResponseFormat(c,code.DelSuccess,data)
} else {
- //code.ServiceInsideError.Message += result["msg"].(string)
- util.ResponseFormat(c, code.ServiceInsideError, result["data"])
+ util.ResponseFormat(c,code.ComError,"鍒犻櫎澶辫触")
}
}
diff --git a/controllers/fileController.go b/controllers/fileController.go
index b1b1ba4..a4c67ae 100644
--- a/controllers/fileController.go
+++ b/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 {//鏈夋瘮瀵笶s鎶撴媿
+ 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("涓婁紶鍒皐eedfs鐢ㄦ椂:", 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 // 鐗瑰緛鍊糱ase64 鐮�
result := addDbPerson(dbperson)
diff --git a/controllers/sdk.go b/controllers/sdk.go
index c95e36f..de1930b 100644
--- a/controllers/sdk.go
+++ b/controllers/sdk.go
@@ -34,7 +34,9 @@
Name string `json:"name"` //鍙傛暟鍚嶇О
Type string `json:"type"` //鍙傛暟绫诲瀷(鏁存暟锛屽瓧绗︿覆鎴栨暟缁�)
Must bool `json:"must"` //鏄惁蹇呭~
+ Unit string `json:"unit"`
Range string `json:"range"` //鍊肩殑鑼冨洿锛宔g锛�0,100琛ㄧず浠�0鍒�100
+ DefaultValue string `json:"default_value"`
Sort int `json:"sort"` //鍙傛暟椤哄簭
}
diff --git a/controllers/taglist.go b/controllers/taglist.go
index 802b018..107532e 100644
--- a/controllers/taglist.go
+++ b/controllers/taglist.go
@@ -2,81 +2,45 @@
import (
"basic.com/dbapi.git"
- "encoding/json"
- "fmt"
+ "webserver/extend/code"
+ "webserver/extend/util"
"github.com/gin-gonic/gin"
- "webserver/extend/code"
- "webserver/extend/config"
- "webserver/extend/esutil"
- "webserver/extend/util"
)
-//鏍囩鍒楄〃
-//浠诲姟鍒楄〃
// @Summary 鏍囩鍒楄〃
// @Description 杩斿洖搴曞簱鏍囩
// @Accept json
// @Produce json
// @Tags es
-// @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/taskList [POST]
func (sc *EsSearchController) PostEsTagList(c *gin.Context) {
- url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
- "/" + config.EsInfo.EsIndex.DbTables.IndexName + "/_search"
- var setApi dbapi.SysSetApi
- _, sysconf := setApi.GetServerInfo()
- prama := "{\"query\":{\"bool\":{\"filter\":[{\"terms\":{\"analyServerId\":[\"\",\"" + sysconf.ServerId + "\"]}}]}},\"size\":1000}"
- tokenRes := esutil.GetEsDataReq(url, prama, true)
- sources := make([]map[string]interface{}, 0)
- for _, value := range tokenRes["datalist"].([]interface{}) {
- tokenRes := make(map[string]interface{})
- tr := value.(map[string]interface{})
- key := tr["id"].(string)
- tokenRes["key"] = key
- tokenRes["title"] = tr["tableName"].(string)
- tokenRes["value"] = tr["id"].(string)
- status := int(tr["isDelete"].(float64))
- tokenRes["status"] = status
- if status == 1 {
- if GetTotalFromDb(key) == false {
- continue
+ var dtApi dbapi.DbTableApi
+ var dbpApi dbapi.DbPersonApi
+ dts, err := dtApi.FindAllDbTablesByCurServer()
+ if err == nil {
+ if dts !=nil {
+ sources := make([]map[string]interface{}, 0)
+ for _, dt := range dts {
+ tokenRes := make(map[string]interface{})
+ tokenRes["key"] = dt.Id
+ tokenRes["title"] = dt.TableName
+ tokenRes["value"] = dt.Id
+ tokenRes["status"] = dt.IsDelete
+ if dt.IsDelete == 1 {
+ personTotal,_ := dbpApi.GetPersonTotal(dt.Id)
+ if personTotal == 0 {
+ continue
+ }
+ }
+ sources = append(sources, tokenRes)
}
+ util.ResponseFormat(c, code.Success, sources)
+ return
}
- sources = append(sources, tokenRes)
}
- util.ResponseFormat(c, code.Success, sources)
-}
-
-//鍒ゆ柇搴曞簱鏄惁鏈夋暟鎹�
-func GetTotalFromDb(id string) (flag bool) {
- flag = false
- url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
- "/" + config.EsInfo.EsIndex.VideoPersons.IndexName + "/_search"
- prama := "{\"query\":{\"bool\":{\"filter\":[{\"term\":{\"baseInfo.tableId\":\"" + id + "\"}}]}},\"size\":0}"
- buf, err := esutil.EsReq("POST", url, []byte(prama))
- if err != nil {
- fmt.Println("http request info is err!")
- return
- }
- var info interface{}
- json.Unmarshal(buf, &info)
- out, ok := info.(map[string]interface{})
- if !ok {
- fmt.Println("http response interface can not change map[string]interface{}")
- return
- }
- middle, ok := out["hits"].(map[string]interface{})
- if !ok {
- fmt.Println("first hits change error!")
- return
- }
-
- total := int(middle["total"].(float64))
- if total > 0 {
- flag = true
- }
- return flag
+ util.ResponseFormat(c,code.ComError,"鏌ヨ搴曞簱鏍囩澶辫触")
}
diff --git a/controllers/task.go b/controllers/task.go
index ccd33ca..f27e9d0 100644
--- a/controllers/task.go
+++ b/controllers/task.go
@@ -256,7 +256,7 @@
func (tc TaskController) SaveTaskSdkRule(c *gin.Context) {
var rules TaskSdkRules
err := c.BindJSON(&rules)
- if err !=nil {
+ if err !=nil || rules.TaskId == "" || rules.SdkId == "" || len(rules.Rules) == 0 {
util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎")
return
}
@@ -277,15 +277,16 @@
// @Param id query string true "id"
// @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}"
// @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}"
-// @Router /data/api-v/task/deleteTaskSdkRuleById [post]
-func (tc TaskController) DeleteTaskSdkRuleById(c *gin.Context) {
- id := c.PostForm("id")
- if id == "" {
+// @Router /data/api-v/task/deleteTaskSdkRule [post]
+func (tc TaskController) DeleteTaskSdkRule(c *gin.Context) {
+ taskId := c.PostForm("taskId")
+ sdkId := c.PostForm("sdkId")
+ if taskId == "" || sdkId == "" {
util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎")
return
}
var api dbapi.TaskSdkRuleApi
- if api.DeleteTaskSdkRuleById(id) {
+ if api.DeleteTaskSdkRule(taskId, sdkId) {
util.ResponseFormat(c,code.Success,"鍒犻櫎鎴愬姛")
} else {
util.ResponseFormat(c,code.ComError, "鍒犻櫎澶辫触")
diff --git a/extend/code/code.go b/extend/code/code.go
index 0a5380d..93a4341 100644
--- a/extend/code/code.go
+++ b/extend/code/code.go
@@ -57,4 +57,5 @@
TaskStoped = &Code{http.StatusOK, false, "姝や换鍔′负鍋滅敤鐘舵�侊紝璇峰湪浠诲姟绠$悊涓紑鍚紒"}
ComError = &Code{http.StatusInternalServerError, false, ""}
+ ClusterNodesEmpty = &Code{http.StatusOK, true, "闆嗙兢鑺傜偣涓虹┖"}
)
diff --git a/extend/config/config.go b/extend/config/config.go
index 488ce86..35e83f6 100644
--- a/extend/config/config.go
+++ b/extend/config/config.go
@@ -69,11 +69,17 @@
var DBconf = &database{}
-type CompareServer struct {
+type dbpersoncompare struct {
+ Url string `mapstructure:"url"`
+}
+
+type espersoncompare struct {
Url []string `mapstructure:"url"`
}
-var CompServerInfo = &CompareServer{}
+var DbPersonCompInfo = &dbpersoncompare{}
+
+var EsCompServerInfo = &espersoncompare{}
// Init is an exported method that takes the environment starts the viper
@@ -93,6 +99,7 @@
viper.UnmarshalKey("redis", RedisConf)
viper.UnmarshalKey("database", DBconf)
viper.UnmarshalKey("weedfs", WeedFs)
- viper.UnmarshalKey("compare", CompServerInfo)
viper.UnmarshalKey("sopath",SoPath)
+ viper.UnmarshalKey("dbpersoncompare",DbPersonCompInfo)
+ viper.UnmarshalKey("espersoncompare", EsCompServerInfo)
}
diff --git a/middlewares/auth/auth.go b/middlewares/auth/auth.go
index 3bac107..8a23438 100644
--- a/middlewares/auth/auth.go
+++ b/middlewares/auth/auth.go
@@ -3,7 +3,6 @@
import (
"github.com/gin-gonic/gin"
"net/http"
- "regexp"
"strings"
"webserver/extend/config"
"webserver/extend/logger"
@@ -38,30 +37,27 @@
//}
c.Next()
} else if strings.Contains(urlPath,"/httpImage") {
- host := c.Request.URL.Host
- logger.Debug("host:", host)
-
- imgUrl := config.Server.ImageUrl
-
domain := config.Server.PublicDomain
- domainReg := regexp.MustCompile(``+domain+``)
- if domainReg.MatchString(host) {//鍩熷悕璁块棶
- imgUrl = domain
- }
+ //domainReg := regexp.MustCompile(``+domain+``)
+ //if domainReg.MatchString(host) {//鍩熷悕璁块棶
+ // imgUrl = domain
+ //}
urlPath = strings.Replace(urlPath, "/httpImage", "", -1)
- idx := strings.Index(urlPath, ":")
- tmpPath := urlPath
+ if strings.Contains(urlPath,domain) {
+ urlPath = strings.Replace(urlPath,"/"+domain,"",-1)
+ }
+ logger.Debug("urlPath:",urlPath)
+ idx := strings.LastIndex(urlPath, ":")
+ tmpPath := ""
if idx >-1 {//璺緞涓寘鍚湁绔彛,鍙栫鍙d互鍚庤矾寰�
tmpPath = urlPath[idx:]
- imgIndx := strings.LastIndex(imgUrl, ":")
- if imgIndx > -1 {
- imgUrl = imgUrl[:imgIndx]
- }
+ } else {
+ tmpPath = ":6080"+tmpPath
}
- logger.Debug("imgUrl+tmpPath:", imgUrl+tmpPath)
c.Header("Access-Control-Allow-Origin","*")
- c.Redirect(http.StatusMovedPermanently, imgUrl+tmpPath)
+ logger.Debug("domain+tmpPath:",domain+tmpPath)
+ c.Redirect(http.StatusMovedPermanently, domain+tmpPath)
return
} else {
c.Next()
diff --git a/router/router.go b/router/router.go
index 95b892e..97ef72f 100644
--- a/router/router.go
+++ b/router/router.go
@@ -39,6 +39,7 @@
pollConfigController := new(controllers.PollConfigController)
fileController := new(controllers.FileController)
sysMenuController :=new(controllers.SysMenuController)
+ clusterController :=new(controllers.ClusterController)
sysApi := r.Group( "/data/api-u/sys")
@@ -123,7 +124,7 @@
task.GET("/delTaskSdk", taskController.DeleteTaskSdk)
task.POST("/updateTaskName", taskController.UpdateTaskName)
task.GET("/getRulesByTaskSdk", taskController.GetRulesByTaskSdk)
- task.POST("/deleteTaskSdkRuleById", taskController.DeleteTaskSdkRuleById)
+ task.POST("/deleteTaskSdkRule", taskController.DeleteTaskSdkRule)
task.POST("/saveTaskSdkRule", taskController.SaveTaskSdkRule)
}
@@ -224,6 +225,18 @@
pollCApi.GET("/getPollConfig", pollConfigController.GetPollConfig)
pollCApi.POST("/updateEnable", pollConfigController.UpdateEnable)
}
+ clusterApi := r.Group(urlPrefix+"/cluster")
+ {
+ clusterApi.GET("/findCluster", clusterController.FindCluster)
+ clusterApi.GET("/randomPwd", clusterController.RandomPwd)
+ clusterApi.POST("/create", clusterController.Create)
+ clusterApi.POST("/search", clusterController.Search)
+ clusterApi.POST("/stopSearching", clusterController.StopSearching)
+ clusterApi.GET("/getSearchNodes", clusterController.GetSearchNodes)
+ clusterApi.POST("/joinCluster", clusterController.JoinCluster)
+ clusterApi.POST("/updateClusterName", clusterController.UpdateClusterName)
+ clusterApi.POST("/leave", clusterController.Leave)
+ }
// 鏂囦欢 涓婁紶
r.Static("static", "./static") // 闈欐�佹枃浠�
diff --git a/service/CamraUpdatesnashot.go b/service/CamraUpdatesnashot.go
index ad5ab9f..0ca5c58 100644
--- a/service/CamraUpdatesnashot.go
+++ b/service/CamraUpdatesnashot.go
@@ -1,14 +1,12 @@
package service
import (
+ "basic.com/dbapi.git"
+ "basic.com/fileServer/WeedFSClient.git"
+ "basic.com/valib/capture.git"
"errors"
- "path/filepath"
"strconv"
"webserver/extend/config"
- "webserver/extend/esutil"
-
- "basic.com/dbapi.git"
- "basic.com/valib/capture.git"
)
/*浠ヤ笅灞炰簬鏃х増鏈湴鎽勫儚鏈鸿幏鍙栨埅鍥撅紙鍥芥爣鎽勫儚鏈哄簳鍥炬棤娉曞埛鏂帮級
func PostFormBufferData(uri string, filepath string, fileName string) (maps map[string]interface{}, err0 error) {
@@ -148,17 +146,15 @@
b,err := capture.Capture("./runtime/libcffmpeg.so",m,camera.Rtsp,capture.JPEGFileExt,1280,720,10)
if err == nil{
var weedfsUri = "http://"+config.WeedFs.Ip+":"+strconv.Itoa(config.WeedFs.UploadPort)+"/submit"
- resp, err := esutil.PostFormBufferData(weedfsUri, camera.Name+".jpg", "file", b)
+ weedFilePath, err := WeedFSClient.UploadFile(weedfsUri, camera.Name+".jpg", b)
if err != nil {
return "",err
} else {
- fileurl := resp["fileUrl"].(string) // 鏂囦欢璺緞
- filename := filepath.Base(fileurl)
- ok := cameraApi.UpdateSnapshotUrl(cid, filename)
+ ok := cameraApi.UpdateSnapshotUrl(cid, weedFilePath)
if !ok {
return "", errors.New("update camera's snapshot fail")
}
- return filename, nil
+ return weedFilePath, nil
}
}else{
return "",err
diff --git a/service/FaceCompareService.go b/service/FaceCompareService.go
index bc94ee3..04d5040 100644
--- a/service/FaceCompareService.go
+++ b/service/FaceCompareService.go
@@ -63,21 +63,22 @@
var CaptureTable = "capturetable" // 鎶撴媿搴�
-func (sv *FaceCompareService) Compare() *CompareOnce{
+func (sv *FaceCompareService) CompareVideoPersons() *CompareList{
+ sv.CompareArgs.TableIds = []string { CaptureTable }
b, err := proto.Marshal(&sv.CompareArgs)
- compServerList := config.CompServerInfo.Url
- logger.Debug("compServerList:", compServerList)
- //1.鍚戝悇涓猚ompare杩涚▼鍙戣捣璇锋眰鎷垮埌姣斿缁撴灉
+ esCompServerList := config.EsCompServerInfo.Url
+ logger.Debug("compServerList:", esCompServerList)
+ //1.鍚戝悇涓狤s compare杩涚▼鍙戣捣璇锋眰鎷垮埌姣斿缁撴灉
var resultList CompareList
- //resultList :=make([]*protomsg.SdkCompareEach,0)
- for _,str :=range compServerList{
+
+ for _,str :=range esCompServerList{
reqUrl := "tcp://"+str
resultB := doCompareRequest(reqUrl,b)
if resultB == nil || len(*resultB) ==0 {
continue
}
var sdkCompResult protomsg.SdkCompareResult
- //rList :=make([]protomsg.Esinfo,0)
+
err = proto.Unmarshal(*resultB, &sdkCompResult)
if err !=nil {
logger.Debug("comp sdkCompareResult unmarshal err:", err)
@@ -87,19 +88,41 @@
logger.Debug("comp len(rList):", len(sdkCompResult.CompareResult))
if len(sdkCompResult.CompareResult) >0 {
resultList = append(resultList, sdkCompResult.CompareResult...)
- //resultList = append(resultList, FillDataToCompareResult(&sdkCompResult)...)
}
}
logger.Debug("comp totalList.len:", len(resultList))
- //2.缂撳瓨姣斿缁撴灉
- co := &CompareOnce{
- CompareNum: sv.CompareNum,
- CompareData: &resultList,
- }
- SetCompResultByNum(co)
+ return &resultList
+}
- return co
+//姣斿搴曞簱
+func (sv *FaceCompareService) CompareDbPersons() *CompareList{
+ b, err := proto.Marshal(&sv.CompareArgs)
+ dbPersonCompServerUrl := config.DbPersonCompInfo.Url
+ logger.Debug("comp Server url:", dbPersonCompServerUrl)
+
+ var resultList CompareList
+
+ reqUrl := "tcp://"+dbPersonCompServerUrl
+ resultB := doCompareRequest(reqUrl,b)
+ if resultB == nil || len(*resultB) ==0 {
+ return nil
+ }
+ var sdkCompResult protomsg.SdkCompareResult
+ err = proto.Unmarshal(*resultB, &sdkCompResult)
+ if err !=nil {
+ logger.Debug("comp sdkCompareResult unmarshal err:", err)
+ return nil
+ }
+
+ logger.Debug("comp len(rList):", len(sdkCompResult.CompareResult))
+ if len(sdkCompResult.CompareResult) >0 {
+ resultList = append(resultList, sdkCompResult.CompareResult...)
+ }
+
+ logger.Debug("comp totalList.len:", len(resultList))
+
+ return &resultList
}
func doCompareRequest(url string,args []byte) *[]byte{
--
Gitblit v1.8.0