Rev 686 | Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 685 | blopes | 1 | package br.com.ec.domain.service.cashback.impl; |
| 2 | |||
| 3 | import java.util.List; |
||
| 4 | |||
| 5 | import org.springframework.beans.factory.annotation.Autowired; |
||
| 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; |
||
| 13 | import br.com.ec.domain.dto.CashbackDTO; |
||
| 14 | import br.com.ec.domain.dto.ParametrosVendaDTO; |
||
| 15 | import br.com.ec.domain.model.Cashback; |
||
| 16 | import br.com.ec.domain.model.Lancamento; |
||
| 17 | import br.com.ec.domain.model.Venda; |
||
| 18 | import br.com.ec.domain.model.tipos.TipoCashback; |
||
| 19 | import br.com.ec.domain.service.cashback.CashbackService; |
||
| 20 | import br.com.ec.infrastructure.repository.CashbackRepository; |
||
| 21 | |||
| 22 | @Service |
||
| 23 | public class CashbackServiceImpl extends AbstractService<Cashback> implements CashbackService { |
||
| 24 | |||
| 25 | private CashbackRepository cashbackRepository; |
||
| 26 | |||
| 27 | @Autowired |
||
| 28 | public CashbackServiceImpl(Validador validador, CashbackRepository cashbackRepository) { |
||
| 29 | super(validador); |
||
| 30 | this.cashbackRepository = cashbackRepository; |
||
| 31 | } |
||
| 32 | |||
| 33 | @Override |
||
| 34 | protected GenericRepository<Cashback> getRepository() { |
||
| 35 | return cashbackRepository; |
||
| 36 | } |
||
| 37 | |||
| 38 | @Override |
||
| 39 | public List<CashbackDTO> consultarCashbackCliente(Long sequencialCliente) { |
||
| 40 | // TODO Auto-generated method stub |
||
| 41 | return null; |
||
| 42 | } |
||
| 43 | |||
| 44 | @Override |
||
| 45 | public Double consultarSaldoCliente(Long sequencialCliente, String tipoCashback) { |
||
| 46 | return cashbackRepository.consultarSaldoCliente(sequencialCliente, tipoCashback); |
||
| 47 | } |
||
| 48 | |||
| 49 | @Override |
||
| 50 | public void gerarCashback(ParametrosVendaDTO parametrosVendaDTO, Venda venda) { |
||
| 51 | // TODO: 10% capas e películas e 5% no geral (sem descontos ou cupons) |
||
| 52 | Double valorCashback = 0.0; |
||
| 53 | if (VerificadorUtil.naoEstaNulo(parametrosVendaDTO.getCliente())) { |
||
| 54 | if (VerificadorUtil.naoEstaNuloOuVazio(parametrosVendaDTO.getLancamentos())) { |
||
| 55 | for (Lancamento lancamento : parametrosVendaDTO.getLancamentos()) { |
||
| 56 | if (VerificadorUtil.naoEstaNulo(lancamento.getValorVenda()) && VerificadorUtil.naoEstaNulo(lancamento.getValorVarejo())) { |
||
| 57 | if (VerificadorUtil.estaNulo(lancamento.getCupom()) && lancamento.getValorVenda() >= lancamento.getValorVarejo()) { |
||
| 58 | if (lancamento.getProduto().tipoProdutoEhCapaOuPelicula()) { |
||
| 59 | valorCashback = valorCashback + lancamento.getValorVenda()/10; |
||
| 60 | } else { |
||
| 61 | valorCashback = valorCashback + lancamento.getValorVenda()/20; |
||
| 62 | } |
||
| 63 | } |
||
| 64 | } |
||
| 65 | } |
||
| 66 | } |
||
| 67 | if (valorCashback > 0.0) { |
||
| 68 | Cashback cashback = new Cashback(); |
||
| 69 | cashback.setCliente(parametrosVendaDTO.getCliente()); |
||
| 70 | cashback.setVenda(venda); |
||
| 71 | cashback.setDataHoraEmissao(DataUtils.getDataAtual()); |
||
| 72 | cashback.setPrazoInicial(DataUtils.acrescentarDias(DataUtils.getDataAtual(), 7)); |
||
| 73 | cashback.setPrazoFinal(DataUtils.acrescentarDias(DataUtils.getDataAtual(), 365)); |
||
| 74 | cashback.setTipoCashback(TipoCashback.ENTRADA.getValor()); |
||
| 75 | cashback.setValor(valorCashback); |
||
| 76 | cashback.setAtivo(true); |
||
| 77 | cashbackRepository.cadastrar(cashback); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | @Override |
||
| 83 | public void utilizarCashback(CashbackDTO cashbackDTO) { |
||
| 84 | // TODO Auto-generated method stub |
||
| 85 | |||
| 86 | } |
||
| 87 | |||
| 88 | } |