Просмотр исходного кода

【BI商业智能】【MySQL、SQL server图表制作】

zhaoy 6 лет назад
Родитель
Сommit
591a49d85f

+ 25 - 4
bi-server/src/main/java/com/usoftchina/bi/server/dao/chart/ShowChartsMapper.java

@@ -40,7 +40,7 @@ public interface ShowChartsMapper {
     /*
     获取其他类数据
      */
-    @Select("select ${columnList} from (select ${columnList} from ${tableName} ${screen} order by ${columnName} ${sort})")
+    @Select("select ${columnList} from (select ${columnList} from ${tableName} ${screen} order by ${columnName} ${sort}) dept")
     List<LinkedHashMap<String, Object>> getOtherData(@Param("columnList") String columnList, @Param("tableName") String tableName, @Param("columnName") String columnName,
                                                      @Param("sort") String sort, @Param("screen") String screen, TestPage testPage);
 
@@ -121,8 +121,21 @@ public interface ShowChartsMapper {
      * @param condition
      * @return
      */
-    @Select("SELECT ${fieldName} FROM ${tableName} WHERE ${condition}")
-    List<PieSeriesMap> getPieValueWithoutGroup(@Param("fieldName") String fieldName, @Param("tableName") String tableName, @Param("condition") String condition);
+    @Select("SELECT ${fieldName} FROM ${tableName} WHERE ${condition} GROUP BY ${groupCondition} ORDER BY ${sort} ${rule}")
+    List<PieSeriesMap> getPieValueWithoutGroup(@Param("fieldName") String fieldName, @Param("tableName") String tableName, @Param("condition") String condition, @Param("groupCondition") String groupCondition,
+                                               @Param("sort") String sort, @Param("rule") String rule);
+
+    /**
+     * 饼图无分组取数
+     * @param fieldName
+     * @param tableName
+     * @param condition
+     * @return
+     */
+    @Select("SELECT ${fieldName} FROM ${tableName} WHERE ${condition} ORDER BY ${sort} ${rule}")
+    List<PieSeriesMap> getPieValueWithoutOutGroup(@Param("fieldName") String fieldName, @Param("tableName") String tableName, @Param("condition") String condition,
+                                               @Param("sort") String sort, @Param("rule") String rule);
+
 
     /**
      * 指标图取数
@@ -133,8 +146,16 @@ public interface ShowChartsMapper {
      * @param rule
      * @return
      */
-    @Select("SELECT * FROM (SELECT ${fieldName} FROM ${tableName} WHERE ${condition} ORDER BY ${sort} ${rule}) WHERE ROWNUM <= #{threshold}")
+    @Select("SELECT * FROM (SELECT ${fieldName} FROM ${tableName} WHERE ${condition} ORDER BY ${sort} ${rule}) DEPT WHERE ROWNUM <= #{threshold}")
     List<Map<String, Object>> getIndicatorValue(@Param("fieldName") String fieldName, @Param("tableName") String tableName, @Param("condition") String condition,
                                                @Param("sort") String sort, @Param("rule") String rule, @Param("threshold") int threshold);
 
+    @Select("SELECT * FROM (SELECT ${fieldName} FROM ${tableName} WHERE ${condition} ORDER BY ${sort} ${rule}) DEPT limit 0,#{threshold}")
+    List<Map<String, Object>> getIndicatorValue1(@Param("fieldName") String fieldName, @Param("tableName") String tableName, @Param("condition") String condition,
+                                                @Param("sort") String sort, @Param("rule") String rule, @Param("threshold") int threshold);
+
+    @Select("SELECT * FROM (SELECT ${fieldName} FROM ${tableName} WHERE ${condition} ORDER BY ${sort} ${rule}) DEPT")
+    List<Map<String, Object>> getIndicatorValue2(@Param("fieldName") String fieldName, @Param("tableName") String tableName, @Param("condition") String condition,
+                                                 @Param("sort") String sort, @Param("rule") String rule);
+
 }

+ 28 - 0
bi-server/src/main/java/com/usoftchina/bi/server/model/vo/configVo/PieConfigInfo.java

@@ -11,6 +11,34 @@ public class PieConfigInfo {
     private Column legendData;
     private Column series;
     private List<Screen> filters;
+    private List<String> groups;
+    private String sort;
+    private String rule;
+
+    public List<String> getGroups() {
+        return groups;
+    }
+
+    public void setGroups(List<String> groups) {
+        this.groups = groups;
+    }
+
+    public String getSort() {
+        return sort;
+    }
+
+    public void setSort(String sort) {
+        this.sort = sort;
+    }
+
+    public String getRule() {
+        return rule;
+    }
+
+    public void setRule(String rule) {
+        this.rule = rule;
+    }
+
     /**
      * 需要展示的条数
      */

+ 15 - 1
bi-server/src/main/java/com/usoftchina/bi/server/service/chart/ShowHistogramService.java

@@ -9,6 +9,7 @@ import com.usoftchina.bi.server.dao.chart.ChartsConfigMapper;
 import com.usoftchina.bi.server.dao.chart.ShowChartsMapper;
 import com.fasterxml.jackson.databind.ObjectMapper;
 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.HistogramConfigInfo;
@@ -43,6 +44,8 @@ public class ShowHistogramService {
     ChartsUtilService chartsUtilService;
     @Autowired
     UserService userService;
+    @Autowired
+    DataConnectorMapper dataConnectorMapper;
 
     /*
     柱状图数据展示
@@ -77,7 +80,7 @@ public class ShowHistogramService {
         String screen = "",               //正常筛选条件
                screenToColumn = "",       //跟目标列相同的筛选条件
                screenToColumnS = "";      //跟目标列相同的筛选条件
-        String tableName = chartsUtilService.getSqlStr(token, id, dashId);
+        String tableName = chartsUtilService.getSqlStr(token, id, dashId) + " tmp ";
         ChartsColumnConfig chartsColumnConfig = chartsConfigMapper.getChartsColumn(id);
         /* 参数校验 */
         if (StringUtils.isEmpty(xColumn) || StringUtils.isEmpty(yColumn)){
@@ -89,6 +92,7 @@ public class ShowHistogramService {
         if (StringUtils.isEmpty(tableName)){
             return new RepEntity(RepCode.NoAuthority);
         }
+        String databaseType = dataConnectorMapper.getDatabases(baseId).getDatabaseType();
         /* 取数逻辑 */
         try{
             if (!DynamicDataSourceContextHolder.isContainsDataSource(baseId)) {
@@ -140,6 +144,11 @@ public class ShowHistogramService {
             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");
+            }
             if (CollectionUtils.isEmpty(groupBy)) {
                 List<HistogramData> histogramList = showChartsMapper.getHistogramValueWithoutGroup(fieldName, tableName, condition, sort, rule);
                 if (histogramList.size() > histogramConfigInfo.getMaxCount()) {
@@ -155,6 +164,11 @@ public class ShowHistogramService {
                 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");
+                }
                 List<HistogramGroupData> histogramGroupList  = showChartsMapper.getHistogramValueWithGroup(fieldName, tableName, condition, groupCondition, sort, rule);
                 //X轴数据
                 xAxisData = histogramGroupList.stream().map(HistogramGroupData::getName).distinct().collect(Collectors.toList());

+ 14 - 2
bi-server/src/main/java/com/usoftchina/bi/server/service/chart/ShowIndicatorService.java

@@ -6,6 +6,7 @@ import com.usoftchina.bi.core.jdbc.DynamicDataSourceContextHolder;
 import com.usoftchina.bi.core.utils.CalculationJudgeUtil;
 import com.usoftchina.bi.server.dao.chart.ChartsConfigMapper;
 import com.usoftchina.bi.server.dao.chart.ShowChartsMapper;
+import com.usoftchina.bi.server.dao.dataSource.DataConnectorMapper;
 import com.usoftchina.bi.server.model.bo.Screen;
 import com.usoftchina.bi.server.model.bo.ScreenStr;
 import com.usoftchina.bi.server.model.vo.configVo.IndicatorConfigInfo;
@@ -38,6 +39,8 @@ public class ShowIndicatorService {
     private ScreenUtil screenUtil;
     @Autowired
     private GetChartsDataUtilService getChartsDataUtilService;
+    @Autowired
+    DataConnectorMapper dataConnectorMapper;
 
     /**
      * 指标图
@@ -52,7 +55,7 @@ public class ShowIndicatorService {
         String fields = "", otherFields = "";
         String sort = indicatorConfigInfo.getSort();
         String condition = getCondition(filters, indicatorConfigInfo.getxField().getColumnRename(), indicatorConfigInfo.getyField().getColumnRename());
-        String tableName = chartsUtilService.getSqlStr(token, indicatorConfigInfo.getId(), 0);
+        String tableName = chartsUtilService.getSqlStr(token, indicatorConfigInfo.getId(), 0) + " emp ";
         String operate = CalculationJudgeUtil.Judge(indicatorConfigInfo.getyField().getShowDataType());
         chartsDataInfo.setChartsColumnConfig(chartsConfigMapper.getChartsColumn(indicatorConfigInfo.getId()));
         if (ObjectUtils.isEmpty(indicatorConfigInfo.getxField())) {
@@ -72,13 +75,22 @@ public class ShowIndicatorService {
             condition += "," + String.join(",", indicatorConfigInfo.getOtherColumn());
         }
         int baseId = getChartsDataUtilService.getBaseId(indicatorConfigInfo.getId());
+        String databaseType = dataConnectorMapper.getDatabases(baseId).getDatabaseType();
         try {
             if (!DynamicDataSourceContextHolder.isContainsDataSource(baseId)) {
                 return new RepEntity(RepCode.DataSourceNull);
             } else {
                 DynamicDataSourceContextHolder.setDataSourceType(baseId);
             }
-            List<Map<String, Object>> indicatorSeriesMapList = showChartsMapper.getIndicatorValue(fields, tableName, condition, sort, indicatorConfigInfo.getRule(), indicatorConfigInfo.getThreshold());
+            List<Map<String, Object>> indicatorSeriesMapList = null;
+            if ("mysql".equals(databaseType)) {
+                indicatorSeriesMapList = showChartsMapper.getIndicatorValue1(fields, tableName, condition, sort, indicatorConfigInfo.getRule(), indicatorConfigInfo.getThreshold());
+            }else if ("sqlServer".equals(databaseType)) {
+                fields = "TOP "+ indicatorConfigInfo.getThreshold() +" PERCENT " + fields;
+                indicatorSeriesMapList = showChartsMapper.getIndicatorValue2(fields, tableName, condition, sort, indicatorConfigInfo.getRule());
+            }else {
+                indicatorSeriesMapList = showChartsMapper.getIndicatorValue(fields, tableName, condition, sort, indicatorConfigInfo.getRule(), indicatorConfigInfo.getThreshold());
+            }
             chartsDataInfo.setSerieses(indicatorSeriesMapList);
             chartsDataInfo.setStyleConfig(styleConfig);
         } catch (Exception e) {

+ 13 - 2
bi-server/src/main/java/com/usoftchina/bi/server/service/chart/ShowIndividualService.java

@@ -5,6 +5,7 @@ import com.usoftchina.bi.core.base.RepEntity;
 import com.usoftchina.bi.server.dao.chart.ChartsConfigMapper;
 import com.usoftchina.bi.server.dao.chart.ShowChartsMapper;
 import com.github.pagehelper.PageInfo;
+import com.usoftchina.bi.server.dao.dataSource.DataConnectorMapper;
 import com.usoftchina.bi.server.model.bo.ChartsColumnConfig;
 import com.usoftchina.bi.server.model.bo.Screen;
 import com.usoftchina.bi.server.model.bo.ScreenStr;
@@ -38,6 +39,8 @@ public class ShowIndividualService {
     ScreenUtil screenUtil;
     @Autowired
     ChartsUtilService chartsUtilService;
+    @Autowired
+    DataConnectorMapper dataConnectorMapper;
 
     public RepEntity showIndividual(IndividualConfigInfo individualConfigInfo, String token, int dashId){
         Assert.notNull(individualConfigInfo, "请求参数不能为空");
@@ -46,7 +49,7 @@ public class ShowIndividualService {
         List<LinkedHashMap<String, Object>> targetValue = new ArrayList<>();
         int id = individualConfigInfo.getId();
         ChartsColumnConfig chartsColumn = chartsConfigMapper.getChartsColumn(id);
-        String tableName = chartsUtilService.getSqlStr(token, id, dashId);
+        String tableName = chartsUtilService.getSqlStr(token, id, dashId) + " emp";
         int baseId = getChartsDataUtilService.getBaseId(id);
         List<Screen> screens = individualConfigInfo.getFilters();
         ScreenStr scr = new ScreenStr();
@@ -56,6 +59,7 @@ public class ShowIndividualService {
         String columnListName = individualConfigInfo.getColumnListName().toString();
         String sort = individualConfigInfo.getSort();
         String tableListName = columnListName.replace("[", "").replace("]", "");
+        String databaseType = dataConnectorMapper.getDatabases(baseId).getDatabaseType();
         /* 参数校验 */
         if (ObjectUtils.isEmpty(chartsColumn)) {
             return new RepEntity(RepCode.Null);
@@ -75,7 +79,14 @@ public class ShowIndividualService {
                 StringBuilder sb = new StringBuilder(screen);
                 screenStr = String.valueOf(sb .replace(1, 5, "where "));
             }
-            targetValue = showChartsMapper.getOtherData(tableListName, tableName, columnName, sort, screenStr, individualConfigInfo.getTestPage().enablePaging());
+            if ("mysql".equals(databaseType)) {
+                targetValue = showChartsMapper.getOtherData(tableListName, tableName, columnName, sort, screenStr, null);
+            }else if ("sqlServer".equals(databaseType)) {
+                tableListName = " top 100 percent " + tableListName;
+                targetValue = showChartsMapper.getOtherData(tableListName, tableName, columnName, sort, screenStr, null);
+            }else{
+                targetValue = showChartsMapper.getOtherData(tableListName, tableName, columnName, sort, screenStr, individualConfigInfo.getTestPage().enablePaging());
+            }
             PageInfo<LinkedHashMap<String, Object>> pageInfo = new PageInfo<>(targetValue);
             popAndIndDataInfo.setChartsColumnConfig(chartsColumn);
             popAndIndDataInfo.setValueList(pageInfo);

+ 22 - 1
bi-server/src/main/java/com/usoftchina/bi/server/service/chart/ShowLineService.java

@@ -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.LineConfigInfo;
@@ -39,6 +40,9 @@ public class ShowLineService {
     ChartsUtilService chartsUtilService;
     @Autowired
     UserService userService;
+    @Autowired
+    DataConnectorMapper dataConnectorMapper;
+
     /*
     Line数据展示
      */
@@ -71,6 +75,7 @@ public class ShowLineService {
         int baseId = getChartsDataUtilService.getBaseId(id);
         ChartsColumnConfig chartsColumn = chartsConfigMapper.getChartsColumn(id);
         String tableName = chartsUtilService.getSqlStr(token, id, dashId) + " emp ";
+        String databaseType = dataConnectorMapper.getDatabases(baseId).getDatabaseType();
         /* 参数校验 */
         if (ObjectUtils.isEmpty(chartsColumn)){
             return new RepEntity(RepCode.Null);
@@ -101,7 +106,13 @@ public class ShowLineService {
             }else {
                 screenToColumnS = " 1 = 1 ";
             }
-            xColumn = TimeConverterUtil.convertToOracleDateStr(xColumn, xAxisType);         //X轴 -> 折线图X轴只能为日期类型
+            if ("mysql".equals(databaseType)) {
+                xColumn = TimeConverterUtil.convertToMySqlDateStr(xColumn, xAxisType);
+            }else if ("sqlServer".equals(databaseType)) {
+                xColumn = TimeConverterUtil.convertToSqlServerDateStr(xColumn, xAxisType);
+            }else {
+                xColumn = TimeConverterUtil.convertToOracleDateStr(xColumn, xAxisType);         //X轴 -> 折线图X轴只能为日期类型
+            }
             String fieldName = yAxisType + "(nvl(" + yColumn + ",0)) as value," + xColumn + " as name ";
             if ("time".equals(yColumnType)) {
                 fieldName = yAxisType + "(" + yColumn + ") as value," + xColumn + " as name ";
@@ -112,6 +123,11 @@ public class ShowLineService {
                 condition += "," + yColumn;
             }
             String sort = xColumn, rule = "ASC";
+            if ("mysql".equals(databaseType)) {
+                fieldName = fieldName.replaceAll("nvl", "ifNull");
+            }else if ("sqlServer".equals(databaseType)) {
+                fieldName = fieldName.replaceAll("nvl", "isNull");
+            }
             if (CollectionUtils.isEmpty(groupBy)) {
                 /*List<LineSeriesMap> lineSeriesMapList = showChartsMapper.getLineValueWithoutGroup(fieldName, tableName, condition, sort, rule);
                 xAxisData = lineSeriesMapList.stream().map(LineSeriesMap::getDate).collect(Collectors.toList());
@@ -151,6 +167,11 @@ public class ShowLineService {
                     copyProperties(entry.getValue(), lineSeriesMapList);
                     serieses.add(new LineSeries(entry.getKey(), lineSeriesMapList));
                 }*/
+                if ("mysql".equals(databaseType)) {
+                    fieldName = fieldName.replaceAll("nvl", "ifNull");
+                }else if ("sqlServer".equals(databaseType)) {
+                    fieldName = fieldName.replaceAll("nvl", "isNull");
+                }
                 List<HistogramGroupData> histogramGroupList  = showChartsMapper.getHistogramValueWithGroup(fieldName, tableName, condition, groupCondition, sort, rule);
                 //X轴数据
                 xAxisData = histogramGroupList.stream().map(HistogramGroupData::getName).distinct().collect(Collectors.toList());

+ 64 - 25
bi-server/src/main/java/com/usoftchina/bi/server/service/chart/ShowPieService.java

@@ -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();

+ 1 - 1
bi-server/src/main/java/com/usoftchina/bi/server/service/chart/ShowPopulationService.java

@@ -41,7 +41,7 @@ public class ShowPopulationService {
         int id = populationInfo.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) + " emp ";
         List<String> groupByList = populationInfo.getGroupByList();     //分组
         String columnName = populationInfo.getColumnName();
         List<String> operators = populationInfo.getOperatorList();

+ 15 - 1
bi-server/src/main/java/com/usoftchina/bi/server/service/chart/ShowScatterService.java

@@ -6,6 +6,7 @@ import com.usoftchina.bi.core.utils.CalculationJudgeUtil;
 import com.usoftchina.bi.core.utils.CollectionUtils;
 import com.usoftchina.bi.server.dao.chart.ChartsConfigMapper;
 import com.usoftchina.bi.server.dao.chart.ShowChartsMapper;
+import com.usoftchina.bi.server.dao.dataSource.DataConnectorMapper;
 import com.usoftchina.bi.server.model.bo.*;
 import com.usoftchina.bi.server.model.vo.configVo.ScatterConfigInfo;
 import com.usoftchina.bi.server.model.vo.dataVo.ChartsDataInfo;
@@ -35,6 +36,8 @@ public class ShowScatterService {
     ScreenUtil screenUtil;
     @Autowired
     ChartsUtilService chartsUtilService;
+    @Autowired
+    DataConnectorMapper dataConnectorMapper;
 
     /*
     Line数据展示
@@ -64,7 +67,7 @@ public class ShowScatterService {
         int baseId = getChartsDataUtilService.getBaseId(id);
         TimeReture timeReture = new TimeReture();
         ChartsColumnConfig chartsColumn = chartsConfigMapper.getChartsColumn(id);
-        String tableName = chartsUtilService.getSqlStr(token, id, dashId);
+        String tableName = chartsUtilService.getSqlStr(token, id, dashId) + " emp ";
         /* 参数校验 */
         if (ObjectUtils.isEmpty(chartsColumn)){
             return new RepEntity(RepCode.Null);
@@ -75,6 +78,7 @@ public class ShowScatterService {
         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 +113,11 @@ public class ShowScatterService {
                 condition += "," + yColumn;
             }
             String sort = xColumn, rule = "ASC";
+            if ("mysql".equals(databaseType)) {
+                fieldName = fieldName.replaceAll("nvl", "ifNull");
+            }else if ("sqlServer".equals(databaseType)) {
+                fieldName = fieldName.replaceAll("nvl", "isNull");
+            }
             if (CollectionUtils.isEmpty(groupBy)) {
                 List<LineSeriesMap> lineSeriesMapList = showChartsMapper.getLineValueWithoutGroup(fieldName, tableName, condition, sort, rule);
                 xAxisData = lineSeriesMapList.stream().map(LineSeriesMap::getDate).collect(Collectors.toList());
@@ -125,6 +134,11 @@ public class ShowScatterService {
                 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");
+                }
                 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();

+ 35 - 0
bi-server/src/main/java/com/usoftchina/bi/server/service/chart/TimeConverterUtil.java

@@ -32,5 +32,40 @@ public class TimeConverterUtil {
             return "TO_CHAR(" + xColumn + ", 'YYYY-MM-DD')";
         }
     }
+    public static String convertToSqlServerDateStr(String xColumn, String timeType) {
+        if ("year".equals(timeType)){
+            return "convert(varchar(4), " + xColumn + ", 120)";
+        } else if("month".equals(timeType)) {
+            return "convert(varchar(7), " + xColumn + ", 120)";
+        } else if ("day".equals(timeType)) {
+            return "convert(varchar(10), " + xColumn + ", 120)";
+        } else if ("quarter".equals(timeType)) {
+            return "datename(yy, " + xColumn + ")+'-'+(datename(q, " + xColumn + "))";
+        } else if ("week".equals(timeType)) {
+            return "datename(yy, " + xColumn + ")+'-'+(datename(ww, " + xColumn + "))";
+        } else if ("halfYear".equals(timeType)){
+            return "case when datepart(mm, " + xColumn + ")<=6 then convert(varchar(4), " + xColumn + ", 120)+ '-H1' when datepart(mm, " + xColumn + ")>6 then convert(varchar(4), " + xColumn + ", 120)+ '-H2' else null end ";
+        } else {
+            return "convert(varchar(10), " + xColumn + ", 120)";
+        }
+    }
+
+    public static String convertToMySqlDateStr(String xColumn, String timeType) {
+        if ("year".equals(timeType)){
+            return "date_format(" + xColumn + ", '%Y')";
+        } else if("month".equals(timeType)) {
+            return "date_format(" + xColumn + ", '%Y-%m')";
+        } else if ("day".equals(timeType)) {
+            return "date_format(" + xColumn + ", '%Y-%m-%d')";
+        } else if ("quarter".equals(timeType)) {
+            return "date_format(" + xColumn + ", '%Y-q')";
+        } else if ("week".equals(timeType)) {
+            return "date_format(" + xColumn + ", '%Y-%w')";
+        } else if ("halfYear".equals(timeType)){
+            return "case when date_format(" + xColumn + ", '%m')<=6 then date_format(" + xColumn + ", '%Y')|| '-H1' when date_format(" + xColumn + ", '%m')>6 then date_format(" + xColumn + ", '%Y')||'-H2' else "+ xColumn +"||'' end ";
+        } else {
+            return "date_format(" + xColumn + ", '%Y-%m-%d')";
+        }
+    }
 
 }