package com.server; import com.dao.ChartsConfigMapper; import com.fasterxml.jackson.databind.ObjectMapper; import com.model.bo.Screen; import com.model.po.ChartsConfigToDash; import com.model.pojo.RepCode; import com.model.pojo.RepEntity; import com.model.vo.configVo.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.sql.SQLException; import java.util.List; /* 看板中调用生成图表 */ @Service public class DashboardsToChartsUtilService { @Autowired ChartsConfigMapper chartsConfigMapper; @Autowired ObjectMapper objectMapper; @Autowired ShowHistogramService showHistogramService; @Autowired ShowIndividualService showIndividualService; @Autowired ShowLineService showLineService; @Autowired ShowPieService showPieService; @Autowired ShowPopulationService showPopulationService; @Autowired ShowScatterService showScatterService; public RepEntity getChartsInDash(ChartsToDashInfo chartsToDashInfo, String token) throws SQLException { int chartId = chartsToDashInfo.getDashCreateId(); ChartsConfigToDash chartsConfigToDash = chartsConfigMapper.getChartConfigToDash(chartId); if (chartsConfigToDash == null || "".equals(chartsConfigToDash)){ return new RepEntity(RepCode.Null); } String chartType = chartsConfigToDash.getChartType(); String fetchConfig = chartsConfigToDash.getFetchConfig(); List filters = chartsToDashInfo.getFilters(); if ("Pie".equals(chartType)){ return getPie(fetchConfig, token, filters); }else if ("Histogram".equals(chartType)){ return getHistogram(fetchConfig, token, filters); }else if ("Line".equals(chartType)){ return getLine(fetchConfig, token, filters); }else if ("population".equals(chartType)){ return getPopulation(fetchConfig, token, filters); }else if ("individual".equals(chartType)){ getIndividual(fetchConfig, token, filters); }else if("scatter".equals(chartType)){ return getScatter(fetchConfig, token, filters); } return new RepEntity(RepCode.success); } public RepEntity getHistogram(String fetchConfig, String token, List filters){ HistogramConfigInfo histogramConfigInfo = new HistogramConfigInfo(); try { histogramConfigInfo = objectMapper.readValue(fetchConfig,HistogramConfigInfo.class); histogramConfigInfo.setFilters(filters); } catch (Exception e) { e.printStackTrace(); } return showHistogramService.showHistogram(histogramConfigInfo, token); } public RepEntity getScatter(String fetchConfig, String token, List filters){ ScatterConfigInfo scatterConfigInfo = new ScatterConfigInfo(); try { System.out.println(fetchConfig); scatterConfigInfo = objectMapper.readValue(fetchConfig,ScatterConfigInfo.class); scatterConfigInfo.setFilters(filters); } catch (Exception e) { e.printStackTrace(); } return showScatterService.showScatter(scatterConfigInfo, token); } public RepEntity getLine(String fetchConfig, String token, List filters){ LineConfigInfo lineConfigInfo = new LineConfigInfo(); try { System.out.println(fetchConfig); lineConfigInfo = objectMapper.readValue(fetchConfig,LineConfigInfo.class); lineConfigInfo.setFilters(filters); } catch (Exception e) { e.printStackTrace(); } return showLineService.showLine(lineConfigInfo, token); } public RepEntity getPopulation(String fetchConfig, String token, List filters) throws SQLException { PopulationInfo populationInfo = new PopulationInfo(); try { System.out.println(fetchConfig); populationInfo = objectMapper.readValue(fetchConfig,PopulationInfo.class); populationInfo.setFilters(filters); } catch (Exception e) { e.printStackTrace(); } return showPopulationService.showPopulation(populationInfo, token); } public RepEntity getIndividual(String fetchConfig, String token, List filters) throws SQLException { IndividualConfigInfo individualConfigInfo = new IndividualConfigInfo(); try { System.out.println(fetchConfig); individualConfigInfo = objectMapper.readValue(fetchConfig,IndividualConfigInfo.class); individualConfigInfo.setFilters(filters); } catch (Exception e) { e.printStackTrace(); } return showIndividualService.showIndividual(individualConfigInfo, token); } public RepEntity getPie(String fetchConfig, String token, List filters){ PieConfigInfo pieConfigInfo = new PieConfigInfo(); try { System.out.println(fetchConfig); pieConfigInfo = objectMapper.readValue(fetchConfig,PieConfigInfo.class); pieConfigInfo.setFilters(filters); } catch (Exception e) { e.printStackTrace(); } return showPieService.showPie(pieConfigInfo, token); } }