Rev 263 | Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 261 | espaco | 1 | package br.com.ec.domain.service.impl; |
| 2 | |||
| 3 | import java.util.ArrayList; |
||
| 4 | import java.util.Arrays; |
||
| 5 | import java.util.Calendar; |
||
| 6 | import java.util.List; |
||
| 7 | |||
| 8 | import org.primefaces.model.charts.ChartData; |
||
| 9 | import org.primefaces.model.charts.axes.cartesian.CartesianScales; |
||
| 10 | import org.primefaces.model.charts.axes.cartesian.linear.CartesianLinearAxes; |
||
| 11 | import org.primefaces.model.charts.axes.cartesian.linear.CartesianLinearTicks; |
||
| 12 | import org.primefaces.model.charts.bar.BarChartDataSet; |
||
| 13 | import org.primefaces.model.charts.bar.BarChartModel; |
||
| 14 | import org.primefaces.model.charts.bar.BarChartOptions; |
||
| 15 | import org.primefaces.model.charts.optionconfig.animation.Animation; |
||
| 16 | import org.primefaces.model.charts.optionconfig.legend.Legend; |
||
| 17 | import org.primefaces.model.charts.optionconfig.legend.LegendLabel; |
||
| 18 | import org.primefaces.model.charts.optionconfig.title.Title; |
||
| 19 | import org.springframework.beans.factory.annotation.Autowired; |
||
| 20 | import org.springframework.stereotype.Service; |
||
| 21 | |||
| 22 | import br.com.ec.core.generic.AbstractService; |
||
| 23 | import br.com.ec.core.generic.GenericRepository; |
||
| 24 | import br.com.ec.core.util.DataUtils; |
||
| 25 | import br.com.ec.core.validador.Validador; |
||
| 26 | import br.com.ec.domain.dto.consulta.ParametrosConsultaVendasDTO; |
||
| 27 | import br.com.ec.domain.dto.grafico.GraficoBarraDTO; |
||
| 28 | import br.com.ec.domain.dto.grafico.GraficoDTO; |
||
| 29 | import br.com.ec.domain.service.GraficoService; |
||
| 30 | import br.com.ec.domain.service.VendaService; |
||
| 31 | |||
| 32 | @Service |
||
| 33 | public class GraficoServiceImpl extends AbstractService<GraficoDTO> implements GraficoService { |
||
| 34 | |||
| 35 | // private DashboardRepository dashboardRepository; |
||
| 36 | |||
| 37 | private VendaService vendaService; |
||
| 38 | |||
| 39 | @Autowired |
||
| 40 | public GraficoServiceImpl(Validador validador, VendaService vendaService/*, DashboardRepository dashboardRepository*/) { |
||
| 41 | super(validador); |
||
| 42 | this.vendaService = vendaService; |
||
| 43 | // this.dashboardRepository = dashboardRepository; |
||
| 44 | } |
||
| 45 | |||
| 46 | @Override |
||
| 47 | protected GenericRepository<GraficoDTO> getRepository() { |
||
| 48 | // return dashboardRepository; |
||
| 49 | return null; |
||
| 50 | } |
||
| 51 | |||
| 52 | @Override |
||
| 53 | public GraficoBarraDTO gerarGraficoVendas(ParametrosConsultaVendasDTO parametrosConsulta) { |
||
| 54 | GraficoBarraDTO graficoLinhaDTO = new GraficoBarraDTO(); |
||
| 55 | BarChartModel graficoBarra = new BarChartModel(); |
||
| 56 | ChartData data = new ChartData(); |
||
| 57 | BarChartDataSet barDataSet = new BarChartDataSet(); |
||
| 58 | barDataSet.setLabel(""); |
||
| 59 | |||
| 60 | List<Number> valores = new ArrayList<>(); |
||
| 61 | List<String> cores = new ArrayList<>(); |
||
| 62 | List<String> bordas = new ArrayList<>(); |
||
| 63 | List<String> marcadores = new ArrayList<>(); |
||
| 64 | for (int mes = 1; mes <= 12; mes++) { |
||
| 65 | Double valorAcumulado = new Double(0.0); |
||
| 66 | Calendar dataInicial = DataUtils.obterCalendario(DataUtils.obterData(1, new Integer(mes)-1, new Integer(parametrosConsulta.getParametrosPeriodoDTO().getAno()))); |
||
| 67 | int qntMaximaDias = dataInicial.getActualMaximum(Calendar.DAY_OF_MONTH); |
||
| 68 | Calendar dataFinal = DataUtils.obterCalendario(DataUtils.obterData(qntMaximaDias, new Integer(mes)-1, new Integer(parametrosConsulta.getParametrosPeriodoDTO().getAno()))); |
||
| 69 | parametrosConsulta.getParametrosPeriodoDTO().setDataInicial(dataInicial.getTime()); |
||
| 70 | parametrosConsulta.getParametrosPeriodoDTO().setDataFinal(dataFinal.getTime()); |
||
| 71 | valorAcumulado = vendaService.obterValorTotalBrutoDeVendasPorLojaEePeriodoEeFormasDePagamento( |
||
| 72 | parametrosConsulta, null/* Arrays.asList(parametrosConsulta.getFormasDePagamentoDTO()) */); |
||
| 73 | valores.add(valorAcumulado); |
||
| 74 | cores.add("rgba(75, 192, 192, 0.2)"); |
||
| 75 | bordas.add("rgb(75, 192, 192)"); |
||
| 76 | marcadores.add("" + mes); |
||
| 77 | } |
||
| 78 | barDataSet.setData(valores); |
||
| 79 | barDataSet.setBackgroundColor(cores); |
||
| 80 | barDataSet.setBorderColor(bordas); |
||
| 81 | barDataSet.setBorderWidth(1); |
||
| 82 | data.addChartDataSet(barDataSet); |
||
| 83 | data.setLabels(marcadores); |
||
| 84 | graficoBarra.setData(data); |
||
| 85 | |||
| 86 | //Options |
||
| 87 | BarChartOptions options = new BarChartOptions(); |
||
| 88 | CartesianScales cScales = new CartesianScales(); |
||
| 89 | CartesianLinearAxes linearAxes = new CartesianLinearAxes(); |
||
| 90 | linearAxes.setOffset(true); |
||
| 91 | CartesianLinearTicks ticks = new CartesianLinearTicks(); |
||
| 92 | ticks.setBeginAtZero(true); |
||
| 93 | linearAxes.setTicks(ticks); |
||
| 94 | cScales.setDisplay(true); |
||
| 95 | cScales.addYAxesData(linearAxes); |
||
| 96 | options.setScales(cScales); |
||
| 97 | |||
| 98 | Title title = new Title(); |
||
| 99 | title.setText("VENDAS"); |
||
| 100 | options.setTitle(title); |
||
| 101 | |||
| 102 | Legend legend = new Legend(); |
||
| 103 | legend.setDisplay(true); |
||
| 104 | legend.setPosition("top"); |
||
| 105 | LegendLabel legendLabels = new LegendLabel(); |
||
| 106 | legendLabels.setFontStyle("bold"); |
||
| 107 | legendLabels.setFontColor("#2980B9"); |
||
| 108 | legendLabels.setFontSize(24); |
||
| 109 | legend.setLabels(legendLabels); |
||
| 110 | options.setLegend(legend); |
||
| 111 | |||
| 112 | // disable animation |
||
| 113 | Animation animation = new Animation(); |
||
| 114 | animation.setDuration(0); |
||
| 115 | options.setAnimation(animation); |
||
| 116 | |||
| 117 | graficoBarra.setOptions(options); |
||
| 118 | |||
| 119 | graficoLinhaDTO.setGraficoBarra(graficoBarra); |
||
| 120 | return graficoLinhaDTO; |
||
| 121 | } |
||
| 122 | |||
| 123 | } |