From c4ab4a96dfdd097d0faedd14f10b93b18786101d Mon Sep 17 00:00:00 2001 From: sunty <1172534965@qq.com> Date: 星期二, 02 七月 2019 17:37:54 +0800 Subject: [PATCH] update dbtable and dbtablepersons update taglist add ageDecription taskName alarmLevel conditions into inputvalue --- controllers/fileController.go | 127 +++++++++++++++++++++++++++++++++++------ 1 files changed, 107 insertions(+), 20 deletions(-) diff --git a/controllers/fileController.go b/controllers/fileController.go index 33a2d81..c21b53f 100644 --- a/controllers/fileController.go +++ b/controllers/fileController.go @@ -1,20 +1,26 @@ package controllers import ( + "basic.com/pubsub/protomsg.git" "bytes" "encoding/base64" + "errors" "fmt" "github.com/gin-gonic/gin" "github.com/satori/go.uuid" "image" "image/jpeg" + "io/ioutil" "log" "mime/multipart" "net/http" + "strings" "webserver/extend/code" "webserver/extend/esutil" "webserver/extend/util" "webserver/models" + "webserver/service" + ) type FileController struct { @@ -28,9 +34,9 @@ //var picUrlField = "fid" /**涓婁紶鏂规硶**/ -//var weedfsUri = "http://192.168.1.182:6333/submit" +var weedfsUri = "http://192.168.1.182:6333/submit" -var weedfsUri = "http://192.168.1.182:9500/submit" +//var weedfsUri = "http://192.168.1.182:9500/submit" // @Summary 渚濇嵁鍥剧墖娣诲姞搴曞簱浜哄憳 // @Description 渚濇嵁鍥剧墖娣诲姞搴曞簱杩斿洖鏁版嵁浜哄憳 @@ -85,6 +91,31 @@ } } +// @Description 浜哄憳鐓х墖涓婁紶骞惰幏鍙栫壒寰佸�� +// @Router /data/api-v/dbperson/fileUploadTest [POST] +func (controller FileController) UploadPersonTest(c *gin.Context) { + file, _, err := c.Request.FormFile("file") //image杩欎釜鏄痷plaodify鍙傛暟瀹氫箟涓殑 'fileObjName':'image' + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎") + return + } + + + //灏嗕笂浼犵殑鍥剧墖浜や汉鑴告娴嬪拰浜鸿劯鎻愬彇锛岃幏寰楃壒寰� + fileBytes, _ := ioutil.ReadAll(file) + faceExtArr, err := getFaceFeaFromSdk(fileBytes) + if err ==nil && len(faceExtArr) >0 { + var faceBase64= "" + for _,r := range faceExtArr { + faceBase64 = base64.StdEncoding.EncodeToString(r.Feats)//鑾峰彇鎻愬彇鍒扮殑绗竴寮犱汉鑴哥壒寰� + break + } + util.ResponseFormat(c,code.Success,faceBase64) + } else { + util.ResponseFormat(c,code.ComError,"鏈彁鍙栧埌浜鸿劯") + } +} + /*// 瀵逛笂闈㈢殑缂栫爜缁撴灉杩涜base64瑙g爜 decodeBytes, err := base64.StdEncoding.DecodeString(encodeString) if err != nil { @@ -96,17 +127,21 @@ defer file.Close() field := "" // weedfs 涓婁紶 - { - fileInfo, e := esutil.PostFormData(weedfsUri, filename, "file", file) - if e != nil { - fmt.Println(e.Error()) - return "", nil, e - } else { - field = fileInfo[picUrlField].(string) // 鏂囦欢璺緞 - } + fileBytes, err := ioutil.ReadAll(file) + if err !=nil { + return "",nil,err } - if tableId != "" && field != "" { + fileInfo, e := esutil.PostFormData(weedfsUri, filename, "file", fileBytes) + if e != nil { + fmt.Println(e.Error()) + return "", nil, e + } else { + field = fileInfo[picUrlField].(string) // 鏂囦欢璺緞 + } + + if field != "" { // 杩斿洖鐗瑰緛鍊� fileInfo["point"] = v.RcFace fileInfo["feature"] = feat + /*features := gorun.GetSimpleFaceDetect(picIp+field) // 鐗瑰緛鍊� // linux if len(features) == 0 { // linux return field,nil,errors.New("NotFeatureFindError") // linux @@ -116,19 +151,63 @@ feat := features[0]["feature"].([]byte) // linux if len(feat) != 2560 { // linux return field,nil,errors.New("NotFeatureFindError") - } */ // linux - feat := []byte("hello world") // windows 娴嬭瘯鏀惧紑 + + } */ // linux + if strings.Contains(field,"/"){ + idx := strings.Index(field, "/") + field = field[idx+1:] + } + fmt.Println("field:",field) + //imgB, _ := ioutil.ReadAll(file) + //fmt.Println("img.length:",len(imgB)) + + //灏嗕笂浼犵殑鍥剧墖浜や汉鑴告娴嬪拰浜鸿劯鎻愬彇锛岃幏寰楃壒寰� + var faceBase64="" + faceExtArr, err := getFaceFeaFromSdk(fileBytes) + if faceExtArr ==nil { + return "",nil,errors.New("NotFeatureFindError") + } + if err ==nil && len(faceExtArr) >0 { + for _,r := range faceExtArr { + faceBase64 = base64.StdEncoding.EncodeToString(r.Feats)//鑾峰彇鎻愬彇鍒扮殑绗竴寮犱汉鑴哥壒寰� + break + } + } + + dbperson := new(models.Dbtablepersons) - dbperson.FaceFeature = picIp + field // 鍥剧墖璺粡 + dbperson.PersonPicUrl = field // 鍥剧墖璺粡 dbperson.TableId = tableId // dbperson.PersonName = filename // 鍥剧墖鍚� // 婕旂ずbase64缂栫爜 - encodeString := base64.StdEncoding.EncodeToString(feat) - dbperson.FaceFeature = encodeString // 鐗瑰緛鍊糱ase64 鐮� + + dbperson.FaceFeature = faceBase64 // 鐗瑰緛鍊糱ase64 鐮� + result := addDbPerson(dbperson) return field, result, nil } else { return field, nil, nil + } +} + +func getFaceFeaFromSdk(fileBytes []byte) ([]*protomsg.ResultFaceExtCom,error){ + s := service.NewFaceSdkService(fileBytes) + i, err := s.ReadFromUploadImg() + if err !=nil{ + fmt.Println("readFromUploadImg err:",err) + return nil,err + } + bc, err := service.ImgCompress(i) + if err !=nil { + fmt.Println("ImgCompress err:",err) + return nil,err + } + s.PushImgMsg(bc) + s.GetFaceFea() + if s.Result == nil{ + return nil,errors.New("no fea") + } else { + return s.Result,nil } } @@ -192,6 +271,14 @@ } } +type EsPersonSave struct { + FaceFeature string `json:"faceFeature"` + TableId string `json:"tableId"` + Id string `json:"id"` + PersonPicUrl string `json:"personPicUrl"` + IdCard string `json:"idCard"` +} + // @Summary 涓婁紶鍥剧墖 骞跺垏鍥� // @Description 涓婁紶鍥剧墖 骞跺垏鍥� // @Accept mpfd @@ -199,8 +286,8 @@ // @Tags dbperson 搴曞簱浜哄憳 // @Param file formData file true "搴曞簱浜哄憳鍥剧墖" // @Param tableId formData string false "搴曞簱id,鏈塱d 鍒欏姞鍏ュ簳搴擄紝鏃犲垯鍙笂浼犲浘鐗�" -// @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, data:""}" +// @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false, data:""}" // @Router /data/api-v/es/ImageUploadReturnPics [POST] func (fc FileController) ImageUploadReturnPics(c *gin.Context) { //寰楀埌涓婁紶鐨勬枃浠� @@ -212,9 +299,9 @@ } //鏂囦欢鐨勫悕绉� filename := header.Filename - fmt.Println(file, err, filename) defer file.Close() field := "" + // weedfs 涓婁紶 uploadData := make([]byte, header.Size) i, err2 := file.ReadAt(uploadData, 0) @@ -237,7 +324,7 @@ // fileInfo["point"] = v.RcFace // 杩斿洖鐗瑰緛鍊� // fileInfo["feature"] = feat //features := gorun.GetSimpleFaceDetect(picIp + "/" + field) // 鐗瑰緛鍊� 鍙湪linux 涓� - //feat := []byte("hello world") // windows 娴嬭瘯鏀惧紑 + result := make(map[string]interface{}, 0) result["uploadImage"] = picIp + field smUrl := make([]string, 0) -- Gitblit v1.8.0