From a5e6ddc46a0306f630ac53a8e0e3843bf8c17a05 Mon Sep 17 00:00:00 2001 From: liuxiaolong <liuxiaolong@aiotlink.com> Date: 星期三, 07 四月 2021 16:43:09 +0800 Subject: [PATCH] 修复日志路径问题 --- esutil/EsClient.go | 67 +++++++++++++++++++++++++-------- 1 files changed, 51 insertions(+), 16 deletions(-) diff --git a/esutil/EsClient.go b/esutil/EsClient.go index 7215b26..f0239fc 100644 --- a/esutil/EsClient.go +++ b/esutil/EsClient.go @@ -98,6 +98,17 @@ if !exist { continue } + alarmRules, exist := source["alarmRules"] + if exist { + if alarmB,ae := json.Marshal(alarmRules);ae ==nil { + var alarmRArr []AlarmRule + if ae = json.Unmarshal(alarmB, &alarmRArr);ae ==nil && len(alarmRArr) >0 { + d["alarmLevel"] = alarmRArr[0].AlarmLevel + } + } + } else { + d["alarmLevel"] = "" + } pmArr := pmax.([]interface{}) if len(pmArr) > 0 { d["picMaxUrl"] = pmArr[0] @@ -121,23 +132,29 @@ if len(tiArr) > 0 { ti := tiArr[0] d["picSmUrl"] = ti.PicSmUrl - if ti.TargetType == "face" { + d["targetType"] = ti.TargetType + if ti.TargetType == "FaceDetect" { sLabelStr, ok := source["showLabels"] if ok { - labelArr := strings.Split(sLabelStr.(string), "/") - if len(labelArr) == 3 { - d["gender"] = labelArr[0] - d["ageDescription"] = labelArr[1] - d["race"] = labelArr[2] - } + //labelArr := strings.Split(sLabelStr.(string), "/") + //if len(labelArr) == 3 { + // d["gender"] = labelArr[0] + // d["ageDescription"] = labelArr[1] + // d["race"] = labelArr[2] + //} + d["showLabels"] = sLabelStr + } else { + d["showLabels"] = "" } + if bInfos,ok := source["baseInfo"]; ok && bInfos != nil { - d["baseInfo"] = getSourceBaseInfo(bInfos) + bd := getSourceBaseInfo(bInfos) + d["baseInfo"] = bd //姣斿鍒扮殑搴曞簱鐨勪汉 } else { d["baseInfo"] = []interface{}{} } - d["sdkType"] = "浜鸿劯" + d["sdkType"] = source["taskName"] } else { d["sdkType"] = source["taskName"] d["picSmUrl"] = d["picMaxUrl"] @@ -146,8 +163,12 @@ d["picSmUrl"] = d["picMaxUrl"] } - - d["videoNum"] = source["videoUrl"] + vUri := source["videoUrl"] + if vUri != nil && vUri.(string) != "" { + d["videoNum"] = "http://"+vUri.(string) + } else { + d["videoNum"] = "" + } sources = append(sources, d) } @@ -156,6 +177,11 @@ } else { return nil, dat } +} + +type AlarmRule struct { + GroupId string `json:"groupId"` + AlarmLevel string `json:"alarmLevel"` } type TargetInfo struct { @@ -168,7 +194,7 @@ type BaseInfo struct { TaskId string `json:"taskId"` TaskName string `json:"taskName"` - LikePer string `json:"likePer"` + LikePer float32 `json:"likePer"` TableId string `json:"tableId"` TableName string `json:"tableName"` PersonId string `json:"personId"` @@ -187,7 +213,7 @@ TargetName string `json:"targetName"` TargetId string `json:"targetId"` TableId string `json:"tableId"` - CompareScore string `json:"compareScore"` + CompareScore float32 `json:"compareScore"` MonitorLevel string `json:"monitorLevel"` Content string `json:"content"` TableName string `json:"tableName"` @@ -236,7 +262,11 @@ Content: t.Content, }) } + } else { + fmt.Println("unmarshal bInfos err:", err) } + } else { + fmt.Println("marshal bInfos err:", err) } return baseInfoArr @@ -259,19 +289,24 @@ preSec = strconv.Itoa(sec) } var filterArr []string + var mustNotArr []string //鏄惁鏌ユ姤璀︽暟鎹� if ishub == "hub" { - filterArr = append(filterArr,"{\"term\":{\"alarmRules.alarmLevel.raw\":\"浜岀骇\"}}") + mustNotArr = append(mustNotArr,"{\"term\":{\"alarmRules.alarmLevel.raw\":\"浜旂骇\"}}") } filterArr = append(filterArr, "{\"range\":{\"picDate\":{\"gte\":\"now+8h-"+preSec+"s\",\"lt\":\"now+8h\"}}}") filterStr := "" + mustNotStr := "" if len(filterArr) >0 { filterStr = strings.Join(filterArr, ",") } - param := "{\"query\":{\"bool\":{\"filter\":["+filterStr+"]}},\"size\":\""+sizeStr+"\",\"sort\":[{\"picDate\":{\"order\":\"desc\"}}]," + - "\"_source\":{\"includes\":[\"cameraAddr\",\"baseInfo\",\"targetInfo\",\"content\",\"id\",\"picMaxUrl\",\"picDate\",\"showLabels\",\"taskName\",\"sdkName\",\"videoUrl\"],\"excludes\":[\"*.feature\",\"*.attachTarget\",\"*.targetLocation\",\"alarmRules\"]}" + + if len(mustNotArr) > 0 { + mustNotStr = strings.Join(mustNotArr, ",") + } + param := "{\"query\":{\"bool\":{\"filter\":["+filterStr+"],\"must_not\":["+mustNotStr+"]}},\"size\":\""+sizeStr+"\",\"sort\":[{\"picDate\":{\"order\":\"desc\"}}]," + + "\"_source\":{\"includes\":[\"cameraAddr\",\"baseInfo\",\"targetInfo\",\"content\",\"id\",\"picMaxUrl\",\"picDate\",\"showLabels\",\"taskName\",\"sdkName\",\"videoUrl\",\"alarmRules\"],\"excludes\":[\"*.feature\",\"*.attachTarget\",\"*.targetLocation\"]}" + "}" err, tokenRes := GetEsDataReq(url, param, true) -- Gitblit v1.8.0