| | |
| | | "size": 0, |
| | | } |
| | | |
| | | query = map[string]interface{}{ |
| | | "query": map[string]interface{}{ |
| | | "bool": map[string]interface{}{ |
| | | "filter": filters, |
| | | }, |
| | | }, |
| | | "size": 10000, |
| | | } |
| | | //query = map[string]interface{}{ |
| | | // "query": map[string]interface{}{ |
| | | // "bool": map[string]interface{}{ |
| | | // "filter": filters, |
| | | // }, |
| | | // }, |
| | | // "size": 10000, |
| | | //} |
| | | if err := json.NewEncoder(&buf).Encode(query); err != nil { |
| | | return nil, fmt.Errorf("error encoding query: %s", err) |
| | | } |
| | |
| | | var records []*LocationRecord |
| | | //dat, ok := result["hits"].(map[string]interface{}) |
| | | |
| | | dat := result["hits"].(map[string]interface{}) |
| | | |
| | | var data = make(map[string]interface{}, 2) |
| | | |
| | | tmp, b := dat["total"].(map[string]interface{}) |
| | | if b != true { |
| | | data["total"] = dat["total"].(float64) |
| | | } else { |
| | | data["total"] = tmp["value"].(float64) |
| | | } |
| | | sources := []interface{}{} |
| | | for _, value := range dat["hits"].([]interface{}) { |
| | | sourceData := value.(map[string]interface{}) |
| | | source := sourceData["_source"].(map[string]interface{}) |
| | | source["_id"] = sourceData["_id"] |
| | | /*sdkType := source["sdkType"] |
| | | if sdkType != nil { |
| | | sdk, _ := strconv.Atoi(sdkType.(string)) |
| | | source["sdkType"] = sdkTypeToValue(sdk) |
| | | }*/ |
| | | sources = append(sources, source) |
| | | } |
| | | data["datalist"] = sources |
| | | logger.Debugf("ressss--------------data------------------------- %s", data) |
| | | //if aggs, ok := result["aggregations"].(map[string]interface{}); ok { |
| | | // if orgBuckets, ok := aggs["orgs"].(map[string]interface{})["buckets"].([]interface{}); ok { |
| | | // for _, orgBucket := range orgBuckets { |
| | | // orgId := orgBucket.(map[string]interface{})["key"].(string) |
| | | // logger.Debugf("orgId--------------------------------------- %s", orgId) |
| | | // // 解析按communityId的聚合结果 |
| | | // if communityBuckets, ok := orgBucket.(map[string]interface{})["community"].(map[string]interface{})["buckets"].([]interface{}); ok { |
| | | // for _, communityBucket := range communityBuckets { |
| | | // communityId := communityBucket.(map[string]interface{})["key"].(string) |
| | | // logger.Debugf("communityId--------------------------------------- %s", communityId) |
| | | // // 解析按building的聚合结果 |
| | | // if locationBuckets, ok := communityBucket.(map[string]interface{})["location"].(map[string]interface{})["buckets"].([]interface{}); ok { |
| | | // for _, locationBucket := range locationBuckets { |
| | | // building := locationBucket.(map[string]interface{})["key"].(string) |
| | | // logger.Debugf("building--------------------------------------- %s", building) |
| | | // // 解析按floor的聚合结果 |
| | | // if floorBuckets, ok := locationBucket.(map[string]interface{})["floor"].(map[string]interface{})["buckets"].([]interface{}); ok { |
| | | // for _, floorBucket := range floorBuckets { |
| | | // floor := floorBucket.(map[string]interface{})["key"].(string) |
| | | // appearCount := floorBucket.(map[string]interface{})["filter_floor"].(int) |
| | | // // 构建 LocationRecord 结构体 |
| | | // var persons []string |
| | | // if docNumBuckets, ok := floorBucket.(map[string]interface{})["document_numbers"].(map[string]interface{})["buckets"].([]interface{}); ok { |
| | | // for _, docNumBucket := range docNumBuckets { |
| | | // persons = append(persons, docNumBucket.(map[string]interface{})["key"].(string)) |
| | | // } |
| | | // } |
| | | //dat := result["hits"].(map[string]interface{}) |
| | | // |
| | | // logger.Debugf("floor--------------------------------------- %s-- %s --", floor, appearCount) |
| | | // record := &LocationRecord{ |
| | | // //PicDate: timestamp, |
| | | // DocumentNumbers: persons, |
| | | // CommunityId: communityId, |
| | | // Building: building, |
| | | // Floor: floor, |
| | | // OrgId: orgId, |
| | | // AppearCount: appearCount, |
| | | // } |
| | | //var data = make(map[string]interface{}, 2) |
| | | // |
| | | // records = append(records, record) |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | //tmp, b := dat["total"].(map[string]interface{}) |
| | | //if b != true { |
| | | // data["total"] = dat["total"].(float64) |
| | | //} else { |
| | | // data["total"] = tmp["value"].(float64) |
| | | //} |
| | | //sources := []interface{}{} |
| | | //for _, value := range dat["hits"].([]interface{}) { |
| | | // sourceData := value.(map[string]interface{}) |
| | | // source := sourceData["_source"].(map[string]interface{}) |
| | | // source["_id"] = sourceData["_id"] |
| | | // /*sdkType := source["sdkType"] |
| | | // if sdkType != nil { |
| | | // sdk, _ := strconv.Atoi(sdkType.(string)) |
| | | // source["sdkType"] = sdkTypeToValue(sdk) |
| | | // }*/ |
| | | // sources = append(sources, source) |
| | | //} |
| | | //data["datalist"] = sources |
| | | //logger.Debugf("ressss--------------data------------------------- %s", data) |
| | | if aggs, ok := result["aggregations"].(map[string]interface{}); ok { |
| | | if orgBuckets, ok := aggs["orgs"].(map[string]interface{})["buckets"].([]interface{}); ok { |
| | | for _, orgBucket := range orgBuckets { |
| | | orgId := orgBucket.(map[string]interface{})["key"].(string) |
| | | logger.Debugf("orgId--------------------------------------- %s", orgId) |
| | | // 解析按communityId的聚合结果 |
| | | if communityBuckets, ok := orgBucket.(map[string]interface{})["community"].(map[string]interface{})["buckets"].([]interface{}); ok { |
| | | for _, communityBucket := range communityBuckets { |
| | | communityId := communityBucket.(map[string]interface{})["key"].(string) |
| | | logger.Debugf("communityId--------------------------------------- %s", communityId) |
| | | // 解析按building的聚合结果 |
| | | if locationBuckets, ok := communityBucket.(map[string]interface{})["location"].(map[string]interface{})["buckets"].([]interface{}); ok { |
| | | for _, locationBucket := range locationBuckets { |
| | | building := locationBucket.(map[string]interface{})["key"].(string) |
| | | logger.Debugf("building--------------------------------------- %s", building) |
| | | // 解析按floor的聚合结果 |
| | | if floorBuckets, ok := locationBucket.(map[string]interface{})["floor"].(map[string]interface{})["buckets"].([]interface{}); ok { |
| | | for _, floorBucket := range floorBuckets { |
| | | floor := floorBucket.(map[string]interface{})["key"].(string) |
| | | appearCount := floorBucket.(map[string]interface{})["filter_floor"].(int) |
| | | // 构建 LocationRecord 结构体 |
| | | var persons []string |
| | | if docNumBuckets, ok := floorBucket.(map[string]interface{})["document_numbers"].(map[string]interface{})["buckets"].([]interface{}); ok { |
| | | for _, docNumBucket := range docNumBuckets { |
| | | persons = append(persons, docNumBucket.(map[string]interface{})["key"].(string)) |
| | | } |
| | | } |
| | | |
| | | logger.Debugf("floor--------------------------------------- %s-- %s --", floor, appearCount) |
| | | record := &LocationRecord{ |
| | | //PicDate: timestamp, |
| | | DocumentNumbers: persons, |
| | | CommunityId: communityId, |
| | | Building: building, |
| | | Floor: floor, |
| | | OrgId: orgId, |
| | | AppearCount: appearCount, |
| | | } |
| | | |
| | | records = append(records, record) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | return records, nil |
| | | } |