| | |
| | | } |
| | | } |
| | | |
| | | //***********************重庆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] |
| | | |
| | | // 解析开始时间的小时和分钟 |
| | | startParts := strings.Split(startHour, ":") |
| | | startHourInt, _ := strconv.Atoi(startParts[0]) |
| | | |
| | | // 解析结束时间的小时和分钟 |
| | | 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 |
| | |
| | | } |
| | | |
| | | //按日期范围,服务器Id删除数据 |
| | | func DeleteAnalyServerData(serverIp string, serverPort string, indexName string, startTime string, endTime string, analyServerId string) (total int, err error, ) { |
| | | 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":{ |
| | |
| | | "time" |
| | | ) |
| | | |
| | | |
| | | func Parsesources(sources []map[string]interface{}) (multiInfos []*protomsg.MultiFeaCache) { |
| | | var ok bool |
| | | for _, source := range sources { |
| | |
| | | return total, nil |
| | | } |
| | | |
| | | func SourceAggregationList(buf []byte) (sources []map[string]interface{}, err error) { |
| | | var info interface{} |
| | | json.Unmarshal(buf, &info) |
| | | out, ok := info.(map[string]interface{}) |
| | | if !ok { |
| | | return nil, errors.New("http response interface can not change map[string]interface{}") |
| | | } |
| | | |
| | | middle, ok := out["aggregations"].(map[string]interface{}) |
| | | if !ok { |
| | | return nil, errors.New("first hits change error!") |
| | | } |
| | | |
| | | documentAggregations := middle["group_by_documentnumber"].(map[string]interface{}) |
| | | buckets := documentAggregations["buckets"].([]interface{}) |
| | | if len(buckets) == 0 { |
| | | return nil, nil |
| | | } |
| | | for _, in := range buckets { |
| | | tmpbuf, ok := in.(map[string]interface{}) |
| | | if !ok { |
| | | return nil, errors.New("") |
| | | } |
| | | sources = append(sources, tmpbuf) |
| | | } |
| | | return sources, nil |
| | | } |
| | | |
| | | func EsReq(method string, url string, parama []byte) (buf []byte, err error) { |
| | | //defer elapsed("page")() |
| | | timeout := time.Duration(100 * time.Second) |
| | |
| | | Username string `mapstructure: "username"` |
| | | Userpassword string `mapstructure: "userpassword"` |
| | | } |
| | | |
| | | |
| | | var Account = &account{} |
| | | |