diff --git a/src/com/rjconsultores/ventaboletos/dao/TarifaDAO.java b/src/com/rjconsultores/ventaboletos/dao/TarifaDAO.java index 698a2de71..3a8047f66 100644 --- a/src/com/rjconsultores/ventaboletos/dao/TarifaDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/TarifaDAO.java @@ -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 { public List buscarTarifasAtivasPorVigencia(VigenciaTarifa vigenciaTarifa); public boolean buscarTarifaExisteTramo(Tramo tramo) ; + + public void copiarTarifas(VigenciaTarifa vigenciaTarifaOrigem, VigenciaTarifa vigenciaTarifaDestino, boolean excluirTarifasDestino) throws BusinessException; + + public boolean existeTarifas(VigenciaTarifa vigenciaTarifa); + } diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/TarifaHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/TarifaHibernateDAO.java index 14265804f..76c1525ee 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/TarifaHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/TarifaHibernateDAO.java @@ -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 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); + } } diff --git a/src/com/rjconsultores/ventaboletos/service/TarifaService.java b/src/com/rjconsultores/ventaboletos/service/TarifaService.java index f1efe5ea7..b2be78cec 100644 --- a/src/com/rjconsultores/ventaboletos/service/TarifaService.java +++ b/src/com/rjconsultores/ventaboletos/service/TarifaService.java @@ -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 { 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); + } diff --git a/src/com/rjconsultores/ventaboletos/service/impl/TarifaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/TarifaServiceImpl.java index 2894219bb..7c296eb9a 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/TarifaServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/TarifaServiceImpl.java @@ -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); + } }