760 lines
38 KiB
Java
760 lines
38 KiB
Java
/*
|
|
* To change this template, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
package com.rjconsultores.ventaboletos.dao.hibernate;
|
|
|
|
import java.math.BigDecimal;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import org.hibernate.Criteria;
|
|
import org.hibernate.Query;
|
|
import org.hibernate.SQLQuery;
|
|
import org.hibernate.Session;
|
|
import org.hibernate.SessionFactory;
|
|
import org.hibernate.criterion.Projections;
|
|
import org.hibernate.criterion.Restrictions;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
import org.springframework.stereotype.Repository;
|
|
|
|
import com.rjconsultores.ventaboletos.dao.RutaCombinacionDAO;
|
|
import com.rjconsultores.ventaboletos.dao.TramoDAO;
|
|
import com.rjconsultores.ventaboletos.entidad.Categoria;
|
|
import com.rjconsultores.ventaboletos.entidad.ClaseServicio;
|
|
import com.rjconsultores.ventaboletos.entidad.Empresa;
|
|
import com.rjconsultores.ventaboletos.entidad.Marca;
|
|
import com.rjconsultores.ventaboletos.entidad.Moneda;
|
|
import com.rjconsultores.ventaboletos.entidad.Parada;
|
|
import com.rjconsultores.ventaboletos.entidad.Ruta;
|
|
import com.rjconsultores.ventaboletos.entidad.RutaCombinacion;
|
|
import com.rjconsultores.ventaboletos.entidad.TipoPuntoVenta;
|
|
import com.rjconsultores.ventaboletos.entidad.Tramo;
|
|
import com.rjconsultores.ventaboletos.entidad.VigenciaTarifa;
|
|
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
|
import com.rjconsultores.ventaboletos.vo.esquemaoperacional.TarifaEscalaGroupVO;
|
|
import com.rjconsultores.ventaboletos.vo.esquemaoperacional.TarifaEscalaVO;
|
|
import com.rjconsultores.ventaboletos.vo.esquemaoperacional.TarifaOficialEscalaGroupVO;
|
|
import com.rjconsultores.ventaboletos.vo.esquemaoperacional.TarifaOficialEscalaVO;
|
|
import org.hibernate.transform.AliasToBeanResultTransformer;
|
|
|
|
/**
|
|
*
|
|
* @author Rafius
|
|
*/
|
|
@Repository("rutaCombinacionDAO")
|
|
public class RutaCombinacionHibernateDAO extends GenericHibernateDAO<RutaCombinacion, Integer>
|
|
implements RutaCombinacionDAO {
|
|
|
|
private static Logger log = LoggerFactory.getLogger(RutaCombinacionHibernateDAO.class);
|
|
@Autowired
|
|
private TramoDAO tramoDAO;
|
|
private String schema = "";
|
|
|
|
@Autowired
|
|
public RutaCombinacionHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
|
setSessionFactory(factory);
|
|
}
|
|
|
|
public boolean busquedaRutaTramo(Ruta ruta, Tramo tramo, Boolean ativo) {
|
|
|
|
Criteria c = getSession().createCriteria(getPersistentClass());
|
|
|
|
if (ativo) {
|
|
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
|
} else {
|
|
c.add(Restrictions.eq("activo", Boolean.FALSE));
|
|
}
|
|
|
|
c.setProjection(Projections.rowCount());
|
|
|
|
c.add(Restrictions.eq("ruta", ruta));
|
|
c.add(Restrictions.eq("tramo", tramo));
|
|
|
|
return HibernateFix.count(c.list()) > 0;
|
|
}
|
|
|
|
public RutaCombinacion busquedaTramoRutaTramo(Ruta ruta, Tramo trBuscaOrigemDestino) {
|
|
|
|
String hql = " select rc from RutaCombinacion rc, Tramo t "
|
|
+ " where rc.tramo.tramoId = t.tramoId and rc.activo = 0 "
|
|
+ " and rc.ruta.rutaId = " + ruta.getRutaId()
|
|
+ " and t.origem.paradaId = " + trBuscaOrigemDestino.getOrigem().getParadaId()
|
|
+ " and t.destino.paradaId = " + trBuscaOrigemDestino.getDestino().getParadaId();
|
|
Query sq = getSession().createQuery(hql);
|
|
|
|
RutaCombinacion rc = new RutaCombinacion();
|
|
if (sq.list().size() > 0) {
|
|
rc = (RutaCombinacion) sq.list().get(sq.list().size() - 1);
|
|
}
|
|
|
|
return rc;
|
|
}
|
|
|
|
public Tramo busqueda(Ruta ruta, Parada origen, Parada destino) {
|
|
Criteria c = this.makeCriteria();
|
|
c.add(Restrictions.eq("ruta", ruta));
|
|
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
|
|
|
Criteria c2 = c.createCriteria("tramo");
|
|
c2.add(Restrictions.eq("origem", origen));
|
|
c2.add(Restrictions.eq("destino", destino));
|
|
c2.add(Restrictions.eq("activo", Boolean.TRUE));
|
|
|
|
List<RutaCombinacion> list = c.list();
|
|
|
|
if (list.size() != 1) {
|
|
return null;
|
|
}
|
|
return list.get(0).getTramo();
|
|
}
|
|
|
|
public RutaCombinacion busquedaTramoRutaOrigemDestino(Ruta ruta, Parada origem, Parada destino) {
|
|
Criteria c = this.makeCriteria();
|
|
c.add(Restrictions.eq("ruta", ruta));
|
|
|
|
Criteria c2 = c.createCriteria("tramo");
|
|
c2.add(Restrictions.eq("origem", origem));
|
|
c2.add(Restrictions.eq("destino", destino));
|
|
c2.add(Restrictions.eq("activo", Boolean.TRUE));
|
|
|
|
if (c.list().size() > 0) {
|
|
return (RutaCombinacion) c.list().get(0);
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
public List<RutaCombinacion> obtenerPorRuta(Ruta ruta) {
|
|
Criteria c = this.makeCriteria();
|
|
c.add(Restrictions.eq("ruta", ruta));
|
|
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
|
|
|
return c.list();
|
|
}
|
|
|
|
public boolean buscarRutaCombinacionExisteTramo(Tramo tramo) {
|
|
Criteria c = this.makeCriteria();
|
|
c.add(Restrictions.eq("tramo", tramo));
|
|
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
|
|
|
if (c.list().isEmpty()) {
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
@Override
|
|
public List<Tramo> tramosFaltantes(Integer rutaId) {
|
|
Session session = getSession();
|
|
List<Tramo> lsTramoFaltantes = new ArrayList<Tramo>();
|
|
|
|
StringBuilder sb = new StringBuilder("");
|
|
sb.append(" select t.origen_id, ");
|
|
sb.append(" rs.numsecuencia ");
|
|
sb.append(" from ruta_secuencia rs ");
|
|
sb.append(" inner join tramo t on t.tramo_id = rs.tramo_id ");
|
|
sb.append(" where rs.activo = 1 and ");
|
|
sb.append(" t.activo = 1 and ");
|
|
sb.append(" rs.ruta_id = :rutaId ");
|
|
sb.append(" union ");
|
|
sb.append(" select t.destino_id, ");
|
|
sb.append(" rs.numsecuencia ");
|
|
sb.append(" from ruta_secuencia rs ");
|
|
sb.append(" inner join tramo t on t.tramo_id = rs.tramo_id ");
|
|
sb.append(" where rs.activo = 1 and ");
|
|
sb.append(" t.activo = 1 and ");
|
|
sb.append(" rs.ruta_id = :rutaId and ");
|
|
sb.append(" rs.numsecuencia = ");
|
|
sb.append(" (select max(rs.numsecuencia) from ");
|
|
sb.append(" ruta_secuencia rs inner join tramo t on ");
|
|
sb.append(" t.tramo_id = rs.tramo_id where rs.activo = ");
|
|
sb.append(" 1 and t.activo = 1 and rs.ruta_id = :rutaId ) ");
|
|
sb.append(" order by 2 ");
|
|
|
|
|
|
SQLQuery sqlQuery = session.createSQLQuery(sb.toString());
|
|
sqlQuery.setInteger("rutaId", rutaId);
|
|
|
|
List<Object[]> lsParadas = sqlQuery.list();
|
|
Integer origenId = null;
|
|
Integer destinoId = null;
|
|
for (int i = 0; i < lsParadas.size(); i++) {
|
|
origenId = ((BigDecimal) lsParadas.get(i)[0]).intValue();
|
|
for (int j = i + 1; j < lsParadas.size(); j++) {
|
|
destinoId = ((BigDecimal) lsParadas.get(j)[0]).intValue();
|
|
|
|
log.debug(origenId + " - " + destinoId);
|
|
|
|
sb = new StringBuilder();
|
|
sb.append(" select count(*) ");
|
|
sb.append(" from ruta_combinacion rc ");
|
|
sb.append(" inner join tramo t on t.tramo_id = rc.tramo_id ");
|
|
sb.append(" where ");
|
|
sb.append(" rc.ruta_id = :rutaId ");
|
|
sb.append(" and rc.activo = 1 ");
|
|
sb.append(" and t.activo = 1 ");
|
|
sb.append(" and t.origen_id = :origenId ");
|
|
sb.append(" and t.destino_id = :destinoId ");
|
|
|
|
|
|
SQLQuery sqlQueryExists = session.createSQLQuery(sb.toString());
|
|
sqlQueryExists.setInteger("rutaId", rutaId);
|
|
sqlQueryExists.setInteger("origenId", origenId);
|
|
sqlQueryExists.setInteger("destinoId", destinoId);
|
|
|
|
Long count = HibernateFix.count(sqlQueryExists.list());
|
|
|
|
if (count == 0) {
|
|
log.info("No existe combinacion " + origenId + " - " + destinoId);
|
|
|
|
|
|
Parada paradaOrigem = new Parada();
|
|
paradaOrigem.setParadaId(origenId);
|
|
|
|
Parada paradaDestino = new Parada();
|
|
paradaDestino.setParadaId(destinoId);
|
|
|
|
List<Tramo> list = tramoDAO.obtenerListPorOrigemDestino(paradaOrigem, paradaDestino);
|
|
|
|
if (list.size() == 0) {
|
|
log.info("No existe tramo " + origenId + " - " + destinoId);
|
|
} else {
|
|
lsTramoFaltantes.add(list.get(0));
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return lsTramoFaltantes;
|
|
}
|
|
|
|
public int borrarCombinaciones(Ruta ruta) {
|
|
Query query = this.getSession().createQuery("UPDATE RutaCombinacion set activo = false, fecmodif = current_timestamp(), usuarioId= :usuario where ruta = :ruta");
|
|
query.setParameter("ruta", ruta);
|
|
query.setParameter("usuario", UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
|
|
|
return query.executeUpdate();
|
|
}
|
|
|
|
public void activar(Ruta ruta, Tramo trBuscaOrigemDestino) {
|
|
String sql = " select rc.rutacombinacionId from RutaCombinacion rc, Tramo t "
|
|
+ " where rc.tramo.tramoId = t.tramoId and rc.activo = 0 "
|
|
+ " and rc.ruta.rutaId = " + ruta.getRutaId()
|
|
+ " and t.origem.paradaId = " + trBuscaOrigemDestino.getOrigem().getParadaId()
|
|
+ " and t.destino.paradaId = " + trBuscaOrigemDestino.getDestino().getParadaId();
|
|
|
|
getSession().createQuery("update RutaCombinacion set activo = true where rutacombinacionId in (" + sql + " )").executeUpdate();
|
|
}
|
|
|
|
public List<Object> pesquisaTarifaObj(List<Moneda> lsMoneda, List<Marca> lsMarca, List<ClaseServicio> lsClaseServicio, List<Categoria> lsCategoria, List<Empresa> lsEmpresa, List<Ruta> lsRuta, List<TipoPuntoVenta> lsTipoPuntoVenta, List<VigenciaTarifa> lsVigenciaTarifa) {
|
|
|
|
StringBuilder hql = new StringBuilder(" ");
|
|
hql.append(" SELECT T.TARIFA_ID,TRA.DESCTRAMO, ");
|
|
hql.append(" ORI.DESCPARADA as origem,DES.DESCPARADA as destino, ");
|
|
hql.append(" R.DESCRUTA,M.DESCMARCA, ");
|
|
hql.append(" CS.DESCCLASE,VT.feciniciovigencia, ");
|
|
hql.append(" VT.fecfinvigencia,MON.descmoneda, ");
|
|
hql.append(" T.preciooriginal, T.PRECIO,R.RUTA_ID,MON.moneda_id,VT.VIGENCIATARIFA_ID,M.MARCA_ID ");
|
|
hql.append(" FROM ");
|
|
hql.append(" ").append(schema).append("RUTA_COMBINACION RC ");
|
|
hql.append(" inner join ").append(schema).append("RUTA R on (RC.RUTA_ID = R.RUTA_ID) ");
|
|
hql.append(" inner join ").append(schema).append("TRAMO TRA on (RC.TRAMO_ID = TRA.TRAMO_ID) ");
|
|
hql.append(" ,").append(schema).append("TARIFA T ");
|
|
if (!lsEmpresa.isEmpty()) {
|
|
hql.append(" ,").append(schema).append("RUTA_EMPRESA RE ");
|
|
}
|
|
hql.append(" ,").append(schema).append("MARCA M,").append(schema).append("MONEDA MON,").append(schema).append("VIGENCIA_TARIFA VT ");
|
|
hql.append(" ,").append(schema).append("CLASE_SERVICIO CS , ").append(schema).append("PARADA ORI, ").append(schema).append("PARADA DES ");
|
|
hql.append(" WHERE T.activo = 1 AND RC.activo = 1 AND R.activo = 1 ");
|
|
if (!lsEmpresa.isEmpty()) {
|
|
hql.append(" AND RE.activo = 1 AND RC.RUTA_ID = RE.RUTA_ID ");
|
|
}
|
|
hql.append(" AND T.TRAMO_ID = TRA.TRAMO_ID ");
|
|
hql.append(" AND T.MARCA_ID = M.MARCA_ID ");
|
|
hql.append(" AND T.MONEDA_ID = MON.MONEDA_ID ");
|
|
hql.append(" AND T.VIGENCIATARIFA_ID = VT.VIGENCIATARIFA_ID ");
|
|
hql.append(" AND T.CLASESERVICIO_ID = CS.CLASESERVICIO_ID ");
|
|
hql.append(" AND T.CLASESERVICIO_ID = R.CLASESERVICIO_ID ");
|
|
hql.append(" AND TRA.ORIGEN_ID = ORI.PARADA_ID ");
|
|
hql.append(" AND TRA.DESTINO_ID = DES.PARADA_ID ");
|
|
|
|
|
|
if (!lsVigenciaTarifa.isEmpty()) {
|
|
StringBuilder sb = new StringBuilder("");
|
|
for (VigenciaTarifa vt : lsVigenciaTarifa) {
|
|
sb.append(vt.getVigenciatarifaId()).append(",");
|
|
}
|
|
String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
hql.append(" AND VT.VIGENCIATARIFA_ID in (").append(listInt).append(")");
|
|
}
|
|
if (!lsEmpresa.isEmpty()) {
|
|
StringBuilder sb = new StringBuilder("");
|
|
for (Empresa vt : lsEmpresa) {
|
|
sb.append(vt.getEmpresaId()).append(",");
|
|
}
|
|
String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
hql.append(" AND RE.EMPRESA_ID in (").append(listInt).append(") ");
|
|
}
|
|
if (!lsRuta.isEmpty()) {
|
|
StringBuilder sb = new StringBuilder("");
|
|
for (Ruta vt : lsRuta) {
|
|
sb.append(vt.getRutaId()).append(",");
|
|
}
|
|
String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
hql.append(" AND RC.RUTA_ID in (").append(listInt).append(")");
|
|
}
|
|
if (!lsMarca.isEmpty()) {
|
|
StringBuilder sb = new StringBuilder("");
|
|
for (Marca vt : lsMarca) {
|
|
sb.append(vt.getMarcaId()).append(",");
|
|
}
|
|
String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
hql.append(" AND M.MARCA_ID in (").append(listInt).append(") ");
|
|
}
|
|
if (!lsMoneda.isEmpty()) {
|
|
StringBuilder sb = new StringBuilder("");
|
|
for (Moneda vt : lsMoneda) {
|
|
sb.append(vt.getMonedaId()).append(",");
|
|
}
|
|
String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
hql.append(" AND MON.MONEDA_ID in (").append(listInt).append(") ");
|
|
}
|
|
if (!lsClaseServicio.isEmpty()) {
|
|
StringBuilder sb = new StringBuilder("");
|
|
for (ClaseServicio cs : lsClaseServicio) {
|
|
sb.append(cs.getClaseservicioId()).append(",");
|
|
}
|
|
String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
hql.append(" AND CS.CLASESERVICIO_ID in (").append(listInt).append(") ");
|
|
}
|
|
|
|
hql.append(" order by R.DESCRUTA, R.RUTA_ID, RC.RUTACOMBINACION_ID,t.tarifa_id ");
|
|
|
|
System.out.println(hql.toString());
|
|
|
|
List<Object> lsObj = this.getSession().createSQLQuery(hql.toString()).list();
|
|
|
|
return lsObj;
|
|
}
|
|
|
|
public List<Object> pesquisaTarifaOficialObj(List<Moneda> lsMoneda, List<Marca> lsMarca, List<ClaseServicio> lsClaseServicio, List<Empresa> lsEmpresa, List<Ruta> lsRuta, List<VigenciaTarifa> lsVigenciaTarifa) {
|
|
|
|
StringBuilder hql = new StringBuilder(" ");
|
|
hql.append(" SELECT T.TARIFAOFICIAL_ID,TRA.DESCTRAMO, ");
|
|
hql.append(" ORI.DESCPARADA as origem,DES.DESCPARADA as destino, ");
|
|
hql.append(" R.DESCRUTA,M.DESCMARCA, ");
|
|
hql.append(" CS.DESCCLASE,'' as feciniciovigencia, ");
|
|
hql.append(" '' as fecfinvigencia,MON.descmoneda, ");
|
|
hql.append(" T.preciooriginal, T.PRECIO,R.RUTA_ID,MON.moneda_id,'' AS VIGENCIATARIFA_ID,M.MARCA_ID,T.IMPORTETAXAEMBARQUE,T.IMPORTESEGURO,T.IMPORTEPEDAGIO,T.IMPORTEOUTROS ");
|
|
hql.append(" FROM ");
|
|
hql.append(" ").append(schema).append("RUTA_COMBINACION RC ");
|
|
hql.append(" inner join ").append(schema).append("RUTA R on (RC.RUTA_ID = R.RUTA_ID) ");
|
|
hql.append(" inner join ").append(schema).append("TRAMO TRA on (RC.TRAMO_ID = TRA.TRAMO_ID) ");
|
|
hql.append(" ,").append(schema).append("TARIFA_OFICIAL T ");
|
|
if (!lsEmpresa.isEmpty()) {
|
|
hql.append(" ,").append(schema).append("RUTA_EMPRESA RE ");
|
|
}
|
|
hql.append(" ,").append(schema).append("MARCA M,").append(schema).append("MONEDA MON");//.append(,+schema).append("VIGENCIA_TARIFA VT ");
|
|
hql.append(" ,").append(schema).append("CLASE_SERVICIO CS , ").append(schema).append("PARADA ORI, ").append(schema).append("PARADA DES ");
|
|
hql.append(" WHERE T.activo = 1 AND RC.activo = 1 AND R.activo = 1 ");
|
|
if (!lsEmpresa.isEmpty()) {
|
|
hql.append(" AND RE.activo = 1 AND RC.RUTA_ID = RE.RUTA_ID ");
|
|
}
|
|
hql.append(" AND T.TRAMO_ID = TRA.TRAMO_ID ");
|
|
hql.append(" AND T.MARCA_ID = M.MARCA_ID ");
|
|
hql.append(" AND T.MONEDA_ID = MON.MONEDA_ID ");
|
|
//hql.append(" AND T.VIGENCIATARIFA_ID = VT.VIGENCIATARIFA_ID ");
|
|
hql.append(" AND T.CLASESERVICIO_ID = CS.CLASESERVICIO_ID ");
|
|
hql.append(" AND T.CLASESERVICIO_ID = R.CLASESERVICIO_ID ");
|
|
hql.append(" AND TRA.ORIGEN_ID = ORI.PARADA_ID ");
|
|
hql.append(" AND TRA.DESTINO_ID = DES.PARADA_ID ");
|
|
|
|
|
|
// if (!lsVigenciaTarifa.isEmpty()) {
|
|
// StringBuilder sb = new StringBuilder("");
|
|
// for (VigenciaTarifa vt : lsVigenciaTarifa) {
|
|
// sb.append(vt.getVigenciatarifaId()).append(",");
|
|
// }
|
|
// String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
// hql.append(" AND VT.VIGENCIATARIFA_ID in (").append(listInt).append(")");
|
|
// }
|
|
if (!lsEmpresa.isEmpty()) {
|
|
StringBuilder sb = new StringBuilder("");
|
|
for (Empresa vt : lsEmpresa) {
|
|
sb.append(vt.getEmpresaId()).append(",");
|
|
}
|
|
String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
hql.append(" AND RE.EMPRESA_ID in (").append(listInt).append(") ");
|
|
}
|
|
if (!lsRuta.isEmpty()) {
|
|
StringBuilder sb = new StringBuilder("");
|
|
for (Ruta vt : lsRuta) {
|
|
sb.append(vt.getRutaId()).append(",");
|
|
}
|
|
String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
hql.append(" AND RC.RUTA_ID in (").append(listInt).append(")");
|
|
}
|
|
if (!lsMarca.isEmpty()) {
|
|
StringBuilder sb = new StringBuilder("");
|
|
for (Marca vt : lsMarca) {
|
|
sb.append(vt.getMarcaId()).append(",");
|
|
}
|
|
String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
hql.append(" AND M.MARCA_ID in (").append(listInt).append(") ");
|
|
}
|
|
if (!lsMoneda.isEmpty()) {
|
|
StringBuilder sb = new StringBuilder("");
|
|
for (Moneda vt : lsMoneda) {
|
|
sb.append(vt.getMonedaId()).append(",");
|
|
}
|
|
String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
hql.append(" AND MON.MONEDA_ID in (").append(listInt).append(") ");
|
|
}
|
|
if (!lsClaseServicio.isEmpty()) {
|
|
StringBuilder sb = new StringBuilder("");
|
|
for (ClaseServicio cs : lsClaseServicio) {
|
|
sb.append(cs.getClaseservicioId()).append(",");
|
|
}
|
|
String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
hql.append(" AND CS.CLASESERVICIO_ID in (").append(listInt).append(") ");
|
|
}
|
|
|
|
hql.append(" order by R.DESCRUTA, R.RUTA_ID, RC.RUTACOMBINACION_ID,t.TARIFAOFICIAL_id ");
|
|
|
|
System.out.println(hql.toString());
|
|
|
|
List<Object> lsObj = this.getSession().createSQLQuery(hql.toString()).list();
|
|
|
|
return lsObj;
|
|
}
|
|
|
|
public List<TarifaEscalaGroupVO> pesquisaTarifaGroupObj(List<Moneda> lsMoneda, List<Marca> lsMarca, List<ClaseServicio> lsClaseServicio, List<Categoria> lsCategoria, List<Empresa> lsEmpresa, List<Ruta> lsRuta, List<TipoPuntoVenta> lsTipoPuntoVenta, List<VigenciaTarifa> lsVigenciaTarifa) {
|
|
|
|
StringBuilder sql = new StringBuilder(" ");
|
|
sql.append(" SELECT R.descruta,R.RUTA_ID,MON.moneda_id,'' AS VIGENCIATARIFA_ID,M.MARCA_ID,mon.descmoneda,vt.FECINICIOVIGENCIA,vt.FECFINVIGENCIA, M.descmarca,CS.descclase ");
|
|
sql.append(" FROM ");
|
|
sql.append(" ").append(schema).append("RUTA_COMBINACION RC ");
|
|
sql.append(" inner join ").append(schema).append("RUTA R on (RC.RUTA_ID = R.RUTA_ID) ");
|
|
sql.append(" inner join ").append(schema).append("TRAMO TRA on (RC.TRAMO_ID = TRA.TRAMO_ID) ");
|
|
sql.append(" ,").append(schema).append("TARIFA_OFICIAL T ,").append(schema).append("RUTA_EMPRESA RE ");
|
|
sql.append(" ,").append(schema).append("MARCA M,").append(schema).append("MONEDA MON,");//.append(schema).append("VIGENCIA_TARIFA VT ");
|
|
sql.append(" ,").append(schema).append("CLASE_SERVICIO CS , ").append(schema).append("PARADA ORI, ").append(schema).append("PARADA DES ");
|
|
sql.append(" WHERE T.activo = 1 AND RC.activo = 1 AND RE.activo = 1 AND R.activo = 1 ");
|
|
sql.append(" AND T.TRAMO_ID = TRA.TRAMO_ID ");
|
|
sql.append(" AND RC.RUTA_ID = RE.RUTA_ID ");
|
|
sql.append(" AND T.MARCA_ID = M.MARCA_ID ");
|
|
sql.append(" AND T.MONEDA_ID = MON.MONEDA_ID ");
|
|
//sql.append(" AND T.VIGENCIATARIFA_ID = VT.VIGENCIATARIFA_ID ");
|
|
sql.append(" AND T.CLASESERVICIO_ID = CS.CLASESERVICIO_ID ");
|
|
sql.append(" AND T.CLASESERVICIO_ID = R.CLASESERVICIO_ID ");
|
|
sql.append(" AND TRA.ORIGEN_ID = ORI.PARADA_ID ");
|
|
sql.append(" AND TRA.DESTINO_ID = DES.PARADA_ID ");
|
|
|
|
|
|
|
|
// if (!lsVigenciaTarifa.isEmpty()) {
|
|
// StringBuilder sb = new StringBuilder("");
|
|
// for (VigenciaTarifa vt : lsVigenciaTarifa) {
|
|
// sb.append(vt.getVigenciatarifaId()).append(",");
|
|
// }
|
|
// String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
// sql.append(" AND VT.VIGENCIATARIFA_ID in (").append(listInt).append(")");
|
|
// }
|
|
if (!lsEmpresa.isEmpty()) {
|
|
StringBuilder sb = new StringBuilder("");
|
|
for (Empresa vt : lsEmpresa) {
|
|
sb.append(vt.getEmpresaId()).append(",");
|
|
}
|
|
String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
sql.append(" AND RE.EMPRESA_ID in (").append(listInt).append(") ");
|
|
}
|
|
if (!lsRuta.isEmpty()) {
|
|
StringBuilder sb = new StringBuilder("");
|
|
for (Ruta vt : lsRuta) {
|
|
sb.append(vt.getRutaId()).append(",");
|
|
}
|
|
String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
sql.append(" AND RC.RUTA_ID in (").append(listInt).append(")");
|
|
}
|
|
if (!lsMarca.isEmpty()) {
|
|
StringBuilder sb = new StringBuilder("");
|
|
for (Marca vt : lsMarca) {
|
|
sb.append(vt.getMarcaId()).append(",");
|
|
}
|
|
String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
sql.append(" AND M.MARCA_ID in (").append(listInt).append(") ");
|
|
}
|
|
if (!lsMoneda.isEmpty()) {
|
|
StringBuilder sb = new StringBuilder("");
|
|
for (Moneda vt : lsMoneda) {
|
|
sb.append(vt.getMonedaId()).append(",");
|
|
}
|
|
String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
sql.append(" AND MON.MONEDA_ID in (").append(listInt).append(") ");
|
|
}
|
|
if (!lsClaseServicio.isEmpty()) {
|
|
StringBuilder sb = new StringBuilder("");
|
|
for (ClaseServicio cs : lsClaseServicio) {
|
|
sb.append(cs.getClaseservicioId()).append(",");
|
|
}
|
|
String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
sql.append(" AND CS.CLASESERVICIO_ID in (").append(listInt).append(") ");
|
|
}
|
|
|
|
sql.append(" GROUP by R.descruta,R.RUTA_ID,MON.moneda_id,VT.VIGENCIATARIFA_ID,M.MARCA_ID,mon.descmoneda,vt.FECINICIOVIGENCIA,vt.FECFINVIGENCIA, M.descmarca,CS.descclase ");
|
|
sql.append(" ORDER by R.descruta,R.RUTA_ID,MON.moneda_id,VT.VIGENCIATARIFA_ID,M.MARCA_ID");
|
|
|
|
SQLQuery query = getSession().createSQLQuery(sql.toString());
|
|
query.setResultTransformer(new AliasToBeanResultTransformer(TarifaEscalaGroupVO.class));
|
|
|
|
return query.list();
|
|
}
|
|
|
|
public List<TarifaEscalaVO> pesquisaTarifaEscalaObj(String rutaId, String monedaId, String vigenciaId, String marcaId) {
|
|
|
|
StringBuilder sql = new StringBuilder(" ");
|
|
sql.append("select distinct po.cveparada as cveOrigem,po.descparada as descOrigem, ");
|
|
sql.append(" pd.cveparada as cveDestino,pd.descparada as descDestino,tmp.numsecuencia as NUMSECORIGEM,tmp2.numsecuencia as NUMSECDESTINO, ");
|
|
sql.append(" ta.PRECIO as precio,ruta.ruta_id as rutaId,ruta.descruta as descruta ");
|
|
sql.append("from ");
|
|
sql.append(" ").append(schema).append("ruta_combinacion rc ");
|
|
sql.append(" inner join ").append(schema).append("ruta on (ruta.ruta_id = rc.ruta_id) ");
|
|
sql.append(" inner join ").append(schema).append("tramo t on t.tramo_id = rc.tramo_id ");
|
|
sql.append(" inner join ").append(schema).append("parada po on po.parada_id = t.origen_id ");
|
|
sql.append(" inner join ").append(schema).append("parada pd on pd.parada_id = t.destino_id ");
|
|
sql.append(" inner join ( ");
|
|
sql.append(" (SELECT ");
|
|
sql.append(" p.parada_id,p.cveparada,rs.numsecuencia+1 as numsecuencia,rs.ruta_id ");
|
|
sql.append(" FROM ");
|
|
sql.append(" ").append(schema).append("ruta_secuencia rs ");
|
|
sql.append(" INNER JOIN ").append(schema).append("tramo t ON t.tramo_id = rs.tramo_id ");
|
|
sql.append(" INNER JOIN ").append(schema).append("parada p ON p.parada_id = t.destino_id ");
|
|
sql.append(" WHERE ");
|
|
sql.append(" rs.ruta_id = ").append(rutaId);
|
|
sql.append(" AND rs.activo = 1 ");
|
|
sql.append(" and rownum =1 ");
|
|
sql.append(" and rs.numsecuencia = (select max(numsecuencia) from ").append(schema).append("ruta_secuencia where activo = 1 and ruta_id = rs.ruta_id)) ");
|
|
sql.append(" ");
|
|
sql.append(" union ");
|
|
|
|
sql.append(" (SELECT ");
|
|
sql.append(" p.parada_id,p.cveparada,rs.numsecuencia,rs.ruta_id ");
|
|
sql.append(" FROM ");
|
|
sql.append(" ").append(schema).append("ruta_secuencia rs ");
|
|
sql.append(" INNER JOIN ").append(schema).append("tramo t ON t.tramo_id = rs.tramo_id ");
|
|
sql.append(" INNER JOIN ").append(schema).append("parada p ON p.parada_id = t.origen_id ");
|
|
sql.append(" WHERE ");
|
|
sql.append(" rs.ruta_id = ").append(rutaId);
|
|
sql.append(" AND rs.activo = 1) ");
|
|
sql.append(" ) tmp on tmp.parada_id = po.parada_id ");
|
|
|
|
sql.append("left join ( ");
|
|
sql.append(" (SELECT ");
|
|
sql.append(" p.parada_id,p.cveparada,rs.numsecuencia+1 as numsecuencia,rs.ruta_id ");
|
|
sql.append(" FROM ");
|
|
sql.append(" ").append(schema).append("ruta_secuencia rs ");
|
|
sql.append(" INNER JOIN ").append(schema).append("tramo t ON t.tramo_id = rs.tramo_id ");
|
|
sql.append(" INNER JOIN ").append(schema).append("parada p ON p.parada_id = t.destino_id ");
|
|
sql.append(" WHERE ");
|
|
sql.append(" rs.ruta_id = ").append(rutaId);
|
|
sql.append(" AND rs.activo = 1 ");
|
|
sql.append(" and rs.numsecuencia = (select max(numsecuencia) from ").append(schema).append("ruta_secuencia where activo = 1 and ruta_id = rs.ruta_id)) ");
|
|
sql.append(" union ");
|
|
sql.append(" (SELECT ");
|
|
sql.append(" p.parada_id,p.cveparada,rs.numsecuencia,rs.ruta_id ");
|
|
sql.append(" FROM ");
|
|
sql.append(" ").append(schema).append("ruta_secuencia rs ");
|
|
sql.append(" INNER JOIN ").append(schema).append("tramo t ON t.tramo_id = rs.tramo_id ");
|
|
sql.append(" INNER JOIN ").append(schema).append("parada p ON p.parada_id = t.origen_id ");
|
|
sql.append(" WHERE ");
|
|
sql.append(" rs.ruta_id = ").append(rutaId);
|
|
sql.append(" AND rs.activo = 1) ");
|
|
sql.append(" ) tmp2 on tmp2.parada_id = pd.parada_id ");
|
|
sql.append(" inner join ").append(schema).append("ruta r on r.ruta_id = rc.ruta_id ");
|
|
sql.append(" left join ").append(schema).append("tarifa ta on ta.TRAMO_ID = rc.tramo_id and ta.claseservicio_id = r.claseservicio_id and ta.MONEDA_ID = ").append(monedaId).append(" and ta.activo = 1 ");
|
|
sql.append(" where ");
|
|
sql.append(" rc.ruta_id = ").append(rutaId);
|
|
sql.append(" and rc.activo = 1 ");
|
|
sql.append(" and ta.MARCA_ID = ").append(marcaId);
|
|
sql.append(" and ta.VIGENCIATARIFA_ID = ").append(vigenciaId);
|
|
sql.append(" and ta.moneda_id = ").append(monedaId);
|
|
sql.append(" order by ruta.ruta_id ,tmp.numsecuencia,tmp2.numsecuencia ");
|
|
|
|
|
|
SQLQuery query = getSession().createSQLQuery(sql.toString());
|
|
query.setResultTransformer(new AliasToBeanResultTransformer(TarifaEscalaVO.class));
|
|
|
|
return query.list();
|
|
}
|
|
|
|
public List<TarifaOficialEscalaGroupVO> pesquisaTarifaOficialGroupObj(List<Moneda> lsMoneda, List<Marca> lsMarca, List<ClaseServicio> lsClaseServicio, List<Empresa> lsEmpresa, List<Ruta> lsRuta, List<VigenciaTarifa> lsVigenciaTarifa) {
|
|
|
|
StringBuilder sql = new StringBuilder(" ");
|
|
sql.append(" SELECT R.descruta,R.RUTA_ID,MON.moneda_id,M.MARCA_ID,mon.descmoneda, M.descmarca,CS.descclase ");
|
|
sql.append(" FROM ");
|
|
sql.append(" ").append(schema).append("RUTA_COMBINACION RC ");
|
|
sql.append(" inner join ").append(schema).append("RUTA R on (RC.RUTA_ID = R.RUTA_ID) ");
|
|
sql.append(" inner join ").append(schema).append("TRAMO TRA on (RC.TRAMO_ID = TRA.TRAMO_ID) ");
|
|
sql.append(" ,").append(schema).append("TARIFA_OFICIAL T ,").append(schema).append("RUTA_EMPRESA RE ");
|
|
sql.append(" ,").append(schema).append("MARCA M,").append(schema).append("MONEDA MON");//.append(schema).append("VIGENCIA_TARIFA VT ");
|
|
sql.append(" ,").append(schema).append("CLASE_SERVICIO CS , ").append(schema).append("PARADA ORI, ").append(schema).append("PARADA DES ");
|
|
sql.append(" WHERE T.activo = 1 AND RC.activo = 1 AND RE.activo = 1 AND R.activo = 1 ");
|
|
sql.append(" AND T.TRAMO_ID = TRA.TRAMO_ID ");
|
|
sql.append(" AND RC.RUTA_ID = RE.RUTA_ID ");
|
|
sql.append(" AND T.MARCA_ID = M.MARCA_ID ");
|
|
sql.append(" AND T.MONEDA_ID = MON.MONEDA_ID ");
|
|
// sql.append(" AND T.VIGENCIATARIFA_ID = VT.VIGENCIATARIFA_ID ");
|
|
sql.append(" AND T.CLASESERVICIO_ID = CS.CLASESERVICIO_ID ");
|
|
sql.append(" AND T.CLASESERVICIO_ID = R.CLASESERVICIO_ID ");
|
|
sql.append(" AND TRA.ORIGEN_ID = ORI.PARADA_ID ");
|
|
sql.append(" AND TRA.DESTINO_ID = DES.PARADA_ID ");
|
|
|
|
|
|
|
|
// if (!lsVigenciaTarifa.isEmpty()) {
|
|
// StringBuilder sb = new StringBuilder("");
|
|
// for (VigenciaTarifa vt : lsVigenciaTarifa) {
|
|
// sb.append(vt.getVigenciatarifaId()).append(",");
|
|
// }
|
|
// String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
// sql.append(" AND VT.VIGENCIATARIFA_ID in (").append(listInt).append(")");
|
|
// }
|
|
if (!lsEmpresa.isEmpty()) {
|
|
StringBuilder sb = new StringBuilder("");
|
|
for (Empresa vt : lsEmpresa) {
|
|
sb.append(vt.getEmpresaId()).append(",");
|
|
}
|
|
String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
sql.append(" AND RE.EMPRESA_ID in (").append(listInt).append(") ");
|
|
}
|
|
if (!lsRuta.isEmpty()) {
|
|
StringBuilder sb = new StringBuilder("");
|
|
for (Ruta vt : lsRuta) {
|
|
sb.append(vt.getRutaId()).append(",");
|
|
}
|
|
String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
sql.append(" AND RC.RUTA_ID in (").append(listInt).append(")");
|
|
}
|
|
if (!lsMarca.isEmpty()) {
|
|
StringBuilder sb = new StringBuilder("");
|
|
for (Marca vt : lsMarca) {
|
|
sb.append(vt.getMarcaId()).append(",");
|
|
}
|
|
String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
sql.append(" AND M.MARCA_ID in (").append(listInt).append(") ");
|
|
}
|
|
if (!lsMoneda.isEmpty()) {
|
|
StringBuilder sb = new StringBuilder("");
|
|
for (Moneda vt : lsMoneda) {
|
|
sb.append(vt.getMonedaId()).append(",");
|
|
}
|
|
String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
sql.append(" AND MON.MONEDA_ID in (").append(listInt).append(") ");
|
|
}
|
|
if (!lsClaseServicio.isEmpty()) {
|
|
StringBuilder sb = new StringBuilder("");
|
|
for (ClaseServicio cs : lsClaseServicio) {
|
|
sb.append(cs.getClaseservicioId()).append(",");
|
|
}
|
|
String listInt = sb.toString().substring(0, sb.toString().length() - 1);
|
|
sql.append(" AND CS.CLASESERVICIO_ID in (").append(listInt).append(") ");
|
|
}
|
|
|
|
sql.append(" GROUP by R.descruta,R.RUTA_ID,MON.moneda_id,M.MARCA_ID,mon.descmoneda, M.descmarca,CS.descclase ");
|
|
sql.append(" ORDER by R.descruta,R.RUTA_ID,MON.moneda_id,M.MARCA_ID");
|
|
|
|
SQLQuery query = getSession().createSQLQuery(sql.toString());
|
|
query.setResultTransformer(new AliasToBeanResultTransformer(TarifaOficialEscalaGroupVO.class));
|
|
|
|
return query.list();
|
|
}
|
|
|
|
public List<TarifaOficialEscalaVO> pesquisaTarifaOficialEscalaObj(String rutaId, String monedaId, String vigenciaId, String marcaId) {
|
|
|
|
StringBuilder sql = new StringBuilder(" ");
|
|
sql.append("select distinct po.cveparada as cveOrigem,po.descparada as descOrigem, ");
|
|
sql.append(" pd.cveparada as cveDestino,pd.descparada as descDestino,tmp.numsecuencia as NUMSECORIGEM,tmp2.numsecuencia as NUMSECDESTINO, ");
|
|
sql.append(" ta.PRECIO as precio,IMPORTETAXAEMBARQUE as TAXAEMBARQUE, IMPORTEPEDAGIO AS PEDAGIO,IMPORTEOUTROS AS OUTROS,IMPORTESEGURO AS SEGURO,ruta.ruta_id as rutaId,ruta.descruta as descruta ");
|
|
sql.append("from ");
|
|
sql.append(" ").append(schema).append("ruta_combinacion rc ");
|
|
sql.append(" inner join ").append(schema).append("ruta on (ruta.ruta_id = rc.ruta_id) ");
|
|
sql.append(" inner join ").append(schema).append("tramo t on t.tramo_id = rc.tramo_id ");
|
|
sql.append(" inner join ").append(schema).append("parada po on po.parada_id = t.origen_id ");
|
|
sql.append(" inner join ").append(schema).append("parada pd on pd.parada_id = t.destino_id ");
|
|
sql.append(" inner join ( ");
|
|
sql.append(" (SELECT ");
|
|
sql.append(" p.parada_id,p.cveparada,rs.numsecuencia+1 as numsecuencia,rs.ruta_id ");
|
|
sql.append(" FROM ");
|
|
sql.append(" ").append(schema).append("ruta_secuencia rs ");
|
|
sql.append(" INNER JOIN ").append(schema).append("tramo t ON t.tramo_id = rs.tramo_id ");
|
|
sql.append(" INNER JOIN ").append(schema).append("parada p ON p.parada_id = t.destino_id ");
|
|
sql.append(" WHERE ");
|
|
sql.append(" rs.ruta_id = ").append(rutaId);
|
|
sql.append(" AND rs.activo = 1 ");
|
|
sql.append(" and rownum =1 ");
|
|
sql.append(" and rs.numsecuencia = (select max(numsecuencia) from ").append(schema).append("ruta_secuencia where activo = 1 and ruta_id = rs.ruta_id)) ");
|
|
sql.append(" ");
|
|
sql.append(" union ");
|
|
|
|
sql.append(" (SELECT ");
|
|
sql.append(" p.parada_id,p.cveparada,rs.numsecuencia,rs.ruta_id ");
|
|
sql.append(" FROM ");
|
|
sql.append(" ").append(schema).append("ruta_secuencia rs ");
|
|
sql.append(" INNER JOIN ").append(schema).append("tramo t ON t.tramo_id = rs.tramo_id ");
|
|
sql.append(" INNER JOIN ").append(schema).append("parada p ON p.parada_id = t.origen_id ");
|
|
sql.append(" WHERE ");
|
|
sql.append(" rs.ruta_id = ").append(rutaId);
|
|
sql.append(" AND rs.activo = 1) ");
|
|
sql.append(" ) tmp on tmp.parada_id = po.parada_id ");
|
|
|
|
sql.append("left join ( ");
|
|
sql.append(" (SELECT ");
|
|
sql.append(" p.parada_id,p.cveparada,rs.numsecuencia+1 as numsecuencia,rs.ruta_id ");
|
|
sql.append(" FROM ");
|
|
sql.append(" ").append(schema).append("ruta_secuencia rs ");
|
|
sql.append(" INNER JOIN ").append(schema).append("tramo t ON t.tramo_id = rs.tramo_id ");
|
|
sql.append(" INNER JOIN ").append(schema).append("parada p ON p.parada_id = t.destino_id ");
|
|
sql.append(" WHERE ");
|
|
sql.append(" rs.ruta_id = ").append(rutaId);
|
|
sql.append(" AND rs.activo = 1 ");
|
|
sql.append(" and rs.numsecuencia = (select max(numsecuencia) from ").append(schema).append("ruta_secuencia where activo = 1 and ruta_id = rs.ruta_id)) ");
|
|
sql.append(" union ");
|
|
sql.append(" (SELECT ");
|
|
sql.append(" p.parada_id,p.cveparada,rs.numsecuencia,rs.ruta_id ");
|
|
sql.append(" FROM ");
|
|
sql.append(" ").append(schema).append("ruta_secuencia rs ");
|
|
sql.append(" INNER JOIN ").append(schema).append("tramo t ON t.tramo_id = rs.tramo_id ");
|
|
sql.append(" INNER JOIN ").append(schema).append("parada p ON p.parada_id = t.origen_id ");
|
|
sql.append(" WHERE ");
|
|
sql.append(" rs.ruta_id = ").append(rutaId);
|
|
sql.append(" AND rs.activo = 1) ");
|
|
sql.append(" ) tmp2 on tmp2.parada_id = pd.parada_id ");
|
|
sql.append(" inner join ").append(schema).append("ruta r on r.ruta_id = rc.ruta_id ");
|
|
sql.append(" left join ").append(schema).append("tarifa_oficial ta on ta.TRAMO_ID = rc.tramo_id and ta.claseservicio_id = r.claseservicio_id and ta.MONEDA_ID = ").append(monedaId).append(" and ta.activo = 1 ");
|
|
sql.append(" where ");
|
|
sql.append(" rc.ruta_id = ").append(rutaId);
|
|
sql.append(" and rc.activo = 1 ");
|
|
sql.append(" and ta.MARCA_ID = ").append(marcaId);
|
|
// sql.append(" and ta.VIGENCIATARIFA_ID = ").append(vigenciaId);
|
|
sql.append(" and ta.moneda_id = ").append(monedaId);
|
|
sql.append(" order by ruta.ruta_id ,tmp.numsecuencia,tmp2.numsecuencia ");
|
|
|
|
|
|
SQLQuery query = getSession().createSQLQuery(sql.toString());
|
|
query.setResultTransformer(new AliasToBeanResultTransformer(TarifaOficialEscalaVO.class));
|
|
|
|
return query.list();
|
|
}
|
|
|
|
}
|