From ebfa610f8c66fd2827a2eec619bfb3e0e22c332f Mon Sep 17 00:00:00 2001
From: sunty <1172534965@qq.com>
Date: 星期一, 25 三月 2024 17:13:14 +0800
Subject: [PATCH] 昼伏夜出调试
---
EsApi.go | 274 ++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 232 insertions(+), 42 deletions(-)
diff --git a/EsApi.go b/EsApi.go
index 96348c7..eb96adc 100644
--- a/EsApi.go
+++ b/EsApi.go
@@ -22,6 +22,141 @@
}
}
+//***********************閲嶅簡Start**********************************//
+
+type activeHourFormat struct {
+ startTime string
+ endTime string
+ startHour int
+ endHour int
+}
+
+func formatActiveHour(activeHour string) (activeHourFormat, error) {
+ hours := strings.Split(activeHour, "-")
+
+ if len(hours) == 2 {
+ startHour := hours[0]
+ endHour := hours[1]
+
+ // 瑙f瀽寮�濮嬫椂闂寸殑灏忔椂鍜屽垎閽�
+ startParts := strings.Split(startHour, ":")
+ startHourInt, _ := strconv.Atoi(startParts[0])
+
+ // 瑙f瀽缁撴潫鏃堕棿鐨勫皬鏃跺拰鍒嗛挓
+ endParts := strings.Split(endHour, ":")
+ endHourInt, _ := strconv.Atoi(endParts[0])
+
+ // 杈撳嚭寮�濮嬫椂闂寸殑灏忔椂
+ fmt.Println("寮�濮嬫椂闂寸殑灏忔椂:", startHourInt)
+
+ // 杈撳嚭缁撴潫鏃堕棿鐨勫皬鏃� + 1
+ endHourPlusOne := (endHourInt + 1) % 24 // 鍙栦綑纭繚涓嶈秴杩�24灏忔椂
+ fmt.Println("缁撴潫鏃堕棿鐨勫皬鏃� + 1:", endHourPlusOne)
+ activeHourFormat := activeHourFormat{startTime: startHour, endTime: endHour, startHour: startHourInt, endHour: endHourPlusOne}
+ return activeHourFormat, nil
+ }
+ return activeHourFormat{}, errors.New("閿欒锛氭棤娉曡В鏋愬紑濮嬫椂闂村拰缁撴潫鏃堕棿")
+
+}
+
+func DayNightActivityQuery(communityId string, startTime string, endTime string, activeHour string, indexName string, serverIp string, serverPort string) ([]string, error) {
+ activityId := make([]string, 0)
+ esURL := "http://" + serverIp + ":" + serverPort + "/" + indexName + "/_search"
+
+ activeHourFormat, err := formatActiveHour(activeHour)
+ if err != nil {
+ return nil, err
+ }
+
+ queryDSL := `
+ {
+ "size": 0,
+ "query": {
+ "bool": {
+ "filter": [
+ {
+ "range": {
+ "picDate": {
+ "gte": "` + startTime + `",
+ "lt": "` + endTime + `"
+ }
+ }
+ },
+ {
+ "term": {
+ "communityId": "` + communityId + `"
+ }
+ },
+ {
+ "script": {
+ "script": {
+ "source": "doc['picDate'].value.hourOfDay >= ` + strconv.Itoa(activeHourFormat.startHour) + ` || doc['picDate'].value.hourOfDay < ` + strconv.Itoa(activeHourFormat.endHour) + `",
+ "lang": "painless"
+ }
+ }
+ }
+ ],
+ "must_not": [
+ {
+ "term": {
+ "documentNumber": ""
+ }
+ }
+ ]
+ }
+ },
+ "aggs": {
+ "group_by_documentnumber": {
+ "terms": {
+ "field": "documentNumber",
+ "size": 100000
+ },
+ "aggs": {
+ "group_by_date": {
+ "date_histogram": {
+ "field": "picDate",
+ "interval": "1d", // 鎸夊ぉ鍒嗘《
+ "format": "yyyy-MM-dd"
+ },
+ "aggs": {
+ "top_hits": {
+ "top_hits": {
+ "_source": [
+ "picDate"
+ ],
+ "size": 100000,
+ "sort": [
+ {
+ "picDate": {
+ "order": "desc"
+ }
+ }
+ ]
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }`
+ //fmt.Println(esURL)
+ //fmt.Println(queryDSL)
+ buf, err := EsReq("POST", esURL, []byte(queryDSL))
+ if err != nil {
+ return nil, err
+ }
+ source, err := SourceAggregationList(buf)
+ if err != nil {
+ return nil, err
+ }
+ result, _ := decodeDocumentInfos(source)
+ return result, nil
+
+ return activityId, nil
+}
+
+// ***********************閲嶅簡End************************************//
// 鏍规嵁鎶撴媿浜哄憳id鏌ヨ鎶撴媿浜哄憳淇℃伅
func AIOceaninfosbyid(id []string, indexName string, serverIp string, serverPort string) ([]protomsg.AIOcean, error) {
var aIOceanInfo []protomsg.AIOcean
@@ -56,7 +191,43 @@
return aIOcean, nil
}
-//鏍规嵁鎶撴媿搴撲汉鍛榠d鏌ヨ鐗瑰緛鍊�
+// 鏍规嵁鎶撴媿浜哄憳id鏌ヨ瑙嗛鍦板潃
+func AIOceanVideoUrlbyid(id string, indexName string, serverIp string, serverPort string) (string, error) {
+ //var aIOceanInfo []protomsg.AIOcean
+ //videopersonsPersonId := strings.Replace(strings.Trim(fmt.Sprint(id), "[]"), " ", "\",\"", -1)
+ var dbinfoRequest = `
+ {
+ "query": {
+ "bool": {
+ "filter": [
+ {
+ "term": {
+ "id": "` + id + `"
+ }
+ }
+ ]
+ }
+ },
+ "_source": [
+ "videoUrl"
+ ]
+ }
+ `
+ buf, err := EsReq("POST", "http://"+serverIp+":"+serverPort+"/"+indexName+"/_search", []byte(dbinfoRequest))
+ if err != nil {
+ return "", err
+ }
+
+ sources, err := Sourcelist(buf)
+ if err != nil {
+ return "", err
+ }
+ videoUrl := sources[0]["videoUrl"].(string)
+ //aIOcean := AIOceanAnalysis(sources)
+ return videoUrl, nil
+}
+
+// 鏍规嵁鎶撴媿搴撲汉鍛榠d鏌ヨ鐗瑰緛鍊�
func GetVideoPersonFaceFeatureById(id string, indexName string, serverIp string, serverPort string) (string, error) {
var jsonDSL = `
{
@@ -86,7 +257,7 @@
return feature, nil
}
-//鏍规嵁鐩爣id鏌ヨ宸茶拷鍔犳潯鏁�
+// 鏍规嵁鐩爣id鏌ヨ宸茶拷鍔犳潯鏁�
func GetLinkTagInfoSize(id string, indexName string, serverIp string, serverPort string) (size int, err error) {
url := "http://" + serverIp + ":" + serverPort + "/" + indexName + "/_search"
queryDSL := `{
@@ -112,7 +283,7 @@
return size, nil
}
-//鏍规嵁鐩爣id杩藉姞璺熻釜淇℃伅
+// 鏍规嵁鐩爣id杩藉姞璺熻釜淇℃伅
func AppendTargetInfo(id string, targetInfo string, indexName string, serverIp string, serverPort string, updateTime string) (string, error) {
if targetInfo == "" {
return "", errors.New("append data is nil")
@@ -454,7 +625,7 @@
return ids, nil
}
-//缁熻鍚勪釜鍖哄煙浜烘暟
+// 缁熻鍚勪釜鍖哄煙浜烘暟
func StatisticsEveryAreaPersonsNumber(startTime string, endTime string, serverIp string, serverPort string, indexName string) ([]map[string]interface{}, error) {
var requestUrl = "http://" + serverIp + ":" + serverPort + "/" + indexName + "/_search"
var requestBody = `{
@@ -581,7 +752,7 @@
}
-//鏍规嵁鏃堕棿鑼冨洿锛屾憚鍍忔満鍒楄〃锛屽垎缁勮仛鍚堜汉鑴稿垪琛�,杩斿洖鍒嗙粍鏁版嵁
+// 鏍规嵁鏃堕棿鑼冨洿锛屾憚鍍忔満鍒楄〃锛屽垎缁勮仛鍚堜汉鑴稿垪琛�,杩斿洖鍒嗙粍鏁版嵁
func GetFaceDataBucketsByCameraIdAndTimeReturnByGrouped(cameraId []string, personId []string, startTime string, endTime string, thresholdTime float64, serverIp string, ServerPort string, indexName string) (buckersDate map[string]interface{}, err error) {
var filterArr []string
if cameraId != nil && len(cameraId) > 0 {
@@ -687,7 +858,7 @@
return sources, nil
}
-//鏍规嵁鏃堕棿鑼冨洿锛屾憚鍍忔満鍒楄〃锛屽垎缁勮仛鍚堜汉鑴稿垪琛�
+// 鏍规嵁鏃堕棿鑼冨洿锛屾憚鍍忔満鍒楄〃锛屽垎缁勮仛鍚堜汉鑴稿垪琛�
func GetFaceDataBucketsByCameraIdAndTime(cameraId []string, personId []string, startTime string, endTime string, thresholdTime float64, serverIp string, ServerPort string, indexName string) (buckersDate map[string]interface{}, err error) {
var filterArr []string
if cameraId != nil && len(cameraId) > 0 {
@@ -788,7 +959,7 @@
return sources, nil
}
-//鏍规嵁鎶撴媿浜哄憳id鏇存柊锛坧icurl锛夊浘鐗囧湴鍧�
+// 鏍规嵁鎶撴媿浜哄憳id鏇存柊锛坧icurl锛夊浘鐗囧湴鍧�
func UpdatePicUrlById(id string, picUrl string, indexName string, serverIp string, serverPort string) (err error) {
updateTime := time.Now().Format("2006-01-02 15:04:05")
tRes, err := AIOceaninfosbyid([]string{id}, indexName, serverIp, serverPort)
@@ -851,7 +1022,7 @@
return nil
}
-//鏍规嵁鎶撴媿浜哄憳id鏇存柊锛坴ideourl锛夋憚鍍忔満鍦板潃
+// 鏍规嵁鎶撴媿浜哄憳id鏇存柊锛坴ideourl锛夋憚鍍忔満鍦板潃
func UpdateVideourlById(id string, videoUrl string, indexName string, serverIp string, serverPort string, command int) (statu int, err error) {
var info interface{}
@@ -888,23 +1059,30 @@
return statu, errors.New("http response interface can not change map[string]interface{}")
}
middle, ok := out["updated"].(float64)
- if !ok {
+ batches, ok1 := out["batches"].(float64)
+ if !ok || !ok1 {
logPrint("first updated change error!")
statu = 500
return statu, errors.New("first updated change error!")
}
- if middle == 1 {
- statu = 200
- return statu, nil
- }
- if middle == 0 {
- statu = 201
- return statu, errors.New("宸茬粡淇敼")
+ if batches == 0 {
+ logPrint("no such doc in database")
+ statu = 400
+ return statu, errors.New("鐩爣鏁版嵁涓嶅瓨鍦�")
+ } else {
+ if middle == 1 {
+ statu = 200
+ return statu, nil
+ }
+ if middle == 0 {
+ statu = 201
+ return statu, errors.New("宸茬粡淇敼")
+ }
}
return statu, nil
}
-//鑾峰彇褰撳墠鑺傜偣鎶撴媿搴撴墍鏈変汉鍛業D*缂撳瓨*
+// 鑾峰彇褰撳墠鑺傜偣鎶撴媿搴撴墍鏈変汉鍛業D*缂撳瓨*
func GetAllLocalVideopersonsId(compareArgs protomsg.CompareArgs, indexName string, serverIp string, serverPort string, alarmLevelTypes string) (capturetable []string) {
queryStr := ""
queryBody := compareArgs.InputValue
@@ -944,7 +1122,12 @@
isCollectStr := ""
isCollect := compareArgs.Collection
if isCollect != "" {
- isCollectStr = "{\"term\":{\"isCollect\":\"" + isCollect + "\"}},"
+ //isCollectStr = "{\"term\":{\"isCollect\":\"" + isCollect + "\"}},"
+ if isCollect == "1" {
+ isCollectStr = "{\"term\":{\"isCollect\":true}},"
+ } else if isCollect == "0" {
+ isCollectStr = "{\"term\":{\"isCollect\":false}},"
+ }
}
//鍒ゆ柇甯冮槻绛夌骇
@@ -1068,7 +1251,7 @@
return capturetable
}
-//鍒濆鍖栧疄鏃舵姄鎷�
+// 鍒濆鍖栧疄鏃舵姄鎷�
func InitRealTimeCapture(serverIp string, serverPort string, indexName string, isAlarm string, category string, quantity int) ([]protomsg.AIOcean, error) {
var aIOceanInfo []protomsg.AIOcean
url := "http://" + serverIp + ":" + serverPort +
@@ -1121,7 +1304,7 @@
return aIOcean, nil
}
-//瀹炴椂鎶撴媿
+// 瀹炴椂鎶撴媿
func RealTimeCapture(serverIp string, serverPort string, indexName string, isAlarm bool) ([]protomsg.AIOcean, error) {
var aIOceanInfo []protomsg.AIOcean
url := "http://" + serverIp + ":" + serverPort +
@@ -1165,7 +1348,7 @@
return aIOcean, nil
}
-//缁煎悎缁熻
+// 缁煎悎缁熻
func StatisticsComprehensive(serverIp string, serverPort string, indexName string, isAlarm string) (total int, err error) {
url := "http://" + serverIp + ":" + serverPort +
"/" + indexName + "/_search"
@@ -1214,7 +1397,7 @@
return total, nil
}
-//瀹炴椂鎶ヨ浠诲姟姣旂巼
+// 瀹炴椂鎶ヨ浠诲姟姣旂巼
func RealTimeAlarmTaskRate(serverIp string, serverPort string, indexName string) (sources []map[string]interface{}, err error) {
url := "http://" + serverIp + ":" + serverPort +
"/" + indexName + "/_search"
@@ -1275,11 +1458,20 @@
return sources, nil
}
-//鑱氬悎浠诲姟鍒楄〃锛宼askId+taskName
-func AggregateTaskList(serverIp string, serverPort string, indexName string, analyServerId string) (sources []map[string]interface{}, err error) {
+// 鑱氬悎浠诲姟鍒楄〃锛宼askId+taskName
+func AggregateTaskList(serverIp string, serverPort string, indexName string, analyServerId string, cameraIds []string) (sources []map[string]interface{}, err error) {
url := "http://" + serverIp + ":" + serverPort +
"/" + indexName + "/_search"
serverFilterStr := ""
+ cameIdFilterStr := ""
+ if cameraIds != nil && len(cameraIds) > 0 {
+ cameIdsStr := strings.Replace(strings.Trim(fmt.Sprint(cameraIds), "[]"), " ", "\",\"", -1)
+ cameIdFilterStr = `,{
+ "term": {
+ "cameraId": "` + cameIdsStr + `"
+ }
+ }`
+ }
if analyServerId != "" {
serverFilterStr = `,
"query": {
@@ -1288,8 +1480,9 @@
{
"term": {
"analyServerId": "` + analyServerId + `"
+ }
}
- }
+ ` + cameIdFilterStr + `
]
}
}`
@@ -1361,7 +1554,7 @@
}
-//娣诲姞鍗冲皢鍒犻櫎淇″彿
+// 娣诲姞鍗冲皢鍒犻櫎淇″彿
func AddDeleteSignal() {
}
@@ -1402,7 +1595,7 @@
}
-//鏌ヨ鏃堕棿娈垫暟鎹� *缂撳瓨*
+// 鏌ヨ鏃堕棿娈垫暟鎹� *缂撳瓨*
func GetPeriodInfos(serverIp string, serverPort string, startTime string, endTime string, indexName string, shards string, targetType string) ([]*protomsg.MultiFeaCache, error) {
var capdbinfo []*protomsg.MultiFeaCache
url := "http://" + serverIp + ":" + serverPort + "/" + indexName + "/_search?preference=_shards:" + shards + "|_only_local"
@@ -1580,8 +1773,8 @@
return dbinfos, nil
}
-//************************CORN TASK*******************************
-//鏌ヨ鏃ユ湡鑼冨洿鍐呮槸鍚﹁繕瀛樺湪鏁版嵁
+// ************************CORN TASK*******************************
+// 鏌ヨ鏃ユ湡鑼冨洿鍐呮槸鍚﹁繕瀛樺湪鏁版嵁
func QueryAnalyServerData(serverIp string, serverPort string, indexName string, startTime string, endTime string, analyServerId string) (result bool, err error) {
url := "http://" + serverIp + ":" + serverPort + "/" + indexName + "/_search"
deleteJson := `{
@@ -1620,8 +1813,8 @@
return result, nil
}
-//鎸夋棩鏈熻寖鍥达紝鏈嶅姟鍣↖d鍒犻櫎鏁版嵁
-func DeleteAnalyServerData(serverIp string, serverPort string, indexName string, startTime string, endTime string, analyServerId string) (result bool, err error) {
+// 鎸夋棩鏈熻寖鍥达紝鏈嶅姟鍣↖d鍒犻櫎鏁版嵁
+func DeleteAnalyServerData(serverIp string, serverPort string, indexName string, startTime string, endTime string, analyServerId string) (total int, err error) {
url := "http://" + serverIp + ":" + serverPort + "/" + indexName + "/_delete_by_query"
deleteJson := `{
"query":{
@@ -1643,23 +1836,20 @@
}
}
} `
+ fmt.Println(url)
+ fmt.Println(deleteJson)
buf, err := EsReq("POST", url, []byte(deleteJson))
if err != nil {
- return false, errors.New("璇锋眰澶辫触")
+ return -1, errors.New("璇锋眰澶辫触")
}
deleteRes, err := SourceDeleted(buf)
if err != nil {
- return false, errors.New("瑙g爜澶辫触")
+ return -1, errors.New("瑙g爜澶辫触")
}
- if deleteRes == -1 {
- result = false
- } else {
- result = true
- }
- return result, nil
+ return deleteRes, nil
}
-//缁欐墍鏈夎妭鐐硅拷鍔犲垹闄や换鍔′俊鎭�
+// 缁欐墍鏈夎妭鐐硅拷鍔犲垹闄や换鍔′俊鎭�
func AddDelTask(serverIp string, serverPort string, indexName string, startTime string, endTime string, analyServerId string) (result bool, err error) {
url := "http://" + serverIp + ":" + serverPort + "/" + indexName + "/_update_by_query"
addJson := `{
@@ -1702,7 +1892,7 @@
return result, nil
}
-//绉婚櫎宸叉墽琛屽畬鐨勫垹闄や换鍔�
+// 绉婚櫎宸叉墽琛屽畬鐨勫垹闄や换鍔�
func DeleteDelTask(serverIp string, serverPort string, indexName string, analyServerId string) (result bool, err error) {
url := "http://" + serverIp + ":" + serverPort + "/" + indexName + "/_update_by_query"
deleteJson := `{
@@ -1747,7 +1937,7 @@
ShardNode string `json:"shardNode"` //鍒嗙墖鎵�鍦ㄨ妭鐐瑰悕绉�
}
-//鑾峰彇绱㈠紩鍒嗙墖淇℃伅
+// 鑾峰彇绱㈠紩鍒嗙墖淇℃伅
func GetShardsByIndex(serverIp string, serverPort string, indexName string) ([]ShardInfo, error) {
url := "http://" + serverIp + ":" + serverPort + "/_cat/shards?v"
buf, err := EsReq("GET", url, []byte(""))
--
Gitblit v1.8.0