gleimar 2012-08-28 17:09:55 +00:00
parent 27ff85a7c5
commit 9d0b54f20e
14 changed files with 204 additions and 130 deletions

View File

@ -0,0 +1,13 @@
package com.rjconsultores.ventaboletos.dao;
import com.rjconsultores.ventaboletos.entidad.SeguroTarifa;
public interface SeguroTarifaDAO {
/**
* See {@link SeguroTarifa#atualizarSeguroPorTarifa(Integer, Integer, Integer)}
* @param rutaId
* @param orgaoId
* @param usuarioId
*/
public void atualizarSeguroPorTarifa(Integer rutaId, Integer orgaoId,Integer usuarioId);
}

View File

@ -29,4 +29,12 @@ public interface TarifaOficialDAO {
* @param usuarioId TODO
*/
public void copiarParaTarifa(VigenciaTarifa vigenciaTarifa, Integer usuarioId);
/**
* See {@link TarifaOficialService#atualizarTaxaEmbarque(Integer, Integer)}
* @param rutaId
* @param usuarioId TODO
* @param orgaoConcedenteId TODO
*/
public void atualizarTaxaEmbarque(Integer rutaId, Integer usuarioId, Integer orgaoConcedenteId);
}

View File

@ -1,12 +0,0 @@
package com.rjconsultores.ventaboletos.dao;
public interface TaxaEmbarqueDAO {
/**
* See {@link TaxaEmbarqueServic#atualizarTaxaEmbarque(Integer, Integer, Integer)}
* @param rutaId
* @param usuarioId TODO
* @param orgaoConcedenteId TODO
*/
public void atualizarTaxaEmbarque(Integer rutaId, Integer usuarioId, Integer orgaoConcedenteId);
}

View File

@ -0,0 +1,30 @@
package com.rjconsultores.ventaboletos.dao.hibernate;
import org.hibernate.SQLQuery;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import com.rjconsultores.ventaboletos.dao.SeguroTarifaDAO;
import com.rjconsultores.ventaboletos.dao.sqlbuilder.SQLBuilder;
import com.rjconsultores.ventaboletos.entidad.SeguroTarifa;
@Repository("seguroTarifaDAO")
public class SeguroTarifaHibernateDAO extends GenericHibernateDAO<SeguroTarifa, Integer> implements SeguroTarifaDAO {
@Autowired
private SQLBuilder sqlBuilder;
@Autowired
public SeguroTarifaHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
setSessionFactory(factory);
}
@Override
public void atualizarSeguroPorTarifa(Integer rutaId, Integer orgaoId, Integer usuarioId) {
SQLQuery query = getSession().createSQLQuery(sqlBuilder.getSQLAtualizarSeguroPorTarifa(rutaId, usuarioId, orgaoId));
query.executeUpdate();
}
}

View File

@ -1,6 +1,7 @@
package com.rjconsultores.ventaboletos.dao.hibernate;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@ -36,7 +37,7 @@ public class TarifaOficialHibernateDAO extends GenericHibernateDAO<TarifaOficial
@Override
public Integer atualizarTarifaCoeficiente(Integer rutaId, Integer usuarioId, Integer orgaoConcedenteId) {
String sql = sqlBuilder.getSQLAtualizarTarifaOficial(rutaId,usuarioId, orgaoConcedenteId);
String sql = sqlBuilder.getSQLAtualizarTarifaOficial(rutaId, usuarioId, orgaoConcedenteId);
int qtd = getSession().createSQLQuery(sql).executeUpdate();
@ -102,15 +103,29 @@ public class TarifaOficialHibernateDAO extends GenericHibernateDAO<TarifaOficial
sb.append(" to.activo =1 ");
sb.append(" and vt.vigenciatarifaId = :vigenciaId ");
Query query = getSession().createQuery("DELETE FROM Tarifa t where t.vigenciaTarifa = :vigencia");
query.setParameter("vigencia",vigenciaTarifa);
query.setParameter("vigencia", vigenciaTarifa);
query.executeUpdate();
query = getSession().createQuery(sb.toString());
query.setParameter("vigenciaId",vigenciaTarifa.getVigenciatarifaId());
query.setParameter("vigenciaId", vigenciaTarifa.getVigenciatarifaId());
query.executeUpdate();
}
@Override
public void atualizarTaxaEmbarque(Integer rutaId, Integer usuarioId, Integer orgaoConcedenteId) {
// Atualizo a taxa de embarque de acordo a parada e km
SQLQuery query = getSession().createSQLQuery(sqlBuilder.getAtualizarTaxaEmbarquePorKmParada(rutaId, usuarioId, orgaoConcedenteId));
query.executeUpdate();
// Atualizo a taxa de embarque de acordo a km do orgao
query = getSession().createSQLQuery(sqlBuilder.getSQLAtualizarTaxaEmbarquePorKmOrgao(rutaId, usuarioId, orgaoConcedenteId));
query.executeUpdate();
// Atualizo a taxa de embarque de acordo a parada e valor fixo
query = getSession().createSQLQuery(sqlBuilder.getSQLAtualizarTaxaEmbarquePorParadaFixo(rutaId, usuarioId, orgaoConcedenteId));
query.executeUpdate();
}
}

