wilian 2015-02-02 13:01:35 +00:00
parent 4e1e3022b0
commit 4e285555ac
4 changed files with 75 additions and 4 deletions

View File

@ -17,6 +17,7 @@ import com.rjconsultores.ventaboletos.entidad.Tarifa;
import com.rjconsultores.ventaboletos.entidad.TipoPuntoVenta;
import com.rjconsultores.ventaboletos.entidad.Tramo;
import com.rjconsultores.ventaboletos.entidad.VigenciaTarifa;
import com.rjconsultores.ventaboletos.exception.BusinessException;
import com.rjconsultores.ventaboletos.service.TarifaService;
/**
@ -64,4 +65,9 @@ public interface TarifaDAO extends GenericDAO<Tarifa, Integer> {
public List<Tarifa> buscarTarifasAtivasPorVigencia(VigenciaTarifa vigenciaTarifa);
public boolean buscarTarifaExisteTramo(Tramo tramo) ;
public void copiarTarifas(VigenciaTarifa vigenciaTarifaOrigem, VigenciaTarifa vigenciaTarifaDestino, boolean excluirTarifasDestino) throws BusinessException;
public boolean existeTarifas(VigenciaTarifa vigenciaTarifa);
}

View File

@ -7,15 +7,18 @@ package com.rjconsultores.ventaboletos.dao.hibernate;
import java.util.List;
import org.apache.commons.lang.Validate;
import org.apache.cxf.BusException;
import org.apache.log4j.Logger;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Projections;
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.RutaDAO;
import com.rjconsultores.ventaboletos.dao.TarifaDAO;
@ -31,6 +34,8 @@ import com.rjconsultores.ventaboletos.entidad.Tarifa;
import com.rjconsultores.ventaboletos.entidad.TipoPuntoVenta;
import com.rjconsultores.ventaboletos.entidad.Tramo;
import com.rjconsultores.ventaboletos.entidad.VigenciaTarifa;
import com.rjconsultores.ventaboletos.exception.BusinessException;
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
/**
*
@ -173,4 +178,47 @@ public class TarifaHibernateDAO extends GenericHibernateDAO<Tarifa, Integer> imp
return (HibernateFix.count(c.list()) > 0);
}
@Override
@Transactional(rollbackFor = BusinessException.class)
public void copiarTarifas(VigenciaTarifa vigenciaTarifaOrigem, VigenciaTarifa vigenciaTarifaDestino, boolean excluirTarifasDestino) throws BusinessException {
try {
StringBuilder sQuery = null;
if(excluirTarifasDestino) {
sQuery = new StringBuilder("DELETE FROM TARIFA WHERE VIGENCIATARIFA_ID = :VIGENCIATARIFAID ");
SQLQuery qrUpdate = getSession().createSQLQuery(sQuery.toString());
qrUpdate.setParameter("VIGENCIATARIFAID", vigenciaTarifaDestino.getVigenciatarifaId());
qrUpdate.executeUpdate();
}
sQuery = new StringBuilder("INSERT INTO TARIFA( ");
sQuery.append("TARIFA_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) ")
.append("SELECT ")
.append("TARIFA_SEQ.NEXTVAL,PRECIO,PRECIOREDABIERTO,TRAMO_ID,MARCA_ID,CLASESERVICIO_ID,PRECIOORIGINAL,MONEDA_ID,:VIGENCIATARIFAIDDESTINO,STATUSTARIFA,1,sysdate,")
.append(":USUARIOID,IMPORTETAXAEMBARQUE,IMPORTEPEDAGIO,IMPORTEOUTROS,IMPORTESEGURO,ORGAOCONCEDENTE_ID,RUTA_ID,ORIGEN_ID,DESTINO_ID ")
.append("FROM TARIFA ")
.append("WHERE ACTIVO = 1 ")
.append("AND VIGENCIATARIFA_ID = :VIGENCIATARIFAIDORIGEM ");
SQLQuery qrInsert = getSession().createSQLQuery(sQuery.toString());
qrInsert.setParameter("VIGENCIATARIFAIDORIGEM", vigenciaTarifaOrigem.getVigenciatarifaId());
qrInsert.setParameter("VIGENCIATARIFAIDDESTINO", vigenciaTarifaDestino.getVigenciatarifaId());
qrInsert.setParameter("USUARIOID", UsuarioLogado.getUsuarioLogado().getUsuarioId());
qrInsert.executeUpdate();
} catch (Exception e) {
log.error(e.getMessage());
throw new BusinessException(e.getMessage(), e.getCause());
}
}
@Override
public boolean existeTarifas(VigenciaTarifa vigenciaTarifa) {
Criteria c = getSession().createCriteria(getPersistentClass());
c.add(Restrictions.eq("activo", Boolean.TRUE));
c.add(Restrictions.eq("vigenciaTarifa", vigenciaTarifa));
c.setProjection(Projections.rowCount());
return (HibernateFix.count(c.list()) > 0);
}
}

View File

@ -18,6 +18,7 @@ import com.rjconsultores.ventaboletos.entidad.Tarifa;
import com.rjconsultores.ventaboletos.entidad.TipoPuntoVenta;
import com.rjconsultores.ventaboletos.entidad.Tramo;
import com.rjconsultores.ventaboletos.entidad.VigenciaTarifa;
import com.rjconsultores.ventaboletos.exception.BusinessException;
/**
*
@ -55,4 +56,9 @@ public interface TarifaService extends GenericService<Tarifa, Integer> {
public Boolean generarTarifas(VigenciaTarifa vigencia, Marca marca);
public boolean buscarTarifaExisteTramo(Tramo tramo);
public void copiarTarifas(VigenciaTarifa vigenciaTarifaOrigem, VigenciaTarifa vigenciaTarifaDestino, boolean excluirTarifasDestino) throws BusinessException;
public boolean existeTarifas(VigenciaTarifa vigenciaTarifa);
}

View File

@ -4,23 +4,24 @@
*/
package com.rjconsultores.ventaboletos.service.impl;
import com.rjconsultores.ventaboletos.entidad.Plaza;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Calendar;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.rjconsultores.ventaboletos.dao.TarifaDAO;
import com.rjconsultores.ventaboletos.entidad.Categoria;
import com.rjconsultores.ventaboletos.entidad.ClaseServicio;
import com.rjconsultores.ventaboletos.entidad.Constante;
import com.rjconsultores.ventaboletos.entidad.Empresa;
import com.rjconsultores.ventaboletos.entidad.Marca;
import com.rjconsultores.ventaboletos.entidad.Moneda;
import com.rjconsultores.ventaboletos.entidad.OrgaoConcedente;
import com.rjconsultores.ventaboletos.entidad.Parada;
import com.rjconsultores.ventaboletos.entidad.Plaza;
import com.rjconsultores.ventaboletos.entidad.Ruta;
import com.rjconsultores.ventaboletos.entidad.RutaCombinacion;
import com.rjconsultores.ventaboletos.entidad.Tarifa;
@ -31,6 +32,7 @@ import com.rjconsultores.ventaboletos.entidad.TarifaTipoptovta;
import com.rjconsultores.ventaboletos.entidad.TipoPuntoVenta;
import com.rjconsultores.ventaboletos.entidad.Tramo;
import com.rjconsultores.ventaboletos.entidad.VigenciaTarifa;
import com.rjconsultores.ventaboletos.exception.BusinessException;
import com.rjconsultores.ventaboletos.service.ConstanteService;
import com.rjconsultores.ventaboletos.service.MonedaService;
import com.rjconsultores.ventaboletos.service.ParadaService;
@ -39,7 +41,6 @@ import com.rjconsultores.ventaboletos.service.TarifaHistService;
import com.rjconsultores.ventaboletos.service.TarifaMinimaService;
import com.rjconsultores.ventaboletos.service.TarifaService;
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
import org.apache.log4j.Logger;
/**
*
@ -268,4 +269,14 @@ public class TarifaServiceImpl implements TarifaService {
public boolean buscarTarifaExisteTramo(Tramo tramo) {
return tarifaDAO.buscarTarifaExisteTramo(tramo);
}
@Override
public void copiarTarifas(VigenciaTarifa vigenciaTarifaOrigem, VigenciaTarifa vigenciaTarifaDestino, boolean excluirTarifasDestino) throws BusinessException {
tarifaDAO.copiarTarifas(vigenciaTarifaOrigem, vigenciaTarifaDestino, excluirTarifasDestino);
}
@Override
public boolean existeTarifas(VigenciaTarifa vigenciaTarifa) {
return tarifaDAO.existeTarifas(vigenciaTarifa);
}
}