Rev 584 | Rev 586 | 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) |
| 582 | blopes | 68 | for (RankingProdutoDTO rankingProdutoDTO : rankingProdutosDTO) { |
| 585 | blopes | 69 | if (rankingProdutoDTO.getProduto().getTipo().equals(TipoProduto.PELICULA.getValor())) { |
| 70 | rankingProdutoDTO.getProduto().setSubtipoProduto(null); |
||
| 582 | blopes | 71 | } |
| 72 | } |
||
| 73 | |||
| 583 | blopes | 74 | // CONSULTAR SUBTIPOS |
| 582 | blopes | 75 | // VERIFICAR ITENS POR TIPO, SEM SUBTIPO |
| 584 | blopes | 76 | Integer quantidadeAlertasPossiveisSemSubtipo = 0; |
| 77 | Integer quantidadeAlertasPossiveisComSubtipo = 0; |
||
| 583 | blopes | 78 | for (TipoProduto tipoProdutoSelecionado : alertasGeralDTO.getTiposProdutoSelecionados()) { |
| 79 | AlertasComprasGeralDTO alertasComprasGeralDTO = new AlertasComprasGeralDTO(); |
||
| 80 | alertasComprasGeralDTO.setTipoProduto(tipoProdutoSelecionado); |
||
| 81 | |||
| 82 | List<SubtipoProduto> subtiposProduto = subtipoProdutoService.consultarPorTipo(tipoProdutoSelecionado.getValor()); |
||
| 83 | List<RankingProdutoDTO> rankingProdutosDTOComSubtipo = new ArrayList<RankingProdutoDTO>(); |
||
| 84 | for (RankingProdutoDTO rankingProdutoDTO : rankingProdutosDTO) { |
||
| 85 | if (rankingProdutoDTO.getProduto().getTipo().equals(tipoProdutoSelecionado.getValor())) { |
||
| 86 | if (VerificadorUtil.estaNulo(rankingProdutoDTO.getProduto().getSubtipoProduto())) { |
||
| 584 | blopes | 87 | quantidadeAlertasPossiveisSemSubtipo++; |
| 88 | // ALERTA PARA CADA PRODUTO COM MENOS DE DIAS PRE-DEFINIDO |
||
| 583 | blopes | 89 | if (rankingProdutoDTO.getTempoEstoque() <= alertasGeralDTO.getTempoDeEstoqueParaAlerta()) { |
| 90 | alertasComprasGeralDTO.getAlertasProdutosSemSubtipo().add(rankingProdutoDTO); |
||
| 91 | } |
||
| 92 | } else { |
||
| 93 | rankingProdutosDTOComSubtipo.add(rankingProdutoDTO); |
||
| 94 | } |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | for (SubtipoProduto subtipoProduto : subtiposProduto) { |
||
| 584 | blopes | 99 | quantidadeAlertasPossiveisComSubtipo++; |
| 100 | AlertasComprasGeralSubTipoDTO alertasComprasGeralSubTipoDTO = new AlertasComprasGeralSubTipoDTO(); |
||
| 101 | alertasComprasGeralSubTipoDTO.setSubtipoProduto(subtipoProduto); |
||
| 583 | blopes | 102 | for (RankingProdutoDTO rankingProdutoDTOComSubtipo : rankingProdutosDTOComSubtipo) { |
| 103 | if (subtipoProduto.equals(rankingProdutoDTOComSubtipo.getProduto().getSubtipoProduto())) { |
||
| 584 | blopes | 104 | alertasComprasGeralSubTipoDTO.getRankingProdutosDTO().add(rankingProdutoDTOComSubtipo); |
| 583 | blopes | 105 | } |
| 106 | } |
||
| 584 | blopes | 107 | if (!alertasComprasGeralSubTipoDTO.getRankingProdutosDTO().isEmpty() && |
| 108 | alertasComprasGeralSubTipoDTO.getQuantidadeTotalTempoEstoque() <= alertasGeralDTO.getTempoDeEstoqueParaAlerta()) { |
||
| 109 | alertasComprasGeralDTO.getAlertasComprasGeralSubTipoDTO().add(alertasComprasGeralSubTipoDTO); |
||
| 110 | } |
||
| 583 | blopes | 111 | } |
| 584 | blopes | 112 | alertasComprasGeralDTO.setQuantidadeAlertasPossiveis(quantidadeAlertasPossiveisSemSubtipo); |
| 113 | alertasComprasGeralDTO.setQuantidadeAlertasPossiveisComSubtipo(quantidadeAlertasPossiveisComSubtipo); |
||
| 583 | blopes | 114 | alertasGeralDTO.getAlertasComprasGeralDTO().add(alertasComprasGeralDTO); |
| 115 | } |
||
| 582 | blopes | 116 | |
| 117 | // CONSULTAR ITENS SEM SUBTIPO: TOTAL DE VENDAS (90 DIAS), TOTAL DE ESTOQUE, TEMPO DE ESTOQUE E QNT PARA COMPRAR (90 DIAS) |
||
| 118 | /* |
||
| 119 | List<SubtipoProduto> subtiposProduto = new ArrayList<SubtipoProduto>(); |
||
| 120 | for (TipoProduto tipoProduto : tiposProduto) { |
||
| 121 | if (!tipoProduto.getValor().equals(TipoProduto.CAPA.getValor())) { |
||
| 122 | subtiposProduto.addAll(subtipoProdutoService.consultarPorTipo(tipoProduto.getValor())); |
||
| 123 | } |
||
| 124 | } |
||
| 125 | */ |
||
| 126 | |||
| 583 | blopes | 127 | |
| 582 | blopes | 128 | // LISTA DE TODOS OS SUBTIPOS DO TIPO |
| 129 | // CONSULTAR ITENS DO SUBTIPO: TOTAL DE VENDAS (90 DIAS), TOTAL DE ESTOQUE, TEMPO DE ESTOQUE E QNT PARA COMPRAR (90 DIAS) |
||
| 130 | // ALERTA PARA CADA SUBTIPO COM MENOS DE 15 DIAS DE ESTOQUE |
||
| 131 | |||
| 132 | // PERMITIR DETALHAR A LISTA DOS ITENS DO SUBTIPO |
||
| 133 | |||
| 134 | return alertasGeralDTO; |
||
| 135 | } |
||
| 136 | |||
| 137 | private List<RankingModeloDTO> consultarModelosMaisVendidos(AlertasGeralDTO alertasGeralDTO) { |
||
| 138 | List<RankingModeloDTO> modelosMaisVendidos = new ArrayList<RankingModeloDTO>(); |
||
| 139 | ParametrosConsultaModelosMaisVendidosDTO parametrosConsulta = new ParametrosConsultaModelosMaisVendidosDTO(); |
||
| 140 | parametrosConsulta.setDataFinal(DataUtils.getDataAtual()); |
||
| 141 | parametrosConsulta.setDataInicial(DataUtils.acrescentarDias(DataUtils.getDataAtual(), alertasGeralDTO.getQuantidadeDiasVendas()*-1)); |
||
| 142 | modelosMaisVendidos.addAll(vendaService.consultarRankingModelos(parametrosConsulta, alertasGeralDTO.getAdicionarModelosFavoritosSemVendas())); |
||
| 143 | return modelosMaisVendidos; |
||
| 144 | } |
||
| 145 | |||
| 146 | } |