Browse Source

图表增加数据返回

chenw 6 years ago
parent
commit
073ed7476b

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

@@ -43,7 +43,7 @@ public class ShowChartsController {
     @CheckToken
     @PostMapping("/showHistogram")
     public RepEntity showHistogram(@RequestHeader String token,@RequestBody HistogramConfigInfo body){
-        return showHistogramService.showHistogram(body, token, 0);
+        return showHistogramService.showHistogram(body, token, 0, null);
     }
 
     /*
@@ -53,7 +53,7 @@ public class ShowChartsController {
     @CheckToken
     @PostMapping("/showPie")
     public RepEntity showPie(@RequestHeader String token,@RequestBody PieConfigInfo body){
-        return showPieService.showPie(body, token, 0);
+        return showPieService.showPie(body, token, 0, null);
     }
 
     /*
@@ -63,7 +63,7 @@ public class ShowChartsController {
     @CheckToken
     @PostMapping("/showLine")
     public RepEntity showLine(@RequestHeader String token,@RequestBody LineConfigInfo body){
-        return showLineService.showLine(body, token, 0);
+        return showLineService.showLine(body, token, 0, null);
     }
 
     /*
@@ -73,7 +73,7 @@ public class ShowChartsController {
     @CheckToken
     @PostMapping("/showScatter")
     public RepEntity showScatter(@RequestHeader String token,@RequestBody ScatterConfigInfo body){
-        return showScatterService.showScatter(body, token, 0);
+        return showScatterService.showScatter(body, token, 0, null);
     }
 
     /*

+ 1 - 1
bi-server/src/main/java/com/usoftchina/bi/server/dao/chart/ChartsConfigMapper.java

@@ -329,7 +329,7 @@ public interface ChartsConfigMapper {
     /*
     通过图表ID获取图表配置
      */
-    @Select("select id, chart_type as chartType, BC_FETCHCONFIG as fetchConfig from bi_charts where id = #{id}")
+    @Select("select id, chart_type as chartType, BC_FETCHCONFIG as fetchConfig,BC_CHART_STYLE as styleConfig from bi_charts where id = #{id}")
     ChartsConfigToDash getChartConfigToDash(int id);
 
     /*

+ 9 - 0
bi-server/src/main/java/com/usoftchina/bi/server/model/po/ChartsConfigToDash.java

@@ -4,6 +4,15 @@ public class ChartsConfigToDash {
     private int chartId;
     private String fetchConfig;
     private String chartType;
+    private String styleConfig;
+
+    public String getStyleConfig() {
+        return styleConfig;
+    }
+
+    public void setStyleConfig(String styleConfig) {
+        this.styleConfig = styleConfig;
+    }
 
     public String getChartType() {
         return chartType;

+ 9 - 0
bi-server/src/main/java/com/usoftchina/bi/server/model/vo/dataVo/ChartsDataInfo.java

@@ -9,6 +9,15 @@ public class ChartsDataInfo<T> {
     private List<T> serieses;
     private ChartsColumnConfig chartsColumnConfig;
     private boolean tooMany;
+    private String styleConfig;
+
+    public String getStyleConfig() {
+        return styleConfig;
+    }
+
+    public void setStyleConfig(String styleConfig) {
+        this.styleConfig = styleConfig;
+    }
 
     public boolean isTooMany() {
         return tooMany;

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

@@ -38,8 +38,9 @@ public class ShowHistogramService {
     /*
     柱状图数据展示
      */
-    public RepEntity showHistogram(HistogramConfigInfo histogramConfigInfo, String token, int dashId){
+    public RepEntity showHistogram(HistogramConfigInfo histogramConfigInfo, String token, int dashId, String styleConfig){
         ChartsDataInfo chartsDataInfo = new ChartsDataInfo();
+        chartsDataInfo.setStyleConfig(styleConfig);
         TimeReture timeReture = new TimeReture();
         if (histogramConfigInfo == null || "".equals(histogramConfigInfo)){
             return new RepEntity(RepCode.Null);

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

@@ -11,7 +11,6 @@ import com.usoftchina.bi.server.model.vo.configVo.LineConfigInfo;
 import com.usoftchina.bi.server.model.vo.dataVo.ChartsDataInfo;
 import com.usoftchina.bi.core.jdbc.DynamicDataSourceContextHolder;
 import com.usoftchina.bi.server.utils.ScreenUtil;
-import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -38,8 +37,9 @@ public class ShowLineService {
     /*
     Line数据展示
      */
-    public RepEntity showLine(LineConfigInfo lineConfigInfo, String token, int dashId){
+    public RepEntity showLine(LineConfigInfo lineConfigInfo, String token, int dashId, String styleConfig){
         ChartsDataInfo chartsDataInfo = new ChartsDataInfo();
+        chartsDataInfo.setStyleConfig(styleConfig);
         TimeReture timeReture = new TimeReture();
         if (lineConfigInfo == null || "".equals(lineConfigInfo)){
             return new RepEntity(RepCode.Null);

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

@@ -35,8 +35,9 @@ public class ShowPieService {
     /*
     Pie数据展示
      */
-    public RepEntity showPie(PieConfigInfo pieConfigInfo, String token, int dashId){
+    public RepEntity showPie(PieConfigInfo pieConfigInfo, String token, int dashId, String styleConfig){
         ChartsDataInfo<PieSeries> chartsDataInfo = new ChartsDataInfo();
+        chartsDataInfo.setStyleConfig(styleConfig);
         TimeReture timeReture = new TimeReture();
         if (pieConfigInfo == null || "".equals(pieConfigInfo)){
             return new RepEntity(RepCode.Null);

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

@@ -35,8 +35,9 @@ public class ShowScatterService {
     /*
     Line数据展示
      */
-    public RepEntity showScatter(ScatterConfigInfo scatterConfigInfo, String token, int dashId){
+    public RepEntity showScatter(ScatterConfigInfo scatterConfigInfo, String token, int dashId, String styleConfig){
         ChartsDataInfo chartsDataInfo = new ChartsDataInfo();
+        chartsDataInfo.setStyleConfig(styleConfig);
         TimeReture timeReture = new TimeReture();
         if (scatterConfigInfo == null || "".equals(scatterConfigInfo)){
             return new RepEntity(RepCode.Null);

+ 20 - 27
bi-server/src/main/java/com/usoftchina/bi/server/service/dashboard/DashboardsToChartsUtilService.java

@@ -47,22 +47,15 @@ public class DashboardsToChartsUtilService {
     @Autowired
     private UserService userService;
 
-    private int chartId;
-
-    private Lock lock = new ReentrantLock();
-
     public RepEntity getChartsInDash(ChartsToDashInfo chartsToDashInfo, String token) throws SQLException {
         if (StringUtils.isEmpty(token)) {
             User user = userService.getUserById(chartsToDashInfo.getDashboardCreatorId()).getData();
             LoginInfo loginInfo = new LoginInfo(user.getUserName(), EncryUtil.decryptPassword(user.getPassWord()));
             token = userService.login(loginInfo).getData().getToken();
         }
-        lock.lock();
-        try {
-            chartId = chartsToDashInfo.getChartId();
-        } finally {
-            lock.unlock();
-        }
+
+        int chartId = chartsToDashInfo.getChartId();
+
         //拿到图表配置
         ChartsConfigToDash chartsConfigToDash = chartsConfigMapper.getChartConfigToDash(chartId);
         if (chartsConfigToDash == null || "".equals(chartsConfigToDash)){
@@ -70,6 +63,7 @@ public class DashboardsToChartsUtilService {
         }
         String chartType = chartsConfigToDash.getChartType();
         String fetchConfig = chartsConfigToDash.getFetchConfig();
+        String styleConfig = chartsConfigToDash.getStyleConfig();
         if (fetchConfig == null || "".equals(fetchConfig)){
             return new RepEntity(RepCode.Null);
         }
@@ -77,27 +71,26 @@ public class DashboardsToChartsUtilService {
         //判断图表类型
         List<Screen> filters = chartsToDashInfo.getFilters();
         if ("Pie".equals(chartType)){
-            return getPie(fetchConfig, token, filters);
-
+            return getPie(fetchConfig, token, filters, chartId, styleConfig);
         }else if ("Histogram".equals(chartType)){
-            return getHistogram(fetchConfig, token, filters);
+            return getHistogram(fetchConfig, token, filters, chartId, styleConfig);
 
         }else if ("Line".equals(chartType)){
-            return getLine(fetchConfig, token, filters);
+            return getLine(fetchConfig, token, filters, chartId, styleConfig);
 
         }else if ("population".equals(chartType)){
-            return getPopulation(fetchConfig, token, filters);
+            return getPopulation(fetchConfig, token, filters, chartId, styleConfig);
 
         }else if ("individual".equals(chartType)){
-            return getIndividual(fetchConfig, token, filters, chartsToDashInfo.getTestPage());
+            return getIndividual(fetchConfig, token, filters, chartsToDashInfo.getTestPage(), chartId, styleConfig);
 
         }else if("scatter".equals(chartType)){
-            return getScatter(fetchConfig, token, filters);
+            return getScatter(fetchConfig, token, filters, chartId, styleConfig);
         }
         return new RepEntity(RepCode.success);
     }
 
-    public RepEntity getHistogram(String fetchConfig, String token, List<Screen> filters){
+    public RepEntity getHistogram(String fetchConfig, String token, List<Screen> filters, int chartId, String styleConfig){
         HistogramConfigInfo histogramConfigInfo = new HistogramConfigInfo();
         try {
             histogramConfigInfo = objectMapper.readValue(fetchConfig,HistogramConfigInfo.class);
@@ -105,10 +98,10 @@ public class DashboardsToChartsUtilService {
         } catch (Exception e) {
             e.printStackTrace();
         }
-        return showHistogramService.showHistogram(histogramConfigInfo, token, chartId);
+        return showHistogramService.showHistogram(histogramConfigInfo, token, chartId, styleConfig);
     }
 
-    public RepEntity getScatter(String fetchConfig, String token, List<Screen> filters){
+    public RepEntity getScatter(String fetchConfig, String token, List<Screen> filters, int chartId, String styleConfig){
             ScatterConfigInfo scatterConfigInfo = new ScatterConfigInfo();
             try {
                 scatterConfigInfo = objectMapper.readValue(fetchConfig,ScatterConfigInfo.class);
@@ -116,10 +109,10 @@ public class DashboardsToChartsUtilService {
             } catch (Exception e) {
                 e.printStackTrace();
             }
-            return showScatterService.showScatter(scatterConfigInfo, token, chartId);
+            return showScatterService.showScatter(scatterConfigInfo, token, chartId, styleConfig);
     }
 
-    public RepEntity getLine(String fetchConfig, String token, List<Screen> filters){
+    public RepEntity getLine(String fetchConfig, String token, List<Screen> filters, int chartId, String styleConfig){
         LineConfigInfo lineConfigInfo = new LineConfigInfo();
         try {
             lineConfigInfo = objectMapper.readValue(fetchConfig,LineConfigInfo.class);
@@ -127,10 +120,10 @@ public class DashboardsToChartsUtilService {
         } catch (Exception e) {
             e.printStackTrace();
         }
-        return showLineService.showLine(lineConfigInfo, token, chartId);
+        return showLineService.showLine(lineConfigInfo, token, chartId, styleConfig);
     }
 
-    public RepEntity getPopulation(String fetchConfig, String token, List<Screen> filters) throws SQLException {
+    public 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);
@@ -141,7 +134,7 @@ public class DashboardsToChartsUtilService {
         return showPopulationService.showPopulation(populationInfo, token, chartId);
     }
 
-    public RepEntity getIndividual(String fetchConfig, String token, List<Screen> filters, TestPage testPage) throws SQLException {
+    public 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);
@@ -153,7 +146,7 @@ public class DashboardsToChartsUtilService {
         return showIndividualService.showIndividual(individualConfigInfo, token, chartId);
     }
 
-    public RepEntity getPie(String fetchConfig, String token, List<Screen> filters){
+    public RepEntity getPie(String fetchConfig, String token, List<Screen> filters, int chartId, String styleConfig){
         PieConfigInfo pieConfigInfo = new PieConfigInfo();
         try {
             pieConfigInfo = objectMapper.readValue(fetchConfig,PieConfigInfo.class);
@@ -161,7 +154,7 @@ public class DashboardsToChartsUtilService {
         } catch (Exception e) {
             e.printStackTrace();
         }
-        return showPieService.showPie(pieConfigInfo, token, chartId);
+        return showPieService.showPie(pieConfigInfo, token, chartId, styleConfig);
     }
 
 }