package com.rjconsultores.ventaboletos.dao.hibernate; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import org.hibernate.Query; import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Repository; import com.rjconsultores.ventaboletos.dao.NotaCreditoVendaPacoteDAO; import com.rjconsultores.ventaboletos.entidad.CajaDiversos; import com.rjconsultores.ventaboletos.entidad.CajaDiversosPago; import com.rjconsultores.ventaboletos.entidad.CajaTarjeta; import com.rjconsultores.ventaboletos.entidad.NotaCreditoVendaPacote; import com.rjconsultores.ventaboletos.enums.SituacaoVendaPacote; import com.rjconsultores.ventaboletos.vo.reembolsoocdnotacredito.ReembolsoOcdNotaCreditoVO; @Repository("notaCreditoVendaPacoteDAO") public class NotaCreditoVendaPacoteHibernateDAO extends GenericHibernateDAO implements NotaCreditoVendaPacoteDAO { @Autowired public NotaCreditoVendaPacoteHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) { setSessionFactory(factory); } @SuppressWarnings("unchecked") @Override public List busquedaDatosReembolsoOcdNotaCreditoRS(Date fecInicial, Date fecFinal, Date fecPagamentoInicial, Date fecPagamentoFinal, Boolean indPago) { Map params = new HashMap(); StringBuilder queryString = new StringBuilder("SELECT n FROM NotaCreditoVendaPacote n "); queryString.append("LEFT JOIN FETCH n.ocdDatosPagamentoList ") .append("LEFT JOIN FETCH n.vendapacotecancelamento vpc ") .append("WHERE 1=1 "); if (fecInicial != null) { queryString.append("AND n.datanotacredito >= :fecInicial "); params.put("fecInicial", fecInicial); } if (fecFinal != null) { queryString.append("AND n.datanotacredito <= :fecFinal "); params.put("fecFinal", fecFinal); } if (fecPagamentoInicial != null) { queryString.append("AND n.datapagamento >= :fecPagamentoInicial "); params.put("fecPagamentoInicial", fecPagamentoInicial); } if (fecPagamentoFinal != null) { queryString.append("AND n.datapagamento <= :fecPagamentoFinal "); params.put("fecPagamentoFinal", fecPagamentoFinal); } if (indPago != null) { if (indPago) { queryString.append("AND n.situacao = :indPago "); } else { queryString.append("AND (n.situacao != :indPago OR n.situacao IS NULL) "); } params.put("indPago", SituacaoVendaPacote.PAGO.getShortValue()); } Query query = getSession().createQuery(queryString.toString()); for (String p : query.getNamedParameters()) { query.setParameter(p, params.get(p)); } List result = new ArrayList(); List listNotaCredito = query.list(); for (NotaCreditoVendaPacote notaCredito :listNotaCredito) { List cajaTarjetaList = new ArrayList(); List listCajaDiversos = notaCredito.getCajaDiversosList(); for (CajaDiversos cajaDiversos : listCajaDiversos) { List listCajaDiversosPago = cajaDiversos.getCajaDiversosPagosList(); for (CajaDiversosPago cajaDiversosPago : listCajaDiversosPago) { cajaTarjetaList.add(cajaDiversosPago.getCajaTarjeta()); } } ReembolsoOcdNotaCreditoVO vo = ReembolsoOcdNotaCreditoVO.builder().notaCredito(notaCredito) .datosPagamento(notaCredito.getOcdDatosPagamentoList()).cajaTarjeta(cajaTarjetaList).build(); result.add(vo); } return result; } }