Commit 6c35c9d1 authored by duanruiming's avatar duanruiming

Merge remote-tracking branch 'origin/master'

parents 02844cc3 d09151f5
......@@ -8,6 +8,8 @@ import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.core.CountRequest;
import org.elasticsearch.client.core.CountResponse;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.MatchQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
......@@ -54,7 +56,9 @@ public class LaneSnapshotDataQueryService implements LaneSnapshotService {
.must(matchQuery)
.must(rangeQuery);
searchSourceBuilder.query(boolQuery);
searchSourceBuilder
.query(boolQuery)
.size(5000000);
searchRequest.source(searchSourceBuilder);
SearchResponse response = client.search(searchRequest, RequestOptions.DEFAULT);
......@@ -72,4 +76,33 @@ public class LaneSnapshotDataQueryService implements LaneSnapshotService {
}
return result;
}
@Override
public int queryCountsByCrossIdAndTimeSpan(String crossId, int startTimeStamp, int endTimeStamp) throws Exception {
try {
CountRequest countRequest = new CountRequest(Constants.LANE_SNAPSHOT_DATA_ES_INDEX);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
MatchQueryBuilder matchQuery = QueryBuilders.matchQuery("crossId", crossId);
RangeQueryBuilder rangeQuery = QueryBuilders.rangeQuery("timeStamp")
.gte(startTimeStamp)
.lte(endTimeStamp);
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery()
.must(matchQuery)
.must(rangeQuery);
searchSourceBuilder.query(boolQuery);
countRequest.source(searchSourceBuilder);
CountResponse countResponse = client.count(countRequest, RequestOptions.DEFAULT);
long count = countResponse.getCount();
return (int) count;
} catch (Exception e) {
log.error("ES数据获取错误", e);
throw new Exception(e);
}
}
}
......@@ -11,4 +11,6 @@ import java.util.List;
*/
public interface LaneSnapshotService {
List<CrossLaneSnapshotDataDTO> queryByCrossIdAndTimeSpan(String crossId, int startTimeStamp, int endTimeStamp) throws Exception;
int queryCountsByCrossIdAndTimeSpan(String crossId, int startTimeStamp, int endTimeStamp) throws Exception;
}
......@@ -1062,9 +1062,9 @@ public class TrendServiceImpl implements TrendService {
int endTimeStamp = (int) now.toEpochSecond();
// 统计实时条数
List<CrossLaneSnapshotDataDTO> dtoList =
laneSnapshotDataQueryService.queryByCrossIdAndTimeSpan(crossId, startTimeStamp, endTimeStamp);
countRealTimeVO.setRealTimeCount(dtoList.size());
int counts = laneSnapshotDataQueryService.queryCountsByCrossIdAndTimeSpan(
crossId, startTimeStamp, endTimeStamp);
countRealTimeVO.setRealTimeCount(counts);
// 统计周期条数
Integer cycleCount = crossLaneDataHistMapper.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment