Преглед изворни кода

新增图表类型:指标图

chenw пре 6 година
родитељ
комит
b22edc1a25

+ 12 - 0
bi-server/src/main/java/com/usoftchina/bi/server/controller/chart/ShowChartsController.java

@@ -33,6 +33,8 @@ public class ShowChartsController {
     @Autowired
     ShowPopulationService showPopulationService;
     @Autowired
+    ShowIndicatorService showIndicatorService;
+    @Autowired
     ColumnScreenService columnScreenService;
     @Autowired
     GetChartsDataUtilService getChartsDataUtilService;
@@ -96,6 +98,16 @@ public class ShowChartsController {
         return showPopulationService.showPopulation(body, token, 0);
     }
 
+    /**
+     * 指标图
+     */
+    @ApiOperation(value = "展示指标图", notes = "展示指标图", response = RepEntity.class)
+    @CheckToken
+    @PostMapping("/showIndicator")
+    public RepEntity showIndicator(@RequestHeader String token,@RequestBody IndicatorConfigInfo indicatorConfigInfo) {
+        return showIndicatorService.showIndicator(indicatorConfigInfo, token);
+    }
+
     /*
     展示列数据
      */

+ 13 - 0
bi-server/src/main/java/com/usoftchina/bi/server/dao/chart/ShowChartsMapper.java

@@ -124,4 +124,17 @@ public interface ShowChartsMapper {
     @Select("SELECT ${fieldName} FROM ${tableName} WHERE ${condition}")
     List<PieSeriesMap> getPieValueWithoutGroup(@Param("fieldName") String fieldName, @Param("tableName") String tableName, @Param("condition") String condition);
 
+    /**
+     * 指标图取数
+     * @param fieldName
+     * @param tableName
+     * @param condition
+     * @param sort
+     * @param rule
+     * @return
+     */
+    @Select("SELECT ${fieldName} FROM ${tableName} WHERE ${condition} ORDER BY ${sort} ${rule}")
+    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);
+
 }

+ 28 - 0
bi-server/src/main/java/com/usoftchina/bi/server/model/bo/IndicatorSeriesMap.java

@@ -0,0 +1,28 @@
+package com.usoftchina.bi.server.model.bo;
+
+/**
+ * @Author chenwei
+ * @Date 2019-07-11
+ */
+public class IndicatorSeriesMap {
+
+    private String name;
+
+    private String value;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+}

+ 105 - 0
bi-server/src/main/java/com/usoftchina/bi/server/model/vo/configVo/IndicatorConfigInfo.java

@@ -0,0 +1,105 @@
+package com.usoftchina.bi.server.model.vo.configVo;
+
+import com.usoftchina.bi.server.model.bo.Column;
+import com.usoftchina.bi.server.model.bo.Screen;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+import java.util.List;
+
+/**
+ * 指标图
+ * @Author chenwei
+ * @Date 2019-07-11
+ */
+@ApiModel(value = "IndicatorConfigInfo", description = "指标图数据请求对象")
+public class IndicatorConfigInfo {
+
+    @ApiModelProperty(value = "图表id")
+    private int id;
+
+    @ApiModelProperty(value = "xField")
+    private Column xField;
+
+    @ApiModelProperty(value = "yField")
+    private Column yField;
+
+    @ApiModelProperty(value = "需要展示的其他字段")
+    private List<String> otherColumn;
+
+    @ApiModelProperty(value = "过滤条件")
+    private List<Screen> filters;
+
+    @ApiModelProperty(value = "排序字段")
+    private String sort;
+
+    @ApiModelProperty(value = "排序规则,ASC->升序,DESC->降序")
+    private String rule;
+
+    @ApiModelProperty("阈值")
+    private String threshold;
+
+    public String getThreshold() {
+        return threshold;
+    }
+
+    public void setThreshold(String threshold) {
+        this.threshold = threshold;
+    }
+
+    public List<Screen> getFilters() {
+        return filters;
+    }
+
+    public void setFilters(List<Screen> filters) {
+        this.filters = filters;
+    }
+
+    public String getRule() {
+        return rule;
+    }
+
+    public void setRule(String rule) {
+        this.rule = rule;
+    }
+
+    public String getSort() {
+        return sort;
+    }
+
+    public void setSort(String sort) {
+        this.sort = sort;
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public Column getxField() {
+        return xField;
+    }
+
+    public void setxField(Column xField) {
+        this.xField = xField;
+    }
+
+    public Column getyField() {
+        return yField;
+    }
+
+    public void setyField(Column yField) {
+        this.yField = yField;
+    }
+
+    public List<String> getOtherColumn() {
+        return otherColumn;
+    }
+
+    public void setOtherColumn(List<String> otherColumn) {
+        this.otherColumn = otherColumn;
+    }
+}

+ 44 - 0
bi-server/src/main/java/com/usoftchina/bi/server/model/vo/dataVo/IndicatorDTO.java

@@ -0,0 +1,44 @@
+package com.usoftchina.bi.server.model.vo.dataVo;
+
+import com.usoftchina.bi.server.model.bo.IndicatorSeriesMap;
+
+import java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Author chenwei
+ * @Date 2019-07-11
+ */
+public class IndicatorDTO implements Serializable {
+
+    private List<IndicatorSeriesMap> normalResult;
+
+    private List<Map<String, Object>> otherResult;
+
+    public IndicatorDTO() {
+    }
+
+    public IndicatorDTO(List<IndicatorSeriesMap> normalResult, List<Map<String, Object>> otherResult) {
+
+        this.normalResult = normalResult;
+        this.otherResult = otherResult;
+    }
+
+    public List<IndicatorSeriesMap> getNormalResult() {
+
+        return normalResult;
+    }
+
+    public void setNormalResult(List<IndicatorSeriesMap> normalResult) {
+        this.normalResult = normalResult;
+    }
+
+    public List<Map<String, Object>> getOtherResult() {
+        return otherResult;
+    }
+
+    public void setOtherResult(List<Map<String, Object>> otherResult) {
+        this.otherResult = otherResult;
+    }
+}

+ 98 - 0
bi-server/src/main/java/com/usoftchina/bi/server/service/chart/ShowIndicatorService.java

@@ -0,0 +1,98 @@
+package com.usoftchina.bi.server.service.chart;
+
+import com.usoftchina.bi.core.base.RepCode;
+import com.usoftchina.bi.core.base.RepEntity;
+import com.usoftchina.bi.server.dao.chart.ShowChartsMapper;
+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;
+import com.usoftchina.bi.server.utils.ScreenUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.Assert;
+import org.springframework.util.CollectionUtils;
+import org.springframework.util.ObjectUtils;
+import org.springframework.util.StringUtils;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Author chenwei
+ * @Date 2019-07-11
+ */
+@Service
+public class ShowIndicatorService {
+
+    @Autowired
+    private ChartsUtilService chartsUtilService;
+    @Autowired
+    private ShowChartsMapper showChartsMapper;
+    @Autowired
+    private ScreenUtil screenUtil;
+
+    /**
+     * 指标图
+     * @param indicatorConfigInfo
+     * @param token
+     * @return
+     */
+    public RepEntity<?> showIndicator(IndicatorConfigInfo indicatorConfigInfo, String token) {
+        Assert.notNull(indicatorConfigInfo, "请求参数不正确");
+        List<Screen> filters = indicatorConfigInfo.getFilters();
+        String fields = "", otherFields = "";
+        String sort = indicatorConfigInfo.getSort();
+        String condition = getCondition(filters, indicatorConfigInfo.getxField().getColumnRename(), indicatorConfigInfo.getyField().getColumnRename());
+        condition = condition + (StringUtils.isEmpty(condition) ? "" : " AND") + " ROWNUM <= " + indicatorConfigInfo.getThreshold();
+                String tableName = chartsUtilService.getSqlStr(token, indicatorConfigInfo.getId(), 0);
+        String operate = indicatorConfigInfo.getyField().getShowDataType();
+        if (ObjectUtils.isEmpty(indicatorConfigInfo.getxField())) {
+            fields += StringUtils.isEmpty(operate) ? indicatorConfigInfo.getyField().getColumnRename() + " as \"value\" " : operate + "(" + indicatorConfigInfo.getyField().getColumnRename() + ") as \"value\" ";
+        }else {
+            fields += indicatorConfigInfo.getxField().getColumnRename() + " as \"name\"," + (StringUtils.isEmpty(operate) ? indicatorConfigInfo.getyField().getColumnRename() + " as \"value\" " : operate + "(" + indicatorConfigInfo.getyField().getColumnRename() + ") as \"value\" ");
+            condition += " group by " + indicatorConfigInfo.getxField().getColumnRename();
+        }
+        if (indicatorConfigInfo.getyField().getColumnRename().equalsIgnoreCase(sort)) {
+            sort = indicatorConfigInfo.getyField().getShowDataType() + "(" + sort + ")";
+        }
+        if (!CollectionUtils.isEmpty(indicatorConfigInfo.getOtherColumn())) {
+            fields += "," + String.join(",", indicatorConfigInfo.getOtherColumn());
+            condition += "," + String.join(",", indicatorConfigInfo.getOtherColumn());
+        }
+        List<Map<String, Object>> indicatorSeriesMapList = showChartsMapper.getIndicatorValue(fields, tableName, condition, sort, indicatorConfigInfo.getRule());
+        return new RepEntity<>(RepCode.success, indicatorSeriesMapList);
+    }
+
+    /**
+     * 获取条件语句
+     * @param filters
+     * @param xColumn
+     * @param yColumn
+     * @return
+     */
+    private String getCondition(List<Screen> filters, String xColumn, String yColumn) {
+        String condition = "";
+        if (!CollectionUtils.isEmpty(filters)){
+            ScreenStr screenStr = screenUtil.screensUtil(filters, xColumn, yColumn);
+            String screen = screenStr.getRet();
+            String screenToColumn = screenStr.getWithColumnRet();
+            if (StringUtils.isEmpty(screenToColumn)){
+                if (screen.startsWith(" and ")) {
+                    condition = screen.substring(5);
+                }else {
+                    condition = screen;
+                }
+            } else {
+                if (screenToColumn.startsWith(" and ")) {
+                    condition = screenToColumn.substring(5) + screen;
+                }else {
+                    condition = screenToColumn + screen;
+                }
+            }
+        }else {
+            condition = " 1 = 1 ";
+        }
+        return condition;
+    }
+
+}

+ 22 - 7
bi-server/src/main/java/com/usoftchina/bi/server/service/dashboard/DashboardsToChartsUtilService.java

@@ -46,6 +46,8 @@ public class DashboardsToChartsUtilService {
     @Autowired
     ShowScatterService showScatterService;
     @Autowired
+    ShowIndicatorService showIndicatorService;
+    @Autowired
     private UserService userService;
 
     public RepEntity getChartsInDash(ChartsToDashInfo chartsToDashInfo, String token) throws SQLException {
@@ -82,16 +84,18 @@ public class DashboardsToChartsUtilService {
         }else if ("population".equals(chartType)){
             return getPopulation(fetchConfig, token, filters, chartId, styleConfig);
 
-        }else if ("individual".equals(chartType) || "indicator".equalsIgnoreCase(chartType)){
+        }else if ("individual".equals(chartType)){
             return getIndividual(fetchConfig, token, filters, chartsToDashInfo.getTestPage(), chartId, styleConfig);
 
         }else if("scatter".equals(chartType)){
             return getScatter(fetchConfig, token, filters, chartId, styleConfig);
+        }else if ("indicator".equalsIgnoreCase(chartType)) {
+            return getIndicator(fetchConfig, token, filters);
         }
         return new RepEntity(RepCode.success);
     }
 
-    public RepEntity getHistogram(String fetchConfig, String token, List<Screen> filters, int chartId, String styleConfig){
+    private RepEntity getHistogram(String fetchConfig, String token, List<Screen> filters, int chartId, String styleConfig){
         HistogramConfigInfo histogramConfigInfo = new HistogramConfigInfo();
         try {
             histogramConfigInfo = objectMapper.readValue(fetchConfig,HistogramConfigInfo.class);
@@ -102,7 +106,7 @@ public class DashboardsToChartsUtilService {
         return showHistogramService.showHistogram(histogramConfigInfo, token, chartId);
     }
 
-    public RepEntity getScatter(String fetchConfig, String token, List<Screen> filters, int chartId, String styleConfig){
+    private RepEntity getScatter(String fetchConfig, String token, List<Screen> filters, int chartId, String styleConfig){
             ScatterConfigInfo scatterConfigInfo = new ScatterConfigInfo();
             try {
                 scatterConfigInfo = objectMapper.readValue(fetchConfig,ScatterConfigInfo.class);
@@ -113,7 +117,7 @@ public class DashboardsToChartsUtilService {
             return showScatterService.showScatter(scatterConfigInfo, token, chartId, styleConfig);
     }
 
-    public RepEntity getLine(String fetchConfig, String token, List<Screen> filters, int chartId, String styleConfig){
+    private RepEntity getLine(String fetchConfig, String token, List<Screen> filters, int chartId, String styleConfig){
         LineConfigInfo lineConfigInfo = new LineConfigInfo();
         try {
             lineConfigInfo = objectMapper.readValue(fetchConfig,LineConfigInfo.class);
@@ -124,7 +128,7 @@ public class DashboardsToChartsUtilService {
         return showLineService.showLine(lineConfigInfo, token, chartId, styleConfig);
     }
 
-    public RepEntity getPopulation(String fetchConfig, String token, List<Screen> filters, int chartId, String styleConfig) throws SQLException {
+    private RepEntity getPopulation(String fetchConfig, String token, List<Screen> filters, int chartId, String styleConfig) throws SQLException {
         PopulationInfo populationInfo = new PopulationInfo();
         try {
             populationInfo = objectMapper.readValue(fetchConfig,PopulationInfo.class);
@@ -137,7 +141,7 @@ public class DashboardsToChartsUtilService {
         return repEntity;
     }
 
-    public RepEntity getIndividual(String fetchConfig, String token, List<Screen> filters, TestPage testPage, int chartId, String styleConfig) throws SQLException {
+    private RepEntity getIndividual(String fetchConfig, String token, List<Screen> filters, TestPage testPage, int chartId, String styleConfig) throws SQLException {
         IndividualConfigInfo individualConfigInfo = new IndividualConfigInfo();
         try {
             individualConfigInfo = objectMapper.readValue(fetchConfig,IndividualConfigInfo.class);
@@ -151,7 +155,7 @@ public class DashboardsToChartsUtilService {
         return repEntity;
     }
 
-    public RepEntity getPie(String fetchConfig, String token, List<Screen> filters, int chartId, String styleConfig){
+    private RepEntity getPie(String fetchConfig, String token, List<Screen> filters, int chartId, String styleConfig){
         PieConfigInfo pieConfigInfo = new PieConfigInfo();
         try {
             pieConfigInfo = objectMapper.readValue(fetchConfig,PieConfigInfo.class);
@@ -162,4 +166,15 @@ public class DashboardsToChartsUtilService {
         return showPieService.showPie(pieConfigInfo, token, chartId, styleConfig);
     }
 
+    private RepEntity getIndicator(String fetchConfig, String token, List<Screen> filters){
+        IndicatorConfigInfo indicatorConfigInfo = new IndicatorConfigInfo();
+        try {
+            indicatorConfigInfo = objectMapper.readValue(fetchConfig,IndicatorConfigInfo.class);
+            indicatorConfigInfo.setFilters(filters);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return showIndicatorService.showIndicator(indicatorConfigInfo, token);
+    }
+
 }