Rev 586 | Rev 588 | 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; |
| 587 | blopes | 23 | import br.com.ec.domain.model.tipos.TipoStatusPedidoCompra; |
| 582 | blopes | 24 | import br.com.ec.domain.service.AlertasService; |
| 25 | import br.com.ec.domain.service.LojaService; |
||
| 26 | import br.com.ec.domain.service.ModeloService; |
||
| 27 | import br.com.ec.domain.service.SubtipoProdutoService; |
||
| 28 | import br.com.ec.domain.service.VendaService; |
||
| 29 | |||
| 30 | @Service |
||
| 31 | public class AlertasServiceImpl extends AbstractService<AlertasGeralDTO> implements AlertasService { |
||
| 32 | |||
| 33 | private LojaService lojaService; |
||
| 34 | private ModeloService modeloService; |
||
| 35 | |||
| 36 | private SubtipoProdutoService subtipoProdutoService; |
||
| 37 | private VendaService vendaService; |
||
| 38 | |||
| 39 | public AlertasServiceImpl(Validador validador, LojaService lojaService, ModeloService modeloService, SubtipoProdutoService subtipoProdutoService, |
||
| 40 | VendaService vendaService) { |
||
| 41 | super(validador); |
||
| 42 | this.lojaService = lojaService; |
||
| 43 | this.modeloService = modeloService; |
||
| 44 | this.subtipoProdutoService = subtipoProdutoService; |
||
| 45 | this.vendaService = vendaService; |
||
| 46 | } |
||
| 47 | |||
| 48 | @Override |
||
| 49 | protected GenericRepository<AlertasGeralDTO> getRepository() { |
||
| 50 | return null; |
||
| 51 | } |
||
| 52 | |||
| 53 | @Override |
||
| 54 | public AlertasGeralDTO consultarAlertasComprasGeral(AlertasGeralDTO alertasGeralDTO) { |
||
| 587 | blopes | 55 | // ADICIONAR PRODUTOS ESSENCIAIS DOS 30 MODELOS MAIS VENDIDOS |
| 56 | // TIPO: CAPA, ESTILO: TPU, COR: TRANSPARENTE |
||
| 57 | // TIPO: PELÍCULA, SUBTIPO: VIDRO |
||
| 58 | // TIPO: PELÍCULA, SUBTIPO: SOFT NORMAL |
||
| 59 | |||
| 582 | blopes | 60 | // CONSULTAR TODOS OS PRODUTOS VENDIDOS NOS ULTIMOS 90 DIAS |
| 587 | blopes | 61 | List<RankingProdutoDTO> rankingProdutosDTOGeral = new ArrayList<RankingProdutoDTO>(); |
| 582 | blopes | 62 | List<RankingProdutoDTO> rankingProdutosDTO = new ArrayList<RankingProdutoDTO>(); |
| 63 | |||
| 64 | ParametrosConsultaProdutosVendidosDTO parametrosConsulta = new ParametrosConsultaProdutosVendidosDTO(); |
||
| 65 | parametrosConsulta.setDataFinal(DataUtils.getDataAtual()); |
||
| 66 | parametrosConsulta.setDataInicial(DataUtils.acrescentarDias(DataUtils.getDataAtual(), alertasGeralDTO.getQuantidadeDiasVendas()*-1)); |
||
| 583 | blopes | 67 | parametrosConsulta.setTipoOrdenacao(TipoOrdenacaoMaisVendidos.QUANTIDADE.getValor()); |
| 582 | blopes | 68 | |
| 69 | for (TipoProduto tipoProdutoSelecionado : alertasGeralDTO.getTiposProdutoSelecionados()) { |
||
| 70 | parametrosConsulta.setTipoProduto(tipoProdutoSelecionado.getValor()); |
||
| 587 | blopes | 71 | rankingProdutosDTOGeral.addAll(vendaService.consultarProdutosVendidos(parametrosConsulta)); |
| 582 | blopes | 72 | } |
| 73 | |||
| 587 | blopes | 74 | // RETIRAR PRODUTOS PARA NÃO COMPRAR |
| 75 | for (RankingProdutoDTO rankingProdutoDTO : rankingProdutosDTOGeral) { |
||
| 76 | if (VerificadorUtil.naoEstaNulo(rankingProdutoDTO.getStatusPedidoCompra())) { |
||
| 77 | if (!rankingProdutoDTO.getStatusPedidoCompra().equals(TipoStatusPedidoCompra.NAO_COMPRAR.getValor())) { |
||
| 78 | rankingProdutosDTO.add(rankingProdutoDTO); |
||
| 79 | } |
||
| 582 | blopes | 80 | } |
| 587 | blopes | 81 | } |
| 582 | blopes | 82 | |
| 583 | blopes | 83 | // CONSULTAR SUBTIPOS |
| 582 | blopes | 84 | // VERIFICAR ITENS POR TIPO, SEM SUBTIPO |
| 583 | blopes | 85 | for (TipoProduto tipoProdutoSelecionado : alertasGeralDTO.getTiposProdutoSelecionados()) { |
| 586 | blopes | 86 | Integer quantidadeAlertasPossiveisSemSubtipo = 0; |
| 87 | Integer quantidadeAlertasPossiveisComSubtipo = 0; |
||
| 583 | blopes | 88 | AlertasComprasGeralDTO alertasComprasGeralDTO = new AlertasComprasGeralDTO(); |
| 89 | alertasComprasGeralDTO.setTipoProduto(tipoProdutoSelecionado); |
||
| 90 | |||
| 91 | List<SubtipoProduto> subtiposProduto = subtipoProdutoService.consultarPorTipo(tipoProdutoSelecionado.getValor()); |
||
| 92 | List<RankingProdutoDTO> rankingProdutosDTOComSubtipo = new ArrayList<RankingProdutoDTO>(); |
||
| 93 | for (RankingProdutoDTO rankingProdutoDTO : rankingProdutosDTO) { |
||
| 94 | if (rankingProdutoDTO.getProduto().getTipo().equals(tipoProdutoSelecionado.getValor())) { |
||
| 95 | if (VerificadorUtil.estaNulo(rankingProdutoDTO.getProduto().getSubtipoProduto())) { |
||
| 584 | blopes | 96 | quantidadeAlertasPossiveisSemSubtipo++; |
| 97 | // ALERTA PARA CADA PRODUTO COM MENOS DE DIAS PRE-DEFINIDO |
||
| 583 | blopes | 98 | if (rankingProdutoDTO.getTempoEstoque() <= alertasGeralDTO.getTempoDeEstoqueParaAlerta()) { |
| 99 | alertasComprasGeralDTO.getAlertasProdutosSemSubtipo().add(rankingProdutoDTO); |
||
| 100 | } |
||
| 587 | blopes | 101 | if (rankingProdutoDTO.getTempoEstoque() <= alertasGeralDTO.getTempoDeEstoqueParaAlerta()/2) { |
| 102 | alertasComprasGeralDTO.adicionarQuantidadeAlertasCriticos(); |
||
| 103 | } |
||
| 583 | blopes | 104 | } else { |
| 586 | blopes | 105 | if (tipoProdutoSelecionado.getValor().equals(TipoProduto.PELICULA.getValor())) { |
| 106 | quantidadeAlertasPossiveisSemSubtipo++; |
||
| 107 | } |
||
| 583 | blopes | 108 | rankingProdutosDTOComSubtipo.add(rankingProdutoDTO); |
| 109 | } |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | for (SubtipoProduto subtipoProduto : subtiposProduto) { |
||
| 586 | blopes | 114 | if (!tipoProdutoSelecionado.getValor().equals(TipoProduto.PELICULA.getValor())) { |
| 115 | quantidadeAlertasPossiveisComSubtipo++; |
||
| 116 | } |
||
| 584 | blopes | 117 | AlertasComprasGeralSubTipoDTO alertasComprasGeralSubTipoDTO = new AlertasComprasGeralSubTipoDTO(); |
| 118 | alertasComprasGeralSubTipoDTO.setSubtipoProduto(subtipoProduto); |
||
| 583 | blopes | 119 | for (RankingProdutoDTO rankingProdutoDTOComSubtipo : rankingProdutosDTOComSubtipo) { |
| 586 | blopes | 120 | if ((!tipoProdutoSelecionado.getValor().equals(TipoProduto.PELICULA.getValor()) && |
| 121 | subtipoProduto.equals(rankingProdutoDTOComSubtipo.getProduto().getSubtipoProduto())) || |
||
| 122 | (tipoProdutoSelecionado.getValor().equals(TipoProduto.PELICULA.getValor()) && |
||
| 123 | subtipoProduto.equals(rankingProdutoDTOComSubtipo.getProduto().getSubtipoProduto()) && |
||
| 124 | rankingProdutoDTOComSubtipo.getTempoEstoque() <= alertasGeralDTO.getTempoDeEstoqueParaAlerta())) { |
||
| 584 | blopes | 125 | alertasComprasGeralSubTipoDTO.getRankingProdutosDTO().add(rankingProdutoDTOComSubtipo); |
| 583 | blopes | 126 | } |
| 127 | } |
||
| 584 | blopes | 128 | if (!alertasComprasGeralSubTipoDTO.getRankingProdutosDTO().isEmpty() && |
| 586 | blopes | 129 | (tipoProdutoSelecionado.getValor().equals(TipoProduto.PELICULA.getValor()) || |
| 130 | alertasComprasGeralSubTipoDTO.getQuantidadeTotalTempoEstoque() <= alertasGeralDTO.getTempoDeEstoqueParaAlerta())) { |
||
| 584 | blopes | 131 | alertasComprasGeralDTO.getAlertasComprasGeralSubTipoDTO().add(alertasComprasGeralSubTipoDTO); |
| 587 | blopes | 132 | if (alertasComprasGeralSubTipoDTO.getQuantidadeTotalTempoEstoque() <= alertasGeralDTO.getTempoDeEstoqueParaAlerta()/2) { |
| 133 | alertasComprasGeralDTO.adicionarQuantidadeAlertasCriticos(); |
||
| 134 | } |
||
| 584 | blopes | 135 | } |
| 583 | blopes | 136 | } |
| 584 | blopes | 137 | alertasComprasGeralDTO.setQuantidadeAlertasPossiveis(quantidadeAlertasPossiveisSemSubtipo); |
| 138 | alertasComprasGeralDTO.setQuantidadeAlertasPossiveisComSubtipo(quantidadeAlertasPossiveisComSubtipo); |
||
| 583 | blopes | 139 | alertasGeralDTO.getAlertasComprasGeralDTO().add(alertasComprasGeralDTO); |
| 140 | } |
||
| 582 | blopes | 141 | |
| 142 | // CONSULTAR ITENS SEM SUBTIPO: TOTAL DE VENDAS (90 DIAS), TOTAL DE ESTOQUE, TEMPO DE ESTOQUE E QNT PARA COMPRAR (90 DIAS) |
||
| 143 | /* |
||
| 144 | List<SubtipoProduto> subtiposProduto = new ArrayList<SubtipoProduto>(); |
||
| 145 | for (TipoProduto tipoProduto : tiposProduto) { |
||
| 146 | if (!tipoProduto.getValor().equals(TipoProduto.CAPA.getValor())) { |
||
| 147 | subtiposProduto.addAll(subtipoProdutoService.consultarPorTipo(tipoProduto.getValor())); |
||
| 148 | } |
||
| 149 | } |
||
| 150 | */ |
||
| 151 | |||
| 583 | blopes | 152 | |
| 582 | blopes | 153 | // LISTA DE TODOS OS SUBTIPOS DO TIPO |
| 154 | // CONSULTAR ITENS DO SUBTIPO: TOTAL DE VENDAS (90 DIAS), TOTAL DE ESTOQUE, TEMPO DE ESTOQUE E QNT PARA COMPRAR (90 DIAS) |
||
| 155 | // ALERTA PARA CADA SUBTIPO COM MENOS DE 15 DIAS DE ESTOQUE |
||
| 156 | |||
| 157 | // PERMITIR DETALHAR A LISTA DOS ITENS DO SUBTIPO |
||
| 158 | |||
| 159 | return alertasGeralDTO; |
||
| 160 | } |
||
| 161 | |||
| 162 | private List<RankingModeloDTO> consultarModelosMaisVendidos(AlertasGeralDTO alertasGeralDTO) { |
||
| 163 | List<RankingModeloDTO> modelosMaisVendidos = new ArrayList<RankingModeloDTO>(); |
||
| 164 | ParametrosConsultaModelosMaisVendidosDTO parametrosConsulta = new ParametrosConsultaModelosMaisVendidosDTO(); |
||
| 165 | parametrosConsulta.setDataFinal(DataUtils.getDataAtual()); |
||
| 166 | parametrosConsulta.setDataInicial(DataUtils.acrescentarDias(DataUtils.getDataAtual(), alertasGeralDTO.getQuantidadeDiasVendas()*-1)); |
||
| 167 | modelosMaisVendidos.addAll(vendaService.consultarRankingModelos(parametrosConsulta, alertasGeralDTO.getAdicionarModelosFavoritosSemVendas())); |
||
| 168 | return modelosMaisVendidos; |
||
| 169 | } |
||
| 170 | |||
| 171 | } |