- correção: apagar antes as tarifas que estão com activo = 0
git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@30315 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
d0f4cbc73c
commit
539ff4f869
|
@ -1,8 +1,12 @@
|
|||
package com.rjconsultores.ventaboletos.dao.hibernate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.SQLQuery;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
@ -15,6 +19,8 @@ import com.rjconsultores.ventaboletos.entidad.VigenciaTarifa;
|
|||
@Repository("tarifaOficialDAO")
|
||||
public class TarifaOficialHibernateDAO extends GenericHibernateDAO<TarifaOficial, Integer> implements TarifaOficialDAO {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(TarifaOficialHibernateDAO.class);
|
||||
|
||||
@Autowired
|
||||
private SQLBuilder sqlBuilder;
|
||||
|
||||
|
@ -48,10 +54,56 @@ public class TarifaOficialHibernateDAO extends GenericHibernateDAO<TarifaOficial
|
|||
query.executeUpdate();
|
||||
}
|
||||
|
||||
private void apagarTarifasInativas(VigenciaTarifa vigenciaTarifa){
|
||||
StringBuilder sb = new StringBuilder("");
|
||||
sb.append("select ");
|
||||
sb.append(" tar.tarifaId ");
|
||||
sb.append("from ");
|
||||
sb.append(" Tarifa tar,TarifaOficial tao ");
|
||||
sb.append("where ");
|
||||
sb.append(" tar.activo=0 ");
|
||||
sb.append(" and tao.activo = 1 ");
|
||||
sb.append(" and tar.tramo=tao.tramo ");
|
||||
sb.append(" and tar.marca=tao.marca ");
|
||||
sb.append(" and tar.claseServicio =tao.claseServicio ");
|
||||
sb.append(" and tar.moneda=tao.moneda ");
|
||||
sb.append(" and tar.orgaoConcedente=tao.orgaoConcedente ");
|
||||
sb.append(" and tar.ruta=tao.ruta ");
|
||||
sb.append(" and tar.vigenciaTarifa.vigenciatarifaId = :vigenciaId ");
|
||||
|
||||
Query query = getSession().createQuery(sb.toString());
|
||||
query.setParameter("vigenciaId", vigenciaTarifa.getVigenciatarifaId());
|
||||
|
||||
List<Integer> list = query.list();
|
||||
|
||||
if (!list.isEmpty()){
|
||||
query = getSession().createQuery("DELETE FROM TarifaTipoptovta WHERE tarifa.tarifaId in (:ids)");
|
||||
query.setParameterList("ids", list);
|
||||
int qtd = query.executeUpdate();
|
||||
log.info("qtd TarifaTipoptovta apagada = " + qtd);
|
||||
|
||||
query = getSession().createQuery("DELETE FROM TarifaCategoria WHERE tarifa.tarifaId in (:ids)");
|
||||
query.setParameterList("ids", list);
|
||||
qtd = query.executeUpdate();
|
||||
log.info("qtd TarifaCategoria apagada = " + qtd);
|
||||
|
||||
query = getSession().createQuery("DELETE FROM Tarifa WHERE activo = 0 and tarifaId in (:ids)");
|
||||
query.setParameterList("ids", list);
|
||||
qtd = query.executeUpdate();
|
||||
log.info("qtd Tarifa apagada = " + qtd);
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copiarParaTarifa(VigenciaTarifa vigenciaTarifa, Integer usuarioId, Boolean calculaPegagio) {
|
||||
|
||||
|
||||
//Apago antes as tarifas que podem estar como activo =0
|
||||
apagarTarifasInativas(vigenciaTarifa);
|
||||
|
||||
// Insiro as tarifas que não existem
|
||||
SQLQuery querySQL = getSession().createSQLQuery(sqlBuilder.getSQLInserirTarifaPelaTarifaOficial(vigenciaTarifa.getVigenciatarifaId(), usuarioId));
|
||||
querySQL.executeUpdate();
|
||||
|
|
|
@ -7,13 +7,16 @@ package com.rjconsultores.ventaboletos.entidad;
|
|||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.SequenceGenerator;
|
||||
import javax.persistence.Table;
|
||||
|
@ -49,6 +52,9 @@ public class TarifaCategoria implements Serializable {
|
|||
@OneToOne
|
||||
@JoinColumn(name = "CATEGORIA_ID")
|
||||
private Categoria categoria;
|
||||
@JoinColumn(name = "TARIFA_ID", referencedColumnName = "TARIFA_ID")
|
||||
@ManyToOne(fetch=FetchType.LAZY)
|
||||
private Tarifa tarifa;
|
||||
|
||||
public TarifaCategoria() {
|
||||
}
|
||||
|
@ -113,7 +119,16 @@ public class TarifaCategoria implements Serializable {
|
|||
this.categoria = categoria;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public Tarifa getTarifa() {
|
||||
return tarifa;
|
||||
}
|
||||
|
||||
public void setTarifa(Tarifa tarifa) {
|
||||
this.tarifa = tarifa;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
hash += (tarifacategoriaId != null ? tarifacategoriaId.hashCode() : 0);
|
||||
|
|
|
@ -7,13 +7,16 @@ package com.rjconsultores.ventaboletos.entidad;
|
|||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.SequenceGenerator;
|
||||
import javax.persistence.Table;
|
||||
|
@ -49,6 +52,9 @@ public class TarifaTipoptovta implements Serializable {
|
|||
@OneToOne
|
||||
@JoinColumn(name = "TIPOPTOVTA_ID")
|
||||
private TipoPuntoVenta tipoPuntoVenta;
|
||||
@JoinColumn(name = "TARIFA_ID", referencedColumnName = "TARIFA_ID")
|
||||
@ManyToOne(fetch=FetchType.LAZY)
|
||||
private Tarifa tarifa;
|
||||
|
||||
public TarifaTipoptovta() {
|
||||
}
|
||||
|
@ -113,7 +119,17 @@ public class TarifaTipoptovta implements Serializable {
|
|||
this.tipoPuntoVenta = tipoPuntoVenta;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
|
||||
public Tarifa getTarifa() {
|
||||
return tarifa;
|
||||
}
|
||||
|
||||
public void setTarifa(Tarifa tarifa) {
|
||||
this.tarifa = tarifa;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 0;
|
||||
hash += (tarifatipoptovtaId != null ? tarifatipoptovtaId.hashCode() : 0);
|
||||
|
|
Loading…
Reference in New Issue