DashboardsToChartsUtilService.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package com.server;
  2. import com.dao.ChartsConfigMapper;
  3. import com.fasterxml.jackson.databind.ObjectMapper;
  4. import com.model.bo.Screen;
  5. import com.model.po.ChartsConfigToDash;
  6. import com.model.pojo.RepCode;
  7. import com.model.pojo.RepEntity;
  8. import com.model.vo.configVo.*;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. import java.sql.SQLException;
  12. import java.util.List;
  13. /*
  14. 看板中调用生成图表
  15. */
  16. @Service
  17. public class DashboardsToChartsUtilService {
  18. @Autowired
  19. ChartsConfigMapper chartsConfigMapper;
  20. @Autowired
  21. ObjectMapper objectMapper;
  22. @Autowired
  23. ShowHistogramService showHistogramService;
  24. @Autowired
  25. ShowIndividualService showIndividualService;
  26. @Autowired
  27. ShowLineService showLineService;
  28. @Autowired
  29. ShowPieService showPieService;
  30. @Autowired
  31. ShowPopulationService showPopulationService;
  32. @Autowired
  33. ShowScatterService showScatterService;
  34. public RepEntity getChartsInDash(ChartsToDashInfo chartsToDashInfo, String token) throws SQLException {
  35. int chartId = chartsToDashInfo.getDashCreateId();
  36. ChartsConfigToDash chartsConfigToDash = chartsConfigMapper.getChartConfigToDash(chartId);
  37. if (chartsConfigToDash == null || "".equals(chartsConfigToDash)){
  38. return new RepEntity(RepCode.Null);
  39. }
  40. String chartType = chartsConfigToDash.getChartType();
  41. String fetchConfig = chartsConfigToDash.getFetchConfig();
  42. List<Screen> filters = chartsToDashInfo.getFilters();
  43. if ("Pie".equals(chartType)){
  44. return getPie(fetchConfig, token, filters);
  45. }else if ("Histogram".equals(chartType)){
  46. return getHistogram(fetchConfig, token, filters);
  47. }else if ("Line".equals(chartType)){
  48. return getLine(fetchConfig, token, filters);
  49. }else if ("population".equals(chartType)){
  50. return getPopulation(fetchConfig, token, filters);
  51. }else if ("individual".equals(chartType)){
  52. getIndividual(fetchConfig, token, filters);
  53. }else if("scatter".equals(chartType)){
  54. return getScatter(fetchConfig, token, filters);
  55. }
  56. return new RepEntity(RepCode.success);
  57. }
  58. public RepEntity getHistogram(String fetchConfig, String token, List<Screen> filters){
  59. HistogramConfigInfo histogramConfigInfo = new HistogramConfigInfo();
  60. try {
  61. histogramConfigInfo = objectMapper.readValue(fetchConfig,HistogramConfigInfo.class);
  62. histogramConfigInfo.setFilters(filters);
  63. } catch (Exception e) {
  64. e.printStackTrace();
  65. }
  66. return showHistogramService.showHistogram(histogramConfigInfo, token);
  67. }
  68. public RepEntity getScatter(String fetchConfig, String token, List<Screen> filters){
  69. ScatterConfigInfo scatterConfigInfo = new ScatterConfigInfo();
  70. try {
  71. System.out.println(fetchConfig);
  72. scatterConfigInfo = objectMapper.readValue(fetchConfig,ScatterConfigInfo.class);
  73. scatterConfigInfo.setFilters(filters);
  74. } catch (Exception e) {
  75. e.printStackTrace();
  76. }
  77. return showScatterService.showScatter(scatterConfigInfo, token);
  78. }
  79. public RepEntity getLine(String fetchConfig, String token, List<Screen> filters){
  80. LineConfigInfo lineConfigInfo = new LineConfigInfo();
  81. try {
  82. System.out.println(fetchConfig);
  83. lineConfigInfo = objectMapper.readValue(fetchConfig,LineConfigInfo.class);
  84. lineConfigInfo.setFilters(filters);
  85. } catch (Exception e) {
  86. e.printStackTrace();
  87. }
  88. return showLineService.showLine(lineConfigInfo, token);
  89. }
  90. public RepEntity getPopulation(String fetchConfig, String token, List<Screen> filters) throws SQLException {
  91. PopulationInfo populationInfo = new PopulationInfo();
  92. try {
  93. System.out.println(fetchConfig);
  94. populationInfo = objectMapper.readValue(fetchConfig,PopulationInfo.class);
  95. populationInfo.setFilters(filters);
  96. } catch (Exception e) {
  97. e.printStackTrace();
  98. }
  99. return showPopulationService.showPopulation(populationInfo, token);
  100. }
  101. public RepEntity getIndividual(String fetchConfig, String token, List<Screen> filters) throws SQLException {
  102. IndividualConfigInfo individualConfigInfo = new IndividualConfigInfo();
  103. try {
  104. System.out.println(fetchConfig);
  105. individualConfigInfo = objectMapper.readValue(fetchConfig,IndividualConfigInfo.class);
  106. individualConfigInfo.setFilters(filters);
  107. } catch (Exception e) {
  108. e.printStackTrace();
  109. }
  110. return showIndividualService.showIndividual(individualConfigInfo, token);
  111. }
  112. public RepEntity getPie(String fetchConfig, String token, List<Screen> filters){
  113. PieConfigInfo pieConfigInfo = new PieConfigInfo();
  114. try {
  115. System.out.println(fetchConfig);
  116. pieConfigInfo = objectMapper.readValue(fetchConfig,PieConfigInfo.class);
  117. pieConfigInfo.setFilters(filters);
  118. } catch (Exception e) {
  119. e.printStackTrace();
  120. }
  121. return showPieService.showPie(pieConfigInfo, token);
  122. }
  123. }