Rev 638 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 623 | blopes | 1 | package br.com.ec.domain.service.impl; |
| 2 | |||
| 3 | import java.util.List; |
||
| 4 | |||
| 5 | import org.springframework.beans.factory.annotation.Autowired; |
||
| 6 | import org.springframework.stereotype.Service; |
||
| 7 | |||
| 630 | blopes | 8 | import br.com.ec.core.exception.NegocioException; |
| 623 | blopes | 9 | import br.com.ec.core.generic.AbstractService; |
| 10 | import br.com.ec.core.generic.GenericRepository; |
||
| 630 | blopes | 11 | import br.com.ec.core.util.DataUtils; |
| 12 | import br.com.ec.core.util.VerificadorUtil; |
||
| 623 | blopes | 13 | import br.com.ec.core.validador.Validador; |
| 630 | blopes | 14 | import br.com.ec.domain.dto.ComercialPosVendaDTO; |
| 15 | import br.com.ec.domain.dto.NpsPosVendaDTO; |
||
| 623 | blopes | 16 | import br.com.ec.domain.dto.PosVendaDTO; |
| 17 | import br.com.ec.domain.model.PosVenda; |
||
| 630 | blopes | 18 | import br.com.ec.domain.model.tipos.TipoNpsPosVenda; |
| 19 | import br.com.ec.domain.service.NpsPosVendaService; |
||
| 623 | blopes | 20 | import br.com.ec.domain.service.PosVendaService; |
| 631 | blopes | 21 | import br.com.ec.domain.service.VendaService; |
| 623 | blopes | 22 | import br.com.ec.repository.PosVendaRepository; |
| 636 | blopes | 23 | import br.com.ec.web.message.LancadorMensagem; |
| 24 | import br.com.ec.web.util.ConstantesWebHelper.Mensagem; |
||
| 623 | blopes | 25 | |
| 26 | @Service |
||
| 27 | public class PosVendaServiceImpl extends AbstractService<PosVenda> implements PosVendaService { |
||
| 630 | blopes | 28 | |
| 623 | blopes | 29 | private PosVendaRepository posVendaRepository; |
| 630 | blopes | 30 | private NpsPosVendaService npsPosVendaService; |
| 631 | blopes | 31 | private VendaService vendaService; |
| 623 | blopes | 32 | |
| 33 | @Autowired |
||
| 631 | blopes | 34 | public PosVendaServiceImpl(Validador validador, PosVendaRepository posVendaRepository, NpsPosVendaService npsPosVendaService, |
| 35 | VendaService vendaService) { |
||
| 623 | blopes | 36 | super(validador); |
| 37 | this.posVendaRepository = posVendaRepository; |
||
| 630 | blopes | 38 | this.npsPosVendaService = npsPosVendaService; |
| 631 | blopes | 39 | this.vendaService = vendaService; |
| 623 | blopes | 40 | } |
| 41 | |||
| 42 | @Override |
||
| 43 | protected GenericRepository<PosVenda> getRepository() { |
||
| 44 | return posVendaRepository; |
||
| 656 | blopes | 45 | } |
| 623 | blopes | 46 | |
| 47 | @Override |
||
| 630 | blopes | 48 | public ComercialPosVendaDTO consultarPosVendaEmAndamento() { |
| 49 | ComercialPosVendaDTO comercialPosVendaDTO = new ComercialPosVendaDTO(); |
||
| 50 | List<PosVendaDTO> listaPosVendaNaoFinalizadas = posVendaRepository.consultarNaoFinalizadas(); |
||
| 51 | for (PosVendaDTO posVendaNaoFinalizada : listaPosVendaNaoFinalizadas) { |
||
| 631 | blopes | 52 | if (VerificadorUtil.naoEstaNulo(posVendaNaoFinalizada.getSequencialDaVenda())) { |
| 53 | posVendaNaoFinalizada.setVendaDTO(vendaService.detalharPorSequencial(posVendaNaoFinalizada.getSequencialDaVenda())); |
||
| 54 | } |
||
| 630 | blopes | 55 | NpsPosVendaDTO npsPosVendaAgradecimento = npsPosVendaService.consultarPorPosVendaEeTipo(posVendaNaoFinalizada.getSequencial(), TipoNpsPosVenda.ATENDIMENTO_A.getValor()); |
| 56 | if (VerificadorUtil.naoEstaNulo(npsPosVendaAgradecimento)) { |
||
| 57 | if (VerificadorUtil.estaNulo(npsPosVendaAgradecimento.getDataFinalizacao())) { |
||
| 58 | posVendaNaoFinalizada.setNpsPosVendaAgradecimento(npsPosVendaAgradecimento); |
||
| 59 | comercialPosVendaDTO.getListaPosVendaAgradecimento().add(posVendaNaoFinalizada); |
||
| 60 | } |
||
| 631 | blopes | 61 | } else { |
| 62 | comercialPosVendaDTO.getListaPosVendaAgradecimento().add(posVendaNaoFinalizada); |
||
| 630 | blopes | 63 | } |
| 64 | posVendaNaoFinalizada.setNpsPosVendaAgradecimento(npsPosVendaService.consultarPorPosVendaEeTipo(posVendaNaoFinalizada.getSequencial(), TipoNpsPosVenda.ATENDIMENTO_A.getValor())); |
||
| 65 | } |
||
| 66 | comercialPosVendaDTO.setListaEmAndamento(listaPosVendaNaoFinalizadas); |
||
| 67 | return comercialPosVendaDTO; |
||
| 623 | blopes | 68 | } |
| 69 | |||
| 630 | blopes | 70 | @Override |
| 71 | public void iniciarAtendimento(PosVendaDTO posVendaDTO) { |
||
| 72 | try { |
||
| 73 | PosVenda posVendaParaAlterar = this.consultarPorId(new PosVenda(posVendaDTO.getSequencial())); |
||
| 74 | posVendaParaAlterar.setDataInicio(DataUtils.getDataAtual()); |
||
| 75 | posVendaParaAlterar.setObservacao(posVendaDTO.getObservacao()); |
||
| 76 | posVendaParaAlterar.setTipoFinalizacao(posVendaDTO.getTipoFinalizacao()); |
||
| 77 | this.alterar(posVendaParaAlterar); |
||
| 78 | } catch (Exception e) { |
||
| 79 | throw new NegocioException(e.getMessage()); |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 636 | blopes | 83 | @Override |
| 84 | public void finalizarAtendimento(PosVendaDTO posVendaDTO) { |
||
| 85 | try { |
||
| 86 | PosVenda posVendaParaFinalizar = this.consultarPorId(new PosVenda(posVendaDTO.getSequencial())); |
||
| 87 | if (VerificadorUtil.estaNulo(posVendaParaFinalizar.getDataInicio())) { |
||
| 88 | posVendaParaFinalizar.setDataInicio(DataUtils.getDataAtual()); |
||
| 89 | } |
||
| 90 | posVendaParaFinalizar.setDataFinalizacao(DataUtils.getDataAtual()); |
||
| 91 | posVendaParaFinalizar.setObservacao(posVendaDTO.getObservacao()); |
||
| 92 | if (VerificadorUtil.estaNulo(posVendaDTO.getTipoFinalizacao())) { |
||
| 93 | throw new NegocioException("OBRIGATÓRIO INFORMAR O TIPO DE FINALIZAÇÃO"); |
||
| 94 | } |
||
| 95 | posVendaParaFinalizar.setTipoFinalizacao(posVendaDTO.getTipoFinalizacao()); |
||
| 96 | this.alterar(posVendaParaFinalizar); |
||
| 97 | } catch (Exception e) { |
||
| 98 | throw new NegocioException(e.getMessage()); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 623 | blopes | 102 | } |