Rev 585 | Rev 587 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 582 | blopes | 1 | package br.com.ec.domain.service.impl; |
| 2 | |||
| 3 | import java.util.ArrayList; |
||
| 4 | import java.util.List; |
||
| 5 | |||
| 6 | import org.springframework.stereotype.Service; |
||
| 7 | |||
| 8 | import br.com.ec.core.generic.AbstractService; |
||
| 9 | import br.com.ec.core.generic.GenericRepository; |
||
| 10 | import br.com.ec.core.util.DataUtils; |
||
| 11 | import br.com.ec.core.util.VerificadorUtil; |
||
| 12 | import br.com.ec.core.validador.Validador; |
||
| 583 | blopes | 13 | import br.com.ec.domain.dto.AlertasComprasGeralDTO; |
| 584 | blopes | 14 | import br.com.ec.domain.dto.AlertasComprasGeralSubTipoDTO; |
| 582 | blopes | 15 | import br.com.ec.domain.dto.AlertasGeralDTO; |
| 16 | import br.com.ec.domain.dto.RankingModeloDTO; |
||
| 17 | import br.com.ec.domain.dto.RankingProdutoDTO; |
||
| 18 | import br.com.ec.domain.dto.consulta.ParametrosConsultaModelosMaisVendidosDTO; |
||
| 19 | import br.com.ec.domain.dto.consulta.ParametrosConsultaProdutosVendidosDTO; |
||
| 20 | import br.com.ec.domain.model.SubtipoProduto; |
||
| 583 | blopes | 21 | import br.com.ec.domain.model.tipos.TipoOrdenacaoMaisVendidos; |
| 582 | blopes | 22 | import br.com.ec.domain.model.tipos.TipoProduto; |
| 23 | import br.com.ec.domain.service.AlertasService; |
||
| 24 | import br.com.ec.domain.service.LojaService; |
||
| 25 | import br.com.ec.domain.service.ModeloService; |
||
| 26 | import br.com.ec.domain.service.SubtipoProdutoService; |
||
| 27 | import br.com.ec.domain.service.VendaService; |
||
| 28 | |||
| 29 | @Service |
||
| 30 | public class AlertasServiceImpl extends AbstractService<AlertasGeralDTO> implements AlertasService { |
||
| 31 | |||
| 32 | private LojaService lojaService; |
||
| 33 | private ModeloService modeloService; |
||
| 34 | |||
| 35 | private SubtipoProdutoService subtipoProdutoService; |
||
| 36 | private VendaService vendaService; |
||
| 37 | |||
| 38 | public AlertasServiceImpl(Validador validador, LojaService lojaService, ModeloService modeloService, SubtipoProdutoService subtipoProdutoService, |
||
| 39 | VendaService vendaService) { |
||
| 40 | super(validador); |
||
| 41 | this.lojaService = lojaService; |
||
| 42 | this.modeloService = modeloService; |
||
| 43 | this.subtipoProdutoService = subtipoProdutoService; |
||
| 44 | this.vendaService = vendaService; |
||
| 45 | } |
||
| 46 | |||
| 47 | @Override |
||
| 48 | protected GenericRepository<AlertasGeralDTO> getRepository() { |
||
| 49 | return null; |
||
| 50 | } |
||
| 51 | |||
| 52 | @Override |
||
| 53 | public AlertasGeralDTO consultarAlertasComprasGeral(AlertasGeralDTO alertasGeralDTO) { |
||
| 54 | // CONSULTAR TODOS OS PRODUTOS VENDIDOS NOS ULTIMOS 90 DIAS |
||
| 55 | List<RankingProdutoDTO> rankingProdutosDTO = new ArrayList<RankingProdutoDTO>(); |
||
| 56 | |||
| 57 | ParametrosConsultaProdutosVendidosDTO parametrosConsulta = new ParametrosConsultaProdutosVendidosDTO(); |
||
| 58 | parametrosConsulta.setDataFinal(DataUtils.getDataAtual()); |
||
| 59 | parametrosConsulta.setDataInicial(DataUtils.acrescentarDias(DataUtils.getDataAtual(), alertasGeralDTO.getQuantidadeDiasVendas()*-1)); |
||
| 583 | blopes | 60 | parametrosConsulta.setTipoOrdenacao(TipoOrdenacaoMaisVendidos.QUANTIDADE.getValor()); |
| 582 | blopes | 61 | |
| 62 | for (TipoProduto tipoProdutoSelecionado : alertasGeralDTO.getTiposProdutoSelecionados()) { |
||
| 63 | parametrosConsulta.setTipoProduto(tipoProdutoSelecionado.getValor()); |
||
| 64 | rankingProdutosDTO.addAll(vendaService.consultarProdutosVendidos(parametrosConsulta)); |
||
| 65 | } |
||
| 66 | |||
| 585 | blopes | 67 | // RETIRAR SUBTIPOS DAS PELÍCULAS (PARA ANÁLISE INDIVIDUAL) |
| 586 | blopes | 68 | /* |
| 582 | blopes | 69 | for (RankingProdutoDTO rankingProdutoDTO : rankingProdutosDTO) { |
| 585 | blopes | 70 | if (rankingProdutoDTO.getProduto().getTipo().equals(TipoProduto.PELICULA.getValor())) { |
| 71 | rankingProdutoDTO.getProduto().setSubtipoProduto(null); |
||
| 582 | blopes | 72 | } |
| 586 | blopes | 73 | }*/ |
| 582 | blopes | 74 | |
| 583 | blopes | 75 | // CONSULTAR SUBTIPOS |
| 582 | blopes | 76 | // VERIFICAR ITENS POR TIPO, SEM SUBTIPO |
| 583 | blopes | 77 | for (TipoProduto tipoProdutoSelecionado : alertasGeralDTO.getTiposProdutoSelecionados()) { |
| 586 | blopes | 78 | Integer quantidadeAlertasPossiveisSemSubtipo = 0; |
| 79 | Integer quantidadeAlertasPossiveisComSubtipo = 0; |
||
| 583 | blopes | 80 | AlertasComprasGeralDTO alertasComprasGeralDTO = new AlertasComprasGeralDTO(); |
| 81 | alertasComprasGeralDTO.setTipoProduto(tipoProdutoSelecionado); |
||
| 82 | |||
| 83 | List<SubtipoProduto> subtiposProduto = subtipoProdutoService.consultarPorTipo(tipoProdutoSelecionado.getValor()); |
||
| 84 | List<RankingProdutoDTO> rankingProdutosDTOComSubtipo = new ArrayList<RankingProdutoDTO>(); |
||
| 85 | for (RankingProdutoDTO rankingProdutoDTO : rankingProdutosDTO) { |
||
| 86 | if (rankingProdutoDTO.getProduto().getTipo().equals(tipoProdutoSelecionado.getValor())) { |
||
| 87 | if (VerificadorUtil.estaNulo(rankingProdutoDTO.getProduto().getSubtipoProduto())) { |
||
| 584 | blopes | 88 | quantidadeAlertasPossiveisSemSubtipo++; |
| 89 | // ALERTA PARA CADA PRODUTO COM MENOS DE DIAS PRE-DEFINIDO |
||
| 583 | blopes | 90 | if (rankingProdutoDTO.getTempoEstoque() <= alertasGeralDTO.getTempoDeEstoqueParaAlerta()) { |
| 91 | alertasComprasGeralDTO.getAlertasProdutosSemSubtipo().add(rankingProdutoDTO); |
||
| 92 | } |
||
| 93 | } else { |
||
| 586 | blopes | 94 | if (tipoProdutoSelecionado.getValor().equals(TipoProduto.PELICULA.getValor())) { |
| 95 | quantidadeAlertasPossiveisSemSubtipo++; |
||
| 96 | } |
||
| 583 | blopes | 97 | rankingProdutosDTOComSubtipo.add(rankingProdutoDTO); |
| 98 | } |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | for (SubtipoProduto subtipoProduto : subtiposProduto) { |
||
| 586 | blopes | 103 | if (!tipoProdutoSelecionado.getValor().equals(TipoProduto.PELICULA.getValor())) { |
| 104 | quantidadeAlertasPossiveisComSubtipo++; |
||
| 105 | } |
||
| 584 | blopes | 106 | AlertasComprasGeralSubTipoDTO alertasComprasGeralSubTipoDTO = new AlertasComprasGeralSubTipoDTO(); |
| 107 | alertasComprasGeralSubTipoDTO.setSubtipoProduto(subtipoProduto); |
||
| 583 | blopes | 108 | for (RankingProdutoDTO rankingProdutoDTOComSubtipo : rankingProdutosDTOComSubtipo) { |
| 586 | blopes | 109 | if ((!tipoProdutoSelecionado.getValor().equals(TipoProduto.PELICULA.getValor()) && |
| 110 | subtipoProduto.equals(rankingProdutoDTOComSubtipo.getProduto().getSubtipoProduto())) || |
||
| 111 | (tipoProdutoSelecionado.getValor().equals(TipoProduto.PELICULA.getValor()) && |
||
| 112 | subtipoProduto.equals(rankingProdutoDTOComSubtipo.getProduto().getSubtipoProduto()) && |
||
| 113 | rankingProdutoDTOComSubtipo.getTempoEstoque() <= alertasGeralDTO.getTempoDeEstoqueParaAlerta())) { |
||
| 584 | blopes | 114 | alertasComprasGeralSubTipoDTO.getRankingProdutosDTO().add(rankingProdutoDTOComSubtipo); |
| 583 | blopes | 115 | } |
| 116 | } |
||
| 584 | blopes | 117 | if (!alertasComprasGeralSubTipoDTO.getRankingProdutosDTO().isEmpty() && |
| 586 | blopes | 118 | (tipoProdutoSelecionado.getValor().equals(TipoProduto.PELICULA.getValor()) || |
| 119 | alertasComprasGeralSubTipoDTO.getQuantidadeTotalTempoEstoque() <= alertasGeralDTO.getTempoDeEstoqueParaAlerta())) { |
||
| 584 | blopes | 120 | alertasComprasGeralDTO.getAlertasComprasGeralSubTipoDTO().add(alertasComprasGeralSubTipoDTO); |
| 121 | } |
||
| 583 | blopes | 122 | } |
| 584 | blopes | 123 | alertasComprasGeralDTO.setQuantidadeAlertasPossiveis(quantidadeAlertasPossiveisSemSubtipo); |
| 124 | alertasComprasGeralDTO.setQuantidadeAlertasPossiveisComSubtipo(quantidadeAlertasPossiveisComSubtipo); |
||
| 583 | blopes | 125 | alertasGeralDTO.getAlertasComprasGeralDTO().add(alertasComprasGeralDTO); |
| 126 | } |
||
| 582 | blopes | 127 | |
| 128 | // CONSULTAR ITENS SEM SUBTIPO: TOTAL DE VENDAS (90 DIAS), TOTAL DE ESTOQUE, TEMPO DE ESTOQUE E QNT PARA COMPRAR (90 DIAS) |
||
| 129 | /* |
||
| 130 | List<SubtipoProduto> subtiposProduto = new ArrayList<SubtipoProduto>(); |
||
| 131 | for (TipoProduto tipoProduto : tiposProduto) { |
||
| 132 | if (!tipoProduto.getValor().equals(TipoProduto.CAPA.getValor())) { |
||
| 133 | subtiposProduto.addAll(subtipoProdutoService.consultarPorTipo(tipoProduto.getValor())); |
||
| 134 | } |
||
| 135 | } |
||
| 136 | */ |
||
| 137 | |||
| 583 | blopes | 138 | |
| 582 | blopes | 139 | // LISTA DE TODOS OS SUBTIPOS DO TIPO |
| 140 | // CONSULTAR ITENS DO SUBTIPO: TOTAL DE VENDAS (90 DIAS), TOTAL DE ESTOQUE, TEMPO DE ESTOQUE E QNT PARA COMPRAR (90 DIAS) |
||
| 141 | // ALERTA PARA CADA SUBTIPO COM MENOS DE 15 DIAS DE ESTOQUE |
||
| 142 | |||
| 143 | // PERMITIR DETALHAR A LISTA DOS ITENS DO SUBTIPO |
||
| 144 | |||
| 145 | return alertasGeralDTO; |
||
| 146 | } |
||
| 147 | |||
| 148 | private List<RankingModeloDTO> consultarModelosMaisVendidos(AlertasGeralDTO alertasGeralDTO) { |
||
| 149 | List<RankingModeloDTO> modelosMaisVendidos = new ArrayList<RankingModeloDTO>(); |
||
| 150 | ParametrosConsultaModelosMaisVendidosDTO parametrosConsulta = new ParametrosConsultaModelosMaisVendidosDTO(); |
||
| 151 | parametrosConsulta.setDataFinal(DataUtils.getDataAtual()); |
||
| 152 | parametrosConsulta.setDataInicial(DataUtils.acrescentarDias(DataUtils.getDataAtual(), alertasGeralDTO.getQuantidadeDiasVendas()*-1)); |
||
| 153 | modelosMaisVendidos.addAll(vendaService.consultarRankingModelos(parametrosConsulta, alertasGeralDTO.getAdicionarModelosFavoritosSemVendas())); |
||
| 154 | return modelosMaisVendidos; |
||
| 155 | } |
||
| 156 | |||
| 157 | } |