/** * @param schema * @param area * @param items * @param axisType * @return * @throws QueryModelBuildException */ private static AxisMeta buildAxisMeta( Schema schema, ExtendArea area, Map<Item, Object> items, AxisType axisType) throws QueryModelBuildException { AxisMeta meta = new AxisMeta(axisType); for (Map.Entry<Item, Object> entry : items.entrySet()) { Item item = entry.getKey(); OlapElement olapElement = ReportDesignModelUtils.getDimOrIndDefineWithId( schema, area.getCubeId(), item.getOlapElementId()); if (olapElement == null) { continue; } if (olapElement instanceof Dimension) { meta.getCrossjoinDims().add(olapElement.getName()); } else { meta.getQueryMeasures().add(olapElement.getName()); } } return meta; }
/** * 通过查询 * * @param reportModel * @param area * @param queryAction * @return Map<AxisType, AxisMeta> */ private static Map<AxisType, AxisMeta> buildAxisMeta( Schema schema, ExtendArea area, QueryAction queryAction) throws QueryModelBuildException { Map<Item, Object> columns = queryAction.getColumns(); Map<AxisType, AxisMeta> rs = new HashMap<AxisType, AxisMeta>(); AxisMeta columnMeta = buildAxisMeta(schema, area, columns, AxisType.COLUMN); rs.put(columnMeta.getAxisType(), columnMeta); Map<Item, Object> rows = queryAction.getRows(); AxisMeta rowMeta = buildAxisMeta(schema, area, rows, AxisType.ROW); rs.put(rowMeta.getAxisType(), rowMeta); AxisMeta filterMeta = buildAxisMeta(schema, area, queryAction.getSlices(), AxisType.FILTER); rs.put(filterMeta.getAxisType(), filterMeta); return rs; }
/** * 判断是否需要汇总 * * @param questionModel * @return */ private static boolean needSummary(QuestionModel questionModel) { ConfigQuestionModel configQuestionModel = (ConfigQuestionModel) questionModel; for (AxisMeta meta : questionModel.getAxisMetas().values()) { if (meta.getAxisType() == AxisType.ROW) { for (String str : meta.getCrossjoinDims()) { DimensionCondition condition = (DimensionCondition) questionModel.getQueryConditions().get(str); Dimension dim = configQuestionModel.getCube().getDimensions().get(condition.getMetaName()); if (dim != null && dim.getType() == DimensionType.CALLBACK) { if (condition.getQueryDataNodes() != null && condition.getQueryDataNodes().size() == 1) { List<Member> members = dim.getLevels() .values() .toArray(new Level[0])[0] .getMembers( configQuestionModel.getCube(), configQuestionModel.getDataSourceInfo(), configQuestionModel.getRequestParams()); String uniqueName = condition.getQueryDataNodes().get(0).getUniqueName(); if (MetaNameUtil.isAllMemberUniqueName(uniqueName)) { return false; } else if (meta.getCrossjoinDims().size() > 1) { return false; } else if (members.size() == 1) { MiniCubeMember m = (MiniCubeMember) members.get(0); if (m.getChildren() != null && m.getChildren().size() > 1) { return false; } else if (m.getChildren() == null) { return false; } } } else if (CollectionUtils.isEmpty(condition.getQueryDataNodes())) { return false; } return true; } if (condition.getQueryDataNodes() == null || condition.getQueryDataNodes().isEmpty()) { return false; } else { List<QueryData> queryDatas = condition.getQueryDataNodes(); for (QueryData queryData : queryDatas) { if (MetaNameUtil.isAllMemberName(queryData.getUniqueName())) { return false; } else { // TODO 这里需要修改 需要修改为可配置方式 String[] tmp = MetaNameUtil.parseUnique2NameArray(queryData.getUniqueName()); if (tmp[tmp.length - 1].contains(":")) { return false; } } } } } break; } } return true; }