فهرست منبع

完善视图聚合。

zhangjinjun 6 سال پیش
والد
کامیت
cefb8515aa
1فایلهای تغییر یافته به همراه26 افزوده شده و 11 حذف شده
  1. 26 11
      src/main/java/com/yihu/quota/service/view/ViewService.java

+ 26 - 11
src/main/java/com/yihu/quota/service/view/ViewService.java

@ -158,12 +158,28 @@ public class ViewService extends BaseJpaService<View, ViewDao> {
        //region 聚合组装
        if (groupTopRowDimensionList.size() == 0) {
            if (!"1".equals(view.getDisplayType())) {
                // 视图展示类型非数值场合
                // 视图展示为非数值类型场合
                throw new ApiException("请为视图至少配置一个行维度。");
            } else if (viewQuotaList == null || viewQuotaList.size() == 0) {
                throw new ApiException("请为视图至少配置一个指标。");
            } else {
                // 视图为数值展示类型的场合,没有行/列维度,直接对指标聚合。
                // 视图展示为数值类型的场合
                // 如果有多个多维数据集时,添加指标的过滤条件,指定其数据来自哪个多维数据集。
                for (ViewQuota quota : viewQuotaList) {
                    ViewQuotaFilter indexFilter = new ViewQuotaFilter();
                    indexFilter.setDimensionCode("_index");
                    indexFilter.setCompareType("and");
                    indexFilter.setCompareType("belong");
                    indexFilter.setFilterValue(quota.getEsIndex());
                    quota.getQuotaFilterList().add(indexFilter);
                    ViewQuotaFilter typeFilter = new ViewQuotaFilter();
                    typeFilter.setDimensionCode("_type");
                    typeFilter.setCompareType("and");
                    typeFilter.setCompareType("belong");
                    typeFilter.setFilterValue(quota.getEsType());
                    quota.getQuotaFilterList().add(typeFilter);
                }
                // 因为该场合没有行/列维度,直接对指标聚合。
                List<AbstractAggregationBuilder> quotaAggList = this.gatherQuotaMetricsAgg(viewQuotaList, null);
                for (AbstractAggregationBuilder quotaAgg : quotaAggList) {
                    searchRequestBuilder.addAggregation(quotaAgg);
@ -175,13 +191,15 @@ public class ViewService extends BaseJpaService<View, ViewDao> {
                // 有多个多维度数据集时,设定顶层行维度聚合的数据来自哪个多维数据集。
                FilterAggregationBuilder topFilterAgg = null;
                if (indexCount > 1) {
                    String aggName = topRowDimension.getDimensionCode() + "-index-filter";
                    QueryBuilder queryBuilder = QueryBuilders.termQuery("_index", topRowDimension.getEsIndex());
                    topFilterAgg = AggregationBuilders.filter(aggName).filter(queryBuilder);
                    String aggName = topRowDimension.getDimensionCode() + "-filter";
                    QueryBuilder indexQueryBuilder = QueryBuilders.termQuery("_index", topRowDimension.getEsIndex());
                    QueryBuilder typeQueryBuilder = QueryBuilders.termQuery("_type", topRowDimension.getEsType());
                    BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
                    boolQueryBuilder.must(indexQueryBuilder);
                    boolQueryBuilder.must(typeQueryBuilder);
                    topFilterAgg = AggregationBuilders.filter(aggName).filter(boolQueryBuilder);
                }
                // TODO 当顶层行维度是合计维度时,合计维度与列维度组合的聚合都在聚合节点顶层。
                // 顶层行维度聚合
                AggregationBuilder topAgg = this.joinDimensionAgg(topRowDimension);
@ -338,7 +356,7 @@ public class ViewService extends BaseJpaService<View, ViewDao> {
            }
            // 设置分组个数
            if (memberCount!= null && memberCount > 0) {
            if (memberCount != null && memberCount > 0) {
                ((TermsBuilder) dimensionAgg).size(memberCount);
            } else {
                // TODO 需动态获取全部的分组个数进行设置
@ -423,9 +441,6 @@ public class ViewService extends BaseJpaService<View, ViewDao> {
                if (viewDimension == null) {
                    // 视图展示为数值类型的场合
                    aggNamePre += quota.getCode() + "-";
                } else if (ViewConstant.TOTAL_DIMENSION_CODE.equals(viewDimension.getDimensionCode())) {
                    // 合计维度场合
                    aggNamePre = ViewConstant.TOTAL_DIMENSION_CODE + "-";
                }
                if ("sum".equals(quota.getBasicFormulaType())) {