View File

@ -1,38 +0,0 @@
package com.rjconsultores.ventaboletos.dao.hibernate;
import org.hibernate.SQLQuery;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
import com.rjconsultores.ventaboletos.dao.TaxaEmbarqueDAO;
import com.rjconsultores.ventaboletos.dao.sqlbuilder.SQLBuilder;
@Repository("taxaEmbarqueDAO")
public class TaxaEmbarqueHibernateDAO extends GenericHibernateDAO<Object, Integer> implements TaxaEmbarqueDAO {
@Autowired
private SQLBuilder sqlBuilder;
@Autowired
public TaxaEmbarqueHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
setSessionFactory(factory);
}
@Override
public void atualizarTaxaEmbarque(Integer rutaId, Integer usuarioId, Integer orgaoConcedenteId) {
// Atualizo a taxa de embarque de acordo a parada e km
SQLQuery query = getSession().createSQLQuery(sqlBuilder.getAtualizarTaxaEmbarquePorKmParada(rutaId, usuarioId, orgaoConcedenteId));
query.executeUpdate();
// Atualizo a taxa de embarque de acordo a km do orgao
query = getSession().createSQLQuery(sqlBuilder.getSQLAtualizarTaxaEmbarquePorKmOrgao(rutaId, usuarioId, orgaoConcedenteId));
query.executeUpdate();
// Atualizo a taxa de embarque de acordo a parada e valor fixo
query = getSession().createSQLQuery(sqlBuilder.getSQLAtualizarTaxaEmbarquePorParadaFixo(rutaId, usuarioId, orgaoConcedenteId));
query.executeUpdate();
}
}

View File

@ -26,5 +26,7 @@ public interface SQLBuilder {
public String getSQLAtualizarSeguroPorKm(Integer rutaId, Integer usuarioId, Integer orgaoConcedenteId);
public String getSQLAtualizarSeguroPorTarifa(Integer rutaId, Integer usuarioId, Integer orgaoConcedenteId);
}

View File

