| | |
| | | package controllers |
| | | |
| | | import ( |
| | | "basic.com/dbapi.git" |
| | | "basic.com/pubsub/protomsg.git" |
| | | "basic.com/fileServer/WeedFSClient.git" |
| | | "basic.com/valib/deliver.git" |
| | |
| | | } |
| | | |
| | | var captureTable = "capturetable" // 抓拍库 |
| | | type SearchCondition struct { |
| | | PicUrl string `json:"picUrl"` |
| | | Databases []string `json:"databases"` |
| | | Threshold string `json:"threshold"` |
| | | } |
| | | // @Summary 以图搜图 |
| | | // @Description 以图搜图 |
| | | // @Accept json |
| | | // @Produce json |
| | | // @Tags 以图搜图 |
| | | // @Param condition body controllers.SearchCondition true "搜索参数" |
| | | // @Param condition body models.EsSearch true "搜索参数" |
| | | // @Success 200 {string} json "{"code":200, msg:"", data:"", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"", data:"", success:false}" |
| | | // @Router /data/api-v/dbperson/searchByPhoto [POST] |
| | | func (controller FileController) SearchByPhoto(c *gin.Context) { |
| | | var condition SearchCondition |
| | | err := c.BindJSON(&condition) |
| | | if err !=nil || condition.PicUrl == "" || len(condition.Databases) == 0 { |
| | | var searchBody models.EsSearch |
| | | err := c.BindJSON(&searchBody) |
| | | if err !=nil || searchBody.PicUrl == "" || len(searchBody.DataBases) == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数有误") |
| | | return |
| | | } |
| | | compThreshold, err := strconv.ParseFloat(condition.Threshold,32) |
| | | if condition.PicUrl == "" || err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数有误") |
| | | var sysSetApi dbapi.SysSetApi |
| | | analyServerId := "" |
| | | flag, sysconf := sysSetApi.GetServerInfo() |
| | | if flag { |
| | | analyServerId = sysconf.ServerId |
| | | } else { |
| | | util.ResponseFormat(c, code.ComError, "analyServerId为空,配置有误") |
| | | return |
| | | } |
| | | if face,ok := faceExtractedMap[condition.PicUrl];!ok{ |
| | | if face,ok := faceExtractedMap[searchBody.PicUrl];!ok{ |
| | | util.ResponseFormat(c, code.RequestParamError, "请重新上传图片") |
| | | return |
| | | } else { |
| | | arg := protomsg.CompareArgs{ |
| | | TableIds: condition.Databases, |
| | | FaceFeature: face.FaceBytes, |
| | | CompareThreshold: float32(compThreshold), |
| | | CompareThreshold: searchBody.Threshold, |
| | | } |
| | | if condition.Databases !=nil { |
| | | arg.TableIds = append(arg.TableIds, condition.Databases...) |
| | | if searchBody.DataBases !=nil { |
| | | for idx,tableId :=range searchBody.DataBases { |
| | | if tableId == captureTable{ |
| | | searchBody.DataBases = append(searchBody.DataBases[:idx], searchBody.DataBases[idx+1:]...) |
| | | searchBody.DataBases = append(searchBody.DataBases,captureTable) |
| | | break |
| | | } |
| | | } |
| | | arg.TableIds = searchBody.DataBases |
| | | } |
| | | arg.Source = true // 标识来源是web |
| | | arg.AlarmLevel = searchBody.AlarmLevel |
| | | arg.Tasks = searchBody.Tasks |
| | | arg.TreeNodes = searchBody.TreeNodes |
| | | arg.Tabs = searchBody.Tabs |
| | | arg.SearchTime = searchBody.SearchTime |
| | | arg.InputValue = searchBody.InputValue |
| | | arg.Collection = searchBody.Collection |
| | | arg.AnalyServerId = analyServerId |
| | | |
| | | logger.Debug("arg.TableIds:", arg.TableIds, ",alarmLevel:",arg.AlarmLevel,",treeNodes:",arg.TreeNodes,",searchTime:",arg.SearchTime, |
| | | ",inputValue:",arg.InputValue,",tasks:",arg.Tasks,",compThreshold:",arg.CompareThreshold) |
| | | b, err := proto.Marshal(&arg) |
| | | if err !=nil{ |
| | | util.ResponseFormat(c, code.ComError, "请求marshal失败") |