From 4e30b339ac10cdbce8a6aa1078a8ebcdafc37350 Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期三, 29 五月 2019 10:11:50 +0800 Subject: [PATCH] fix dateformat --- esutil/EsClient.go | 79 +++++++++++++++++++++++++++++++++------ 1 files changed, 67 insertions(+), 12 deletions(-) diff --git a/esutil/EsClient.go b/esutil/EsClient.go index 5e7a606..c57bd2a 100644 --- a/esutil/EsClient.go +++ b/esutil/EsClient.go @@ -95,9 +95,17 @@ source["picSmUrl"] = picurl + psm } + prace, exist := source["Race"] + if exist { + source["race"] = prace + } + + source["ageDescription"] = getAgeDesc(source["Age"]) + source["videoNum"] = getVideoUrl(source) - timeFormat := "2019-05-28 15:04:05" - picDateStr, err := time.Parse(timeFormat, source["picDate"].(string)) + + picDateStr, err := time.Parse("2006-01-02 15:04:05", source["picDate"].(string)) + fmt.Println("picDate: ", picDateStr) if err == nil { source["picDate"] = picDateStr } @@ -112,6 +120,28 @@ } else { return nil, dat } +} + +func getAgeDesc(age interface{})(ageDesc string) { + fmt.Println("ageInterface: ", age) + if age !=nil { + ageInt := age.(int) + 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 = "" + } + } + fmt.Println("ageDescription: ", ageDesc) + return ageDesc } type BaseInfo struct { @@ -132,23 +162,48 @@ func getSourceBaseInfo(source map[string]interface{}) (baseInfoJson string) { 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) + + baseInfoArr = append(baseInfoArr, baseInfo) + bytes, err := json.Marshal(baseInfoArr) if err !=nil { return "" } @@ -263,7 +318,7 @@ seccond := strconv.Itoa(sec) - prama := "{\"query\":{\"bool\":{\"filter\":[{\"term\":{\"personIsHub\":\"1\"}},{\"range\":{\"picDate\":{\"gte\":\"now+8h-" + seccond + "s\",\"lt\":\"now+8h\"}}}]}},\"size\":\"1000\",\"sort\":[{\"picDate\":{\"order\":\"desc\"}}]," + + 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\"]" + "}" err, tokenRes := GetEsDataReq(url, prama, picurl, true) -- Gitblit v1.8.0