From 1570637a67ec0849dbe53cff570c8691a9cff49b Mon Sep 17 00:00:00 2001
From: panlei <2799247126@qq.com>
Date: 星期一, 16 十二月 2019 13:55:26 +0800
Subject: [PATCH] arg新加一个参数
---
insertdata/insertDataToEs.go | 456 +++-----------------------------------------------------
1 files changed, 29 insertions(+), 427 deletions(-)
diff --git a/insertdata/insertDataToEs.go b/insertdata/insertDataToEs.go
index 5d205a4..05a014e 100644
--- a/insertdata/insertDataToEs.go
+++ b/insertdata/insertDataToEs.go
@@ -1,439 +1,41 @@
package insertdata
import (
- "ruleprocess/logger"
- "encoding/json"
- "errors"
- "fmt"
- "io/ioutil"
- "net"
+ "plugin"
"ruleprocess/cache"
- "strings"
- "time"
-
- "basic.com/pubsub/protomsg.git"
- "github.com/golang/protobuf/proto"
- "github.com/satori/go.uuid"
- "ruleprocess/ruleserver"
- "ruleprocess/util"
- "github.com/go-yaml/yaml"
+ "basic.com/valib/logger.git"
+ "ruleprocess/structure"
+ "strconv"
)
-var weedfsUrl string
-type conf struct {
- PhotoUrl string `yaml:"photoUrl"`
-}
-func init() {
- data, err := ioutil.ReadFile("./config/conf.yml")
+
+//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)
+ }
+ }()
+ localConfig1, err := cache.GetServerInfo()
if err != nil {
- fmt.Println("璇诲彇閰嶇疆鏂囦欢鍑洪敊--",err)
- logger.Error("璇诲彇閰嶇疆鏂囦欢鍑洪敊--",err)
+ panic("閰嶇疆鏂囦欢涓嶅悎娉�")
}
- c := conf{}
- //鎶妝aml褰㈠紡鐨勫瓧绗︿覆瑙f瀽鎴恠truct绫诲瀷
- yaml.Unmarshal(data, &c)
- weedfsUrl = c.PhotoUrl
+ 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)
}
-// 浜鸿劯鐨勬暟鎹粨鏋�
-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 string `json:"sex"`
- Age int32 `json:"age"`
- AgeDescription string `json:"ageDescription"`
- Race string `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"`
- DetectScore float64 `json:"detectScore"`
- IsAlarm int `json:"isAlarm"`
- IsAckAlarm int `json:"isAckAlarm"`
- IsCollect int `json:"isCollect"`
- IsDelete int `json:"isDelete"`
- BaseInfo []*protomsg.Baseinfo `json:"baseInfo"`
-}
-
-// 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 `json:"alarmRules"`
- AnalyServerId string `json:"analyServerId"`
- AnalyServerName string `json:"analyServerName"`
- AnalyServerIp string `json:"analyServerIp"`
- ClusterId string `json:"clusterId"`
- PicSmUrl []string `json:"picSmUrl"`
- PicDate string `json:"picDate"`
- VideoUrl string `json:"videoUrl"`
- IsAlarm int `json:"isAlarm"`
- IsAckAlarm int `json:"isAckAlarm"`
- IsCollect int `json:"isCollect"`
- IsDelete int `json:"isDelete"`
-}
-
-type AlarmRule struct {
- GroupId string `json:"groupId"`
- AlarmLevel string `json:"alarmLevel"`
- RuleText string `json:"ruleText"`
-}
-
-// 寰�ES鎻掓暟鎹�
-func InsertToEs(msg ruleserver.ResultMsg) {
- var timeLabel string
- // 鐩存帴浠庤鍒欑殑鏍囩鏁版嵁閲屾嬁绗﹀悎瑙勫垯鐨勪汉鑴哥粨鏋�
- if msg.RuleResult["timeLabel"] != nil {
- timeLabel = msg.RuleResult["timeLabel"].(string)
+func handle (msg structure.ResultMsg,weedfsUrl,videoPersonUrl,serverIp,serverPort string) {
+ p,err := plugin.Open("./algorithm/middleware.so")
+ if err != nil {
+ panic(err)
}
- logger.Debug("鎻掑叆鏁版嵁鍓嶇湅鐪嬫姤璀︽爣蹇椾綅锛�",msg.RuleResult["timeLabel"].(string))
- if timeLabel == "10" {
- if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]ruleserver.Arg)) > 0 {
- logger.Info("寰�ES鎻掍汉鑴告暟鎹�")
- for _, face := range msg.RuleResult["face"].([]ruleserver.Arg) {
- // 涓婁紶澶у浘
- // 瑙e帇缂╁苟涓婁紶鍥剧墖
- bdata, err := util.UnCompress(msg.Data)
- if err != nil {
- panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
- }
- i := protomsg.Image{}
- err = proto.Unmarshal(bdata, &i)
- bigPhotoUrl := make(map[string]interface{})
- bigPhotoUrl, err = util.PostFormBufferData(weedfsUrl, i, uuid.NewV4().String())
- logger.Info(bigPhotoUrl)
- if len(face.Liker) == 0 {
- // 浜鸿劯妫�娴嬶紝娌℃湁鐩镐技鐨勫簳搴撲汉鍛�
- localConfig, err := cache.GetServerInfo()
- if err != nil {
- logger.Error("鏌ヨ鏈満淇℃伅澶辫触锛�")
- }
- serverIp, err := GetLocalIP()
- // 瑙e帇缂╁苟涓婁紶鍥剧墖
- bdata, err := util.UnCompress(msg.Data)
- if err != nil {
- panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
- }
- // 鏌ヨcameraName
- camera, err := cache.GetCameraById(msg.Cid)
- if err != nil {
- logger.Error("鏌ヨ鎽勫儚鏈轰俊鎭け璐�")
- }
- i := protomsg.Image{}
- err = proto.Unmarshal(bdata, &i)
- bytes := util.SubImg(i, int(face.Location.X), int(face.Location.Y), int(face.Location.X+face.Location.Width), int(face.Location.Y+face.Location.Height))
- resp, err := util.PostFormBufferData1(weedfsUrl, bytes, uuid.NewV4().String())
- if err != nil {
- logger.Error("涓婁紶灏忓浘鍑洪敊")
- }
- logger.Info("================灏忓浘鍦板潃:",resp["fileUrl"].(string))
- sex := ""
- if face.ThftRes.Gender == 1 {
- sex = "鐢�"
- } else {
- sex = "濂�"
- }
- race := getRaceString(face.ThftRes.Race)
- ageDescription := getDescription(face.ThftRes.Age)
-
- pervideo := PerVideoPicture{
- uuid.NewV4().String(),
- msg.Cid,
- camera.Addr,
- time.Now().Format("2006-01-02 15:04:05"),
- strings.Split(bigPhotoUrl["fileUrl"].(string), "/")[1],
- msg.Tasklab.Taskid,
- msg.Tasklab.Taskname,
- "浜鸿劯",
- "",
- time.Now().Format("2006-01-02 15:04:05"), // 鍙娴嬶紝娌℃湁姣斿鏃堕棿
- sex,
- face.ThftRes.Age,
- ageDescription,
- race,
- face.ThftRes.Smile,
- face.ThftRes.Beauty,
- string(face.Feature),
- []string{strings.Split(resp["fileUrl"].(string), "/")[1]},
- "鏆傛棤闆嗙兢",
- localConfig.ServerId,
- localConfig.ServerName,
- serverIp,
- "",
- face.Score,
- 1,
- 0,
- 0,
- 0,
- []*protomsg.Baseinfo{},
- }
- requstbody, err := json.Marshal(pervideo)
-
- if err != nil {
- logger.Info("json parse error ", err)
- return
-
- }
- err1 := EsReq("POST", "http://192.168.1.182:9200/videopersons/perVideoPicture", requstbody)
- if err1 != nil {
- logger.Error("涓婁紶ES鍑洪敊锛�---",err1)
- }
- //logger.Info(err.Error())
- } else {
- // 浜鸿劯姣斿
- logger.Warn("___________________________________________杩欐槸鏈塨aseinfo鐨�")
- localConfig, err := cache.GetServerInfo()
- if err != nil {
- logger.Info("鏌ヨ鏈満淇℃伅澶辫触锛�")
- }
- serverIp, err := GetLocalIP()
- // 瑙e帇缂╁苟涓婁紶鍥剧墖
- bdata, err := util.UnCompress(msg.Data)
- if err != nil {
- panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
- }
- // 鏌ヨcameraName
- camera, err := cache.GetCameraById(msg.Cid)
- if err != nil {
- logger.Error("鏌ヨ鎽勫儚鏈轰俊鎭け璐�")
- }
- i := protomsg.Image{}
- err = proto.Unmarshal(bdata, &i)
- //logger.Info("-------------------------------------------鐪嬩笅瀹藉拰楂�", i.Width, i.Height)
- bytes := util.SubImg(i, int(face.Location.X), int(face.Location.Y), int(face.Location.X+face.Location.Width), int(face.Location.Y+face.Location.Height))
- resp, err := util.PostFormBufferData1(weedfsUrl, bytes, uuid.NewV4().String())
- if err != nil {
- logger.Error("涓婁紶灏忓浘鍑洪敊")
- }
- logger.Info("================灏忓浘鍦板潃:",resp["fileUrl"].(string))
- sex := ""
- if face.ThftRes.Gender == 1 {
- sex = "鐢�"
- } else {
- sex = "濂�"
- }
- race := getRaceString(face.ThftRes.Race)
- ageDescription := getDescription(face.ThftRes.Age)
- pervideo := PerVideoPicture{
- uuid.NewV4().String(),
- msg.Cid,
- camera.Addr,
- time.Now().Format("2006-01-02 15:04:05"),
- strings.Split(bigPhotoUrl["fileUrl"].(string), "/")[1],
- msg.Tasklab.Taskid,
- msg.Tasklab.Taskname,
- "浜鸿劯",
- "",
- time.Now().Format("2006-01-02 15:04:05"), // 鍙娴嬶紝娌℃湁姣斿鏃堕棿
- sex,
- face.ThftRes.Age,
- ageDescription,
- race,
- face.ThftRes.Smile,
- face.ThftRes.Beauty,
- "",
- []string{strings.Split(resp["fileUrl"].(string), "/")[1]},
- "鏆傛棤闆嗙兢",
- localConfig.ServerId,
- localConfig.ServerName,
- serverIp,
- "",
- face.Score,
- 1,
- 0,
- 0,
- 0,
- face.Liker,
- }
- requstbody, err := json.Marshal(pervideo)
-
- if err != nil {
- logger.Error("json parse error ", err)
- return
-
- }
- err = EsReq("POST", "http://192.168.1.182:9200/videopersons/perVideoPicture", requstbody)
- logger.Info("------------------------------------------鍝堝搱鍝堝搱锛屽簳搴撴湁浜�")
-
- }
- }
- }
- if msg.RuleResult["yolo"] != nil && len(msg.RuleResult["yolo"].([]ruleserver.Result)) > 0 {
- logger.Info("寰�ES鎻抷olo鏁版嵁")
- var sdkNames string = ""
- alarmRules := []AlarmRule{}
- for _, yoloResult := range msg.RuleResult["yolo"].([]ruleserver.Result) {
- sdkNames = sdkNames + yoloResult.SdkName
- alarm := ChangeToString(yoloResult.AlarmLevel)
- alarmRules = append(alarmRules, AlarmRule{yoloResult.RuleGroupId, alarm, yoloResult.RuleText})
- }
- isAlarm := 0
- resp := make(map[string]interface{})
- if len(alarmRules) > 0 {
- isAlarm = 1
- // 瑙e帇缂╁苟涓婁紶鍥剧墖
- bdata, err := util.UnCompress(msg.Data)
- if err != nil {
- panic("瑙e帇缂╁浘鐗囨椂鍑虹幇閿欒")
- }
- i := protomsg.Image{}
- err = proto.Unmarshal(bdata, &i)
- //resp, err = util.PostFormBufferData(weedfsUrl, i, uuid.NewV4().String())
- resp, err = util.DrawPolygonOnImage(msg.Cid, i,msg.RuleResult["yolo"].([]ruleserver.Result))
- if err != nil {
- logger.Error("鐢绘鎴栦笂浼犲浘鐗囨湇鍔″櫒鍑洪敊", err)
- } else {
- logger.Info("涓婁紶鐨勫浘鐗囦俊鎭細",resp)
- }
- } else {
- isAlarm = 0
- // 涓嶆槸鎶ヨ鏁版嵁涓嶅瓨
- return
- }
- // logger.Println("鍥剧墖涓婁紶杩斿洖鍊硷細", resp)
- // 鏌ヨ鏈満淇℃伅
- localConfig, err := cache.GetServerInfo()
- if err != nil {
- logger.Error("鏌ヨ鏈満淇℃伅澶辫触锛�")
- }
- // 鏌ヨcameraName
- camera, err := cache.GetCameraById(msg.Cid)
- if err != nil {
- logger.Error("鏌ヨ鎽勫儚鏈轰俊鎭け璐�")
- }
- serverIp, err := GetLocalIP()
- peraction := Personaction{
- uuid.NewV4().String(),
- msg.Cid,
- camera.Name,
- camera.Addr,
- msg.Tasklab.Taskid,
- msg.Tasklab.Taskname,
- sdkNames,
- "",
- alarmRules,
- localConfig.ServerId,
- localConfig.ServerName,
- serverIp,
- "",
- []string{strings.Split(resp["fileUrl"].(string), "/")[1]},
- time.Now().Format("2006-01-02 15:04:05"),
- "",
- isAlarm,
- 0,
- 0,
- 0,
- }
- requstbody, err := json.Marshal(peraction)
-
- if err != nil {
- logger.Info("json parse error ", err)
- return
-
- }
- err = EsReq("POST", "http://192.168.1.182:9200/personaction/perVideoAction", requstbody)
- if err != nil {
- logger.Error("寰�ES鎻掑叆鏁版嵁澶辫触", err)
- } else {
- logger.Warn("__________________________________________寰�ES鎻掑叆yolo鏁版嵁鎴愬姛")
- //os.Exit(1)
- }
- }
+ f,err1 := p.Lookup("InsertToEs")
+ if err1 != nil {
+ panic("娌℃湁鎵惧埌涓棿浠剁殑鏍煎紡鍖栨暟鎹嚱鏁�")
}
-}
-
-// 鑾峰彇鏈満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
- }
- // 鍙栫涓�涓潪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
- }
- }
- }
-
- err = errors.New("ipv4 not found")
- return
-}
-
-// 鎶婃姤璀︾瓑绾ц浆鍖栨垚姹夊瓧
-func ChangeToString(i int32) string {
- alarm := ""
- if i == 1 {
- alarm = "涓�绾�"
- }
- if i == 2 {
- alarm = "浜岀骇"
- }
- if i == 3 {
- alarm = "涓夌骇"
- }
- if i == 4 {
- alarm = "鍥涚骇"
- }
- if i == 5 {
- alarm = "浜旂骇"
- }
- return alarm
-}
-
-//鑾峰彇骞撮緞鎻忚堪
-func getDescription(age int32) string {
- ageInfo := "闈掑勾"
- if age > 0 && age < 7 {
- ageInfo = "绔ュ勾"
- } else if age >= 7 && age < 18 {
- ageInfo = "灏戝勾"
- } else if age >= 18 && age < 40 {
- ageInfo = "闈掑勾"
- } else if age >= 40 && age < 65 {
- ageInfo = "涓勾"
- } else if age >= 65 {
- ageInfo = "鑰佸勾"
- }
- return ageInfo
-}
-
-func getRaceString(i int32) string {
- race := ""
- if i == 1 {
- race = "鐧戒汉"
- } else if i == 2 {
- race = "榛勪汉"
- } else {
- race = "榛戜汉"
- }
- return race
+ f.(func(msg structure.ResultMsg,weedfsUrl,videoPersonUrl,serverIp,serverPort string))(msg,weedfsUrl,videoPersonUrl,serverIp,serverPort)
}
--
Gitblit v1.8.0