|
|
@@ -17,9 +17,7 @@ import org.springframework.util.Assert;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Iterator;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@@ -105,12 +103,21 @@ public class ShowPieService {
|
|
|
String fieldName = yAxisType + "(" + yColumn + ") as value,nvl(" + xColumn + ",'空') as name ";
|
|
|
String condition = screenToColumnS + " GROUP BY " + xColumn;
|
|
|
value = showChartsMapper.getPieValueWithoutGroup(fieldName, tableName, condition);
|
|
|
- xAxisData = value.stream().map(PieSeriesMap::getName).collect(Collectors.toList());
|
|
|
+ xAxisData = value.stream().sorted(Comparator.comparing(PieSeriesMap::getValue)).map(PieSeriesMap::getName).collect(Collectors.toList());
|
|
|
if (CollectionUtils.isEmpty(xAxisData)) {
|
|
|
return new RepEntity(RepCode.Null);
|
|
|
}
|
|
|
+ Optional<Double> total = value.stream().map(PieSeriesMap::getValue).reduce(Double::sum);
|
|
|
+ if (xAxisData.size() > pieConfigInfo.getMaxCount()) {
|
|
|
+ xAxisData = new ArrayList<>(xAxisData.subList(0, pieConfigInfo.getMaxCount()));
|
|
|
+ xAxisData.add("其它");
|
|
|
+ value = new ArrayList<>(value.stream().sorted((p1, p2) -> p2.getValue().compareTo(p1.getValue())).collect(Collectors.toList()).subList(0, pieConfigInfo.getMaxCount()));
|
|
|
+ Optional<Double> part = value.stream().map(PieSeriesMap::getValue).reduce(Double::sum);
|
|
|
+ if (total.isPresent() && part.isPresent()) {
|
|
|
+ value.add(new PieSeriesMap(total.get() - part.get(), "其它"));
|
|
|
+ }
|
|
|
+ }
|
|
|
chartsDataInfo.setxAxis(xAxisData);
|
|
|
-
|
|
|
series.setName(pieConfigInfo.getSeries().getColumnName());
|
|
|
series.setValue(value);
|
|
|
serieses.add(series);
|