diff --git a/src/com/rjconsultores/ventaboletos/dao/SegVKMDAO.java b/src/com/rjconsultores/ventaboletos/dao/SegVKMDAO.java index 2458906e9..2d572e349 100644 --- a/src/com/rjconsultores/ventaboletos/dao/SegVKMDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/SegVKMDAO.java @@ -4,6 +4,7 @@ */ package com.rjconsultores.ventaboletos.dao; +import java.math.BigDecimal; import java.util.List; import com.rjconsultores.ventaboletos.entidad.SegVKM; @@ -15,4 +16,8 @@ import com.rjconsultores.ventaboletos.entidad.SegVKM; public interface SegVKMDAO extends GenericDAO { public List buscar(String segVKm); + + public String seriePorEmpresa(Integer empresaId); + + public BigDecimal buscarSeguroPorKm(Long km, String serie, Integer orgaoConcedenteId); } diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/ParadaHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/ParadaHibernateDAO.java index cc2d6840a..8a8147fe3 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/ParadaHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/ParadaHibernateDAO.java @@ -131,7 +131,8 @@ public class ParadaHibernateDAO extends GenericHibernateDAO imp String sql = "SELECT DISTINCT " + "t.destino " + "FROM Tramo t " - + "WHERE t.origem = :origem"; + + "WHERE t.origem = :origem " + + "ORDER BY t.destino.descparada"; return getSession().createQuery(sql).setEntity("origem", origem).list(); } diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/SegVKMHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/SegVKMHibernateDAO.java index b9cccf0ef..d652e196d 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/SegVKMHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/SegVKMHibernateDAO.java @@ -4,9 +4,12 @@ */ package com.rjconsultores.ventaboletos.dao.hibernate; +import java.math.BigDecimal; import java.util.List; +import org.apache.commons.lang.StringUtils; import org.hibernate.Criteria; +import org.hibernate.Query; import org.hibernate.SessionFactory; import org.hibernate.criterion.Restrictions; import org.springframework.beans.factory.annotation.Autowired; @@ -14,6 +17,7 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Repository; import com.rjconsultores.ventaboletos.dao.SegVKMDAO; +import com.rjconsultores.ventaboletos.entidad.Ruta; import com.rjconsultores.ventaboletos.entidad.SegVKM; /** @@ -45,4 +49,63 @@ public class SegVKMHibernateDAO extends GenericHibernateDAO return c.list(); } + + public BigDecimal buscarSeguroPorKm(Long km, String serie, Integer orgaoConcedenteId) { + StringBuilder sb = new StringBuilder(); + Query miQry = null; + + sb = new StringBuilder(); + sb.append(" select seg.valor"); + sb.append(" from SegVKm seg"); + sb.append(" where seg.activo = 1 and seg.km >= :km and seg.serie in (" + serie + ") and seg.ORGAOCONCEDENTE_ID = :orgaoconcedenteId"); + sb.append(" order by seg.km"); + + miQry = getSession().createSQLQuery(sb.toString()); + miQry.setLong("km", km); + miQry.setInteger("orgaoconcedenteId", orgaoConcedenteId); + + miQry.setMaxResults(1); + + List list = miQry.list(); + + if (list.isEmpty()) { + sb = new StringBuilder(); + sb.append(" select seg.valor"); + sb.append(" from SegVKm seg"); + sb.append(" where seg.activo = 1 and seg.km >= :km and seg.serie in (" + serie + ") and seg.orgaoconcedenteId is null"); + sb.append(" order by seg.km"); + miQry = getSession().createQuery(sb.toString()); + + // miQry.setMaxResults(1); + + miQry.setLong("km", km); + list = miQry.list(); + } + + return list.isEmpty() ? null : list.get(0); + } + + public String seriePorEmpresa(Integer empresaId) { + StringBuilder sb = new StringBuilder(); + sb.append(" select serie "); + sb.append(" from SeguradoraEmpresa segEmp"); + sb.append(" where segEmp.activo = 1 and segEmp.empresa = :empresaId"); + + Query q = getSession().createQuery(sb.toString()); + q.setInteger("empresaId", empresaId); + + List res = q.list(); + String series = ""; + for (String serie : res) { + series += "'" + serie + "',"; + } + if (!series.isEmpty()) { + series = series.substring(0, series.length() - 1); + } + + if (StringUtils.isBlank(series)) { + return "-1"; + } + return series; + } } diff --git a/src/com/rjconsultores/ventaboletos/service/SegVKMService.java b/src/com/rjconsultores/ventaboletos/service/SegVKMService.java index 21ab0ca5a..0a64eaf37 100644 --- a/src/com/rjconsultores/ventaboletos/service/SegVKMService.java +++ b/src/com/rjconsultores/ventaboletos/service/SegVKMService.java @@ -4,6 +4,7 @@ */ package com.rjconsultores.ventaboletos.service; +import java.math.BigDecimal; import java.util.List; import com.rjconsultores.ventaboletos.entidad.SegVKM; @@ -14,5 +15,9 @@ import com.rjconsultores.ventaboletos.entidad.SegVKM; */ public interface SegVKMService extends GenericService { - public List buscar(String serie); + public List buscar(String serie); + + public String seriePorEmpresa(Integer empresaId); + + public BigDecimal buscarSeguroPorKm(Long km, String serie, Integer orgaoConcedenteId); } diff --git a/src/com/rjconsultores/ventaboletos/service/impl/SegVKMServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/SegVKMServiceImpl.java index 194675174..87edb6d7f 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/SegVKMServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/SegVKMServiceImpl.java @@ -4,9 +4,11 @@ */ package com.rjconsultores.ventaboletos.service.impl; +import java.math.BigDecimal; import java.util.Calendar; import java.util.List; +import org.jboss.resteasy.client.core.SelfExpandingBufferredInputStream; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -63,5 +65,16 @@ public class SegVKMServiceImpl implements SegVKMService { public List buscar(String serie) { return segVKMDAO.buscar(serie); + + } + + @Override + public String seriePorEmpresa(Integer empresaId) { + return segVKMDAO.seriePorEmpresa(empresaId); + } + + @Override + public BigDecimal buscarSeguroPorKm(Long km, String serie, Integer orgaoConcedenteId) { + return segVKMDAO.buscarSeguroPorKm(km, serie, orgaoConcedenteId); } }