Rev 524 | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 524 | blopes | 1 | package br.com.ec.repository.jpa; |
| 2 | |||
| 3 | import java.util.List; |
||
| 4 | |||
| 5 | import javax.persistence.TypedQuery; |
||
| 6 | |||
| 7 | import org.springframework.stereotype.Repository; |
||
| 8 | |||
| 9 | import br.com.ec.core.util.VerificadorUtil; |
||
| 10 | import br.com.ec.domain.dto.ModeloDTO; |
||
| 11 | import br.com.ec.domain.model.Modelo; |
||
| 12 | import br.com.ec.repository.ModeloRepository; |
||
| 13 | import br.com.ec.repository.SistemaAbstractRepository; |
||
| 14 | |||
| 15 | @Repository |
||
| 16 | public class ModeloRepositoryJpaImpl extends SistemaAbstractRepository<Modelo> implements ModeloRepository { |
||
| 17 | |||
| 18 | @Override |
||
| 19 | protected String getColunaOrdenadora() { |
||
| 20 | return "sequencial"; |
||
| 21 | } |
||
| 22 | |||
| 23 | @Override |
||
| 24 | public List<ModeloDTO> consultarModelos(ModeloDTO modeloDTO) { |
||
| 25 | StringBuilder jpql = new StringBuilder(); |
||
| 26 | jpql.append("SELECT "); |
||
| 27 | jpql.append(ModeloDTO.CONSULTA_DTO_COMPLETA); |
||
| 28 | jpql.append("FROM Modelo e "); |
||
| 29 | jpql.append("WHERE 1=1 "); |
||
| 30 | if (VerificadorUtil.naoEstaNulo(modeloDTO.getAtivo())) { |
||
| 31 | jpql.append("AND e.ativo = :indicadorAtivo "); |
||
| 32 | } |
||
| 566 | blopes | 33 | if (VerificadorUtil.naoEstaNulo(modeloDTO.getIndicadorFavorito())) { |
| 34 | jpql.append("AND e.indicadorFavorito = :indicadorFavorito "); |
||
| 35 | } |
||
| 524 | blopes | 36 | jpql.append("ORDER BY e.descricao "); |
| 37 | try { |
||
| 38 | TypedQuery<ModeloDTO> query = getEntityManager().createQuery(jpql.toString(), ModeloDTO.class); |
||
| 39 | if (VerificadorUtil.naoEstaNulo(modeloDTO.getAtivo())) { |
||
| 40 | query.setParameter("indicadorAtivo", modeloDTO.getAtivo()); |
||
| 41 | } |
||
| 566 | blopes | 42 | if (VerificadorUtil.naoEstaNulo(modeloDTO.getIndicadorFavorito())) { |
| 43 | query.setParameter("indicadorFavorito", modeloDTO.getIndicadorFavorito()); |
||
| 44 | } |
||
| 524 | blopes | 45 | return query.getResultList(); |
| 46 | } catch (Exception ex) { |
||
| 47 | ex.printStackTrace(); |
||
| 48 | } |
||
| 49 | return null; |
||
| 50 | } |
||
| 51 | |||
| 52 | /* |
||
| 53 | @Override |
||
| 54 | protected void setarStringParametrosConsultar(StringBuilder sql, Conta conta) { |
||
| 55 | if (VerificadorUtil.naoEstaNulo(conta)) { |
||
| 56 | if (VerificadorUtil.naoEstaNuloOuVazio(conta.getSequencialDaVenda())) { |
||
| 57 | sql.append("AND e.venda.sequencial = :sequencialVenda "); |
||
| 58 | } |
||
| 59 | if (VerificadorUtil.naoEstaNuloOuVazio(conta.getIndicadorAtivo())) { |
||
| 60 | sql.append("AND e.indicadorAtivo = :indicadorAtivo "); |
||
| 61 | } |
||
| 62 | } |
||
| 63 | } |
||
| 64 | |||
| 65 | @Override |
||
| 66 | protected void setarQueryParametrosConsultar(Query query, Conta conta) { |
||
| 67 | if (VerificadorUtil.naoEstaNulo(conta)) { |
||
| 68 | if (VerificadorUtil.naoEstaNuloOuVazio(conta.getSequencialDaVenda())) { |
||
| 69 | query.setParameter("sequencialVenda", conta.getSequencialDaVenda()); |
||
| 70 | } |
||
| 71 | if (VerificadorUtil.naoEstaNuloOuVazio(conta.getIndicadorAtivo())) { |
||
| 72 | query.setParameter("indicadorAtivo", conta.getIndicadorAtivo()); |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | @Override |
||
| 78 | public Conta consultarContaAReceber(VendaFormaPagamento vendaFormaPagamento) { |
||
| 79 | StringBuilder sql = new StringBuilder(); |
||
| 80 | sql.append("SELECT c FROM Conta c "); |
||
| 81 | sql.append("WHERE c.venda.sequencial = :sequencialVenda "); |
||
| 82 | try { |
||
| 83 | return getEntityManager().createQuery(sql.toString(),Conta.class) |
||
| 84 | .setParameter("sequencialVenda", vendaFormaPagamento.getSequencialDaVenda()) |
||
| 85 | .getSingleResult(); |
||
| 86 | } catch(NoResultException ex) { |
||
| 87 | return null; |
||
| 88 | } catch(Exception ex) { |
||
| 89 | ex.printStackTrace(); |
||
| 90 | return null; |
||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | @Override |
||
| 95 | @Deprecated |
||
| 96 | public List<Conta> consultarContasAReceber(Venda venda) { |
||
| 97 | StringBuilder sql = new StringBuilder(); |
||
| 98 | sql.append("SELECT c FROM Conta c "); |
||
| 99 | sql.append("WHERE c.venda.sequencial = :sequencialVenda ORDER BY c.sequencial"); |
||
| 100 | try { |
||
| 101 | return getEntityManager().createQuery(sql.toString(),Conta.class).setParameter("sequencialVenda", venda.getSequencial()).getResultList(); |
||
| 102 | } catch(NoResultException ex) { |
||
| 103 | return null; |
||
| 104 | } catch(Exception ex) { |
||
| 105 | ex.printStackTrace(); |
||
| 106 | return null; |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | @Override |
||
| 111 | public List<Conta> consultarContasAReceberPorPeriodo(Date dataInicial, Date dataFinal) { |
||
| 112 | StringBuilder sql = new StringBuilder(); |
||
| 113 | sql.append("SELECT c FROM Conta c "); |
||
| 114 | sql.append("WHERE c.venda.dataVenda >= :dataInicial AND c.venda.dataVenda <= :dataFinal "); |
||
| 115 | sql.append("ORDER BY c.sequencial"); |
||
| 116 | try { |
||
| 117 | return getEntityManager().createQuery(sql.toString(),Conta.class) |
||
| 118 | .setParameter("dataInicial", DataUtils.getDataComHorarioMinimo(dataInicial)) |
||
| 119 | .setParameter("dataFinal", DataUtils.getDataComHorarioMaximo(dataFinal)) |
||
| 120 | .getResultList(); |
||
| 121 | } catch(NoResultException ex) { |
||
| 122 | return null; |
||
| 123 | } catch(Exception ex) { |
||
| 124 | ex.printStackTrace(); |
||
| 125 | return null; |
||
| 126 | } |
||
| 127 | } |
||
| 128 | */ |
||
| 129 | } |