Rev 195 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 106 | espaco | 1 | package br.com.ec.domain.service.ponto.impl; |
| 2 | |||
| 3 | import java.util.Date; |
||
| 4 | import java.util.List; |
||
| 5 | |||
| 6 | import org.springframework.beans.factory.annotation.Autowired; |
||
| 7 | import org.springframework.stereotype.Service; |
||
| 8 | |||
| 195 | espaco | 9 | import br.com.ec.core.exception.NegocioException; |
| 10 | import br.com.ec.core.generic.AbstractService; |
||
| 11 | import br.com.ec.core.generic.GenericRepository; |
||
| 12 | import br.com.ec.core.util.DataUtils; |
||
| 13 | import br.com.ec.core.util.VerificadorUtil; |
||
| 14 | import br.com.ec.core.validador.Validador; |
||
| 580 | blopes | 15 | import br.com.ec.domain.model.AberturaLoja; |
| 106 | espaco | 16 | import br.com.ec.domain.model.Loja; |
| 17 | import br.com.ec.domain.model.Ponto; |
||
| 18 | import br.com.ec.domain.model.Usuario; |
||
| 580 | blopes | 19 | import br.com.ec.domain.service.aberturaloja.AberturaLojaService; |
| 106 | espaco | 20 | import br.com.ec.domain.service.loja.LojaService; |
| 21 | import br.com.ec.domain.service.ponto.PontoService; |
||
| 22 | import br.com.ec.domain.service.usuario.UsuarioService; |
||
| 23 | import br.com.ec.infrastructure.repository.PontoRepository; |
||
| 24 | |||
| 25 | @Service |
||
| 26 | public class PontoServiceImpl extends AbstractService<Ponto> implements PontoService { |
||
| 27 | |||
| 28 | private UsuarioService usuarioService; |
||
| 29 | private LojaService lojaService; |
||
| 580 | blopes | 30 | private AberturaLojaService aberturaLojaService; |
| 106 | espaco | 31 | |
| 32 | private PontoRepository pontoRepository; |
||
| 33 | |||
| 34 | @Autowired |
||
| 580 | blopes | 35 | public PontoServiceImpl(Validador validador, UsuarioService usuarioService, AberturaLojaService aberturaLojaService, |
| 36 | LojaService lojaService, PontoRepository pontoRepository) { |
||
| 106 | espaco | 37 | super(validador); |
| 38 | this.usuarioService = usuarioService; |
||
| 39 | this.lojaService = lojaService; |
||
| 580 | blopes | 40 | this.aberturaLojaService = aberturaLojaService; |
| 41 | this.pontoRepository = pontoRepository; |
||
| 106 | espaco | 42 | } |
| 43 | |||
| 44 | @Override |
||
| 45 | protected GenericRepository<Ponto> getRepository() { |
||
| 46 | return pontoRepository; |
||
| 47 | } |
||
| 48 | |||
| 49 | @Override |
||
| 50 | public Ponto consultarPonto(Date dataAtual, String senhaUsuario, Long lojaSequencial) { |
||
| 51 | Ponto ponto = new Ponto(); |
||
| 52 | ponto.setDataPonto(DataUtils.getDataAtual()); |
||
| 53 | if (VerificadorUtil.naoEstaNulo(lojaSequencial)) { |
||
| 54 | Loja loja = new Loja(); |
||
| 55 | loja.setSequencial(lojaSequencial); |
||
| 56 | ponto.setLoja(lojaService.consultarPorId(loja)); |
||
| 580 | blopes | 57 | |
| 58 | AberturaLoja aberturaLoja = aberturaLojaService.consultarAberturaLoja(dataAtual, loja); |
||
| 59 | if (VerificadorUtil.estaNulo(aberturaLoja)) { |
||
| 60 | throw new NegocioException("ABERTURA DE LOJA PENDENTE"); |
||
| 61 | } |
||
| 106 | espaco | 62 | } |
| 63 | if (VerificadorUtil.estaNulo(ponto.getLoja())) { |
||
| 64 | throw new NegocioException("LOJA NÃO IDENTIFICADA"); |
||
| 65 | } |
||
| 66 | |||
| 580 | blopes | 67 | |
| 106 | espaco | 68 | Usuario usuarioConsultado = usuarioService.consultarUsuarioPorSenha(senhaUsuario); |
| 69 | if (VerificadorUtil.estaNulo(usuarioConsultado)) { |
||
| 70 | throw new NegocioException("USUÁRIO NÃO IDENTIFICADO"); |
||
| 71 | } |
||
| 72 | ponto.setPessoa(usuarioConsultado.getPessoa()); |
||
| 73 | |||
| 74 | List<Ponto> pontoConsultado = pontoRepository.consultarPassandoEntidade(ponto, 0, pontoRepository.obterQuantidadeDeRegistrosPassandoEntidade(ponto)); |
||
| 75 | if (pontoConsultado.isEmpty()) { |
||
| 76 | pontoConsultado.add(ponto); |
||
| 77 | } |
||
| 78 | return pontoConsultado.get(0); |
||
| 79 | } |
||
| 80 | |||
| 81 | /* |
||
| 82 | @Override |
||
| 83 | public void adicionarPonto(final Ponto ponto, final String senhaUsuario) { |
||
| 84 | if (VerificadorUtil.estaNulo(ponto.getCliente()) && |
||
| 85 | VerificadorUtil.estaNuloOuVazio(ponto.getContatoCliente())) { |
||
| 86 | throw new NegocioException("Informe o contato do cliente."); |
||
| 87 | } |
||
| 88 | if (VerificadorUtil.estaNulo(ponto.getProduto()) && |
||
| 89 | (VerificadorUtil.estaNulo(ponto.getModelo()) || |
||
| 90 | VerificadorUtil.estaNulo(ponto.getTipoProduto()) || |
||
| 91 | VerificadorUtil.estaNulo(ponto.getGenero()))) { |
||
| 92 | throw new NegocioException("Informe o produto ou o modelo, tipo e gênero do produto"); |
||
| 93 | } |
||
| 94 | if (VerificadorUtil.naoEstaNulo(ponto.getProduto())) { |
||
| 95 | ponto.setModelo(ponto.getProduto().getModelo()); |
||
| 96 | ponto.setTipoProduto(ponto.getProduto().getTipo()); |
||
| 97 | ponto.setGenero(ponto.getProduto().getGenero()); |
||
| 98 | ponto.setEstiloProduto(ponto.getProduto().getEstilo()); |
||
| 99 | ponto.setCorProduto(ponto.getProduto().getCor()); |
||
| 100 | } |
||
| 101 | ponto.setTipoSituacao(TipoSituacaoPonto.PENDENTE.getValor()); |
||
| 102 | ponto.setUsuarioPonto(usuarioService.consultarUsuarioPorSenha(senhaUsuario)); |
||
| 103 | ponto.setDataPonto(DataUtils.getDataAtual()); |
||
| 104 | cadastrar(ponto); |
||
| 105 | } |
||
| 106 | |||
| 107 | @Override |
||
| 108 | public List<RankingPontoDTO> consultarRankingPontosNaoAtendidos(String generoPontos) { |
||
| 109 | return pontoRepository.consultarRankingPontosNaoAtendidos(generoPontos); |
||
| 110 | } |
||
| 111 | |||
| 112 | @Override |
||
| 113 | public List<RankingPontoDTO> consultarRankingPontos(String generoPontos, Integer quantidadeDiasAnteriores) { |
||
| 114 | return pontoRepository.consultarRankingPontos(generoPontos, quantidadeDiasAnteriores); |
||
| 115 | } |
||
| 116 | */ |
||
| 117 | |||
| 118 | } |