|
|
@@ -16,10 +16,7 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.Assert;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Iterator;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@@ -51,8 +48,9 @@ public class ShowLineService {
|
|
|
xAxisType = lineConfigInfo.getxAxis().getShowDataType();
|
|
|
List<String> groupBy = lineConfigInfo.getGroups(),
|
|
|
xAxisData = new ArrayList<String>(); //X轴自己用
|
|
|
- List<LineSeries> serieses = new ArrayList<LineSeries>(); //生成柱状图的系列
|
|
|
+ List<Series> serieses = new ArrayList<Series>(); //生成柱状图的系列
|
|
|
List<Screen> filters = lineConfigInfo.getFilters();
|
|
|
+ List<Double> value = new ArrayList<Double>();
|
|
|
ScreenStr scr = new ScreenStr();
|
|
|
String screen = "", //正常筛选条件
|
|
|
screenToColumn = "", //跟目标列相同的筛选条件
|
|
|
@@ -93,24 +91,36 @@ public class ShowLineService {
|
|
|
screenToColumnS = " 1 = 1 ";
|
|
|
}
|
|
|
xColumn = TimeConverterUtil.convertToOracleDateStr(xColumn, xAxisType); //X轴 -> 折线图X轴只能为日期类型
|
|
|
- String fieldName = yAxisType + "(" + yColumn + ") as value,nvl(" + xColumn + ",'空') as \"date\" ";
|
|
|
+ String fieldName = yAxisType + "(" + yColumn + ") as value,nvl(" + xColumn + ",'空') as name ";
|
|
|
String condition = screenToColumnS + " GROUP BY " + xColumn;
|
|
|
String sort = xColumn, rule = "ASC";
|
|
|
if (CollectionUtils.isEmpty(groupBy)) {
|
|
|
- List<LineSeriesMap> lineSeriesMapList = showChartsMapper.getLineValueWithoutGroup(fieldName, tableName, condition, sort, rule);
|
|
|
+ /*List<LineSeriesMap> lineSeriesMapList = showChartsMapper.getLineValueWithoutGroup(fieldName, tableName, condition, sort, rule);
|
|
|
xAxisData = lineSeriesMapList.stream().map(LineSeriesMap::getDate).collect(Collectors.toList());
|
|
|
if (CollectionUtils.isEmpty(xAxisData)) {
|
|
|
return new RepEntity(RepCode.Null);
|
|
|
}
|
|
|
if (xAxisData.size() > lineConfigInfo.getMaxCount()) {
|
|
|
chartsDataInfo.setTooMany(true);
|
|
|
+ xAxisData = xAxisData.subList(0, lineConfigInfo.getMaxCount());
|
|
|
}
|
|
|
- serieses.add(new LineSeries(null, lineSeriesMapList));
|
|
|
+ chartsDataInfo.setxAxis(xAxisData);
|
|
|
+ serieses.add(new LineSeries(null, lineSeriesMapList));*/
|
|
|
+ List<HistogramData> histogramList = showChartsMapper.getHistogramValueWithoutGroup(fieldName, tableName, condition, sort, rule);
|
|
|
+ if (histogramList.size() > lineConfigInfo.getMaxCount()) {
|
|
|
+ chartsDataInfo.setTooMany(true);
|
|
|
+ }
|
|
|
+ histogramList = histogramList.subList(0, lineConfigInfo.getMaxCount());
|
|
|
+ xAxisData = histogramList.stream().map(HistogramData::getName).collect(Collectors.toList());
|
|
|
+ chartsDataInfo.setxAxis(xAxisData);
|
|
|
+ value = histogramList.stream().map(HistogramData::getValue).collect(Collectors.toList());
|
|
|
+ Series series = new Series(xColumn, value, null);
|
|
|
+ serieses.add(series);
|
|
|
}else {
|
|
|
fieldName = fieldName + ", nvl(" + groupBy.get(0) + ",'空') as groupName ";
|
|
|
condition = screenToColumnS;
|
|
|
String groupCondition = xColumn + "," + groupBy.get(0);
|
|
|
- List<LineSeriesGroupMap> lineSeriesGroupMapList = showChartsMapper.getLineValueWithGroup(fieldName, tableName, condition, groupCondition,sort, rule);
|
|
|
+ /*List<LineSeriesGroupMap> lineSeriesGroupMapList = showChartsMapper.getLineValueWithGroup(fieldName, tableName, condition, groupCondition,sort, rule);
|
|
|
Map<String, List<LineSeriesGroupMap>> lineSeriesGroupMap = CollectionUtils.groupBy(lineSeriesGroupMapList, LineSeriesGroupMap::getGroupName);
|
|
|
Iterator<Map.Entry<String, List<LineSeriesGroupMap>>> it = lineSeriesGroupMap.entrySet().iterator();
|
|
|
List<LineSeriesMap> lineSeriesMapList = null;
|
|
|
@@ -119,7 +129,47 @@ public class ShowLineService {
|
|
|
lineSeriesMapList = new ArrayList<>();
|
|
|
copyProperties(entry.getValue(), lineSeriesMapList);
|
|
|
serieses.add(new LineSeries(entry.getKey(), lineSeriesMapList));
|
|
|
+ }*/
|
|
|
+ List<HistogramGroupData> histogramGroupList = showChartsMapper.getHistogramValueWithGroup(fieldName, tableName, condition, groupCondition, sort, rule);
|
|
|
+ //X轴数据
|
|
|
+ xAxisData = histogramGroupList.stream().map(HistogramGroupData::getName).distinct().collect(Collectors.toList());
|
|
|
+ if (CollectionUtils.isEmpty(xAxisData)) {
|
|
|
+ return new RepEntity(RepCode.Null);
|
|
|
+ }
|
|
|
+ if (xAxisData.size() > lineConfigInfo.getMaxCount()) {
|
|
|
+ xAxisData = xAxisData.subList(0, lineConfigInfo.getMaxCount());
|
|
|
+ }
|
|
|
+ chartsDataInfo.setxAxis(xAxisData);
|
|
|
+ /* 数据处理 */
|
|
|
+ List<String> groupList = histogramGroupList.stream().map(HistogramGroupData::getGroupName).distinct().limit(5).collect(Collectors.toList());
|
|
|
+ Map<String, List<HistogramGroupData>> histogramNameMap = histogramGroupList.stream().collect(Collectors.groupingBy(HistogramGroupData::getName));
|
|
|
+ Set<String> keyset = histogramNameMap.keySet();
|
|
|
+ Iterator<String> keyIt= keyset.iterator();
|
|
|
+ List<HistogramGroupData> histogramGroupListAfterHandle = new ArrayList<>();
|
|
|
+ while (keyIt.hasNext()) {
|
|
|
+ String key = keyIt.next();
|
|
|
+ List<HistogramGroupData> histogramGroupDataList = histogramNameMap.get(key);
|
|
|
+ groupList.forEach(groupName -> {
|
|
|
+ boolean matched = histogramGroupDataList.stream().noneMatch(histogramGroupData -> groupName.equals(histogramGroupData.getGroupName()));
|
|
|
+ if (matched) {
|
|
|
+ histogramGroupDataList.add(new HistogramGroupData(key, null, groupName));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ histogramGroupListAfterHandle.addAll(histogramGroupDataList);
|
|
|
}
|
|
|
+ /* 返回数据对象组装 */
|
|
|
+ int i = 0;
|
|
|
+ Map<String, List<HistogramGroupData>> histogramGroupMap = histogramGroupListAfterHandle.stream().sorted(Comparator.comparing(HistogramGroupData::getName)).filter(histogramGroupData -> groupList.contains(histogramGroupData.getGroupName())).collect(Collectors.groupingBy(HistogramGroupData::getGroupName));
|
|
|
+ Set<String> groupSet = histogramGroupMap.keySet();
|
|
|
+ Iterator<String> it= groupSet.iterator();
|
|
|
+ do {
|
|
|
+ i++;
|
|
|
+ String key = it.next();
|
|
|
+ List<HistogramGroupData> histogramGroupDataList = histogramGroupMap.get(key);
|
|
|
+ value = histogramGroupDataList.stream().map(HistogramGroupData::getValue).collect(Collectors.toList()).subList(0, xAxisData.size());
|
|
|
+ Series series = new Series(key, value, groupBy.get(0));
|
|
|
+ serieses.add(series);
|
|
|
+ }while (it.hasNext() && i <= 20);
|
|
|
}
|
|
|
chartsDataInfo.setStyleConfig(styleConfig);
|
|
|
chartsDataInfo.setChartsColumnConfig(chartsColumn);
|