liuxiaolong
2019-07-24 0cc8d28ff6bae56fe8f4388aedd4ab1d46a11c96
config compServerList
3个文件已修改
92 ■■■■■ 已修改文件
config/dev.yaml 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/fileController.go 81 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
extend/config/config.go 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
config/dev.yaml
@@ -5,6 +5,9 @@
    url: http://127.0.0.1:8080
    imageUrl: http://192.168.1.203:6080
    networkAdapter: enp59s0f1
compare:
    url:
     - 192.168.1.66:40010
weedfs:
    ip: 192.168.1.203
    uploadport: 6333
controllers/fileController.go
@@ -105,7 +105,13 @@
}
var faceExtractedMap = make(map[string]FaceExtract,0)
// @Description 人脸提取
// @Summary 人脸提取
// @Description  人脸提取
// @Produce json
// @Tags 以图搜图
// @Param file formData file 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/faceExtract [POST]
func (controller FileController) FaceExtract(c *gin.Context) {
    file, _, err := c.Request.FormFile("file") //image这个是uplaodify参数定义中的   'fileObjName':'image'
@@ -132,17 +138,20 @@
                urlArr = append(urlArr, weedFilePath)
            }
        }
        if len(urlArr) == 0{
            util.ResponseFormat(c,code.ComError,"未提取到人脸")
        } else {
            util.ResponseFormat(c,code.Success,urlArr)
        }
        util.ResponseFormat(c,code.Success,urlArr)
    } else {
        util.ResponseFormat(c,code.ComError,"未提取到人脸")
    }
}
// @Description 以图搜图
// @Summary 以图搜图
// @Description  以图搜图
// @Produce json
// @Tags 以图搜图
// @Param url formData string true "url"
// @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) {
    photoUrl := c.Request.FormValue("url")
@@ -154,8 +163,6 @@
        util.ResponseFormat(c, code.RequestParamError, "参数有误")
        return
    } else {
        reqUrl := "tcp://192.168.1.66:40010"
        reqClient := deliver.NewClient(deliver.ReqRep, reqUrl)
        arg := protomsg.CompareArgs{
            FaceFeature:face.FaceBytes,
            CompareThreshold:0.2,
@@ -165,32 +172,38 @@
            util.ResponseFormat(c, code.ComError, "请求marshal失败")
            return
        }
        err = reqClient.Send(b)
        if err !=nil{
            util.ResponseFormat(c, code.ComError, "比对服务请求失败")
            return
        compServerList := config.CompServerInfo.Url
        fmt.Println("compServerList:", compServerList)
        resultList :=make([]protomsg.Dbperson,0)
        for _,str :=range compServerList{
            reqUrl := "tcp://"+str
            reqClient := deliver.NewClient(deliver.ReqRep, reqUrl)
            err = reqClient.Send(b)
            if err !=nil{
                continue
            }
            resultB, err := reqClient.Recv()
            if err !=nil{
                continue
            }
            m :=make(map[string]float32,0)
            err = json.Unmarshal(resultB, &m)
            if err !=nil{
                continue
            }
            personIds := make([]string,len(m))
            for k,_ :=range m{
                personIds = append(personIds,k)
            }
            esServerIp := config.EsInfo.Masterip
            esServerPort := config.EsInfo.Httpport
            index := config.EsInfo.EsIndex.Dbtablepersons.IndexName
            dbpeople, e := esApi.Dbpersoninfosbyid(personIds, index, esServerIp, esServerPort)
            if e ==nil{
                resultList = append(resultList,dbpeople...)
            }
        }
        resultB, err := reqClient.Recv()
        if err !=nil{
            util.ResponseFormat(c, code.ComError, "比对服务响应失败")
            return
        }
        m :=make(map[string]float32,0)
        err = json.Unmarshal(resultB, &m)
        if err !=nil{
            util.ResponseFormat(c, code.ComError, "result Unmarshal err")
            return
        }
        personIds := make([]string,len(m))
        for k,_ :=range m{
            personIds = append(personIds,k)
        }
        dbpeople, e := esApi.Dbpersoninfosbyid(personIds, "dbtablepersons", "192.168.1.182", "9200")
        if e !=nil{
            util.ResponseFormat(c, code.ComError, "result es query err")
        } else {
            util.ResponseFormat(c,code.Success,dbpeople)
        }
        util.ResponseFormat(c,code.Success,resultList)
    }
}
extend/config/config.go
@@ -63,6 +63,13 @@
var DBconf = &database{}
type CompareServer struct {
    Url []string `mapstructure:"url"`
}
var CompServerInfo = &CompareServer{}
// Init is an exported method that takes the environment starts the viper
// (external lib) and returns the configuration struct.
func Init(env string) {
@@ -80,4 +87,5 @@
    viper.UnmarshalKey("redis", RedisConf)
    viper.UnmarshalKey("database", DBconf)
    viper.UnmarshalKey("weedfs", WeedFs)
    viper.UnmarshalKey("compare", CompServerInfo)
}