diff --git a/src/com/rjconsultores/ventaboletos/dao/TarifaOficialDAO.java b/src/com/rjconsultores/ventaboletos/dao/TarifaOficialDAO.java index d26a6d298..1a8d25124 100644 --- a/src/com/rjconsultores/ventaboletos/dao/TarifaOficialDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/TarifaOficialDAO.java @@ -1,5 +1,8 @@ package com.rjconsultores.ventaboletos.dao; +import java.util.List; + +import com.rjconsultores.ventaboletos.entidad.Ruta; import com.rjconsultores.ventaboletos.entidad.TarifaOficial; import com.rjconsultores.ventaboletos.entidad.VigenciaTarifa; import com.rjconsultores.ventaboletos.service.TarifaOficialService; @@ -45,7 +48,7 @@ public interface TarifaOficialDAO extends GenericDAO{ * @param orgaoConcedenteId TODO * @param empresaId TODO */ - public void atualizarTaxaEmbarque(Integer rutaId, Integer usuarioId, Integer orgaoConcedenteId, Integer empresaId); + public void atualizarTaxaEmbarque(List lsRuta, Integer usuarioId, Integer orgaoConcedenteId, Integer empresaId); /** * See {@link TarifaOficialService#atualizarSeguroPorKm(Integer, Integer, Integer)} diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/TarifaOficialHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/TarifaOficialHibernateDAO.java index 9cd5eb2e7..e41537141 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/TarifaOficialHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/TarifaOficialHibernateDAO.java @@ -16,6 +16,7 @@ import org.springframework.stereotype.Repository; import com.rjconsultores.ventaboletos.dao.TarifaOficialDAO; import com.rjconsultores.ventaboletos.dao.sqlbuilder.SQLBuilder; +import com.rjconsultores.ventaboletos.entidad.Ruta; import com.rjconsultores.ventaboletos.entidad.TarifaOficial; import com.rjconsultores.ventaboletos.entidad.VigenciaTarifa; @@ -136,19 +137,35 @@ public class TarifaOficialHibernateDAO extends GenericHibernateDAO lsRuta, Integer usuarioId, Integer orgaoConcedenteId, Integer empresaId) { - // Atualizo a taxa de embarque de acordo a parada e km - SQLQuery query = getSession().createSQLQuery(sqlBuilder.getAtualizarTaxaEmbarquePorKmParada(rutaId, usuarioId, orgaoConcedenteId, empresaId)); - query.executeUpdate(); + + int x = 0; + + if(lsRuta != null && !lsRuta.isEmpty()){ + x=lsRuta.size(); + } + + do{ + Integer rutaId = null ; + + if(lsRuta != null && !lsRuta.isEmpty()){ + rutaId = lsRuta.get(x-1).getRutaId(); + } + + // Atualizo a taxa de embarque de acordo a parada e km + SQLQuery query = getSession().createSQLQuery(sqlBuilder.getAtualizarTaxaEmbarquePorKmParada(rutaId, usuarioId, orgaoConcedenteId, empresaId)); + query.executeUpdate(); - // Atualizo a taxa de embarque de acordo a km do orgao - query = getSession().createSQLQuery(sqlBuilder.getSQLAtualizarTaxaEmbarquePorKmOrgao(rutaId, usuarioId, orgaoConcedenteId, empresaId)); - query.executeUpdate(); + // Atualizo a taxa de embarque de acordo a km do orgao + query = getSession().createSQLQuery(sqlBuilder.getSQLAtualizarTaxaEmbarquePorKmOrgao(rutaId, usuarioId, orgaoConcedenteId, empresaId)); + query.executeUpdate(); - // Atualizo a taxa de embarque de acordo a parada e valor fixo - query = getSession().createSQLQuery(sqlBuilder.getSQLAtualizarTaxaEmbarquePorParadaFixo(rutaId, usuarioId, orgaoConcedenteId, empresaId)); - query.executeUpdate(); + // Atualizo a taxa de embarque de acordo a parada e valor fixo + query = getSession().createSQLQuery(sqlBuilder.getSQLAtualizarTaxaEmbarquePorParadaFixo(rutaId, usuarioId, orgaoConcedenteId, empresaId)); + query.executeUpdate(); + x--; + }while(x > 0); } @Override diff --git a/src/com/rjconsultores/ventaboletos/service/TarifaOficialService.java b/src/com/rjconsultores/ventaboletos/service/TarifaOficialService.java index 4bad7ec48..ce3d21c71 100644 --- a/src/com/rjconsultores/ventaboletos/service/TarifaOficialService.java +++ b/src/com/rjconsultores/ventaboletos/service/TarifaOficialService.java @@ -1,6 +1,9 @@ package com.rjconsultores.ventaboletos.service; +import java.util.List; + import com.rjconsultores.ventaboletos.dao.TarifaOficialDAO; +import com.rjconsultores.ventaboletos.entidad.Ruta; import com.rjconsultores.ventaboletos.entidad.TarifaOficial; import com.rjconsultores.ventaboletos.entidad.VigenciaTarifa; import com.rjconsultores.ventaboletos.exception.BusinessException; @@ -56,7 +59,7 @@ public interface TarifaOficialService { * @param empresaId * @throws BusinessException */ - public void gerarAtualizarTarifa(Integer rudaId, Integer orgaoConcedenteId, Integer empresaId) throws BusinessException ; + public void gerarAtualizarTarifa(List lsRuta, Integer orgaoConcedenteId, Integer empresaId) throws BusinessException ; /** * Copia a tarifa oficial para a tabela de tarifa de acordo com a vigencia especificada.
@@ -85,7 +88,7 @@ public interface TarifaOficialService { * @param empresaId - Empresa para ser filtrada * @throws BusinessException */ - public void atualizarTaxaEmbarque(Integer rutaId, Integer orgaoConcedenteId,boolean gerarTabelaZerada, Integer empresaId) throws BusinessException; + public void atualizarTaxaEmbarque(List lsRuta, Integer orgaoConcedenteId,boolean gerarTabelaZerada, Integer empresaId) throws BusinessException; /** @@ -113,7 +116,7 @@ public interface TarifaOficialService { * @param orgaoId-Se informado, será filtrado pelo orgão * @throws BusinessException */ - public void atualizarSeguro(Integer rutaId, Integer orgaoId) throws BusinessException; + public void atualizarSeguro(List lsRuta, Integer orgaoId) throws BusinessException; /** * See {@link TarifaOficialDAO#aplicarArredondamentoTarifa(Integer, Integer)} @@ -127,7 +130,7 @@ public interface TarifaOficialService { public void borrar(TarifaOficial tarifaOficial); - public void gerarAtualizarTabelaZerada(Integer rudaId, Integer orgaoConcedenteId, Integer empresaId) throws BusinessException ; + public void gerarAtualizarTabelaZerada(List lsRuta, Integer orgaoConcedenteId, Integer empresaId) throws BusinessException ; public void atualizarPedagio(); diff --git a/src/com/rjconsultores/ventaboletos/service/impl/TarifaOficialServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/TarifaOficialServiceImpl.java index 08943ba84..26f75d664 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/TarifaOficialServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/TarifaOficialServiceImpl.java @@ -14,6 +14,7 @@ import com.rjconsultores.ventaboletos.dao.SeguroKmDAO; import com.rjconsultores.ventaboletos.dao.SeguroTarifaDAO; import com.rjconsultores.ventaboletos.dao.TarifaOficialDAO; import com.rjconsultores.ventaboletos.entidad.OrgaoConcedente; +import com.rjconsultores.ventaboletos.entidad.Ruta; import com.rjconsultores.ventaboletos.entidad.TarifaOficial; import com.rjconsultores.ventaboletos.entidad.VigenciaTarifa; import com.rjconsultores.ventaboletos.exception.BusinessException; @@ -54,45 +55,74 @@ public class TarifaOficialServiceImpl implements TarifaOficialService { @Override @Transactional(rollbackFor = BusinessException.class) - public void gerarAtualizarTarifa(Integer rutaId, Integer orgaoConcedenteId, Integer empresaId) throws BusinessException { - log.info("gerarAtualizarTarifa= rudaId:"+rutaId+";orgaoConcedenteId:"+orgaoConcedenteId+";empresaId:"+empresaId); + public void gerarAtualizarTarifa(List lsRuta, Integer orgaoConcedenteId, Integer empresaId) throws BusinessException { // Limpando a tabela de TARIFA_OFICIAL tarifaOficialDAO.limparTarifasOficiais(); - //Gerando as tarifas pelo coeficiente - if(orgaoConcedenteId ==null || orgaoConcedenteId != OrgaoConcedente.CODIGO_ARTESP){ - Integer qtdTarifaCoeficiente = gerarTarifaPorCoeficiente(rutaId, orgaoConcedenteId, empresaId); - log.info("qtdTarifaCoeficiente="+qtdTarifaCoeficiente); + int x = 0; + if(lsRuta != null && !lsRuta.isEmpty()){ + x = lsRuta.size(); } - //Gerando as tarifas para ARTESP - if(orgaoConcedenteId ==null || orgaoConcedenteId == OrgaoConcedente.CODIGO_ARTESP ){ - Integer qtdTarifaArtesp = tarifaOficialDAO.gerarTarifaArtesp(rutaId, UsuarioLogado.getUsuarioLogado().getUsuarioId(), orgaoConcedenteId, empresaId); - log.info("qtdTarifaArtesp="+qtdTarifaArtesp); - } + do{ + Integer rutaId = null; + if(lsRuta != null && !lsRuta.isEmpty()){ + Ruta r = lsRuta.get(x-1); + rutaId = r.getRutaId(); + } + + log.info("gerarAtualizarTarifa= rudaId:"+rutaId+";orgaoConcedenteId:"+orgaoConcedenteId+";empresaId:"+empresaId); + + //Gerando as tarifas pelo coeficiente + if(orgaoConcedenteId ==null || orgaoConcedenteId != OrgaoConcedente.CODIGO_ARTESP){ + Integer qtdTarifaCoeficiente = gerarTarifaPorCoeficiente(rutaId, orgaoConcedenteId, empresaId); + log.info("qtdTarifaCoeficiente="+qtdTarifaCoeficiente); + } + + //Gerando as tarifas para ARTESP + if(orgaoConcedenteId ==null || orgaoConcedenteId == OrgaoConcedente.CODIGO_ARTESP ){ + Integer qtdTarifaArtesp = tarifaOficialDAO.gerarTarifaArtesp(rutaId, UsuarioLogado.getUsuarioLogado().getUsuarioId(), orgaoConcedenteId, empresaId); + log.info("qtdTarifaArtesp="+qtdTarifaArtesp); + } + x--; + }while(x > 0); } @Override @Transactional(rollbackFor = BusinessException.class) - public void gerarAtualizarTabelaZerada(Integer rutaId, Integer orgaoConcedenteId, Integer empresaId) throws BusinessException { + public void gerarAtualizarTabelaZerada(List lsRuta, Integer orgaoConcedenteId, Integer empresaId) throws BusinessException { // Limpando a tabela de TARIFA_OFICIAL tarifaOficialDAO.limparTarifasOficiais(); - //Gerando as tarifas - tarifaOficialDAO.gerarTabelaZerada(rutaId, UsuarioLogado.getUsuarioLogado().getUsuarioId(), orgaoConcedenteId, empresaId); - + + int x =0; + if(lsRuta != null && !lsRuta.isEmpty()){ + x = lsRuta.size(); + } + + do{ + Integer rutaId =null; + if(lsRuta != null && !lsRuta.isEmpty()){ + rutaId = lsRuta.get(x-1).getRutaId(); + } + + //Gerando as tarifas + tarifaOficialDAO.gerarTabelaZerada(rutaId, UsuarioLogado.getUsuarioLogado().getUsuarioId(), orgaoConcedenteId, empresaId); + + x--; + }while(x > 0); } @Override @Transactional(rollbackFor = BusinessException.class) - public void atualizarTaxaEmbarque(Integer rutaId, Integer orgaoConcedenteId,boolean gerarTabelaZerada, Integer empresaId) throws BusinessException{ + public void atualizarTaxaEmbarque(List lsRuta, Integer orgaoConcedenteId,boolean gerarTabelaZerada, Integer empresaId) throws BusinessException{ if (gerarTabelaZerada){ - gerarAtualizarTabelaZerada(rutaId, orgaoConcedenteId, empresaId); + gerarAtualizarTabelaZerada(lsRuta, orgaoConcedenteId, empresaId); } - tarifaOficialDAO.atualizarTaxaEmbarque(rutaId, UsuarioLogado.getUsuarioLogado().getUsuarioId(), orgaoConcedenteId, empresaId); + tarifaOficialDAO.atualizarTaxaEmbarque(lsRuta, UsuarioLogado.getUsuarioLogado().getUsuarioId(), orgaoConcedenteId, empresaId); } - + @Override @Transactional(rollbackFor = BusinessException.class) public void atualizarSeguroPorKm(Integer rutaId, Integer orgaoId) throws BusinessException { @@ -109,7 +139,7 @@ public class TarifaOficialServiceImpl implements TarifaOficialService { @Override @Transactional(rollbackFor = BusinessException.class) - public void atualizarSeguro(Integer rutaId, Integer orgaoId) throws BusinessException { + public void atualizarSeguro(List lsRuta, Integer orgaoId) throws BusinessException { List lsOrgaoId = new ArrayList(); @@ -119,14 +149,26 @@ public class TarifaOficialServiceImpl implements TarifaOficialService { lsOrgaoId.add(orgaoId); } - //O seguro por km é preferencial em relação ao por tarifa. - for (Integer orgaoConcedenteId : lsOrgaoId) { - if (seguroKmDAO.existe(orgaoConcedenteId)) { - atualizarSeguroPorKm(rutaId, orgaoConcedenteId); - } else if (seguroTarifaDAO.existe(orgaoConcedenteId)) { - atualizarSeguroPorTarifa(rutaId, orgaoConcedenteId); - } + int x = 0; + if(lsRuta != null && !lsRuta.isEmpty()){ + x = lsRuta.size(); } + + do{ + Integer rutaId = null; + if(lsRuta != null && !lsRuta.isEmpty()){ + rutaId = lsRuta.get(x-1).getRutaId(); + } + //O seguro por km é preferencial em relação ao por tarifa. + for (Integer orgaoConcedenteId : lsOrgaoId) { + if (seguroKmDAO.existe(orgaoConcedenteId)) { + atualizarSeguroPorKm(rutaId, orgaoConcedenteId); + } else if (seguroTarifaDAO.existe(orgaoConcedenteId)) { + atualizarSeguroPorTarifa(rutaId, orgaoConcedenteId); + } + } + x--; + }while(x > 0); } @Override