diff --git a/src/com/rjconsultores/ventaboletos/dao/MotivoDevolucaoBilheteDAO.java b/src/com/rjconsultores/ventaboletos/dao/MotivoDevolucaoBilheteDAO.java new file mode 100644 index 000000000..41a6d20d1 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/dao/MotivoDevolucaoBilheteDAO.java @@ -0,0 +1,21 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.rjconsultores.ventaboletos.dao; + +import com.rjconsultores.ventaboletos.entidad.MotivoDevolucaoBilhete; +import java.util.List; + +/** + * + * @author Bruno Neves + */ +public interface MotivoDevolucaoBilheteDAO extends GenericDAO { + + public List buscar(String descmotivo, String tipomotivo); + + public List obtenerTodosTipoMotivoB(); + + public List obtenerTodosEspecificos(Integer[] motivos); +} diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/MotivoDevolucaoBilheteHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/MotivoDevolucaoBilheteHibernateDAO.java new file mode 100644 index 000000000..1387f1414 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/MotivoDevolucaoBilheteHibernateDAO.java @@ -0,0 +1,65 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.rjconsultores.ventaboletos.dao.hibernate; + +import com.rjconsultores.ventaboletos.dao.MotivoDevolucaoBilheteDAO; +import com.rjconsultores.ventaboletos.entidad.MotivoDevolucaoBilhete; +import java.util.List; +import org.hibernate.Criteria; +import org.hibernate.SessionFactory; +import org.hibernate.criterion.Order; +import org.hibernate.criterion.Restrictions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Repository; + +/** + * + * @author Bruno Neves + */ +@Repository("motivoDevolucaoBilheteDAO") +public class MotivoDevolucaoBilheteHibernateDAO extends GenericHibernateDAO + implements MotivoDevolucaoBilheteDAO { + + @Autowired + public MotivoDevolucaoBilheteHibernateDAO(@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("descmotivo")); + + return c.list(); + } + + public List buscar(String descmotivo, String tipomotivo) { + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + c.add(Restrictions.eq("descmotivo", descmotivo)); + + + return c.list(); + } + + public List obtenerTodosTipoMotivoB() { + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + c.addOrder(Order.asc("descmotivo")); + + return c.list(); + } + + public List obtenerTodosEspecificos(Integer[] motivos) { + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + c.add(Restrictions.in("motivodevolucaobilheteId", motivos)); + c.addOrder(Order.asc("descmotivo")); + + return c.list(); + } +} diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/PrecioFixoPedagioHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/PrecioFixoPedagioHibernateDAO.java index ff53777bb..4d38ea697 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/PrecioFixoPedagioHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/PrecioFixoPedagioHibernateDAO.java @@ -81,8 +81,13 @@ public class PrecioFixoPedagioHibernateDAO extends GenericHibernateDAO 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())); + if(obj.getOrgaoConcedenteId() != null){ + c.add(Restrictions.eq("orgaoConcedenteId.orgaoConcedenteId", obj.getOrgaoConcedenteId().getOrgaoConcedenteId())); + } + if(obj.getClasseId()!= null){ + c.add(Restrictions.eq("classeId.claseservicioId", obj.getClasseId().getClaseservicioId())); + } + c.setMaxResults(1); return c.list(); } diff --git a/src/com/rjconsultores/ventaboletos/entidad/MotivoDevolucaoBilhete.java b/src/com/rjconsultores/ventaboletos/entidad/MotivoDevolucaoBilhete.java new file mode 100644 index 000000000..6f890e668 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/entidad/MotivoDevolucaoBilhete.java @@ -0,0 +1,134 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.rjconsultores.ventaboletos.entidad; + +import java.io.Serializable; +import java.util.Date; +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.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; +import javax.persistence.SequenceGenerator; + +/** + * + * @author Bruno Neves + */ +/** + * @author Bruno + * + */ +@Entity +@SequenceGenerator(name = "MOTIVO_DEVOLUCAO_BILHETE_SEQ", sequenceName = "MOTIVO_DEVOLUCAO_BILHETE_SEQ", allocationSize = 1) +@Table(name = "MOTIVO_DEVOLUCAO_BILHETE") +public class MotivoDevolucaoBilhete implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.AUTO, generator = "MOTIVO_DEVOLUCAO_BILHETE_SEQ") + @Column(name = "MOTIVODEVOLUCAOBILHETE_ID") + private Integer motivodevolucaobilheteId; + @Column(name = "DESCMOTIVO") + private String descmotivo; + @Column(name = "ACTIVO") + private Boolean activo; + @Column(name = "FECMODIF") + @Temporal(TemporalType.TIMESTAMP) + private Date fecmodif; + @Column(name = "USUARIO_ID") + private Integer usuarioId; + + + public MotivoDevolucaoBilhete() { + } + + + public Integer getMotivodevolucaobilheteId() { + return motivodevolucaobilheteId; + } + + + public void setMotivodevolucaobilheteId(Integer motivodevolucaobilheteId) { + this.motivodevolucaobilheteId = motivodevolucaobilheteId; + } + + + public String getDescmotivo() { + return descmotivo; + } + + + public void setDescmotivo(String descmotivo) { + this.descmotivo = descmotivo; + } + + + public Boolean getActivo() { + return activo; + } + + + public void setActivo(Boolean activo) { + this.activo = activo; + } + + + public Date getFecmodif() { + return fecmodif; + } + + + public void setFecmodif(Date fecmodif) { + this.fecmodif = fecmodif; + } + + + public Integer getUsuarioId() { + return usuarioId; + } + + + public void setUsuarioId(Integer usuarioId) { + this.usuarioId = usuarioId; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((motivodevolucaobilheteId == null) ? 0 : motivodevolucaobilheteId.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; + MotivoDevolucaoBilhete other = (MotivoDevolucaoBilhete) obj; + if (motivodevolucaobilheteId == null) { + if (other.motivodevolucaobilheteId != null) + return false; + } else if (!motivodevolucaobilheteId.equals(other.motivodevolucaobilheteId)) + return false; + return true; + } + + @Override + public String toString() { + return "MotivoDevolucaoBilhete [motivodevolucaobilheteId=" + motivodevolucaobilheteId + ", descmotivo=" + descmotivo + "]"; + } + + +} diff --git a/src/com/rjconsultores/ventaboletos/service/MotivoDevolucaoBilheteService.java b/src/com/rjconsultores/ventaboletos/service/MotivoDevolucaoBilheteService.java new file mode 100644 index 000000000..f37bb7b51 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/MotivoDevolucaoBilheteService.java @@ -0,0 +1,23 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.rjconsultores.ventaboletos.service; + +import com.rjconsultores.ventaboletos.entidad.MotivoDevolucaoBilhete; +import java.util.List; + +/** + * + * @author Bruno Neves + */ +public interface MotivoDevolucaoBilheteService extends GenericService { + + public List buscar(String descmotivo, String tipomotivo); + + public List obtenerTodosTipoMotivoB(); + + public List obtenerTodosEspecificos(Integer[] motivos); + + public boolean validaMotivoDevolucaoBilheteConstante(MotivoDevolucaoBilhete motivoDevolucaoBilhete); +} diff --git a/src/com/rjconsultores/ventaboletos/service/impl/MotivoDevolucaoBilheteServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/MotivoDevolucaoBilheteServiceImpl.java new file mode 100644 index 000000000..eef254585 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/impl/MotivoDevolucaoBilheteServiceImpl.java @@ -0,0 +1,82 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package com.rjconsultores.ventaboletos.service.impl; + +import com.rjconsultores.ventaboletos.dao.MotivoDevolucaoBilheteDAO; +import com.rjconsultores.ventaboletos.entidad.MotivoDevolucaoBilhete; +import com.rjconsultores.ventaboletos.service.MotivoDevolucaoBilheteService; +import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; +import java.util.Calendar; +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +/** + * + * @author Bruno Neves + */ +@Service("motivoDevolucaoBilheteService") +public class MotivoDevolucaoBilheteServiceImpl implements MotivoDevolucaoBilheteService { + + @Autowired + private MotivoDevolucaoBilheteDAO motivoDevolucaoBilheteDAO; + public static final Integer MAX_CONS_MOV_CANCEL = Integer.valueOf(35); + + public List obtenerTodos() { + return motivoDevolucaoBilheteDAO.obtenerTodos(); + } + + public MotivoDevolucaoBilhete obtenerID(Integer id) { + return motivoDevolucaoBilheteDAO.obtenerID(id); + } + + @Transactional + public MotivoDevolucaoBilhete suscribir(MotivoDevolucaoBilhete entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.TRUE); + + return motivoDevolucaoBilheteDAO.suscribir(entidad); + } + + @Transactional + public MotivoDevolucaoBilhete actualizacion(MotivoDevolucaoBilhete entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.TRUE); + + return motivoDevolucaoBilheteDAO.actualizacion(entidad); + } + + @Transactional + public void borrar(MotivoDevolucaoBilhete entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.FALSE); + + motivoDevolucaoBilheteDAO.actualizacion(entidad); + } + + public List buscar(String descmotivo, String tipomotivo) { + return motivoDevolucaoBilheteDAO.buscar(descmotivo, tipomotivo); + } + + public List obtenerTodosTipoMotivoB() { + return motivoDevolucaoBilheteDAO.obtenerTodosTipoMotivoB(); + } + + public List obtenerTodosEspecificos(Integer[] motivos) { + return motivoDevolucaoBilheteDAO.obtenerTodosEspecificos(motivos); + } + + public boolean validaMotivoDevolucaoBilheteConstante(MotivoDevolucaoBilhete motivoDevolucaoBilhete) { + if (motivoDevolucaoBilhete.getMotivodevolucaobilheteId() <= MAX_CONS_MOV_CANCEL) + return false; + else + return true; + } + +}