From edbb60128b0bf53e735d62feab38b5d7f42be7f0 Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期三, 29 五月 2019 13:17:33 +0800 Subject: [PATCH] fix bug --- esutil/EsClient.go | 93 +++++++++++++++++++++++++++++++++++++--------- 1 files changed, 75 insertions(+), 18 deletions(-) diff --git a/esutil/EsClient.go b/esutil/EsClient.go index be812d8..bf7737b 100644 --- a/esutil/EsClient.go +++ b/esutil/EsClient.go @@ -95,9 +95,22 @@ source["picSmUrl"] = picurl + psm } + prace, exist := source["Race"] + if exist { + source["race"] = prace + } + + pGender, exist := source["Gender"] + if exist { + source["gender"] = pGender + } + + source["ageDescription"] = getAgeDesc(source["Age"]) + source["videoNum"] = getVideoUrl(source) - timeFormat := "2019-05-28 15:04:05" - picDateStr, err := time.Parse(timeFormat, source["picDate"].(string)) + picDate := source["picDate"].(string) + lastIdx := strings.LastIndex(picDate,":") + picDateStr := picDate[:lastIdx] if err == nil { source["picDate"] = picDateStr } @@ -112,6 +125,26 @@ } else { return nil, dat } +} + +func getAgeDesc(age interface{})(ageDesc string) { + if age !=nil { + ageInt := age.(float64) + if ageInt >0 && ageInt<7 { + ageDesc = "绔ュ勾" + } else if ageInt >=7 && ageInt<18 { + ageDesc = "灏戝勾" + } else if ageInt >=18 && ageInt<40 { + ageDesc = "闈掑勾" + } else if ageInt >=40 && ageInt<65 { + ageDesc = "涓勾" + } else if ageInt >=65 { + ageDesc = "鑰佸勾" + } else { + ageDesc = "" + } + } + return ageDesc } type BaseInfo struct { @@ -130,31 +163,55 @@ Content string `json:"content"` } -func getSourceBaseInfo(source map[string]interface{}) (baseInfoJson string) { +func getSourceBaseInfo(source map[string]interface{}) []BaseInfo { sdkType := source["sdkType"].(string) + baseInfoArr := make([]BaseInfo,0) if sdkType == "浜鸿劯" { + likePer,baseName,personId,idCard,personPicUrl,gender,content :="","","","","","","" + if source["likePer"] !=nil { + likePer = source["likePer"].(string) + } + if source["BaseName"] !=nil { + baseName = source["BaseName"].(string) + } + if source["personId"] !=nil { + personId = source["personId"].(string) + } + if source["idcard"] !=nil { + idCard = source["idcard"].(string) + } + if source["personPicUrl"] !=nil { + personPicUrl = source["personPicUrl"].(string) + } + if source["Gender"] !=nil { + gender = source["Gender"].(string) + } + if source["content"] !=nil { + content = source["content"].(string) + } var baseInfo = BaseInfo{ TaskId:"",//2.0鏂板瓧娈� TaskName:"",//2.0鏂板瓧娈� - LikePer:source["likePer"].(string), + LikePer:likePer, TableId:"",//2.0鏂板瓧娈� - TableName:source["BaseName"].(string), - PersonId:source["personId"].(string), - PersonName:source["idcard"].(string),//浜哄憳濮撳悕锛屼粠绠$悊骞冲彴鑾峰彇 - PersonPicUrl:source["personPicUrl"].(string), - Gender:source["Gender"].(string), + TableName:baseName, + PersonId:personId, + PersonName:idCard,//浜哄憳濮撳悕锛屼粠绠$悊骞冲彴鑾峰彇 + PersonPicUrl:personPicUrl, + Gender:gender, PhoneNum:"",//鎵嬫満鍙凤紝浠庣鐞嗗钩鍙拌幏鍙� - IDCard:source["idcard"].(string), + IDCard:idCard, MonitorLevel:"",//2.0鏂板瓧娈� - Content:source["content"].(string), + Content:content, } - bytes, err := json.Marshal(baseInfo) - if err !=nil { - return "" - } - return string(bytes) + + baseInfoArr = append(baseInfoArr, baseInfo) + //bytes, err := json.Marshal(baseInfoArr) + //if err !=nil { + // return "" + //} } - return "" + return baseInfoArr } func getVideoUrl(source map[string]interface{}) (videoUrl string){ @@ -264,7 +321,7 @@ seccond := strconv.Itoa(sec) prama := "{\"query\":{\"bool\":{\"filter\":[{\"range\":{\"picDate\":{\"gte\":\"now+8h-" + seccond + "s\",\"lt\":\"now+8h\"}}}]}},\"size\":\"1000\",\"sort\":[{\"picDate\":{\"order\":\"desc\"}}]," + - "\"_source\":[\"baseInfo\",\"Gender\",\"personId\",\"personPicUrl\",\"indeviceName\",\"imgKey\",\"sdkType\",\"ageDescription\",\"indeviceid\",\"content\",\"Id\",\"picAddress\",\"picMaxUrl\",\"picDate\",\"Race\",\"videoNum\",\"picSmUrl\",\"taskName\",\"personIsHub\",\"idcard\",\"videoIp\",\"videoReqNum\"]" + + "\"_source\":[\"baseInfo\",\"Gender\",\"BaseName\",\"Age\",\"personId\",\"personPicUrl\",\"indeviceName\",\"imgKey\",\"sdkType\",\"ageDescription\",\"indeviceid\",\"content\",\"Id\",\"picAddress\",\"picMaxUrl\",\"picDate\",\"Race\",\"videoNum\",\"picSmUrl\",\"taskName\",\"personIsHub\",\"idcard\",\"videoIp\",\"videoReqNum\"]" + "}" err, tokenRes := GetEsDataReq(url, prama, picurl, true) -- Gitblit v1.8.0