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