zhangjinjun преди 6 години
родител
ревизия
017abf9e67
променени са 1 файла, в които са добавени 11 реда и са изтрити 16 реда
  1. 11 16
      src/main/java/com/yihu/quota/service/view/ViewService.java

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

@ -131,6 +131,7 @@ public class ViewService extends BaseJpaService<View, ViewDao> {
        View view = this.getViewRule(viewCode);
        String[] esIndices = view.getEsIndex().split(",");
        String[] esTypes = view.getEsType().split(",");
        int indexCount = esIndices.length;
        TransportClient transportClient = elasticSearchPool.getClient();
        SearchRequestBuilder searchRequestBuilder = transportClient.prepareSearch(esIndices).setTypes(esTypes).setSize(0);
@ -169,13 +170,8 @@ public class ViewService extends BaseJpaService<View, ViewDao> {
                }
            }
        } else {
            int indexCount = esIndices.length;
            // 遍历顶层行维度
            for (ViewDimension topRowDimension : groupTopRowDimensionList) {
                String topRowDimensionCode = topRowDimension.getDimensionCode();
                String topOrderType = topRowDimension.getMemberOrderType();
                boolean isTopAsc = "asc".equals(topRowDimension.getMemberOrderStrategy()) ? true : false;
                // 有多个多维度数据集时,设定顶层行维度聚合的数据来自哪个多维数据集。
                FilterAggregationBuilder topFilterAgg = null;
                if (indexCount > 1) {
@ -316,33 +312,33 @@ public class ViewService extends BaseJpaService<View, ViewDao> {
        String dimensionCode = viewDimension.getDimensionCode();
        String orderType = viewDimension.getMemberOrderType();
        String orderStrategy = viewDimension.getMemberOrderStrategy();
        boolean isTopAsc = StringUtils.isEmpty(orderStrategy) || "asc".equals(orderStrategy) ? true : false;
        boolean isAsc = StringUtils.isEmpty(orderStrategy) || "asc".equals(orderStrategy) ? true : false;
        String memberOrderQuotaId = viewDimension.getMemberOrderQuotaId();
        Integer memberCount = viewDimension.getMemberCount();
        String fieldType = cubeService.findDimensionDataType(viewDimension.getCubeCode(), viewDimension.getDimensionCode());
        String fieldType = cubeService.findDimensionDataType(viewDimension.getCubeCode(), dimensionCode);
        if (!"date".equals(fieldType)) {
            String aggName = dimensionCode + "-terms";
            dimensionAgg = AggregationBuilders.terms(aggName).field(dimensionCode);
            // 设置排序
            if (StringUtils.isEmpty(orderType) || "name".equals(orderType)) {
                ((TermsBuilder) dimensionAgg).order(Terms.Order.term(isTopAsc));
                ((TermsBuilder) dimensionAgg).order(Terms.Order.term(isAsc));
            } else {
                // 按子聚合结果排序,拼接子聚合路径
                String memberOrderQuotaId = viewDimension.getMemberOrderQuotaId();
                if (StringUtils.isNotEmpty(memberOrderQuotaId)) {
                    ViewQuota viewQuota = viewQuotaDao.findOne(memberOrderQuotaId);
                    if ("basic".equals(viewQuota.getFormulaMode())) {
                        String subAggPath = viewQuota.getBasicFormulaType() + "-result";
                        ((TermsBuilder) dimensionAgg).order(Terms.Order.aggregation(subAggPath, isTopAsc));
                        ((TermsBuilder) dimensionAgg).order(Terms.Order.aggregation(subAggPath, isAsc));
                    } else {
                        ((TermsBuilder) dimensionAgg).order(Terms.Order.term(isTopAsc));
                        ((TermsBuilder) dimensionAgg).order(Terms.Order.term(isAsc));
                    }
                }
            }
            // 设置分组个数
            int memberCount = viewDimension.getMemberCount();
            if (memberCount > 0) {
            if (memberCount!= null && memberCount > 0) {
                ((TermsBuilder) dimensionAgg).size(memberCount);
            } else {
                // TODO 需动态获取全部的分组个数进行设置
@ -355,17 +351,16 @@ public class ViewService extends BaseJpaService<View, ViewDao> {
            ((DateHistogramBuilder) dimensionAgg).format(viewDimension.getMemberDateFormat());
            ((DateHistogramBuilder) dimensionAgg).interval(new DateHistogramInterval(viewDimension.getMemberDateInterval()));
            // 设置排序
            Histogram.Order order = isTopAsc ? Histogram.Order.KEY_ASC : Histogram.Order.KEY_DESC;
            Histogram.Order order = isAsc ? Histogram.Order.KEY_ASC : Histogram.Order.KEY_DESC;
            if (StringUtils.isEmpty(orderType) || "name".equals(orderType)) {
                ((DateHistogramBuilder) dimensionAgg).order(order);
            } else {
                // 按子聚合结果排序,拼接子聚合路径
                String memberOrderQuotaId = viewDimension.getMemberOrderQuotaId();
                if (StringUtils.isNotEmpty(memberOrderQuotaId)) {
                    ViewQuota viewQuota = viewQuotaDao.findOne(memberOrderQuotaId);
                    if ("basic".equals(viewQuota.getFormulaMode())) {
                        String subAggPath = viewQuota.getBasicFormulaType() + "-result";
                        ((DateHistogramBuilder) dimensionAgg).order(Histogram.Order.aggregation(subAggPath, isTopAsc));
                        ((DateHistogramBuilder) dimensionAgg).order(Histogram.Order.aggregation(subAggPath, isAsc));
                    } else {
                        ((DateHistogramBuilder) dimensionAgg).order(order);
                    }