194 lines
6.9 KiB
Java
194 lines
6.9 KiB
Java
/*
|
|
* To change this template, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
package com.rjconsultores.ventaboletos.dao.hibernate;
|
|
|
|
import java.util.List;
|
|
|
|
import org.apache.log4j.Logger;
|
|
import org.hibernate.Criteria;
|
|
import org.hibernate.Query;
|
|
import org.hibernate.SQLQuery;
|
|
import org.hibernate.Session;
|
|
import org.hibernate.SessionFactory;
|
|
import org.hibernate.criterion.Restrictions;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Qualifier;
|
|
import org.springframework.stereotype.Repository;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import com.rjconsultores.ventaboletos.dao.TarifaEmbarcadaDAO;
|
|
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.TarifaEmbarcada;
|
|
import com.rjconsultores.ventaboletos.entidad.Via;
|
|
import com.rjconsultores.ventaboletos.entidad.VigenciaTarifa;
|
|
import com.rjconsultores.ventaboletos.exception.BusinessException;
|
|
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
|
|
|
@Repository("tarifaEmbarcadaDAO")
|
|
public class TarifaEmbarcadaHibernateDAO extends GenericHibernateDAO<TarifaEmbarcada, Integer> implements TarifaEmbarcadaDAO {
|
|
|
|
private static Logger log = Logger.getLogger(TarifaEmbarcadaHibernateDAO.class);
|
|
|
|
@Autowired
|
|
public TarifaEmbarcadaHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
|
setSessionFactory(factory);
|
|
}
|
|
|
|
@SuppressWarnings("unchecked")
|
|
@Override
|
|
public List<TarifaEmbarcada> obtenerTodos() {
|
|
Criteria c = getSession().createCriteria(getPersistentClass());
|
|
c.add(Restrictions.eq("activo", Boolean.TRUE));
|
|
return c.list();
|
|
}
|
|
|
|
@Override
|
|
public void excluirTodasTarifas(Moneda moneda, Marca marca, ClaseServicio claseServicio, VigenciaTarifa vigenciaTarifa, Parada origem,
|
|
Parada destino, Ruta ruta, Via via, Boolean vende) {
|
|
StringBuilder hql = new StringBuilder();
|
|
hql.append(" update TarifaEmbarcada set activo = 0 where tarifaembarcadaId in (");
|
|
hql.append(" select t.tarifaembarcadaId from TarifaEmbarcada t ");
|
|
|
|
if (vende != null) {
|
|
hql.append(" inner join t.ruta.rutaCombinacionList AS rutaCombinacionList" );
|
|
}
|
|
|
|
hql.append(" where 0 = 0 ");
|
|
|
|
if (moneda != null) {
|
|
hql.append(" and t.moneda.monedaId = " + moneda.getMonedaId());
|
|
}
|
|
|
|
if (marca != null) {
|
|
hql.append(" and t.marca.marcaId = " + marca.getMarcaId());
|
|
}
|
|
|
|
if (claseServicio != null) {
|
|
hql.append(" and t.claseServicio.claseservicioId = " + claseServicio.getClaseservicioId());
|
|
}
|
|
|
|
if (vigenciaTarifa != null) {
|
|
hql.append(" and t.vigenciaTarifa.vigenciatarifaId = " + vigenciaTarifa.getVigenciatarifaId());
|
|
}
|
|
|
|
if (origem != null) {
|
|
hql.append(" and t.origen.paradaId = " + origem.getParadaId());
|
|
}
|
|
|
|
if (destino != null) {
|
|
hql.append(" and t.destino.paradaId = " + destino.getParadaId());
|
|
}
|
|
|
|
if (ruta != null) {
|
|
hql.append(" and t.ruta.rutaId = " + ruta.getRutaId());
|
|
}
|
|
|
|
if (via != null) {
|
|
hql.append(" and t.tramo.via.viaId = " + via.getViaId());
|
|
}
|
|
|
|
if (vende != null) {
|
|
hql.append(" and rutaCombinacionList.indventa = " + vende);
|
|
}
|
|
|
|
hql.append(")");
|
|
|
|
Query sq = getSession().createQuery(hql.toString());
|
|
sq.executeUpdate();
|
|
}
|
|
|
|
public void updateTarifa(TarifaEmbarcada entity) {
|
|
Session session = getSessionFactory().getCurrentSession();
|
|
session.update(entity);
|
|
}
|
|
|
|
@Override
|
|
@Transactional(rollbackFor = BusinessException.class)
|
|
public void copiarTarifas(VigenciaTarifa vigenciaTarifaOrigem, VigenciaTarifa vigenciaTarifaDestino, Empresa empresa, boolean excluirTarifasDestino) throws BusinessException {
|
|
try {
|
|
StringBuilder sQuery = null;
|
|
if (excluirTarifasDestino) {
|
|
sQuery = new StringBuilder("DELETE FROM TARIFA_EMBARCADA WHERE VIGENCIATARIFA_ID = :VIGENCIATARIFAID ");
|
|
SQLQuery qrUpdate = getSession().createSQLQuery(sQuery.toString());
|
|
qrUpdate.setParameter("VIGENCIATARIFAID", vigenciaTarifaDestino.getVigenciatarifaId());
|
|
qrUpdate.executeUpdate();
|
|
}
|
|
|
|
sQuery = new StringBuilder("INSERT INTO TARIFA_EMBARCADA( ");
|
|
sQuery.append("TARIFAEMBARCADA_ID,PRECIO,PRECIOREDABIERTO,TRAMO_ID,MARCA_ID,CLASESERVICIO_ID,PRECIOORIGINAL,MONEDA_ID,VIGENCIATARIFA_ID,STATUSTARIFA,ACTIVO,FECMODIF,")
|
|
.append("USUARIO_ID,IMPORTETAXAEMBARQUE,IMPORTEPEDAGIO,IMPORTEOUTROS,IMPORTESEGURO,ORGAOCONCEDENTE_ID,RUTA_ID,ORIGEN_ID,DESTINO_ID,IMPORTETPP) ")
|
|
.append(" SELECT "
|
|
+ "TARIFA_EMBARCADA_SEQ.NEXTVAL, "
|
|
+ "PRECIO, "
|
|
+ "PRECIOREDABIERTO, "
|
|
+ "TRAMO_ID, "
|
|
+ "tarifa.MARCA_ID, "
|
|
+ "CLASESERVICIO_ID, "
|
|
+ "PRECIOORIGINAL, "
|
|
+ "MONEDA_ID, "
|
|
+ ":VIGENCIATARIFAIDDESTINO, "
|
|
+ "STATUSTARIFA, "
|
|
+ "1, "
|
|
+ "sysdate, "
|
|
+ ":USUARIOID, "
|
|
+ "IMPORTETAXAEMBARQUE, "
|
|
+ "IMPORTEPEDAGIO, "
|
|
+ "IMPORTEOUTROS, "
|
|
+ "IMPORTESEGURO, "
|
|
+ "ORGAOCONCEDENTE_ID, "
|
|
+ "RUTA_ID, "
|
|
+ "ORIGEN_ID, "
|
|
+ "DESTINO_ID, "
|
|
+ "IMPORTETPP "
|
|
|
|
+ "FROM TARIFA_EMBARCADA tarifa "
|
|
+ "INNER JOIN MARCA marca ON marca.MARCA_ID = tarifa.MARCA_ID "
|
|
+ "WHERE tarifa.ACTIVO = 1 AND VIGENCIATARIFA_ID = :VIGENCIATARIFAIDORIGEM");
|
|
|
|
if (!excluirTarifasDestino) {
|
|
sQuery.append(" AND NOT EXISTS(SELECT"
|
|
+ " tDestino.TRAMO_ID,"
|
|
+ " tDestino.MARCA_ID,"
|
|
+ " tDestino.CLASESERVICIO_ID,"
|
|
+ " tDestino.MONEDA_ID,"
|
|
+ " tDestino.ORGAOCONCEDENTE_ID,"
|
|
+ " tDestino.RUTA_ID"
|
|
+ " FROM TARIFA_EMBARCADA tDestino"
|
|
+ " WHERE"
|
|
+ " tDestino.TRAMO_ID = tarifa.TRAMO_ID"
|
|
+ " AND tDestino.MARCA_ID = tarifa.MARCA_ID"
|
|
+ " AND tDestino.CLASESERVICIO_ID = tarifa.CLASESERVICIO_ID"
|
|
+ " AND tDestino.MONEDA_ID = tarifa.MONEDA_ID"
|
|
+ " AND tDestino.ORGAOCONCEDENTE_ID = tarifa.ORGAOCONCEDENTE_ID"
|
|
+ " AND tDestino.RUTA_ID = tarifa.RUTA_ID"
|
|
+ " AND tdestino.ACTIVO = 1"
|
|
+ " AND VIGENCIATARIFA_ID = :VIGENCIATARIFAIDDESTINO)");
|
|
}
|
|
|
|
if (empresa != null && empresa.getEmpresaId() != -1) {
|
|
sQuery.append(" AND marca.EMPRESA_ID = :EMPRESA_ID");
|
|
}
|
|
|
|
SQLQuery qrInsert = getSession().createSQLQuery(sQuery.toString());
|
|
qrInsert.setParameter("VIGENCIATARIFAIDORIGEM", vigenciaTarifaOrigem.getVigenciatarifaId());
|
|
qrInsert.setParameter("VIGENCIATARIFAIDDESTINO", vigenciaTarifaDestino.getVigenciatarifaId());
|
|
qrInsert.setParameter("USUARIOID", UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
|
|
|
if (empresa != null && empresa.getEmpresaId() != -1) {
|
|
qrInsert.setParameter("EMPRESA_ID", empresa.getEmpresaId());
|
|
}
|
|
qrInsert.executeUpdate();
|
|
|
|
} catch (Exception e) {
|
|
log.error(e.getMessage());
|
|
throw new BusinessException(e.getMessage(), e.getCause());
|
|
}
|
|
}
|
|
} |