From d94f80d854d09e89715ca7c2361cd6057f98f396 Mon Sep 17 00:00:00 2001 From: sunty <suntianyu0923@163.com> Date: 星期三, 31 七月 2019 17:21:42 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- service/FaceCompareService.go | 107 +++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 74 insertions(+), 33 deletions(-) diff --git a/service/FaceCompareService.go b/service/FaceCompareService.go index 4b61f2f..addfce3 100644 --- a/service/FaceCompareService.go +++ b/service/FaceCompareService.go @@ -3,10 +3,12 @@ import ( esApi "basic.com/pubsub/esutil.git" "basic.com/pubsub/protomsg.git" - "basic.com/valib/deliver.git" - "encoding/json" "github.com/gogo/protobuf/proto" "github.com/satori/go.uuid" + "nanomsg.org/go-mangos" + "nanomsg.org/go-mangos/protocol/req" + "nanomsg.org/go-mangos/transport/ipc" + "nanomsg.org/go-mangos/transport/tcp" "sort" "strconv" "sync" @@ -91,6 +93,7 @@ TaskName string `json:"taskName"` BaseInfo []DbPersonVo `json:"baseInfo"` VideoUrl string `json:"videoUrl"` + SdkName string `json:"sdkName"` } type DbPersonVo struct { BwType string `json:"bwType"` @@ -114,28 +117,24 @@ resultList :=make([]CompareResult,0) for _,str :=range compServerList{ reqUrl := "tcp://"+str - reqClient := deliver.NewClient(deliver.ReqRep, reqUrl) - err = reqClient.Send(b) - if err !=nil{ - logger.Debug("reqClient.Send err:",err) + resultB := doCompareRequest(reqUrl,b) + if resultB == nil || len(*resultB) ==0 { continue } - resultB, err := reqClient.Recv() - if err !=nil{ - logger.Debug("reqClient.Recv err:",err) + var sdkCompResult protomsg.SdkCompareResult + //rList :=make([]protomsg.Esinfo,0) + err = proto.Unmarshal(*resultB, &sdkCompResult) + if err !=nil { + logger.Debug("comp sdkCompareResult unmarshal err:", err) continue } - rList :=make([]protomsg.Esinfo,0) - err = json.Unmarshal(resultB, &rList) - if err !=nil{ - logger.Debug("recv result Unmarshal err:", err) - continue - } - logger.Debug("len(rList):", len(rList)) - if len(rList) >0 { - resultList = append(resultList, FillDataToCompareResult(&rList)...) + + logger.Debug("comp len(rList):", len(sdkCompResult.CompareResult)) + if len(sdkCompResult.CompareResult) >0 { + resultList = append(resultList, FillDataToCompareResult(&sdkCompResult)...) } } + logger.Debug("comp totalList.len:", len(resultList)) //2.缂撳瓨姣斿缁撴灉 co := &CompareOnce{ @@ -147,25 +146,55 @@ return co } +func doCompareRequest(url string,args []byte) *[]byte{ + logger.Debug("comp reqUrl:",url) + var sock mangos.Socket + var err error + var msg []byte + + if sock,err = req.NewSocket();err !=nil { + logger.Debug("comp can't new req socket:%s",err.Error()) + return nil + } + sock.AddTransport(ipc.NewTransport()) + sock.AddTransport(tcp.NewTransport()) + if err = sock.Dial(url);err !=nil { + logger.Debug("comp can't dial on req socket:%s",err.Error()) + return nil + } + sock.SetOption(mangos.OptionMaxRecvSize, 1024*1024*100) + //sock.SetOption(mangos.OptionRecvDeadline, time.Second*10) + if err = sock.Send(args);err !=nil { + logger.Debug("comp can't send message on push socket:%s",err.Error()) + return nil + } + if msg,err = sock.Recv();err !=nil { + logger.Debug("comp sock.Recv receive err:%s",err.Error()) + return nil + } + sock.Close() + return &msg +} + //濉厖鍚戝墠绔繑鍥炵殑鏁版嵁 -func FillDataToCompareResult(rList *[]protomsg.Esinfo) []CompareResult { +func FillDataToCompareResult(compResult *protomsg.SdkCompareResult) []CompareResult { resultList :=make([]CompareResult,0) - dbPersonM := make(map[string]*protomsg.Esinfo,0) - captureM := make(map[string]*protomsg.Esinfo,0) + dbPersonM := make(map[string]*protomsg.SdkCompareEach, 0) + captureM := make(map[string]*protomsg.SdkCompareEach, 0) personIds :=make([]string,0) captureIds := make([]string,0) - for _,v :=range *rList{ + for _,v :=range compResult.CompareResult{ if v.Tableid == CaptureTable { - captureM[v.Id] = &v + captureM[v.Id] = v captureIds = append(captureIds,v.Id) } else { - dbPersonM[v.Id] = &v + dbPersonM[v.Id] = v personIds = append(personIds,v.Id) } } - logger.Debug("personIds:", personIds) - logger.Debug("captureIds:",captureIds) + logger.Debug("comp len(personIds):", len(personIds)) + logger.Debug("comp len(captureIds):", len(captureIds)) esServerIp := config.EsInfo.Masterip esServerPort := config.EsInfo.Httpport index := config.EsInfo.EsIndex.Dbtablepersons.IndexName @@ -174,7 +203,7 @@ dbpersons, _ = esApi.Dbpersoninfosbyid(personIds, index, esServerIp, esServerPort) } - logger.Debug("dbpersons:", dbpersons) + logger.Debug("comp dbpersons.len:", len(dbpersons)) if dbpersons !=nil { for _,p :=range dbpersons { var dbP = DbPersonVo { @@ -199,20 +228,18 @@ resultList = append(resultList,cr) } } - var capturePersons []protomsg.Videopersons if len(captureIds) >0 { - logger.Debug("capturePersons:", capturePersons) videopersons, _ := esApi.Videopersonsinfosbyid(captureIds, config.EsInfo.EsIndex.VideoPersons.IndexName, config.EsInfo.Masterip, config.EsInfo.Httpport) - logger.Debug("videoPersons.len:",len(videopersons)) + logger.Debug("comp videoPersons.len:",len(videopersons)) for _,vp :=range videopersons { isAlarmInt, _ := strconv.Atoi(vp.IsAlarm) - var bi []DbPersonVo + bi := make([]DbPersonVo,0) for _,p :=range vp.BaseInfo { bi = append(bi, DbPersonVo{ PersonId: p.PersonId, IdCard: p.IdCard, CompareScore: util.ParseScore(p.CompareScore), - MonitorLevel: p.MonitorLevel, + MonitorLevel: parseMonitorLevel(p.MonitorLevel), PersonName: p.PersonName, PersonPicUrl: p.PersonPicUrl, PhoneNum: p.PhoneNum, @@ -227,7 +254,7 @@ CameraAddr: vp.CameraAddr, PicDate: vp.PicDate, PicMaxUrl: vp.PicMaxUrl, - PicSmUrl: []string{ vp.PicSmUrl }, + PicSmUrl: vp.PicSmUrl, IsAlarm: isAlarmInt, Sex: vp.Sex, AgeDescription: vp.AgeDescription, @@ -236,9 +263,23 @@ TaskId: vp.TaskId, VideoUrl: vp.VideoUrl, BaseInfo: bi, + SdkName: "浜鸿劯", } resultList = append(resultList,vpE) } } return resultList } + +func parseMonitorLevel(level string) string { + if level == "1" { + return "涓�绾�" + } + if level == "2" { + return "浜岀骇" + } + if level == "3" { + return "涓夌骇" + } + return level +} \ No newline at end of file -- Gitblit v1.8.0