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