|
@ -15,15 +15,13 @@ import org.elasticsearch.action.search.SearchRequestBuilder;
|
|
|
import org.elasticsearch.action.search.SearchResponse;
|
|
|
import org.elasticsearch.client.transport.TransportClient;
|
|
|
import org.elasticsearch.index.query.BoolQueryBuilder;
|
|
|
import org.elasticsearch.index.query.QueryBuilder;
|
|
|
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
|
|
import org.elasticsearch.search.aggregations.Aggregation;
|
|
|
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
|
|
import org.elasticsearch.search.aggregations.InternalAggregations;
|
|
|
import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder;
|
|
|
import org.elasticsearch.search.aggregations.bucket.filter.InternalFilter;
|
|
|
import org.elasticsearch.search.aggregations.bucket.terms.*;
|
|
|
import org.elasticsearch.search.aggregations.metrics.avg.InternalAvg;
|
|
|
import org.elasticsearch.search.aggregations.metrics.cardinality.InternalCardinality;
|
|
|
import org.elasticsearch.search.aggregations.metrics.max.InternalMax;
|
|
|
import org.elasticsearch.search.aggregations.metrics.min.InternalMin;
|
|
|
import org.elasticsearch.search.aggregations.metrics.sum.InternalSum;
|
|
@ -151,27 +149,43 @@ public class AggregationBuildHandler {
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Map<String, Object>> tableDataParsing(String viewCode ,Map<String, Aggregation> map){
|
|
|
List<String> rowList = new LinkedList<>();
|
|
|
rowList.add("town_terms");
|
|
|
rowList.add("total");
|
|
|
List<String> cloumnList = new ArrayList<>();
|
|
|
cloumnList.add("total_count_result");
|
|
|
cloumnList.add("sex_terms");
|
|
|
// List<String> rowList = new LinkedList<>();
|
|
|
// rowList.add("town_terms");
|
|
|
// rowList.add("total");
|
|
|
// List<String> cloumnList = new ArrayList<>();
|
|
|
// cloumnList.add("total_count_result");
|
|
|
// cloumnList.add("sex_terms");
|
|
|
|
|
|
View view = viewDao.findByCode(viewCode);
|
|
|
// if(view == null){
|
|
|
// logger.debug("视图不存在");
|
|
|
// return null;
|
|
|
// }
|
|
|
// rowList = getRowDimensionList(view.getId());
|
|
|
// cloumnList = getColumnDimensionList(view.getId());
|
|
|
if(view == null){
|
|
|
logger.debug("视图不存在");
|
|
|
return null;
|
|
|
}
|
|
|
List<String> rowList = getRowDimensionList(view.getId());
|
|
|
List<String> cloumnList = getColumnDimensionList(view.getId());
|
|
|
|
|
|
List<ViewQuota> viewQuotas = viewQuotaDao.findByViewId(view.getId());
|
|
|
// List<ViewQuotaFilter> viewFilters = viewQuotaFilterDao.findByRelationId(view.getId());
|
|
|
Map<String, Object> quotaMap = new HashMap<>();
|
|
|
for(ViewQuota viewQuota :viewQuotas){
|
|
|
List<ViewQuotaFilter> viewQuotaFilters = viewQuotaFilterDao.findByRelationId(viewQuota.getId());
|
|
|
String filter = "noFilter";
|
|
|
if(viewQuotaFilters != null && viewQuotaFilters.size() > 0){
|
|
|
filter = "yesFilter";
|
|
|
}
|
|
|
quotaMap.put(viewQuota.getCode(),filter);
|
|
|
//指标也作为列维度
|
|
|
cloumnList.add(viewQuota.getBasicFormulaType() +"-result");
|
|
|
}
|
|
|
|
|
|
List<Map<String, Object>> resultList = new LinkedList<Map<String, Object>>();
|
|
|
//合计行 数据处理 开始
|
|
|
boolean total = false;
|
|
|
Map<String, Object> totalResultMap = new HashMap<>();
|
|
|
totalResultMap.put(rowList.get(0),"total");//默认第一个行维度
|
|
|
for(String rowAggCode: rowList) {
|
|
|
if (rowAggCode.contains("total")) {
|
|
|
total = true;
|
|
|
for (String cloumnAggCode : cloumnList) {
|
|
|
for(String aggCode:map.keySet()) {
|
|
|
Aggregation aggregation = map.get(aggCode);
|
|
@ -189,8 +203,10 @@ public class AggregationBuildHandler {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
resultList.add(totalResultMap);
|
|
|
//合计行 数据处理 接收
|
|
|
if(total){
|
|
|
resultList.add(totalResultMap);
|
|
|
//合计行 数据处理 接收
|
|
|
}
|
|
|
|
|
|
//非合计数据处理
|
|
|
for(String rowAggCode: rowList){
|
|
@ -240,28 +256,26 @@ public class AggregationBuildHandler {
|
|
|
*/
|
|
|
public Map<String, Object> numericalDataParsing(String viewCode ,Map<String, Aggregation> map){
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
// View view = viewDao.findByCode(viewCode);
|
|
|
// if(view == null){
|
|
|
// logger.debug("视图不存在");
|
|
|
// return null;
|
|
|
// }
|
|
|
// List<ViewQuota> viewQuotas = viewQuotaDao.findByViewId(view.getId());
|
|
|
View view = viewDao.findByCode(viewCode);
|
|
|
if(view == null){
|
|
|
logger.debug("视图不存在");
|
|
|
return null;
|
|
|
}
|
|
|
List<ViewQuota> viewQuotas = viewQuotaDao.findByViewId(view.getId());
|
|
|
Map<String, Object> quotaMap = new HashMap<>();
|
|
|
// for(ViewQuota viewQuota :viewQuotas){
|
|
|
// List<ViewQuotaFilter> viewQuotaFilters = viewQuotaFilterDao.findByRelationId(viewQuota.getId());
|
|
|
// String filter = "noFilter";
|
|
|
// if(viewQuotaFilters != null && viewQuotaFilters.size() > 0){
|
|
|
// quotaMap.put(viewQuota.getCode(),"filter");
|
|
|
// }
|
|
|
// quotaMap.put(viewQuota.getCode(),filter);
|
|
|
// }
|
|
|
quotaMap.put("total_total","noFilter");
|
|
|
quotaMap.put("total_sex-1","noFilter");
|
|
|
for(ViewQuota viewQuota :viewQuotas){
|
|
|
List<ViewQuotaFilter> viewQuotaFilters = viewQuotaFilterDao.findByRelationId(viewQuota.getId());
|
|
|
String filter = "noFilter";
|
|
|
if(viewQuotaFilters != null && viewQuotaFilters.size() > 0){
|
|
|
filter = "yesFilter";
|
|
|
}
|
|
|
quotaMap.put(viewQuota.getCode(),filter);
|
|
|
}
|
|
|
for(String aggCode:map.keySet()) {
|
|
|
Aggregation aggregation = map.get(aggCode);
|
|
|
for(String quotaCode :quotaMap.keySet()){
|
|
|
String quotaAggCode = quotaCode;
|
|
|
if(quotaMap.get(quotaCode).equals("filter")){
|
|
|
if(quotaMap.get(quotaCode).equals("yesFilter")){
|
|
|
quotaAggCode = quotaCode + "-filter" ;
|
|
|
}
|
|
|
if(!StringUtils.isEmpty(quotaAggCode) && aggCode.contains(quotaAggCode)){
|
|
@ -366,10 +380,12 @@ public class AggregationBuildHandler {
|
|
|
// 视图各组组内顶层行维度(升序)
|
|
|
List<ViewDimension> groupTopRowDimensionList = viewDimensionDao.getGroupTopRowDimensionList(viewId);
|
|
|
for (ViewDimension viewDimension : groupTopRowDimensionList) {
|
|
|
String dataType = cubeService.findDimensionDataType("cubeCode:1", viewDimension.getDimensionCode());
|
|
|
String aggType = "-terms";
|
|
|
if(dataType.equals("date")){
|
|
|
aggType = "-date_histogram";
|
|
|
String dataType = cubeService.findDimensionDataType("cubeCode:1", viewDimension.getDimensionCode());
|
|
|
if(!StringUtils.isEmpty(dataType)){
|
|
|
if(dataType.equals("date")){
|
|
|
aggType = "-date_histogram";
|
|
|
}
|
|
|
}
|
|
|
rowList.add(viewDimension.getDimensionCode() + aggType);
|
|
|
List<ViewDimension> otherRowDimensionList = viewDimensionDao.getGroupOtherRowDimensionList(viewId, viewDimension.getGroupRow());
|
|
@ -415,7 +431,11 @@ public class AggregationBuildHandler {
|
|
|
}else if (aggregation instanceof InternalFilter) {
|
|
|
InternalFilter internalFilter = (InternalFilter) aggregation;
|
|
|
List<Aggregation> aggregationList = internalFilter.getAggregations().asList();
|
|
|
value = getInternalAggValue(key,aggregationList.get(0));
|
|
|
Map<String, Object> filterValue = getInternalAggValue(key,aggregationList.get(0));
|
|
|
return filterValue;
|
|
|
}else if (aggregation instanceof InternalCardinality) {//去重
|
|
|
InternalCardinality valueCount = (InternalCardinality) aggregation;
|
|
|
value = valueCount.getValue();
|
|
|
}
|
|
|
if(value != null){
|
|
|
map.put(key, value);
|