143 lines
5.2 KiB
Java
143 lines
5.2 KiB
Java
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;
|
|
import org.springframework.stereotype.Repository;
|
|
|
|
import com.rjconsultores.ventaboletos.dao.TarifaOficialDAO;
|
|
import com.rjconsultores.ventaboletos.dao.sqlbuilder.SQLBuilder;
|
|
import com.rjconsultores.ventaboletos.entidad.TarifaOficial;
|
|
import com.rjconsultores.ventaboletos.entidad.VigenciaTarifa;
|
|
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
|
|
|
@Repository("tarifaOficialDAO")
|
|
public class TarifaOficialHibernateDAO extends GenericHibernateDAO<TarifaOficial, Integer> implements TarifaOficialDAO {
|
|
|
|
@Autowired
|
|
private SQLBuilder sqlBuilder;
|
|
|
|
@Autowired
|
|
public TarifaOficialHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
|
|
setSessionFactory(factory);
|
|
}
|
|
|
|
@Override
|
|
public Integer gerarTarifaPorCoeficiente(Integer rutaId, Integer usuarioId, Integer orgaoConcedenteId) {
|
|
|
|
String sql = sqlBuilder.getSQLGerarTarifaOficial(rutaId, usuarioId, orgaoConcedenteId);
|
|
|
|
int qtd = getSession().createSQLQuery(sql).executeUpdate();
|
|
|
|
return qtd;
|
|
}
|
|
|
|
@Override
|
|
public Integer atualizarTarifaCoeficiente(Integer rutaId, Integer usuarioId, Integer orgaoConcedenteId) {
|
|
|
|
String sql = sqlBuilder.getSQLAtualizarTarifaOficial(rutaId, usuarioId, orgaoConcedenteId);
|
|
|
|
int qtd = getSession().createSQLQuery(sql).executeUpdate();
|
|
|
|
return qtd;
|
|
}
|
|
|
|
@Override
|
|
public void copiarParaTarifa(VigenciaTarifa vigenciaTarifa, Integer usuarioId) {
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
sb.append("INSERT ");
|
|
sb.append("INTO ");
|
|
sb.append(" Tarifa ");
|
|
sb.append(" ( ");
|
|
sb.append(" precio, ");
|
|
sb.append(" precioredabierto, ");
|
|
sb.append(" tramo, ");
|
|
sb.append(" marca, ");
|
|
sb.append(" claseServicio, ");
|
|
sb.append(" preciooriginal, ");
|
|
sb.append(" moneda, ");
|
|
sb.append(" vigenciaTarifa, ");
|
|
sb.append(" statustarifa, ");
|
|
sb.append(" activo, ");
|
|
sb.append(" fecmodif, ");
|
|
sb.append(" usuarioId, ");
|
|
sb.append(" importetaxaembarque, ");
|
|
sb.append(" importepedagio, ");
|
|
sb.append(" importeoutros, ");
|
|
sb.append(" importeseguro, ");
|
|
sb.append(" orgaoConcedente, ");
|
|
sb.append(" ruta, ");
|
|
sb.append(" origen, ");
|
|
sb.append(" destino ");
|
|
sb.append(" ) ");
|
|
sb.append("SELECT ");
|
|
sb.append(" ");
|
|
sb.append(" to.precio, ");
|
|
sb.append(" to.precioredabierto, ");
|
|
sb.append(" to.tramo, ");
|
|
sb.append(" to.marca, ");
|
|
sb.append(" to.claseServicio, ");
|
|
sb.append(" to.preciooriginal, ");
|
|
sb.append(" to.moneda, ");
|
|
sb.append(" vt, ");
|
|
sb.append(" to.statustarifa, ");
|
|
sb.append(" to.activo, ");
|
|
sb.append(" current_timestamp(), ");
|
|
sb.append(" ").append(usuarioId).append(", ");
|
|
sb.append(" to.importetaxaembarque, ");
|
|
sb.append(" to.importepedagio, ");
|
|
sb.append(" to.importeoutros, ");
|
|
sb.append(" to.importeseguro, ");
|
|
sb.append(" to.orgaoConcedente, ");
|
|
sb.append(" to.ruta, ");
|
|
sb.append(" to.origen, ");
|
|
sb.append(" to.destino ");
|
|
sb.append("FROM ");
|
|
sb.append(" TarifaOficial to, ");
|
|
sb.append(" VigenciaTarifa vt ");
|
|
sb.append("WHERE ");
|
|
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.executeUpdate();
|
|
|
|
query = getSession().createQuery(sb.toString());
|
|
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();
|
|
}
|
|
|
|
@Override
|
|
public void atualizarSeguroPorKm(Integer rutaId, Integer orgaoId, Integer usuarioId) {
|
|
SQLQuery query = getSession().createSQLQuery(sqlBuilder.getSQLAtualizarSeguroPorKm(rutaId, usuarioId, orgaoId));
|
|
query.executeUpdate();
|
|
}
|
|
|
|
@Override
|
|
public void atualizarSeguroPorTarifa(Integer rutaId, Integer orgaoId, Integer usuarioId) {
|
|
SQLQuery query = getSession().createSQLQuery(sqlBuilder.getSQLAtualizarSeguroPorTarifa(rutaId, usuarioId, orgaoId));
|
|
query.executeUpdate();
|
|
}
|
|
} |