gleimar 2012-08-27 19:15:57 +00:00
parent 3d691abc26
commit bd16c14bee
8 changed files with 209 additions and 24 deletions

View File

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

View File

@ -0,0 +1,38 @@
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) {
// Atualizo a taxa de embarque de acordo a parada e km
SQLQuery query = getSession().createSQLQuery(sqlBuilder.getSQLTaxaEmbarque1(rutaId, usuarioId));
query.executeUpdate();
// Atualizo a taxa de embarque de acordo a km do orgao
query = getSession().createSQLQuery(sqlBuilder.getSQLTaxaEmbarque2(rutaId, usuarioId));
query.executeUpdate();
// Atualizo a taxa de embarque de acordo a parada e valor fixo
query = getSession().createSQLQuery(sqlBuilder.getSQLTaxaEmbarque3(rutaId, usuarioId));
query.executeUpdate();
}
}

View File

@ -18,4 +18,8 @@ public interface SQLBuilder {
public String getSQLTarifaOficial2(Integer rutaId, Integer usuarioId); public String getSQLTarifaOficial2(Integer rutaId, Integer usuarioId);
public String getSQLTaxaEmbarque1(Integer rutaId, Integer usuarioId);
public String getSQLTaxaEmbarque2(Integer rutaId, Integer usuarioId);
public String getSQLTaxaEmbarque3(Integer rutaId, Integer usuarioId);
} }

View File

@ -3,7 +3,6 @@ package com.rjconsultores.ventaboletos.dao.sqlbuilder;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.rjconsultores.ventaboletos.dao.sqlbuilder.impl.SQLBuilderOracle; import com.rjconsultores.ventaboletos.dao.sqlbuilder.impl.SQLBuilderOracle;
import com.rjconsultores.ventaboletos.dao.sqlbuilder.impl.SQLBuilderSQLServer;
import com.rjconsultores.ventaboletos.dao.util.DBUtil; import com.rjconsultores.ventaboletos.dao.util.DBUtil;
public class SQLFactory { public class SQLFactory {
@ -13,12 +12,7 @@ public class SQLFactory {
if (DBUtil.getInstance().isOracle()) { if (DBUtil.getInstance().isOracle()) {
return new SQLBuilderOracle(); return new SQLBuilderOracle();
} }
if (DBUtil.getInstance().isSQLServer()) {
return new SQLBuilderSQLServer(); throw new RuntimeException("Não foi localizado a classe que traduz SQL Nativos");
}
log.error("Não foi identificado a base de dados");
return new SQLBuilderOracle();
} }
} }

View File

@ -147,4 +147,115 @@ public class SQLBuilderOracle implements SQLBuilder {
return sb.toString(); return sb.toString();
} }
@Override
public String getSQLTaxaEmbarque1(Integer rutaId, Integer usuarioId) {
StringBuilder sb = new StringBuilder("");
sb.append("update tarifa_oficial set IMPORTETAXAEMBARQUE = ");
sb.append("( ");
sb.append("select ");
sb.append(" tepKm.valorTaxa ");
sb.append(" ");
sb.append(" ");
sb.append("from ");
sb.append(" tarifa_oficial tao ");
sb.append(" inner join tramo t on t.tramo_id = tao.tramo_id ");
sb.append(" inner join TAXA_EMBARQUE_PARADA tepKm on tepKm.parada_id = t.origen_id and tepKm.KMATE >= t.CANTKMREAL and tepKm.activo = 1 and tepKm.indtipo = 'K' ");
sb.append("where ");
sb.append(" tepKm.kmate= ");
sb.append(" (select min(tepKm1.KMATE) ");
sb.append(" from ");
sb.append(" TAXA_EMBARQUE_PARADA tepKm1 ");
sb.append(" where ");
sb.append(" tepKm1.parada_id = t.origen_id and tepKm1.KMATE >= t.CANTKMREAL and tepKm.activo = 1 ");
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);
}
return sb.toString();
}
@Override
public String getSQLTaxaEmbarque2(Integer rutaId, Integer usuarioId) {
StringBuilder sb = new StringBuilder("");
sb.append("update tarifa_oficial set IMPORTETAXAEMBARQUE = ");
sb.append("coalesce( ");
sb.append("( ");
sb.append("select ");
sb.append(" tek.valorTaxa ");
sb.append(" ");
sb.append("from ");
sb.append(" tarifa_oficial tao ");
sb.append(" inner join tramo t on t.tramo_id = tao.tramo_id ");
sb.append(" inner join taxa_embarque_km tek on tek.orgaoconcedente_id = tao.ORGAOCONCEDENTE_ID and tek.activo = 1 and t.CANTKMREAL <= tek.kmate ");
sb.append("where ");
sb.append(" tek.kmate= ");
sb.append(" (select min(tek1.KMATE) ");
sb.append(" from ");
sb.append(" taxa_embarque_km tek1 ");
sb.append(" where ");
sb.append(" tek1.orgaoconcedente_id = tao.ORGAOCONCEDENTE_ID and t.CANTKMREAL <= tek1.kmate and tek1.activo = 1 ");
sb.append(" ) ");
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("),IMPORTETAXAEMBARQUE) ");
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);
}
return sb.toString();
}
@Override
public String getSQLTaxaEmbarque3(Integer rutaId, Integer usuarioId) {
StringBuilder sb = new StringBuilder("");
sb.append("update tarifa_oficial set IMPORTETAXAEMBARQUE = ");
sb.append("coalesce( ");
sb.append("( ");
sb.append("select ");
sb.append(" tepFixo.valorTaxa ");
sb.append(" ");
sb.append("from ");
sb.append(" tarifa_oficial tao ");
sb.append(" inner join tramo t on t.tramo_id = tao.tramo_id ");
sb.append(" inner join TAXA_EMBARQUE_PARADA tepFixo on tepFixo.parada_id = t.origen_id and tepFixo.indtipo = 'F' and tepFixo.activo = 1 ");
sb.append("where ");
sb.append(" 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("),IMPORTETAXAEMBARQUE) ");
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);
}
return sb.toString();
}
} }

View File

@ -1,16 +0,0 @@
package com.rjconsultores.ventaboletos.dao.sqlbuilder.impl;
import com.rjconsultores.ventaboletos.dao.sqlbuilder.SQLBuilder;
public class SQLBuilderSQLServer implements SQLBuilder {
@Override
public String getSQLTarifaOficial1(Integer codRuta, Integer usuarioId) {
throw new RuntimeException("SQL getSQLTarifaOficial1 não implementado");
}
@Override
public String getSQLTarifaOficial2(Integer rutaId, Integer usuarioId) {
throw new RuntimeException("SQL getSQLTarifaOficial2 não implementado");
}
}

View File

@ -0,0 +1,21 @@
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
*/
public void atualizarTaxaEmbarque(Integer rutaId);
}

View File

@ -0,0 +1,22 @@
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) {
taxaEmbarqueDAO.atualizarTaxaEmbarque(rutaId, UsuarioLogado.getUsuarioLogado().getUsuarioId());
}
}