Go to most recent revision | Details | 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 | } |
||
| 33 | jpql.append("ORDER BY e.descricao "); |
||
| 34 | try { |
||
| 35 | TypedQuery<ModeloDTO> query = getEntityManager().createQuery(jpql.toString(), ModeloDTO.class); |
||
| 36 | if (VerificadorUtil.naoEstaNulo(modeloDTO.getAtivo())) { |
||
| 37 | query.setParameter("indicadorAtivo", modeloDTO.getAtivo()); |
||
| 38 | } |
||
| 39 | return query.getResultList(); |
||
| 40 | } catch (Exception ex) { |
||
| 41 | ex.printStackTrace(); |
||
| 42 | } |
||
| 43 | return null; |
||
| 44 | } |
||
| 45 | |||
| 46 | /* |
||
| 47 | @Override |
||
| 48 | protected void setarStringParametrosConsultar(StringBuilder sql, Conta conta) { |
||
| 49 | if (VerificadorUtil.naoEstaNulo(conta)) { |
||
| 50 | if (VerificadorUtil.naoEstaNuloOuVazio(conta.getSequencialDaVenda())) { |
||
| 51 | sql.append("AND e.venda.sequencial = :sequencialVenda "); |
||
| 52 | } |
||
| 53 | if (VerificadorUtil.naoEstaNuloOuVazio(conta.getIndicadorAtivo())) { |
||
| 54 | sql.append("AND e.indicadorAtivo = :indicadorAtivo "); |
||
| 55 | } |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | @Override |
||
| 60 | protected void setarQueryParametrosConsultar(Query query, Conta conta) { |
||
| 61 | if (VerificadorUtil.naoEstaNulo(conta)) { |
||
| 62 | if (VerificadorUtil.naoEstaNuloOuVazio(conta.getSequencialDaVenda())) { |
||
| 63 | query.setParameter("sequencialVenda", conta.getSequencialDaVenda()); |
||
| 64 | } |
||
| 65 | if (VerificadorUtil.naoEstaNuloOuVazio(conta.getIndicadorAtivo())) { |
||
| 66 | query.setParameter("indicadorAtivo", conta.getIndicadorAtivo()); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | @Override |
||
| 72 | public Conta consultarContaAReceber(VendaFormaPagamento vendaFormaPagamento) { |
||
| 73 | StringBuilder sql = new StringBuilder(); |
||
| 74 | sql.append("SELECT c FROM Conta c "); |
||
| 75 | sql.append("WHERE c.venda.sequencial = :sequencialVenda "); |
||
| 76 | try { |
||
| 77 | return getEntityManager().createQuery(sql.toString(),Conta.class) |
||
| 78 | .setParameter("sequencialVenda", vendaFormaPagamento.getSequencialDaVenda()) |
||
| 79 | .getSingleResult(); |
||
| 80 | } catch(NoResultException ex) { |
||
| 81 | return null; |
||
| 82 | } catch(Exception ex) { |
||
| 83 | ex.printStackTrace(); |
||
| 84 | return null; |
||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | @Override |
||
| 89 | @Deprecated |
||
| 90 | public List<Conta> consultarContasAReceber(Venda venda) { |
||
| 91 | StringBuilder sql = new StringBuilder(); |
||
| 92 | sql.append("SELECT c FROM Conta c "); |
||
| 93 | sql.append("WHERE c.venda.sequencial = :sequencialVenda ORDER BY c.sequencial"); |
||
| 94 | try { |
||
| 95 | return getEntityManager().createQuery(sql.toString(),Conta.class).setParameter("sequencialVenda", venda.getSequencial()).getResultList(); |
||
| 96 | } catch(NoResultException ex) { |
||
| 97 | return null; |
||
| 98 | } catch(Exception ex) { |
||
| 99 | ex.printStackTrace(); |
||
| 100 | return null; |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | @Override |
||
| 105 | public List<Conta> consultarContasAReceberPorPeriodo(Date dataInicial, Date dataFinal) { |
||
| 106 | StringBuilder sql = new StringBuilder(); |
||
| 107 | sql.append("SELECT c FROM Conta c "); |
||
| 108 | sql.append("WHERE c.venda.dataVenda >= :dataInicial AND c.venda.dataVenda <= :dataFinal "); |
||
| 109 | sql.append("ORDER BY c.sequencial"); |
||
| 110 | try { |
||
| 111 | return getEntityManager().createQuery(sql.toString(),Conta.class) |
||
| 112 | .setParameter("dataInicial", DataUtils.getDataComHorarioMinimo(dataInicial)) |
||
| 113 | .setParameter("dataFinal", DataUtils.getDataComHorarioMaximo(dataFinal)) |
||
| 114 | .getResultList(); |
||
| 115 | } catch(NoResultException ex) { |
||
| 116 | return null; |
||
| 117 | } catch(Exception ex) { |
||
| 118 | ex.printStackTrace(); |
||
| 119 | return null; |
||
| 120 | } |
||
| 121 | } |
||
| 122 | */ |
||
| 123 | } |