| | |
| | | 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 |
| | |
| | | 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、sqlite |
| | | 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 |
| | | |
| | | |
New file |
| | |
| | | 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,"退出失败") |
| | | } |
| | | } |
| | |
| | | package controllers |
| | | |
| | | import ( |
| | | "basic.com/dbapi.git" |
| | | "encoding/json" |
| | | "log" |
| | | "strconv" |
| | | "time" |
| | | "webserver/extend/logger" |
| | | |
| | | "github.com/gin-gonic/gin" |
| | |
| | | // @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 |
| | | } |
| | | |
| | |
| | | // @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, "") |
| | | } |
| | | } |
| | | |
| | |
| | | // @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, "删除失败") |
| | | } |
| | | } |
| | | |
| | |
| | | // @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, "删除失败") |
| | | } |
| | | } |
| | | |
| | |
| | | // @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,"参数有误,底库id不能为空") |
| | | return |
| | | } |
| | | orderName := "id" |
| | | if reqBody["orderName"] != nil { |
| | | orderName = reqBody["orderName"].(string) |
| | | } // 列名 |
| | |
| | | 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" { |
| | |
| | | } 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 查询底库人员列表 |
| | |
| | | "fmt" |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/satori/go.uuid" |
| | | "log" |
| | | "time" |
| | | "webserver/extend/code" |
| | | "webserver/extend/config" |
| | |
| | | // @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 查询数据 |
| | |
| | | // @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中获取底库id") |
| | | 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) { |
| | |
| | | // @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() |
| | |
| | | } 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,"新增失败") |
| | | } |
| | | } |
| | | |
| | |
| | | // @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,"删除失败") |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | 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, |
| | |
| | | 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 |
| | |
| | | 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 |
| | | } |
| | | } |
| | |
| | | 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 {//有比对Es抓拍 |
| | | 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 |
| | |
| | | |
| | | } else { |
| | | m["total"] = 0 |
| | | m["compareNum"] = searchBody.CompareNum |
| | | m["compareNum"] = compareService.CompareNum |
| | | m["totalList"] = []CompareResult{} |
| | | } |
| | | util.ResponseFormat(c,code.Success,m) |
| | |
| | | |
| | | 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 { |
| | |
| | | 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("上传到weedfs用时:", 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 // 特征值base64 码 |
| | | |
| | | result := addDbPerson(dbperson) |
| | |
| | | Name string `json:"name"` //参数名称 |
| | | Type string `json:"type"` //参数类型(整数,字符串或数组) |
| | | Must bool `json:"must"` //是否必填 |
| | | Unit string `json:"unit"` |
| | | Range string `json:"range"` //值的范围,eg:0,100表示从0到100 |
| | | DefaultValue string `json:"default_value"` |
| | | Sort int `json:"sort"` //参数顺序 |
| | | } |
| | | |
| | |
| | | |
| | | 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,"查询底库标签失败") |
| | | } |
| | |
| | | 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 |
| | | } |
| | |
| | | // @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, "删除失败") |
| | |
| | | TaskStoped = &Code{http.StatusOK, false, "此任务为停用状态,请在任务管理中开启!"} |
| | | |
| | | ComError = &Code{http.StatusInternalServerError, false, ""} |
| | | ClusterNodesEmpty = &Code{http.StatusOK, true, "集群节点为空"} |
| | | ) |
| | |
| | | |
| | | 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 |
| | |
| | | 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) |
| | | } |
| | |
| | | import ( |
| | | "github.com/gin-gonic/gin" |
| | | "net/http" |
| | | "regexp" |
| | | "strings" |
| | | "webserver/extend/config" |
| | | "webserver/extend/logger" |
| | |
| | | //} |
| | | 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 {//路径中包含有端口,取端口以后路径 |
| | | 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() |
| | |
| | | pollConfigController := new(controllers.PollConfigController) |
| | | fileController := new(controllers.FileController) |
| | | sysMenuController :=new(controllers.SysMenuController) |
| | | clusterController :=new(controllers.ClusterController) |
| | | |
| | | |
| | | sysApi := r.Group( "/data/api-u/sys") |
| | |
| | | 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) |
| | | } |
| | | |
| | |
| | | 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") // 静态文件 |
| | |
| | | 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) { |
| | |
| | | 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 |
| | |
| | | |
| | | 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.向各个compare进程发起请求拿到比对结果 |
| | | esCompServerList := config.EsCompServerInfo.Url |
| | | logger.Debug("compServerList:", esCompServerList) |
| | | //1.向各个Es 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) |
| | |
| | | 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{ |