| | |
| | | "basic.com/dbapi.git" |
| | | "basic.com/fileServer/WeedFSClient.git" |
| | | "basic.com/pubsub/protomsg.git" |
| | | "basic.com/valib/logger.git" |
| | | "encoding/base64" |
| | | "encoding/json" |
| | | "io/ioutil" |
| | | "sort" |
| | | "strconv" |
| | | "time" |
| | | "webserver/extend/logger" |
| | | "webserver/cache" |
| | | "webserver/service" |
| | | |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/satori/go.uuid" |
| | | "webserver/extend/code" |
| | | "webserver/extend/config" |
| | | "webserver/extend/esutil" |
| | | "webserver/extend/util" |
| | | "webserver/models" |
| | | |
| | | esApi "basic.com/pubsub/esutil.git" |
| | | ) |
| | | |
| | | type DbPersonController struct { |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 添加底库人员 |
| | | // @Description 添加底库人员 |
| | | // @Accept json |
| | |
| | | paramBody := util.Struct2Map(dbperson) |
| | | b, data := pApi.AddDbPerson(paramBody) |
| | | if b { |
| | | util.ResponseFormat(c, code.Success, data) |
| | | util.ResponseFormat(c, code.AddSuccess, data) |
| | | } else { |
| | | util.ResponseFormat(c, code.ServiceInsideError, "") |
| | | util.ResponseFormat(c, code.ComError, "") |
| | | } |
| | | } |
| | | |
| | | |
| | | type MultiCarNo struct { |
| | | TableId string `json:"tableId" binding:"required"` |
| | | CarNos []string `json:"carNos" binding:"required"` |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 批量添加底库车辆 |
| | | // @Description 批量添加底库车辆 |
| | | // @Accept json |
| | | // @Produce json |
| | | // @Tags dbperson 底库人员 |
| | | // @Param reqBody body controllers.MultiCarNo true "批量车牌号" |
| | | // @Success 200 {string} json "{"code":200, msg:"", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"", success:false}" |
| | | // @Router /data/api-v/dbperson/multiUploadCarNo [post] |
| | | func (dbc DbPersonController) MultiUploadCarNo(c *gin.Context) { |
| | | var reqBody MultiCarNo |
| | | err := c.BindJSON(&reqBody) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "") |
| | | return |
| | | } |
| | | logger.Debug("multiUploadCarNo reqBody:", reqBody) |
| | | var pApi dbapi.DbPersonApi |
| | | paramBody := util.Struct2Map(reqBody) |
| | | if pApi.MultiUploadCarNo(paramBody) { |
| | | util.ResponseFormat(c,code.UploadSuccess,"上传成功") |
| | | } else { |
| | | util.ResponseFormat(c,code.ComError,"") |
| | | } |
| | | } |
| | | |
| | | func addDbPerson(dbperson *models.Dbtablepersons) (result map[string]interface{}) { |
| | | |
| | | personId := uuid.NewV4().String() |
| | | dbperson.Id = personId |
| | | dbperson.PriInsert() |
| | | |
| | | var pApi dbapi.DbPersonApi |
| | | paramBody := util.Struct2Map(dbperson) |
| | | b, _ := pApi.AddDbPerson(paramBody) |
| | | b, d := pApi.AddDbPerson(paramBody) |
| | | result = map[string]interface{}{} |
| | | if b { |
| | | result["code"] = 200 |
| | | personMap := util.Struct2Map(d) |
| | | data := make(map[string]interface{}) |
| | | data["uuid"] = personId |
| | | data["uuid"] = personMap["id"] |
| | | result["data"] = data |
| | | result["success"] = true |
| | | result["msg"] = "添加成功" |
| | |
| | | return result |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 修改底库人员 |
| | | // @Description 修改底库人员 |
| | | // @Accept json |
| | |
| | | paramBody := util.Struct2Map(dbperson) |
| | | b, data := pApi.UpdateDbPerson(paramBody) |
| | | if b { |
| | | util.ResponseFormat(c, code.Success, data) |
| | | util.ResponseFormat(c, code.UpdateSuccess, data) |
| | | } else { |
| | | util.ResponseFormat(c, code.ServiceInsideError, "") |
| | | util.ResponseFormat(c, code.UpdateFail, "") |
| | | } |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 底库人员以图搜图 |
| | | // @Description 底库人员以图搜图 |
| | | // @Accept json |
| | |
| | | } else { |
| | | faceB = face.FaceBytes |
| | | } |
| | | var sysSetApi dbapi.SysSetApi |
| | | |
| | | analyServerId := "" |
| | | flag, sysconf := sysSetApi.GetServerInfo() |
| | | if flag { |
| | | analyServerId = sysconf.ServerId |
| | | conf, e := cache.GetServerInfo() |
| | | if e ==nil && conf.ServerId != "" { |
| | | analyServerId = conf.ServerId |
| | | } else { |
| | | util.ResponseFormat(c, code.ComError, "analyServerId为空,配置有误") |
| | | return |
| | | } |
| | | |
| | | arg := protomsg.CompareArgs{ |
| | | FaceFeature: faceB, |
| | | CompareThreshold: 0.6, |
| | | CompareThreshold: searchBody.Threshold, |
| | | } |
| | | arg.TableIds = searchBody.DataBases |
| | | arg.AnalyServerId = analyServerId |
| | |
| | | } |
| | | |
| | | //填充向前端返回的数据 |
| | | func FillDbPersonDataToCompareResult(compResult *protomsg.SdkCompareResult) []DbPersonVo { |
| | | func FillDbPersonDataToCompareResult(compResult *protomsg.SdkCompareResult) []models.DbPersonsCompVo { |
| | | |
| | | var resultList = make([]DbPersonVo, len(compResult.CompareResult)) |
| | | var resultList = make([]models.DbPersonsCompVo, 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, |
| | | CompareScore: float64(v.CompareScore), |
| | | } |
| | | personIds = append(personIds,v.Id) |
| | | } |
| | |
| | | } |
| | | |
| | | if len(dbpersons) >0 { |
| | | var dtApi dbapi.DbTableApi |
| | | //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 |
| | | } |
| | | var dbP models.DbPersonsCompVo |
| | | |
| | | dbP.Id = p.Id |
| | | dbP.TableId = p.TableId |
| | | dbP.FaceFeature = p.FaceFeature |
| | | dbP.PersonPicUrl = p.PersonPicUrl |
| | | dbP.PersonName = p.PersonName |
| | | dbP.Age = p.Age |
| | | dbP.Sex = p.Sex |
| | | dbP.IdCard = p.IdCard |
| | | dbP.PhoneNum = p.PhoneNum |
| | | dbP.MonitorLevel = p.MonitorLevel |
| | | dbP.Reserved = p.Reserved |
| | | dbP.IsDelete = int(p.IsDelete) |
| | | dbP.Enable = int(p.Enable) |
| | | dbP.CreateTime = p.CreateTime |
| | | dbP.UpdateTime = p.UpdateTime |
| | | dbP.CreateBy = p.CreateBy |
| | | dbP.CompareScore = dbPersonM[p.Id].CompareScore |
| | | //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 |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 更新底库人脸照片 |
| | | // @Description 更新底库人脸照片 |
| | | // @Accept json |
| | | // @Accept multipart/form-data |
| | | // @Produce json |
| | | // @Tags 底库人员 |
| | | // @Tags dbperson 底库人员 |
| | | // @Param id formData string true "人员id" |
| | | // @Param file formData file true "人脸图片" |
| | | // @Success 200 {string} json "{"code":200, msg:"", success:true}" |
| | |
| | | break |
| | | } |
| | | } |
| | | var weedfsUri = "http://"+config.WeedFs.Ip+":"+strconv.Itoa(config.WeedFs.UploadPort)+"/submit" |
| | | localConf, err2 := cache.GetServerInfo() |
| | | if err2 !=nil || localConf.WebPicIp == "" { |
| | | logger.Debug("localConfig is wrong!!!") |
| | | return |
| | | } |
| | | var weedfsUri = "http://"+localConf.WebPicIp+":"+strconv.Itoa(int(localConf.WebPicPort))+"/submit?collection=persistent" |
| | | //根据人脸坐标扣出人脸小图 |
| | | t1 := time.Now() |
| | | cutFaceImgData := util.SubImg(*pI, int(rcFace.Left), int(rcFace.Top), int(rcFace.Right), int(rcFace.Bottom)) |
| | | cutFaceImgData,_ := util.SubCutImg(pI, rcFace, 20) |
| | | logger.Debug("SubImg用时:", time.Since(t1)) |
| | | t1 = time.Now() |
| | | weedFilePath, e := WeedFSClient.UploadFile(weedfsUri, filename, cutFaceImgData) |
| | |
| | | //} |
| | | } |
| | | |
| | | func UpdateDbPersonsOfDbTable(id string) (message string) { |
| | | url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport + |
| | | "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/_update_by_query?refresh" |
| | | jsonDSL := ` |
| | | { |
| | | "script": { |
| | | "lang": "painless", |
| | | "inline": "ctx._source.enable = 0" |
| | | }, |
| | | "query": { |
| | | "term": { |
| | | "tableId": "` + id + `" |
| | | } |
| | | } |
| | | } |
| | | ` |
| | | buf, err := esutil.EsReq("POST", url, []byte(jsonDSL)) |
| | | if err != nil { |
| | | logger.Debug("http request info is err!") |
| | | message = "修改失败" |
| | | } |
| | | var info interface{} |
| | | json.Unmarshal(buf, &info) |
| | | out, ok := info.(map[string]interface{}) |
| | | if !ok { |
| | | logger.Debug("http response interface can not change map[string]interface{}") |
| | | message = "修改失败" |
| | | } |
| | | middle, ok := out["updated"].(float64) |
| | | if !ok { |
| | | logger.Debug("first result change error!") |
| | | message = "修改失败" |
| | | } |
| | | if middle >= 0 { |
| | | logger.Debug("修改成功") |
| | | message = "修改成功,更新状态条数为" + strconv.Itoa(int(middle)) |
| | | } |
| | | return message |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 删除底库人员 |
| | | // @Description 删除库人员 |
| | | // @Accept x-www-form-urlencoded |
| | |
| | | |
| | | type DelMultiPerson []string |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 删除底库人员 |
| | | // @Description 删除库人员 |
| | | // @Accept json |
| | |
| | | } |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 查询底库人员列表 |
| | | // @Description 查询库人员列表 |
| | | // @Accept json |
| | |
| | | } |
| | | } |
| | | |
| | | type DbtSearch struct { |
| | | TableId string `json:"tableId"` |
| | | OrderName string `json:"orderName"` |
| | | OrderType string `json:"orderType"` |
| | | ContentValue string `json:"contentValue"` |
| | | Page int `json:"page"` |
| | | Size int `json:"size"` |
| | | type JoinDbTVo struct { |
| | | CaptureId string `json:"captureId"` |
| | | TableIds []string `json:"tableIds"` |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 抓拍人员加入底库 |
| | | // @Description 抓拍人员加入底库 |
| | | // @Accept json |
| | | // @Produce json |
| | | // @Tags dbperson 底库人员 |
| | | // @Param obj body controllers.JoinDbTVo true "底库数据" |
| | | // @Success 200 {string} json "{"code":200, msg:"目录结构数据", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"返回错误信息", success:false}" |
| | | // @Router /data/api-v/dbperson/joinDbTable [POST] |
| | | func (dbc *DbPersonController) JoinDbTable(c *gin.Context) { |
| | | var reqBody JoinDbTVo |
| | | c.BindJSON(&reqBody) |
| | | if reqBody.CaptureId == "" || len(reqBody.TableIds) ==0 { |
| | | util.ResponseFormat(c,code.RequestParamError, "参数有误") |
| | | return |
| | | } |
| | | localConf, err := cache.GetServerInfo() |
| | | if err !=nil || localConf.AlarmIp == "" || localConf.AlarmPort <=0 { |
| | | util.ResponseFormat(c,code.ComError,"报警设置有误") |
| | | return |
| | | } |
| | | aiOceans, e := esApi.AIOceaninfosbyid([]string{reqBody.CaptureId}, config.EsInfo.EsIndex.AiOcean.IndexName, localConf.AlarmIp, strconv.Itoa(int(localConf.AlarmPort))) |
| | | if e ==nil && aiOceans !=nil && len(aiOceans) == 1{ |
| | | var personPicUrl = ""//人脸图片 |
| | | var feature = ""//特征 |
| | | if aiOceans[0].TargetInfo !=nil && len(aiOceans[0].TargetInfo) >0 { |
| | | personPicUrl = aiOceans[0].TargetInfo[0].PicSmUrl |
| | | } |
| | | fea, e2 := esApi.GetVideoPersonFaceFeatureById(reqBody.CaptureId, config.EsInfo.EsIndex.AiOcean.IndexName, localConf.AlarmIp, strconv.Itoa(int(localConf.AlarmPort))) |
| | | if e2 == nil && fea !="" { |
| | | feature = fea |
| | | } |
| | | if personPicUrl != "" && feature != "" { |
| | | //将这张抓拍的照片下载下来上传到collection=persistent的集合中,防止被清理掉 |
| | | picB, e3 := util.DownLoad("http://" + personPicUrl) |
| | | if e3 == nil { |
| | | var weedfsUri = "http://"+localConf.WebPicIp+":"+strconv.Itoa(int(localConf.WebPicPort))+"/submit?collection=persistent" |
| | | newPersonPicUrl, e4 := WeedFSClient.UploadFile(weedfsUri, "capturePerson", picB) |
| | | if e4 == nil { |
| | | var dbpApi dbapi.DbPersonApi |
| | | b,d := dbpApi.JoinDbTable(reqBody.TableIds, feature, newPersonPicUrl) |
| | | if b { |
| | | util.ResponseFormat(c,code.Success,d) |
| | | return |
| | | } else { |
| | | util.ResponseFormat(c,code.ComError,"加入失败") |
| | | return |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | util.ResponseFormat(c,code.ComError,"加入失败") |
| | | } |
| | | |
| | | type DbtSearch struct { |
| | | TableId string `json:"tableId"` |
| | | OrderName string `json:"orderName"` |
| | | OrderType string `json:"orderType"` |
| | | ContentValue string `json:"contentValue"` |
| | | Page int `json:"page"` |
| | | Size int `json:"size"` |
| | | } |
| | | |
| | | type DbPersonMove struct { |
| | | PersonId string `json:"personId"` |
| | | TableIds []string `json:"tableIds"` |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 人员移动 |
| | | // @Description 人员移动 |
| | | // @Accept json |
| | | // @Produce json |
| | | // @Tags dbperson 底库人员 |
| | | // @Param obj body controllers.DbPersonMove true "移动参数" |
| | | // @Success 200 {string} json "{"code":200, msg:"", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"", success:false}" |
| | | // @Router /data/api-v/dbperson/move [POST] |
| | | func (dbc *DbPersonController) Move(c *gin.Context) { |
| | | var reqBody DbPersonMove |
| | | c.BindJSON(&reqBody) |
| | | if reqBody.PersonId == "" || len(reqBody.TableIds) == 0 { |
| | | util.ResponseFormat(c,code.RequestParamError, "参数有误") |
| | | return |
| | | } |
| | | var dbpApi dbapi.DbPersonApi |
| | | b,d := dbpApi.Move(reqBody.PersonId, reqBody.TableIds) |
| | | if b { |
| | | util.ResponseFormat(c,code.Success,d) |
| | | } else { |
| | | util.ResponseFormat(c,code.ComError,"") |
| | | } |
| | | } |
| | | |
| | | // @Security ApiKeyAuth |
| | | // @Summary 人员复制 |
| | | // @Description 人员复制 |
| | | // @Accept json |
| | | // @Produce json |
| | | // @Tags dbperson 底库人员 |
| | | // @Param obj body controllers.DbPersonMove true "复制参数" |
| | | // @Success 200 {string} json "{"code":200, msg:"", success:true}" |
| | | // @Failure 500 {string} json "{"code":500, msg:"", success:false}" |
| | | // @Router /data/api-v/dbperson/copy [POST] |
| | | func (dbc *DbPersonController) Copy(c *gin.Context) { |
| | | var reqBody DbPersonMove |
| | | c.BindJSON(&reqBody) |
| | | if reqBody.PersonId == "" || len(reqBody.TableIds) == 0 { |
| | | util.ResponseFormat(c,code.RequestParamError, "参数有误") |
| | | return |
| | | } |
| | | var dbpApi dbapi.DbPersonApi |
| | | b,d := dbpApi.Copy(reqBody.PersonId, reqBody.TableIds) |
| | | if b { |
| | | util.ResponseFormat(c,code.Success,d) |
| | | } else { |
| | | util.ResponseFormat(c,code.ComError,"") |
| | | } |
| | | } |