@ -82,7 +82,7 @@ public class SQLBuilderOracle implements SQLBuilder {
sb.append(" and r.activo = 1 ");
sb.append(" and tc.activo = 1 ");
sb.append(" and m.moneda_id = 1 ");
if (orgaoConcedenteId != null){
if (orgaoConcedenteId != null) {
sb.append(" and oc.orgaoconcedente_id = ").append(orgaoConcedenteId);
}
sb.append(" and ");
@ -128,7 +128,7 @@ public class SQLBuilderOracle implements SQLBuilder {
sb.append(" and r.activo = 1 ");
sb.append(" and tc.activo = 1 ");
sb.append(" and m.moneda_id = 1 ");
if (orgaoConcedenteId != null){
if (orgaoConcedenteId != null) {
sb.append(" and oc.orgaoconcedente_id = ").append(orgaoConcedenteId);
}
sb.append(" and t.tramo_id = TARIFA_OFICIAL.tramo_id ");
@ -143,10 +143,10 @@ public class SQLBuilderOracle implements SQLBuilder {
sb.append(" ");
sb.append("where ");
sb.append(" activo = 1 ");
if (rutaId != null){
if (rutaId != null) {
sb.append(" and ruta_id = ").append(rutaId);
}
if (orgaoConcedenteId != null){
if (orgaoConcedenteId != null) {
sb.append(" and orgaoconcedente_id = ").append(orgaoConcedenteId);
}
@ -185,10 +185,10 @@ public class SQLBuilderOracle implements SQLBuilder {
sb.append(" ");
sb.append("where ");
sb.append(" tarifa_oficial.activo = 1 ");
if (rutaId != null){
if (rutaId != null) {
sb.append(" and tarifa_oficial.ruta_id = ").append(rutaId);
}
if (orgaoConcedenteId != null){
if (orgaoConcedenteId != null) {
sb.append(" and tarifa_oficial.orgaoconcedente_id = ").append(orgaoConcedenteId);
}
@ -229,11 +229,11 @@ public class SQLBuilderOracle implements SQLBuilder {
sb.append("where ");
sb.append(" tarifa_oficial.activo = 1 ");
if (rutaId != null){
if (rutaId != null) {
sb.append(" and tarifa_oficial.ruta_id = ").append(rutaId);
}
if (orgaoConcedenteId != null){
if (orgaoConcedenteId != null) {
sb.append(" and tarifa_oficial.orgaoconcedente_id = ").append(orgaoConcedenteId);
}
return sb.toString();
@ -265,10 +265,10 @@ public class SQLBuilderOracle implements SQLBuilder {
sb.append(" ");
sb.append("where ");
sb.append(" tarifa_oficial.activo = 1 ");
if (rutaId != null){
if (rutaId != null) {
sb.append(" and tarifa_oficial.ruta_id = ").append(rutaId);
}
if (orgaoConcedenteId != null){
if (orgaoConcedenteId != null) {
sb.append(" and tarifa_oficial.orgaoconcedente_id = ").append(orgaoConcedenteId);
}
return sb.toString();
@ -291,7 +291,7 @@ public class SQLBuilderOracle implements SQLBuilder {
sb.append(" from ");
sb.append(" seguro_km sk1 ");
sb.append(" where ");
sb.append(" sk1.KMATE >= t.CANTKMREAL and sk1.activo = 1 ");
sb.append(" sk1.KMATE >= t.CANTKMREAL and sk1.activo = 1 and tao.ORGAOCONCEDENTE_ID = sk1.ORGAOCONCEDENTE_ID ");
sb.append(" ) ");
sb.append(" and tao.marca_id = tarifa_oficial.marca_id ");
sb.append(" and tao.orgaoconcedente_id = tarifa_oficial.orgaoconcedente_id ");
@ -304,10 +304,50 @@ public class SQLBuilderOracle implements SQLBuilder {
sb.append(" ");
sb.append("where ");
sb.append(" tarifa_oficial.activo = 1 ");
if (rutaId != null){
if (rutaId != null) {
sb.append(" and tarifa_oficial.ruta_id = ").append(rutaId);
}
if (orgaoConcedenteId != null){
if (orgaoConcedenteId != null) {
sb.append(" and tarifa_oficial.orgaoconcedente_id = ").append(orgaoConcedenteId);
}
return sb.toString();
}
@Override
public String getSQLAtualizarSeguroPorTarifa(Integer rutaId, Integer usuarioId, Integer orgaoConcedenteId) {
StringBuilder sb = new StringBuilder("");
sb.append("update tarifa_oficial set IMPORTESEGURO = ");
sb.append("( ");
sb.append("select ");
sb.append(" st.VALORTAXA ");
sb.append("from ");
sb.append(" tarifa_oficial tao ");
sb.append(" inner join seguro_tarifa st on st.VALORTARIFAATE >= tao.precio and st.activo = 1 and tao.ORGAOCONCEDENTE_ID = st.ORGAOCONCEDENTE_ID ");
sb.append("where ");
sb.append(" st.VALORTARIFAATE= ");
sb.append(" (select min(st1.VALORTARIFAATE) ");
sb.append(" from ");
sb.append(" seguro_tarifa st1 ");
sb.append(" where ");
sb.append(" st1.VALORTARIFAATE >= tao.precio and st1.activo = 1 and tao.ORGAOCONCEDENTE_ID = st1.ORGAOCONCEDENTE_ID ");
sb.append(" ) ");
sb.append(" and tao.marca_id = tarifa_oficial.marca_id ");
sb.append(" and tao.orgaoconcedente_id = tarifa_oficial.orgaoconcedente_id ");
sb.append(" and tao.claseservicio_id=tarifa_oficial.claseservicio_id ");
sb.append(" and tao.moneda_id = tarifa_oficial.moneda_id ");
sb.append(" and tao.ruta_id = tarifa_oficial.ruta_id ");
sb.append(" and tao.tramo_id = tarifa_oficial.tramo_id ");
sb.append(") ");
sb.append(", usuario_id = ").append(usuarioId).append(",fecmodif = sysdate ");
sb.append(" ");
sb.append("where ");
sb.append(" tarifa_oficial.activo = 1 ");
if (rutaId != null) {
sb.append(" and tarifa_oficial.ruta_id = ").append(rutaId);
}
if (orgaoConcedenteId != null) {
sb.append(" and tarifa_oficial.orgaoconcedente_id = ").append(orgaoConcedenteId);
}

View File

@ -1,5 +1,16 @@
package com.rjconsultores.ventaboletos.service;
import com.rjconsultores.ventaboletos.exception.BusinessException;
public interface SeguroTarifaService {
/**
* Atualiza o seguro de acordo o valor da tarifa
*
* @param rutaId - Se informado, será filtrado pela ruta
* @param orgaoId -Campo obrigatório
*
*/
public void atualizarSeguroPorTarifa(Integer rutaId, Integer orgaoId) throws BusinessException;
}

View File

@ -50,4 +50,21 @@ public interface TarifaOficialService {
*/
public void copiarParaTarifa(VigenciaTarifa vigenciaTarifa);
/**
* Atualiza a taxa de embarque da entidade TarifaOficial.<br/>
*
* Para o cálculo, é usado a seguinte lógica:<br/>
* - Atualiza de acordo a tabela TAXA_EMBARQUE_PARADA por kilometragem<br/>
* - Atualiza de acordo a tabela TAXA_EMBARQUE por kilometragem<br/>
* - Atualiza de acordo a tabela TAXA_EMBARQUE_PARADA por valor fixo<br/>
*
* A sequencia acima indica a ordem de atualização da taxa de embarque.<br/>
*
* A taxa de embarque mais restritiva fica por último (TAXA_EMBARQUE_PARADA por valor fixo)
*
* @param rutaId - Se informado, será atualizado apenas a taxa de embarque da ruta informada
* @param orgaoConcedenteId TODO
*/
public void atualizarTaxaEmbarque(Integer rutaId, Integer orgaoConcedenteId);
}

View File

@ -1,22 +0,0 @@
package com.rjconsultores.ventaboletos.service;
public interface TaxaEmbarqueService {
/**
* Atualiza a taxa de embarque da entidade TarifaOficial.<br/>
*
* Para o cálculo, é usado a seguinte lógica:<br/>
* - Atualiza de acordo a tabela TAXA_EMBARQUE_PARADA por kilometragem<br/>
* - Atualiza de acordo a tabela TAXA_EMBARQUE por kilometragem<br/>
* - Atualiza de acordo a tabela TAXA_EMBARQUE_PARADA por valor fixo<br/>
*
* A sequencia acima indica a ordem de atualização da taxa de embarque.<br/>
*
* A taxa de embarque mais restritiva fica por último (TAXA_EMBARQUE_PARADA por valor fixo)
*
* @param rutaId - Se informado, será atualizado apenas a taxa de embarque da ruta informada
* @param orgaoConcedenteId TODO
*/
public void atualizarTaxaEmbarque(Integer rutaId, Integer orgaoConcedenteId);
}

View File

@ -0,0 +1,26 @@
package com.rjconsultores.ventaboletos.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.rjconsultores.ventaboletos.dao.SeguroTarifaDAO;
import com.rjconsultores.ventaboletos.exception.BusinessException;
import com.rjconsultores.ventaboletos.service.SeguroTarifaService;
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
@Service("seguroTarifaService")
public class SeguroTarifaServiceImpl implements SeguroTarifaService {
@Autowired
private SeguroTarifaDAO seguroTarifaDAO;
@Override
public void atualizarSeguroPorTarifa(Integer rutaId, Integer orgaoId) throws BusinessException {
if (orgaoId == null){
throw new BusinessException("SeguroServiceImpl.msg.validacion.orgaoObligatorio");
}
seguroTarifaDAO.atualizarSeguroPorTarifa(rutaId, orgaoId, UsuarioLogado.getUsuarioLogado().getUsuarioId());
}
}

View File

@ -43,4 +43,10 @@ public class TarifaOficialServiceImpl implements TarifaOficialService {
return qtd;
}
@Override
@Transactional
public void atualizarTaxaEmbarque(Integer rutaId, Integer orgaoConcedenteId) {
tarifaOficialDAO.atualizarTaxaEmbarque(rutaId, UsuarioLogado.getUsuarioLogado().getUsuarioId(), orgaoConcedenteId);
}
}

View File

@ -1,22 +0,0 @@
package com.rjconsultores.ventaboletos.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.rjconsultores.ventaboletos.dao.TaxaEmbarqueDAO;
import com.rjconsultores.ventaboletos.service.TaxaEmbarqueService;
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
@Service("taxaEmbarqueService")
public class TaxaEmbarqueServiceImpl implements TaxaEmbarqueService{
@Autowired
private TaxaEmbarqueDAO taxaEmbarqueDAO;
@Override
@Transactional
public void atualizarTaxaEmbarque(Integer rutaId, Integer orgaoConcedenteId) {
taxaEmbarqueDAO.atualizarTaxaEmbarque(rutaId, UsuarioLogado.getUsuarioLogado().getUsuarioId(), orgaoConcedenteId);
}
}