Rev 195 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 114 | espaco | 1 | package br.com.ec.domain.service.orcamento.impl; |
| 2 | |||
| 3 | import java.util.Date; |
||
| 4 | |||
| 5 | import org.springframework.beans.factory.annotation.Autowired; |
||
| 6 | import org.springframework.stereotype.Service; |
||
| 7 | |||
| 195 | espaco | 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; |
||
| 114 | espaco | 13 | import br.com.ec.domain.dto.FluxoDeCaixaDTO; |
| 14 | import br.com.ec.domain.model.Categoria; |
||
| 15 | import br.com.ec.domain.model.Orcamento; |
||
| 16 | import br.com.ec.domain.service.orcamento.OrcamentoService; |
||
| 17 | import br.com.ec.infrastructure.repository.OrcamentoRepository; |
||
| 18 | |||
| 19 | @Service |
||
| 20 | public class OrcamentoServiceImpl extends AbstractService<Orcamento> implements OrcamentoService { |
||
| 21 | |||
| 22 | private OrcamentoRepository orcamentoRepository; |
||
| 23 | |||
| 24 | @Autowired |
||
| 25 | public OrcamentoServiceImpl(Validador validador, OrcamentoRepository orcamentoRepository) { |
||
| 26 | super(validador); |
||
| 27 | this.orcamentoRepository = orcamentoRepository; |
||
| 28 | } |
||
| 29 | |||
| 30 | @Override |
||
| 31 | protected GenericRepository<Orcamento> getRepository() { |
||
| 32 | return orcamentoRepository; |
||
| 33 | } |
||
| 34 | |||
| 35 | @Override |
||
| 36 | public Orcamento consultarOrcamento(Date dataInicial, Date dataFinal, Categoria categoria, String tipoCategoria) { |
||
| 37 | return orcamentoRepository.consultarOrcamento(dataInicial, dataFinal, categoria, tipoCategoria); |
||
| 38 | } |
||
| 39 | |||
| 40 | @Override |
||
| 41 | public Orcamento prepararGerirOrcado(FluxoDeCaixaDTO fluxo, Categoria categoriaPai, Categoria categoria) { |
||
| 42 | Orcamento orcamento = null; |
||
| 43 | Categoria categoriaOrcado = null; |
||
| 44 | String tipoCategoria = null; |
||
| 45 | if (VerificadorUtil.estaNulo(categoria.getSequencial())) { |
||
| 46 | orcamento = consultarOrcamento(fluxo.getDataInicial(), fluxo.getDataFinal(), categoriaPai, categoriaPai.getTipo()); |
||
| 47 | categoriaOrcado = categoriaPai; |
||
| 48 | tipoCategoria = categoriaPai.getTipo(); |
||
| 49 | } else { |
||
| 50 | orcamento = consultarOrcamento(fluxo.getDataInicial(), fluxo.getDataFinal(), categoria, categoria.getTipo()); |
||
| 51 | categoriaOrcado = categoria; |
||
| 52 | tipoCategoria = categoria.getTipo(); |
||
| 53 | } |
||
| 54 | if (VerificadorUtil.estaNulo(orcamento)) { |
||
| 55 | orcamento = new Orcamento(); |
||
| 56 | orcamento.setCategoria(categoriaOrcado); |
||
| 57 | orcamento.setTipoCategoria(tipoCategoria); |
||
| 286 | espaco | 58 | if (DataUtils.getDataAtual().before(fluxo.getDataInicial())) { |
| 59 | orcamento.setDataOrcado(fluxo.getDataInicial()); |
||
| 60 | } else { |
||
| 61 | orcamento.setDataOrcado(DataUtils.getDataAtual()); |
||
| 62 | } |
||
| 114 | espaco | 63 | } |
| 64 | return orcamento; |
||
| 65 | } |
||
| 66 | |||
| 67 | @Override |
||
| 68 | public void atualizarOrcamento(Orcamento orcamento) { |
||
| 69 | if (VerificadorUtil.naoEstaNulo(orcamento)) { |
||
| 138 | espaco | 70 | if (VerificadorUtil.estaNulo(orcamento.getCategoria()) || |
| 71 | VerificadorUtil.estaNulo(orcamento.getCategoria().getSequencial())) { |
||
| 114 | espaco | 72 | orcamento.setCategoria(null); |
| 73 | } |
||
| 74 | if (VerificadorUtil.naoEstaNulo(orcamento.getSequencial())) { |
||
| 75 | alterar(orcamento); |
||
| 76 | } else { |
||
| 77 | cadastrar(orcamento); |
||
| 78 | } |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | } |