111 lines
4.3 KiB
Java
111 lines
4.3 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;
|
|
|
|
@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;
|
|
}
|
|
|
|
public void limparTarifasOficiais() {
|
|
Query query = getSession().createQuery("DELETE FROM TarifaOficial");
|
|
query.executeUpdate();
|
|
}
|
|
|
|
@Override
|
|
public void copiarParaTarifa(VigenciaTarifa vigenciaTarifa, Integer usuarioId, Boolean calculaPegagio) {
|
|
|
|
|
|
// Insiro as tarifas que não existem
|
|
SQLQuery querySQL = getSession().createSQLQuery(sqlBuilder.getSQLInserirTarifaPelaTarifaOficial(vigenciaTarifa.getVigenciatarifaId(), usuarioId));
|
|
querySQL.executeUpdate();
|
|
// Atualizo o preço e o componente dos preços que já existem
|
|
querySQL = getSession().createSQLQuery(sqlBuilder.getSQLAtualizarTarifaPorTarifaOfical(vigenciaTarifa.getVigenciatarifaId(), usuarioId, calculaPegagio));
|
|
querySQL.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();
|
|
}
|
|
|
|
@Override
|
|
public void aplicarArredondamentoTarifa(Integer orgaoConcedenteId, Integer usuarioId) {
|
|
StringBuilder sql = new StringBuilder();
|
|
sql.append(" UPDATE TarifaOficial tao ");
|
|
sql.append(" SET tao.precio = FN_ARREDONDAMENTO_TARIFA(tao.precio,tao.orgaoConcedente.orgaoConcedenteId,tao.importeseguro,tao.importetaxaembarque,tao.importepedagio,tao.importeoutros), ");
|
|
sql.append(" tao.activo = true , ");
|
|
sql.append(" tao.fecmodif= CURRENT_TIMESTAMP(), ");
|
|
sql.append(" tao.usuarioId =:usuarioId ");
|
|
|
|
if (orgaoConcedenteId != null) {
|
|
sql.append(" WHERE tao.orgaoConcedente.orgaoConcedenteId = :orgao ");
|
|
}
|
|
|
|
Query query = getSession().createQuery(sql.toString());
|
|
if (orgaoConcedenteId != null) {
|
|
query.setParameter("orgao", orgaoConcedenteId);
|
|
}
|
|
query.setParameter("usuarioId", usuarioId);
|
|
query.executeUpdate();
|
|
}
|
|
} |