forked from github/dataease
Merge pull request #11918 from dataease/pr@dev-v2@chart-symbolic-fix
fix(图表-符号地图): 修复符号地图查看数据时,总是会显示记录数的问题
This commit is contained in:
commit
eb4b5adc3d
@ -38,20 +38,16 @@ public class SymbolicMapHandler extends GroupChartHandler {
|
||||
@Override
|
||||
public AxisFormatResult formatAxis(ChartViewDTO view) {
|
||||
var result = super.formatAxis(view);
|
||||
var yAxis = result.getAxisMap().get(ChartAxis.yAxis);
|
||||
yAxis.addAll(view.getExtBubble());
|
||||
result.getAxisMap().put(ChartAxis.extBubble, view.getExtBubble());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private Map<String, Object> customBuildResult(ChartViewDTO view, AxisFormatResult formatResult, CustomFilterResult filterResult, List<String[]> data, List<ChartViewFieldDTO> detailFields, List<String[]> detailData) {
|
||||
boolean isDrill = filterResult
|
||||
.getFilterList()
|
||||
.stream()
|
||||
.anyMatch(ele -> ele.getFilterType() == 1);
|
||||
var xAxis = formatResult.getAxisMap().get(ChartAxis.xAxis);
|
||||
var extBubble = formatResult.getAxisMap().get(ChartAxis.extBubble);
|
||||
var yAxis = formatResult.getAxisMap().get(ChartAxis.yAxis);
|
||||
Map<String, Object> result = ChartDataBuild.transSymbolicMapNormalWithDetail(xAxis, yAxis, data, detailFields, detailData);
|
||||
Map<String, Object> result = ChartDataBuild.transSymbolicMapNormalWithDetail(xAxis, yAxis, extBubble, data, detailFields, detailData);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -67,15 +63,21 @@ public class SymbolicMapHandler extends GroupChartHandler {
|
||||
DatasourceRequest datasourceRequest = new DatasourceRequest();
|
||||
datasourceRequest.setDsList(dsMap);
|
||||
var xAxis = formatResult.getAxisMap().get(ChartAxis.xAxis);
|
||||
var yAxis = formatResult.getAxisMap().get(ChartAxis.yAxis);
|
||||
var extBubble = formatResult.getAxisMap().get(ChartAxis.extBubble);
|
||||
var allFields = (List<ChartViewFieldDTO>) filterResult.getContext().get("allFields");
|
||||
List<ChartViewFieldDTO> countField =chartViewManege.transFieldDTO(Collections.singletonList(chartViewManege.createCountField(view.getTableId())));
|
||||
List<DatasetTableFieldDTO> datasetTableFieldDTOList = FieldUtil.transFields(allFields);
|
||||
SQLMeta sqlMeta1 = new SQLMeta();
|
||||
BeanUtils.copyBean(sqlMeta1, sqlMeta);
|
||||
Dimension2SQLObj.dimension2sqlObj(sqlMeta, xAxis, FieldUtil.transFields(allFields), crossDs, dsMap, Utils.getParams(FieldUtil.transFields(allFields)), view.getCalParams(), pluginManage);
|
||||
List<ChartViewFieldDTO> yFields = new ArrayList<>();
|
||||
yFields.addAll(chartViewManege.transFieldDTO(Collections.singletonList(chartViewManege.createCountField(view.getTableId()))));
|
||||
yAxis.addAll(yFields);
|
||||
Quota2SQLObj.quota2sqlObj(sqlMeta, yAxis, FieldUtil.transFields(allFields), crossDs, dsMap, Utils.getParams(FieldUtil.transFields(allFields)), view.getCalParams(), pluginManage);
|
||||
Dimension2SQLObj.dimension2sqlObj(sqlMeta, xAxis, datasetTableFieldDTOList, crossDs, dsMap, Utils.getParams(datasetTableFieldDTOList), view.getCalParams(), pluginManage);
|
||||
List<ChartViewFieldDTO> yAxis = new ArrayList<>();
|
||||
if(!extBubble.isEmpty() && !"*".equals(extBubble.get(0).getDataeaseName())){
|
||||
yAxis.addAll(extBubble);
|
||||
}
|
||||
yAxis.addAll(countField);
|
||||
datasetTableFieldDTOList.addAll(FieldUtil.transFields(countField));
|
||||
formatResult.getAxisMap().put(ChartAxis.yAxis,countField);
|
||||
Quota2SQLObj.quota2sqlObj(sqlMeta, yAxis, datasetTableFieldDTOList, crossDs, dsMap, Utils.getParams(datasetTableFieldDTOList), view.getCalParams(), pluginManage);
|
||||
String querySql = SQLProvider.createQuerySQL(sqlMeta, true, needOrder, view);
|
||||
querySql = provider.rebuildSQL(querySql, sqlMeta, crossDs, dsMap);
|
||||
datasourceRequest.setQuery(querySql);
|
||||
@ -107,8 +109,6 @@ public class SymbolicMapHandler extends GroupChartHandler {
|
||||
}
|
||||
//自定义排序
|
||||
data = ChartDataUtil.resultCustomSort(xAxis, data);
|
||||
//快速计算
|
||||
quickCalc(xAxis, yAxis, data);
|
||||
//数据重组逻辑可重载
|
||||
var result = customBuildResult(view, formatResult, filterResult, data, detailFields, detailData);
|
||||
T calcResult = (T) new ChartCalcDataResult();
|
||||
@ -116,6 +116,7 @@ public class SymbolicMapHandler extends GroupChartHandler {
|
||||
calcResult.setContext(filterResult.getContext());
|
||||
calcResult.setQuerySql(querySql);
|
||||
calcResult.setOriginData(data);
|
||||
formatResult.getAxisMap().put(ChartAxis.yAxis,new ArrayList<>());
|
||||
return calcResult;
|
||||
}
|
||||
|
||||
@ -124,11 +125,11 @@ public class SymbolicMapHandler extends GroupChartHandler {
|
||||
var desensitizationList = (Map<String, ColumnPermissionItem>) filterResult.getContext().get("desensitizationList");
|
||||
var allFields = (List<ChartViewFieldDTO>) filterResult.getContext().get("allFields");
|
||||
var xAxis = formatResult.getAxisMap().get(ChartAxis.xAxis);
|
||||
var yAxis = formatResult.getAxisMap().get(ChartAxis.yAxis);
|
||||
var extBubble = formatResult.getAxisMap().get(ChartAxis.extBubble);
|
||||
// 如果是表格导出查询 则在此处直接就可以返回
|
||||
var extStack = formatResult.getAxisMap().get(ChartAxis.extStack);
|
||||
if (view.getIsExcelExport()) {
|
||||
Map<String, Object> sourceInfo = ChartDataBuild.transTableNormal(xAxis, yAxis, view, calcResult.getOriginData(), extStack, desensitizationList);
|
||||
Map<String, Object> sourceInfo = ChartDataBuild.transTableNormal(xAxis, extBubble, view, calcResult.getOriginData(), extStack, desensitizationList);
|
||||
sourceInfo.put("sourceData", calcResult.getOriginData());
|
||||
view.setData(sourceInfo);
|
||||
return view;
|
||||
|
@ -1748,7 +1748,7 @@ public class ChartDataBuild {
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, Object> transSymbolicMapNormalWithDetail(List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<String[]> data, List<ChartViewFieldDTO> detailFields, List<String[]> detailData) {
|
||||
public static Map<String, Object> transSymbolicMapNormalWithDetail(List<ChartViewFieldDTO> xAxis, List<ChartViewFieldDTO> yAxis, List<ChartViewFieldDTO> extBubble, List<String[]> data, List<ChartViewFieldDTO> detailFields, List<String[]> detailData) {
|
||||
int detailIndex = xAxis.size();
|
||||
|
||||
List<ChartViewFieldDTO> realDetailFields = detailFields.subList(detailIndex, detailFields.size());
|
||||
@ -1756,22 +1756,24 @@ public class ChartDataBuild {
|
||||
List<ChartViewFieldDTO> fields = new ArrayList<>();
|
||||
if (ObjectUtils.isNotEmpty(xAxis))
|
||||
fields.addAll(xAxis);
|
||||
if (ObjectUtils.isNotEmpty(extBubble))
|
||||
fields.addAll(extBubble);
|
||||
if (ObjectUtils.isNotEmpty(yAxis))
|
||||
fields.addAll(yAxis);
|
||||
Map<String, Object> map = transTableNormal(fields, null, data, new HashMap<>());
|
||||
List<Map<String, Object>> tableRow = (List<Map<String, Object>>) map.get("tableRow");
|
||||
final int xEndIndex = detailIndex;
|
||||
Map<String, List<String[]>> groupDataList = detailData.stream().collect(Collectors.groupingBy(item -> "(" + StringUtils.join(ArrayUtils.subarray(item, 0, xEndIndex), ")-de-(") + ")"));
|
||||
|
||||
String extBubbleDataeaseName = ObjectUtils.isNotEmpty(extBubble)?extBubble.get(0).getDataeaseName():"";
|
||||
tableRow.forEach(row -> {
|
||||
BigDecimal rowValue = new BigDecimal(row.get(yAxis.get(0).getDataeaseName()).toString());
|
||||
BigDecimal rowValue = row.get(extBubbleDataeaseName) == null ? BigDecimal.ZERO : new BigDecimal(row.get(extBubbleDataeaseName).toString());
|
||||
String key = xAxis.stream().map(x -> String.format(format, row.get(x.getDataeaseName()).toString())).collect(Collectors.joining("-de-"));
|
||||
List<String[]> detailFieldValueList = groupDataList.get(key);
|
||||
List<Map<String, Object>> detailValueMapList = Optional.ofNullable(detailFieldValueList).orElse(new ArrayList<>()).stream().map((detailArr -> {
|
||||
Map<String, Object> temp = new HashMap<>();
|
||||
for (int i = 0; i < realDetailFields.size(); i++) {
|
||||
ChartViewFieldDTO realDetailField = realDetailFields.get(i);
|
||||
if(StringUtils.equalsIgnoreCase(yAxis.get(0).getDataeaseName(),realDetailField.getDataeaseName())){
|
||||
if(StringUtils.equalsIgnoreCase(extBubbleDataeaseName,realDetailField.getDataeaseName())){
|
||||
temp.put(realDetailField.getDataeaseName(), rowValue);
|
||||
}else{
|
||||
temp.put(realDetailField.getDataeaseName(), detailArr[detailIndex + i]);
|
||||
@ -1782,7 +1784,15 @@ public class ChartDataBuild {
|
||||
//详情只要一个
|
||||
row.put("details", !detailValueMapList.isEmpty() ?Collections.singletonList(detailValueMapList.getFirst()):detailValueMapList);
|
||||
});
|
||||
map.put("fields", fields);
|
||||
// 先过滤掉所有记录数字段
|
||||
List<ChartViewFieldDTO> filterCountAxis = fields.stream()
|
||||
.filter(item -> !StringUtils.equalsIgnoreCase(item.getDataeaseName(), "*"))
|
||||
.collect(Collectors.toList());
|
||||
// 如果气泡大小是记录数,添加到字段列表中
|
||||
if (ObjectUtils.isNotEmpty(extBubble) && "*".equals(extBubble.get(0).getDataeaseName())) {
|
||||
filterCountAxis.addAll(yAxis);
|
||||
}
|
||||
map.put("fields", filterCountAxis);
|
||||
map.put("detailFields", realDetailFields);
|
||||
map.put("tableRow", tableRow);
|
||||
return map;
|
||||
|
Loading…
Reference in New Issue
Block a user