|
|
@@ -8,6 +8,7 @@ import com.usoftchina.bi.core.utils.EncryUtil;
|
|
|
import com.usoftchina.bi.server.dao.chart.ChartsConfigMapper;
|
|
|
import com.usoftchina.bi.server.dao.chart.ShowChartsMapper;
|
|
|
import com.usoftchina.bi.server.dao.dashboard.DashboardsMapper;
|
|
|
+import com.usoftchina.bi.server.dao.dataSource.DataConnectorMapper;
|
|
|
import com.usoftchina.bi.server.model.bo.*;
|
|
|
import com.usoftchina.bi.server.model.po.User;
|
|
|
import com.usoftchina.bi.server.model.vo.configVo.LoginInfo;
|
|
|
@@ -39,6 +40,8 @@ public class ShowPieService {
|
|
|
ChartsUtilService chartsUtilService;
|
|
|
@Autowired
|
|
|
UserService userService;
|
|
|
+ @Autowired
|
|
|
+ DataConnectorMapper dataConnectorMapper;
|
|
|
|
|
|
/*
|
|
|
Pie数据展示
|
|
|
@@ -58,12 +61,14 @@ public class ShowPieService {
|
|
|
yColumnType = pieConfigInfo.getSeries().getColumnType(),
|
|
|
xAxisType = pieConfigInfo.getLegendData().getShowDataType(),
|
|
|
yType = pieConfigInfo.getSeries().getShowDataType(),
|
|
|
- yAxisType = CalculationJudgeUtil.Judge(yType);
|
|
|
+ yAxisType = CalculationJudgeUtil.Judge(yType),
|
|
|
+ sort = StringUtils.isEmpty(pieConfigInfo.getSort()) ? xColumn : pieConfigInfo.getSort(),
|
|
|
+ rule = StringUtils.isEmpty(pieConfigInfo.getRule()) ? "ASC" : pieConfigInfo.getRule();
|
|
|
+ List<String> groupBy = pieConfigInfo.getGroups(), //分组
|
|
|
+ xAxisData = new ArrayList<String>(); //X轴自己用
|
|
|
PieSeries series = new PieSeries();
|
|
|
List<PieSeriesMap> value = new ArrayList<PieSeriesMap>();
|
|
|
List<PieSeries> serieses = new ArrayList<PieSeries>(); //生成柱状图的系列
|
|
|
- List<String> xAxisData = new ArrayList<String>(); //X轴自己用
|
|
|
-
|
|
|
List<Screen> filters = pieConfigInfo.getFilters();
|
|
|
ScreenStr scr = new ScreenStr();
|
|
|
String screen = "", //正常筛选条件
|
|
|
@@ -74,7 +79,7 @@ public class ShowPieService {
|
|
|
int id = pieConfigInfo.getId();
|
|
|
int baseId = getChartsDataUtilService.getBaseId(id);
|
|
|
ChartsColumnConfig chartsColumn = chartsConfigMapper.getChartsColumn(id);
|
|
|
- String tableName = chartsUtilService.getSqlStr(token, id, dashId);
|
|
|
+ String tableName = chartsUtilService.getSqlStr(token, id, dashId) + " tmp ";
|
|
|
/* 参数校验 */
|
|
|
if (ObjectUtils.isEmpty(chartsColumn)){
|
|
|
return new RepEntity(RepCode.Null);
|
|
|
@@ -85,6 +90,7 @@ public class ShowPieService {
|
|
|
if (StringUtils.isEmpty(xColumn) || StringUtils.isEmpty(yColumn)){
|
|
|
return new RepEntity(RepCode.nullAxis);
|
|
|
}
|
|
|
+ String databaseType = dataConnectorMapper.getDatabases(baseId).getDatabaseType();
|
|
|
/* 取数逻辑 */
|
|
|
try{
|
|
|
if (!DynamicDataSourceContextHolder.isContainsDataSource(baseId)) {
|
|
|
@@ -109,6 +115,13 @@ public class ShowPieService {
|
|
|
//日期类型
|
|
|
if ("time".equals(xColumnType)) {
|
|
|
xColumn = TimeConverterUtil.convertToOracleDateStr(xColumn, xAxisType);
|
|
|
+ sort = xColumn;
|
|
|
+ }
|
|
|
+ //Y轴排序
|
|
|
+ if (sort.equals(yColumn)) {
|
|
|
+ sort = yAxisType + "(" + yColumn + ")";
|
|
|
+ } else {
|
|
|
+ sort = xColumn;
|
|
|
}
|
|
|
String fieldName = yAxisType
|
|
|
+ "(nvl(" + yColumn + ",0)) as value,"
|
|
|
@@ -117,34 +130,60 @@ public class ShowPieService {
|
|
|
if ("time".equals(yColumnType)) {
|
|
|
fieldName = yAxisType + "(" + yColumn + ") as value," + ("scale".equals(xColumnType) ? "nvl(" + xColumn + ",0)" : "nvl(" + xColumn + ",'空')") + " as name ";
|
|
|
}
|
|
|
+ if ("mysql".equals(databaseType)) {
|
|
|
+ fieldName = fieldName.replaceAll("nvl", "ifNull");
|
|
|
+ } else if ("sqlServer".equals(databaseType)) {
|
|
|
+ fieldName = fieldName.replaceAll("nvl", "isNull");
|
|
|
+ }
|
|
|
String condition = screenToColumnS + " GROUP BY " + xColumn;
|
|
|
if (yAxisType.contains("distinct")) {
|
|
|
fieldName = fieldName.replace("distinct", "");
|
|
|
condition += "," + yColumn;
|
|
|
}
|
|
|
- value = showChartsMapper.getPieValueWithoutGroup(fieldName, tableName, condition);
|
|
|
- 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("其它");
|
|
|
- //有其他的时候 tooMany 为 true
|
|
|
- chartsDataInfo.setTooMany(true);
|
|
|
- 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(), "其它"));
|
|
|
+ if (CollectionUtils.isEmpty(groupBy)) {
|
|
|
+ value = showChartsMapper.getPieValueWithoutOutGroup(fieldName, tableName, condition, sort, rule);
|
|
|
+ if (value.size() > pieConfigInfo.getMaxCount()) {
|
|
|
+ chartsDataInfo.setTooMany(true);
|
|
|
+ value = value.subList(0, pieConfigInfo.getMaxCount());
|
|
|
+ }
|
|
|
+ xAxisData = value.stream().map(PieSeriesMap::getName).collect(Collectors.toList());
|
|
|
+ chartsDataInfo.setxAxis(xAxisData);
|
|
|
+ series.setName(pieConfigInfo.getSeries().getColumnName());
|
|
|
+ series.setValue(value);
|
|
|
+ serieses.add(series);
|
|
|
+ }else {
|
|
|
+ fieldName = fieldName + ", nvl(" + groupBy.get(0) + ",'空') as groupName ";
|
|
|
+ condition = screenToColumnS;
|
|
|
+ String groupCondition = xColumn + "," + groupBy.get(0);
|
|
|
+ if ("mysql".equals(databaseType)) {
|
|
|
+ fieldName = fieldName.replaceAll("nvl", "ifNull");
|
|
|
+ } else if ("sqlServer".equals(databaseType)) {
|
|
|
+ fieldName = fieldName.replaceAll("nvl", "isNull");
|
|
|
+ }
|
|
|
+ value = showChartsMapper.getPieValueWithoutGroup(fieldName, tableName, condition, groupCondition, sort, rule);
|
|
|
+ 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("其它");
|
|
|
+ //有其他的时候 tooMany 为 true
|
|
|
+ chartsDataInfo.setTooMany(true);
|
|
|
+ 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);
|
|
|
+ chartsDataInfo.setStyleConfig(styleConfig);
|
|
|
+ chartsDataInfo.setChartsColumnConfig(chartsColumn);
|
|
|
}
|
|
|
- chartsDataInfo.setxAxis(xAxisData);
|
|
|
- series.setName(pieConfigInfo.getSeries().getColumnName());
|
|
|
- series.setValue(value);
|
|
|
- serieses.add(series);
|
|
|
- chartsDataInfo.setStyleConfig(styleConfig);
|
|
|
- chartsDataInfo.setChartsColumnConfig(chartsColumn);
|
|
|
chartsDataInfo.setSerieses(serieses);
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|