| | |
| | | "encoding/base64" |
| | | "encoding/json" |
| | | "io/ioutil" |
| | | "sort" |
| | | "strconv" |
| | | "time" |
| | | "webserver/extend/logger" |
| | |
| | | } |
| | | } |
| | | |
| | | // @Summary 底库人员以图搜图 |
| | | // @Description 底库人员以图搜图 |
| | | // @Accept json |
| | | // @Produce json |
| | | // @Tags dbperson 底库人员 |
| | | // @Param condition body models.EsSearch true "底库以图搜图参数" |
| | | // @Success 200 {string} json "{"code":200, msg:"", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"", success:false}" |
| | | // @Router /data/api-v/dbperson/queryDbPersonsByCompare [POST] |
| | | func (dbc DbPersonController) QueryDbPersonsByCompare(c *gin.Context) { |
| | | var searchBody models.EsSearch |
| | | err := c.BindJSON(&searchBody) |
| | | if err !=nil || searchBody.PicUrl == "" || len(searchBody.DataBases) == 0{ |
| | | util.ResponseFormat(c, code.RequestParamError, "参数有误") |
| | | return |
| | | } |
| | | var faceB []byte |
| | | if face,ok := faceExtractedMap[searchBody.PicUrl];!ok{ |
| | | util.ResponseFormat(c, code.RequestParamError, "请重新上传图片") |
| | | return |
| | | } else { |
| | | faceB = face.FaceBytes |
| | | } |
| | | var sysSetApi dbapi.SysSetApi |
| | | analyServerId := "" |
| | | flag, sysconf := sysSetApi.GetServerInfo() |
| | | if flag { |
| | | analyServerId = sysconf.ServerId |
| | | } else { |
| | | util.ResponseFormat(c, code.ComError, "analyServerId为空,配置有误") |
| | | return |
| | | } |
| | | arg := protomsg.CompareArgs{ |
| | | FaceFeature: faceB, |
| | | CompareThreshold: 0.6, |
| | | } |
| | | arg.TableIds = searchBody.DataBases |
| | | arg.AnalyServerId = analyServerId |
| | | compareService := service.NewFaceCompareService(arg) |
| | | var totalData service.CompareList |
| | | |
| | | dbPersonTargets := compareService.CompareDbPersons() |
| | | if dbPersonTargets !=nil { |
| | | totalData = append(totalData,*dbPersonTargets...) |
| | | } |
| | | |
| | | 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"] = compareService.CompareNum |
| | | m["total"] = total |
| | | var sCompResult protomsg.SdkCompareResult |
| | | if total <= searchBody.Size { |
| | | sCompResult.CompareResult = totalData |
| | | } else { |
| | | sCompResult.CompareResult = totalData[0:searchBody.Size] |
| | | } |
| | | resultList := FillDbPersonDataToCompareResult(&sCompResult) |
| | | m["totalList"] = resultList |
| | | |
| | | } else { |
| | | m["total"] = 0 |
| | | m["compareNum"] = compareService.CompareNum |
| | | m["totalList"] = []CompareResult{} |
| | | } |
| | | util.ResponseFormat(c,code.Success,m) |
| | | } |
| | | |
| | | //填充向前端返回的数据 |
| | | func FillDbPersonDataToCompareResult(compResult *protomsg.SdkCompareResult) []DbPersonVo { |
| | | |
| | | var resultList = make([]DbPersonVo, len(compResult.CompareResult)) |
| | | dbPersonM := make(map[string]ScoreIndex, 0) |
| | | personIds := make([]string,0) |
| | | |
| | | for idx,v :=range compResult.CompareResult{ |
| | | dbPersonM[v.Id] = ScoreIndex{ |
| | | Index: idx, |
| | | CompareScore: v.CompareScore, |
| | | } |
| | | personIds = append(personIds,v.Id) |
| | | } |
| | | logger.Debug("comp len(personIds):", len(personIds)) |
| | | |
| | | var dbpersons []protomsg.Dbperson |
| | | if len(personIds) >0 { |
| | | 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, |
| | | IdCard: p.IdCard, |
| | | CompareScore: util.ParseScore(dbPersonM[p.Id].CompareScore), |
| | | MonitorLevel: p.MonitorLevel, |
| | | PersonName: p.PersonName, |
| | | PersonPicUrl: p.PersonPicUrl, |
| | | PhoneNum: p.PhoneNum, |
| | | Sex: p.Sex, |
| | | TableId: p.TableId, |
| | | Enable: p.Enable, |
| | | } |
| | | dbTableInfos, _ := dtApi.DbtablesById([]string{ p.TableId }) |
| | | if dbTableInfos !=nil{ |
| | | dbP.BwType = dbTableInfos[0].BwType |
| | | dbP.TableName = dbTableInfos[0].TableName |
| | | } |
| | | resultList[dbPersonM[p.Id].Index] = dbP |
| | | } |
| | | } |
| | | |
| | | return resultList |
| | | } |
| | | |
| | | // @Summary 更新底库人脸照片 |
| | | // @Description 更新底库人脸照片 |
| | | // @Accept json |
| | |
| | | util.ResponseFormat(c,code.ComError,"人脸上传失败") |
| | | return |
| | | } |
| | | var dbpApi dbapi.DbPersonApi |
| | | b,d := dbpApi.UpdateFace(id,faceBase64,weedFilePath) |
| | | if b { |
| | | util.ResponseFormat(c,code.UpdateSuccess,d) |
| | | } else { |
| | | util.ResponseFormat(c,code.UpdateFail,"更新人脸失败") |
| | | m := map[string]interface{} { |
| | | "faceFeature": faceBase64, |
| | | "personPicUrl": weedFilePath, |
| | | } |
| | | util.ResponseFormat(c,code.Success, m) |
| | | |
| | | //var dbpApi dbapi.DbPersonApi |
| | | //b,d := dbpApi.UpdateFace(id,faceBase64,weedFilePath) |
| | | //if b { |
| | | // util.ResponseFormat(c,code.UpdateSuccess,d) |
| | | //} else { |
| | | // util.ResponseFormat(c,code.UpdateFail,"更新人脸失败") |
| | | //} |
| | | } |
| | | |
| | | func UpdateDbPersonsOfDbTable(id string) (message string) { |
| | |
| | | orderType := "desc" |
| | | if reqBody.OrderType != "" { |
| | | orderType = reqBody.OrderType |
| | | } // 列类型 |
| | | contentValue := "" |
| | | } |
| | | //搜索内容 |
| | | contentValue := reqBody.ContentValue |
| | | |
| | | page := 1 |
| | | if reqBody.Page >1 { |
| | |
| | | Page int `json:"page"` |
| | | Size int `json:"size"` |
| | | } |
| | | |
| | | /* |
| | | // @Summary 查询底库人员列表 |
| | | // @Description 查询库人员列表 |
| | | // @Accept json |
| | | // @Produce json |
| | | // @Tags dbperson 底库人员 |
| | | // @Param reqMap body controllers.DbtSearch false "{"tableId":"","orderName":"id","orderType":"desc","contentValue":"","page":1,"size":8}" |
| | | // @Success 200 {string} json "{"code":200, "msg":"", "success":true,"data":{}}" |
| | | // @Failure 500 {string} json "{code:500, msg:"", success:false,data:{}}" |
| | | // @Router /data/api-v/dbperson/queryDbPersonsByCampare [POST] |
| | | func (dbc DbPersonController) QueryDbPersonsByCampare(c *gin.Context) { |
| | | url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + |
| | | "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/_search" // ?refresh=wait_for |
| | | var reqBody DbtSearch |
| | | c.BindJSON(&reqBody) |
| | | tableId := "" |
| | | if reqBody.TableId != "" { |
| | | tableId = reqBody.TableId |
| | | } |
| | | orderName := "_id" |
| | | if reqBody.OrderName != "" { |
| | | orderName = reqBody.OrderName |
| | | } // 列名 |
| | | orderType := "desc" |
| | | if reqBody.OrderType != "" { |
| | | orderType = reqBody.OrderType |
| | | } // 列类型 |
| | | faceUrl := "" |
| | | var threshold float32 |
| | | if reqBody["faceUrl"] != nil && reqBody["threshold"] != nil { |
| | | faceUrl = reqBody["faceUrl"].(string) |
| | | threshold = float32(reqBody["threshold"].(float64)) |
| | | } else { |
| | | util.ResponseFormat(c, code.RequestParamError, nil) // 图片路径有问题 |
| | | return |
| | | } |
| | | //输入框内容 |
| | | page := 1 |
| | | if reqBody["page"] != nil { |
| | | page = int(reqBody["page"].(float64)) |
| | | } // 页码 |
| | | size := 8 |
| | | 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 orderType == "desc" { |
| | | orderType = "desc" |
| | | } else { |
| | | orderType = "asc" |
| | | } |
| | | |
| | | //params := "{\"query\":{\"bool\":{\"filter\":[" + |
| | | // "{\"term\":{\"isDelete\":\"0\"}}" + syncTerm + "]" + contentParam + "}},\"from\":" + strconv.Itoa(from) + ",\"size\":" + strconv.Itoa(size) + ",\"sort\":{\"" + orderName + "\":{\"order\":\"" + orderType + "\"}}}" |
| | | params := "{\"query\":{\"bool\":{\"must_not\":[" + |
| | | "{\"term\":{\"isDelete\":\"1\"}}],\"filter\":[" + syncTerm + "]" + contentParam + "}},\"from\":" + strconv.Itoa(from) + ",\"size\":" + strconv.Itoa(size) + ",\"sort\":{\"" + orderName + "\":{\"order\":\"" + orderType + "\"}}}" |
| | | logger.Debug("请求url:%s;\n 请求参数params:%s", url, params) |
| | | data := esutil.GetEsDataReq(url, params, true) |
| | | featByte := make([]byte, 0, 1024) |
| | | if len(faceUrl) > 3 { // linux |
| | | |
| | | } |
| | | to := page * size |
| | | datalist := sourceCompare(data["datalist"].([]interface{}), false, featByte, threshold) |
| | | total := len(datalist) |
| | | if from > total { |
| | | from = total |
| | | } |
| | | if to > total { |
| | | to = total |
| | | } |
| | | data["datalist"] = datalist[from:to] |
| | | data["total"] = len(datalist) |
| | | //c.JSON(200, data) |
| | | util.ResponseFormat(c, code.Success, data) |
| | | }*/ |