diff --git a/src/com/rjconsultores/ventaboletos/dao/PrecioFixoPedagioDAO.java b/src/com/rjconsultores/ventaboletos/dao/PrecioFixoPedagioDAO.java new file mode 100644 index 000000000..6298a53fc --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/dao/PrecioFixoPedagioDAO.java @@ -0,0 +1,24 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.rjconsultores.ventaboletos.dao; + +import java.util.List; + +import com.rjconsultores.ventaboletos.entidad.PrecioFixoPedagio; + +/** + * + * @author Administrador + */ +public interface PrecioFixoPedagioDAO extends GenericDAO { + + public List buscarPorNome(String nomeClaseServicio); + + public List buscarTodosExceto(Integer ... idClase); + + public List buscarPorEmpresasDoUsuario (String idEmpresasUsuario); + + public List buscarPrecioFixoPedagio(PrecioFixoPedagio obj); +} \ No newline at end of file diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/CalcularPeajeHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/CalcularPeajeHibernateDAO.java index 8d0f01df3..a7c54ae29 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/CalcularPeajeHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/CalcularPeajeHibernateDAO.java @@ -32,9 +32,11 @@ import com.rjconsultores.ventaboletos.entidad.ExcepcionPeaje; import com.rjconsultores.ventaboletos.entidad.ExcepcionPeajeVigencia; import com.rjconsultores.ventaboletos.entidad.OrgaoConcedente; import com.rjconsultores.ventaboletos.entidad.Parada; +import com.rjconsultores.ventaboletos.entidad.PrecioFixoPedagio; import com.rjconsultores.ventaboletos.entidad.Ruta; import com.rjconsultores.ventaboletos.entidad.RutaCombinacion; import com.rjconsultores.ventaboletos.service.OrgaoConcedenteService; +import com.rjconsultores.ventaboletos.service.PrecioFixoPedagioService; import com.rjconsultores.ventaboletos.service.RutaCombinacionService; import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties; import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; @@ -48,6 +50,9 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO list = precioFixoPedagioService.buscarPrecioFixoPedagio(pfp); + if(list.size()>1){ + pvo.importePeaje = list.get(0).getValorFixo(); + } + + peajes.add(pvo); } } log.debug("****** FIM LINHA : "+ruta.toString()+" . INSTRUCOES DE INSERT NO BANCO PRONTAS ******"); @@ -440,6 +458,7 @@ public class CalcularPeajeHibernateDAO extends GenericHibernateDAO implements PrecioFixoPedagioDAO { + + @Autowired + public PrecioFixoPedagioHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) { + setSessionFactory(factory); + } + + @Override + public List obtenerTodos() { + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + c.addOrder(Order.asc("descclase")); + + return c.list(); + } + + public List buscarPorEmpresasDoUsuario(String empresasUsuario) { + + String consulta = "SELECT DISTINCT mcs.marcaClaseservicioPK.claseservicio " + + "FROM MarcaClaseServicio mcs " + + "WHERE mcs.marcaClaseservicioPK.marca.empresa.empresaId IN (:empresas) "; + + List ids = new ArrayList(); + for (String empresa : empresasUsuario.split(",")) { + ids.add(new Integer(empresa)); + } + Query query = getSession().createQuery(consulta); + query.setParameterList("empresas", ids); + + List result = (List) query.list(); + return result; + } + + public List buscarPorNome(String nomeClaseServicio) { + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + c.add(Restrictions.eq("descclase", nomeClaseServicio)); + + return c.list(); + } + + public List buscarTodosExceto(Integer... idClase) { + Criteria c = this.makeCriteria(); + for (Integer id : idClase) { + c.add(Restrictions.ne("claseservicioId", id)); + } + c.add(Restrictions.eq("activo", Boolean.TRUE)); + c.addOrder(Order.asc("descclase")); + + return c.list(); + } + @Override + public List buscarPrecioFixoPedagio(PrecioFixoPedagio obj) { + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("pracaPedagioId.casetaPeajeId", obj.getPracaPedagioId().getCasetaPeajeId())); + c.add(Restrictions.eq("orgaoConcedenteId.orgaoConcedenteId", obj.getOrgaoConcedenteId().getOrgaoConcedenteId())); + c.add(Restrictions.eq("classeId.claseservicioId", obj.getClasseId().getClaseservicioId())); + c.setMaxResults(1); + return c.list(); + } +} diff --git a/src/com/rjconsultores/ventaboletos/entidad/CasetaPeaje.java b/src/com/rjconsultores/ventaboletos/entidad/CasetaPeaje.java index 33d16852e..18666df4f 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/CasetaPeaje.java +++ b/src/com/rjconsultores/ventaboletos/entidad/CasetaPeaje.java @@ -25,6 +25,8 @@ import javax.persistence.TemporalType; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; +import org.hibernate.annotations.LazyCollection; +import org.hibernate.annotations.LazyCollectionOption; import org.hibernate.annotations.Where; @Entity @@ -60,6 +62,10 @@ public class CasetaPeaje implements Serializable, Comparable, Clone inverseJoinColumns = { @JoinColumn(name = "RUTASECUENCIA_ID") }) private List lsRutaSecuencia; + @OneToMany(mappedBy = "pracaPedagioId", cascade=CascadeType.ALL) + @LazyCollection(LazyCollectionOption.FALSE) + private List lsPrecoFixoPedagio; + @Override public int hashCode() { @@ -151,6 +157,15 @@ public class CasetaPeaje implements Serializable, Comparable, Clone public void setLsCasetaPeajeExcepcion(List lsCasetaPeajeExcepcion) { this.lsCasetaPeajeExcepcion = lsCasetaPeajeExcepcion; + } + + public List getLsPrecoFixoPedagio() { + return lsPrecoFixoPedagio; + } + + public void setLsPrecoFixoPedagio(List lsPrecoFixoPedagio) { + this.lsPrecoFixoPedagio = lsPrecoFixoPedagio; } + } \ No newline at end of file diff --git a/src/com/rjconsultores/ventaboletos/entidad/PrecioFixoPedagio.java b/src/com/rjconsultores/ventaboletos/entidad/PrecioFixoPedagio.java new file mode 100644 index 000000000..3fc9736d7 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/entidad/PrecioFixoPedagio.java @@ -0,0 +1,141 @@ +/** + * + */ +package com.rjconsultores.ventaboletos.entidad; + +import java.io.Serializable; +import java.math.BigDecimal; + +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +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; + +/** + * @author Bruno Neves + * + */ +@Entity +@SequenceGenerator(name = "PRECIO_FIXO_PEDAGIO_SEQ", sequenceName = "PRECIO_FIXO_PEDAGIO_SEQ", allocationSize = 1) +@Table(name = "PRECIO_FIXO_PEDAGIO") +public class PrecioFixoPedagio implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 1L; + + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.AUTO, generator = "PRECIO_FIXO_PEDAGIO_SEQ") + @Column(name = "PRECIOFIXO_ID") + private Integer precioFixoId; + + @ManyToOne + @JoinColumn(name = "PRACA_PEDAGIO_ID", referencedColumnName = "CASETAPEAJE_ID") + private CasetaPeaje pracaPedagioId; + + @OneToOne + @JoinColumn(name = "ORGAO_CONCEDENTE_ID", referencedColumnName = "ORGAOCONCEDENTE_ID") + private OrgaoConcedente orgaoConcedenteId; + + @OneToOne + @JoinColumn(name = "CLASSE_SERVICO_ID", referencedColumnName = "CLASESERVICIO_ID") + private ClaseServicio classeId; + + @Column(name = "VALOR_FIXO") + private BigDecimal valorFixo; + + public Integer getPrecioFixoId() { + return precioFixoId; + } + + public void setPrecioFixoId(Integer precioFixoId) { + this.precioFixoId = precioFixoId; + } + + public CasetaPeaje getPracaPedagioId() { + return pracaPedagioId; + } + + public void setPracaPedagioId(CasetaPeaje pracaPedagioId) { + this.pracaPedagioId = pracaPedagioId; + } + + public OrgaoConcedente getOrgaoConcedenteId() { + return orgaoConcedenteId; + } + + public void setOrgaoConcedenteId(OrgaoConcedente orgaoConcedenteId) { + this.orgaoConcedenteId = orgaoConcedenteId; + } + + public ClaseServicio getClasseId() { + return classeId; + } + + public void setClasseId(ClaseServicio classeId) { + this.classeId = classeId; + } + + public BigDecimal getValorFixo() { + return valorFixo; + } + + public void setValorFixo(BigDecimal valorFixo) { + this.valorFixo = valorFixo; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((classeId == null) ? 0 : classeId.hashCode()); + result = prime * result + ((orgaoConcedenteId == null) ? 0 : orgaoConcedenteId.hashCode()); + result = prime * result + ((pracaPedagioId == null) ? 0 : pracaPedagioId.hashCode()); + result = prime * result + ((precioFixoId == null) ? 0 : precioFixoId.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + PrecioFixoPedagio other = (PrecioFixoPedagio) obj; + if (classeId == null) { + if (other.classeId != null) + return false; + } else if (!classeId.equals(other.classeId)) + return false; + if (orgaoConcedenteId == null) { + if (other.orgaoConcedenteId != null) + return false; + } else if (!orgaoConcedenteId.equals(other.orgaoConcedenteId)) + return false; + if (pracaPedagioId == null) { + if (other.pracaPedagioId != null) + return false; + } else if (!pracaPedagioId.equals(other.pracaPedagioId)) + return false; + if (precioFixoId == null) { + if (other.precioFixoId != null) + return false; + } else if (!precioFixoId.equals(other.precioFixoId)) + return false; + return true; + } + + + +} diff --git a/src/com/rjconsultores/ventaboletos/service/PrecioFixoPedagioService.java b/src/com/rjconsultores/ventaboletos/service/PrecioFixoPedagioService.java new file mode 100644 index 000000000..da7e21e12 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/PrecioFixoPedagioService.java @@ -0,0 +1,27 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.rjconsultores.ventaboletos.service; + +import java.util.List; + +import com.rjconsultores.ventaboletos.entidad.Empresa; +import com.rjconsultores.ventaboletos.entidad.PrecioFixoPedagio; + +/** + * + * @author Administrador + */ +public interface PrecioFixoPedagioService extends GenericService { + + public List buscarPorNome(String nomeClaseServicio); + + public List buscarTodosExceto(Integer ... idClase); + + public List buscarPorEmpresasDoUsuario (List empresasUsuario); + + public Boolean validarInclusaoPrecoFixo(PrecioFixoPedagio precoFixoPedagio); + + public List buscarPrecioFixoPedagio(PrecioFixoPedagio obj); +} diff --git a/src/com/rjconsultores/ventaboletos/service/impl/PrecioFixoPedagioServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/PrecioFixoPedagioServiceImpl.java new file mode 100644 index 000000000..3a0c03079 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/impl/PrecioFixoPedagioServiceImpl.java @@ -0,0 +1,110 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.rjconsultores.ventaboletos.service.impl; + +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import com.rjconsultores.ventaboletos.dao.PrecioFixoPedagioDAO; +import com.rjconsultores.ventaboletos.dao.hibernate.PrecioFixoPedagioHibernateDAO; +import com.rjconsultores.ventaboletos.entidad.Empresa; +import com.rjconsultores.ventaboletos.entidad.PrecioFixoPedagio; +import com.rjconsultores.ventaboletos.service.PrecioFixoPedagioService; + +/** + * + * @author Administrador + */ +@Service("precioFixoPedagioService") +public class PrecioFixoPedagioServiceImpl implements PrecioFixoPedagioService { + + @Autowired + private PrecioFixoPedagioDAO precioFixoPedagioDAO; + @Autowired + private PrecioFixoPedagioHibernateDAO precioFixoPedagioHibernateDAO; + + public List obtenerTodos() { + return precioFixoPedagioDAO.obtenerTodos(); + } + + public PrecioFixoPedagio obtenerID(Integer id) { + return precioFixoPedagioDAO.obtenerID(id); + } + + + public List buscarPorNome(String nomeClaseServicio) { + return precioFixoPedagioDAO.buscarPorNome(nomeClaseServicio); + } + + public List buscarTodosExceto(Integer ... idClase){ + return precioFixoPedagioDAO.buscarTodosExceto(idClase); + } + + public List buscarPorEmpresasDoUsuario (List empresasUsuario) { + + if(empresasUsuario == null || empresasUsuario.isEmpty()) { + return null; + } + + StringBuilder idEmpresasBuilder = new StringBuilder(); + String idEmpresas = ""; + + for (Empresa empresa : empresasUsuario) { + idEmpresasBuilder.append(empresa.getEmpresaId().toString()).append(","); + } + + idEmpresasBuilder = idEmpresasBuilder.deleteCharAt(idEmpresasBuilder.length() -1); + idEmpresas = idEmpresasBuilder.toString(); + + List result = (List) precioFixoPedagioDAO.buscarPorEmpresasDoUsuario(idEmpresas); + return result; + } + + @Override + public PrecioFixoPedagio suscribir(PrecioFixoPedagio entidad) { + + return precioFixoPedagioDAO.suscribir(entidad); + } + + @Transactional + public PrecioFixoPedagio actualizacion(PrecioFixoPedagio entidad) { + return precioFixoPedagioDAO.actualizacion(entidad); + } + + @Transactional + public void borrar(PrecioFixoPedagio entidad) { + precioFixoPedagioDAO.borrar(entidad); + + } + @Override + public Boolean validarInclusaoPrecoFixo(PrecioFixoPedagio precoFixoPedagio) { + List precos = buscar(precoFixoPedagio); + + + if(precos.isEmpty()){ + return Boolean.TRUE; + } + + return Boolean.FALSE; + + + } + + private List buscar(PrecioFixoPedagio precoFixoPedagio) { + + return precioFixoPedagioHibernateDAO.buscarPrecioFixoPedagio(precoFixoPedagio); + } + + @Override + public List buscarPrecioFixoPedagio(PrecioFixoPedagio obj) { + + return precioFixoPedagioDAO.buscarPrecioFixoPedagio(obj); + } + + +}