From cd60b7e3a0bbc09f4501f66260b5d961d58aaf49 Mon Sep 17 00:00:00 2001 From: panlei <2799247126@qq.com> Date: 星期二, 17 十二月 2019 13:38:07 +0800 Subject: [PATCH] --- --- insertdata/insertDataToEs.go | 269 +++++------------------------------------------------ 1 files changed, 29 insertions(+), 240 deletions(-) diff --git a/insertdata/insertDataToEs.go b/insertdata/insertDataToEs.go index d41ff73..05a014e 100644 --- a/insertdata/insertDataToEs.go +++ b/insertdata/insertDataToEs.go @@ -1,252 +1,41 @@ package insertdata import ( - "errors" - "fmt" - "encoding/json" - "net" - "time" - - "basic.com/pubsub/protomsg.git" - "basic.com/dbapi.git" - "github.com/golang/protobuf/proto" - "ruleprocess/ruleserver" - "github.com/satori/go.uuid" + "plugin" + "ruleprocess/cache" + "basic.com/valib/logger.git" + "ruleprocess/structure" + "strconv" ) -// 浜鸿劯鐨勬暟鎹粨鏋� -type PerVideoPicture struct { - Id string `json:"id"` - CameraId string `json:"cameraId"` - CameraAddr string `json:"cameraAddr"` - PicDate string `json:"picDate"` - PicMaxUrl string `json:"picMaxUrl"` - TaskId string `json:"taskId"` - TaskName string `json:"taskName"` - SdkName string `json:"sdkName"` - Content string `json:"content"` - LikeDate string `json:"likeDate"` - Sex int32 `json:"sex"` - Age int32 `json:"age"` - AgeDescription string `json:"ageDescription"` - Race int32 `json:"race"` - SmileLevel int32 `json:"smileLevel"` - BeautyLevel int32 `json:"beautyLevel"` - FaceFeature string `json:"faceFeature"` - PicSmUrl string `json:"picSmUrl"` - VideoUrl string `json:"videoUrl"` - AnalyServerId string `json:"analyServerId"` - AnalyServerName string `json:"analyServerName"` - AnalyServerIp string `json:"analyServerIp"` - ClusterId string `json:"clusterId"` - IsAlarm string `json:"isAlarm"` - IsAckAlarm string `json:"isAckAlarm"` - IsCollect string `json:"isCollect"` - IsDelete int `json:"isDelete"` - BaseInfo Base `json:"baseInfo"` -} - -type Base struct { - TableId string `json:"tableId"` - TableName string `json:"tableName"` - CompareScore float64 `json:"compareScore"` - PersonId string `json:"personId"` - PersonName string `json:"personName"` - PersonPicUrl string `json:"personPicUrl"` - PhoneNum string `json:"phoneNum"` - Sex string `json:"sex"` - IdCard string `json:"idCard"` - MonitorLevel string `json:"monitorLevel"` - Content string `json:"content"` -} - -// yolo琛屼负鐨勬暟鎹粨鏋� -type Personaction struct { - Id string `json:"id"` - CameraId string `json:"cameraId"` - CameraName string `json:"cameraName"` - CameraAddr string `json:"cameraAddr"` - TaskId string `json:"taskId"` - TaskName string `json:"taskName"` - SdkName string `json:"sdkName"` - Content string `json:"content"` - AlarmRules []AlarmRule - AnalyServerId string `json:"analyServerId"` - AnalyServerName string `json:"analyServerName"` - AnalyServerIp string `json:"analyServerIp"` - ClusterId string `json:"clusterId"` - PicUrl string `json:"picUrl"` - PicDate string `json:"picDate"` - VideoUrl string `json:"videoUrl"` - IsAlarm string `json:"isAlarm"` - IsAckAlarm string `json:"isAckAlarm"` - IsCollect string `json:"isCollect"` - IsDelete int `json:"isDelete"` -} - -type AlarmRule struct { - GroupId string `json:"groupId"` - AlarmLevel string `json:"alarmLevel"` - RuleText string `json:"ruleText"` -} - -func InsertToEs(msg ruleserver.ResultMsg) { - fmt.Println("寰�ES鎻掓暟鎹�") - - for _, sdkinfo := range msg.Tasklab.Sdkinfos { - if sdkinfo.Sdktype == "FaceDetect" { - faceParam := protomsg.ParamFacePos{} - err1 := proto.Unmarshal(sdkinfo.Sdkdata, &faceParam) - if err1 != nil { - fmt.Println("瑙f瀽sdk鏁版嵁鏃跺嚭鐜伴敊璇�", err1) - continue - } - for _, face := range faceParam.Faces { - pervideo := PerVideoPicture{ - uuid.NewV4().String(), - msg.Cid, - msg.Caddr, - time.Now().Format("2006-01-02 15:04:05"), - "", - msg.Tasklab.Taskid, - msg.Tasklab.Taskname, - sdkinfo.SdkName, - "", - "", - face.Result.Gender, - face.Result.Age, - "", - face.Result.Race, - face.Result.Smile, - face.Result.Beauty, - "涓嶆槸姣忎釜浜鸿劯绠楁硶閮芥湁", - "---", - "", - "", - "", - "", - "", - "", - "", - "", - 0, - Base{ - "鏄瘡涓汉鑴哥畻娉曢兘鏈夊悧", - "", - 0, - "", - "", - "", - "", - "", - "", - "", - "", - }, - } - requstbody, err := json.Marshal(pervideo) - - if err != nil { - fmt.Println("json parse error ", err) - return - - } - err = EsReq("POST", "http://192.168.1.182:9200/videopersons/perVideoPicture", requstbody) - if err != nil { - fmt.Println("es can not execute right.") - } - } +//var weedfsUrl, videoPersonUrl, personAction string +//var serverIp string +//var serverPort string +func InsertToEs(msg structure.ResultMsg) { + defer func() { + if err := recover(); err != nil { + logger.Error("es妯″潡鍎跨殑寮傚父鎹曡幏锛�", err) } - if sdkinfo.Sdktype == "Yolo" { - yoloObj := protomsg.ParamYoloObj{} - err1 := proto.Unmarshal(sdkinfo.Sdkdata, &yoloObj) - if err1 != nil { - fmt.Println("瑙f瀽sdk鏁版嵁鏃跺嚭鐜伴敊璇�", err1) - continue - } - alarmRules := []AlarmRule{} - for _,result := range msg.RuleResult { - alarmRules = append(alarmRules,AlarmRule{result.RuleGroupId,result.AlarmLevel,result.RuleText}) - } - isAlarm := "" - if len(alarmRules) > 0 { - isAlarm = "1" - }else { - isAlarm = "0" - } - // 鏌ヨ鏈満淇℃伅 - flag,localConfig := dbapi.SysSetApi{}.GetServerInfo() - if !flag { - fmt.Println("鏌ヨ鏈満淇℃伅澶辫触锛�") - } - // 鏌ヨcameraName - camera,err := dbapi.CameraApi{}.GetCameraById(msg.Cid) - if err == nil { - fmt.Println("鏌ヨ鎽勫儚鏈轰俊鎭け璐�") - } - serverIp,err := GetLocalIP() - peraction := Personaction{ - uuid.NewV4().String(), - msg.Cid, - camera.Name, - msg.Caddr, - msg.Tasklab.Taskid, - msg.Tasklab.Taskname, - sdkinfo.SdkName, - "", - alarmRules, - localConfig.ServerId, - localConfig.ServerName, - serverIp, - "", - "", - time.Now().Format("2006-01-02 15:04:05"), - "", - isAlarm, - "", - "", - 0, - } - requstbody, err := json.Marshal(peraction) - - if err != nil { - fmt.Println("json parse error ", err) - return - - } - err = EsReq("POST", "http://192.168.1.182:9200/videopersons/perVideoPicture", requstbody) - if err != nil { - fmt.Println("es can not execute right.") - } - } - + }() + localConfig1, err := cache.GetServerInfo() + if err != nil { + panic("閰嶇疆鏂囦欢涓嶅悎娉�") } + weedfsUrl := "http://" + localConfig1.WebPicIp + ":" + strconv.Itoa(int(localConfig1.WebPicPort)) + "/submit" + videoPersonUrl := "http://" + localConfig1.AlarmIp + ":" + strconv.Itoa(int(localConfig1.AlarmPort)) + "/" + structure.EsInfo.EsIndex.AIOcean.IndexName + "/" + structure.EsInfo.EsIndex.AIOcean.IndexType+"?refresh=true" + serverIp := localConfig1.AlarmIp + serverPort := strconv.Itoa(int(localConfig1.AlarmPort)) + handle(msg,weedfsUrl,videoPersonUrl,serverIp,serverPort) } -// 鑾峰彇鏈満ip -func GetLocalIP() (ipv4 string, err error) { - var ( - addrs []net.Addr - addr net.Addr - ipNet *net.IPNet // IP鍦板潃 - isIpNet bool - ) - // 鑾峰彇鎵�鏈夌綉鍗� - if addrs, err = net.InterfaceAddrs(); err != nil { - return +func handle (msg structure.ResultMsg,weedfsUrl,videoPersonUrl,serverIp,serverPort string) { + p,err := plugin.Open("./algorithm/middleware.so") + if err != nil { + panic(err) } - // 鍙栫涓�涓潪lo鐨勭綉鍗P - for _, addr = range addrs { - // 杩欎釜缃戠粶鍦板潃鏄疘P鍦板潃: ipv4, ipv6 - if ipNet, isIpNet = addr.(*net.IPNet); isIpNet && !ipNet.IP.IsLoopback() { - // 璺宠繃IPV6 - if ipNet.IP.To4() != nil { - ipv4 = ipNet.IP.String() // 192.168.1.1 - return - } - } + f,err1 := p.Lookup("InsertToEs") + if err1 != nil { + panic("娌℃湁鎵惧埌涓棿浠剁殑鏍煎紡鍖栨暟鎹嚱鏁�") } - - err = errors.New("ipv4 not found") - return + f.(func(msg structure.ResultMsg,weedfsUrl,videoPersonUrl,serverIp,serverPort string))(msg,weedfsUrl,videoPersonUrl,serverIp,serverPort) } -- Gitblit v1.8.0