diff --git a/src/com/rjconsultores/ventaboletos/dao/TarifaKmDAO.java b/src/com/rjconsultores/ventaboletos/dao/TarifaKmDAO.java new file mode 100644 index 000000000..65f98858e --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/dao/TarifaKmDAO.java @@ -0,0 +1,13 @@ +package com.rjconsultores.ventaboletos.dao; + +import java.util.List; + +import com.rjconsultores.ventaboletos.entidad.ClaseServicio; +import com.rjconsultores.ventaboletos.entidad.OrgaoConcedente; +import com.rjconsultores.ventaboletos.entidad.TarifaKm; + +public interface TarifaKmDAO extends GenericDAO{ + + public List buscarPorOrgaoAndClasse(OrgaoConcedente orgaoconcedenteId, ClaseServicio claseId); + +} diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/TarifaKmHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/TarifaKmHibernateDAO.java new file mode 100644 index 000000000..c02ccdd0e --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/TarifaKmHibernateDAO.java @@ -0,0 +1,39 @@ +package com.rjconsultores.ventaboletos.dao.hibernate; + +import java.util.List; + +import org.hibernate.Criteria; +import org.hibernate.SessionFactory; +import org.hibernate.criterion.Restrictions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Repository; + +import com.rjconsultores.ventaboletos.dao.TarifaKmDAO; +import com.rjconsultores.ventaboletos.entidad.ClaseServicio; +import com.rjconsultores.ventaboletos.entidad.OrgaoConcedente; +import com.rjconsultores.ventaboletos.entidad.TarifaKm; + +/** +* +* @author daniel.zauli +*/ +@Repository("tarifaKmDAO") +public class TarifaKmHibernateDAO extends GenericHibernateDAO +implements TarifaKmDAO { + + @Autowired + public TarifaKmHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) { + setSessionFactory(factory); + } + + public List buscarPorOrgaoAndClasse(OrgaoConcedente orgaoconcedenteId, ClaseServicio claseId) { + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + c.add(Restrictions.eq("orgaoconcedenteId", orgaoconcedenteId)); + c.add(Restrictions.eq("claseServicio", claseId)); + + return c.list(); + } + +} diff --git a/src/com/rjconsultores/ventaboletos/entidad/OrgaoConcedente.java b/src/com/rjconsultores/ventaboletos/entidad/OrgaoConcedente.java index 188314bcf..6236f70dd 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/OrgaoConcedente.java +++ b/src/com/rjconsultores/ventaboletos/entidad/OrgaoConcedente.java @@ -22,6 +22,7 @@ import javax.persistence.TemporalType; public class OrgaoConcedente implements Serializable { private static final long serialVersionUID = 1L; + public final static Integer CODIGO_ARTESP = 21; @Id @Basic(optional = false) @GeneratedValue(strategy = GenerationType.AUTO, generator = "ORGAO_CONCEDENTE_SEQ") diff --git a/src/com/rjconsultores/ventaboletos/entidad/TarifaKm.java b/src/com/rjconsultores/ventaboletos/entidad/TarifaKm.java new file mode 100644 index 000000000..d5122d22e --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/entidad/TarifaKm.java @@ -0,0 +1,157 @@ +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.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +/** +* +* @author daniel.zauli +*/ +@Entity +@SequenceGenerator(name = "TARIFA_KM_SEQ", sequenceName = "TARIFA_KM_SEQ", allocationSize = 1) +@Table(name = "TARIFA_KM") +public class TarifaKm implements Serializable, Comparable{ + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.AUTO, generator = "TARIFA_KM_SEQ") + @Column(name = "TARIFAKM_ID") + private Integer tarifakmId; + + @JoinColumn(name = "ORGAOCONCEDENTE_ID", referencedColumnName = "ORGAOCONCEDENTE_ID") + @ManyToOne + private OrgaoConcedente orgaoconcedenteId; + + @Column(name = "KMATE") + private Integer kmate; + + // @Max(value=?) @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation + @Column(name = "VALORTAXA") // tarifa + private BigDecimal valortaxa; + + @JoinColumn(name = "CLASESERVICIO_ID", referencedColumnName = "CLASESERVICIO_ID") + @ManyToOne + private ClaseServicio claseServicio; + + @Column(name = "ACTIVO") + private Boolean activo; + + @Column(name = "FECMODIF") + @Temporal(TemporalType.TIMESTAMP) + private Date fecmodif; + + @Column(name = "USUARIO_ID") + private Integer usuarioId; + + public TarifaKm(){} + + @Override + public int hashCode() { + int hash = 0; + hash += (tarifakmId != null ? tarifakmId.hashCode() : 0); + return hash; + } + + @Override + public boolean equals(Object object) { + // TODO: Warning - this method won't work in the case the id fields are not set + if (!(object instanceof TarifaKm)) { + return false; + } + TarifaKm other = (TarifaKm) object; + if ((this.tarifakmId == null && other.tarifakmId != null) || (this.tarifakmId != null && !this.tarifakmId.equals(other.tarifakmId))) { + return false; + } + return true; + } + + @Override + public String toString() { + return "com.rjconsultores.ventaboletos.entidad.TarifaKm[ tarifakmId=" + tarifakmId + " ]"; + } + + public Integer getTarifakmId() { + return tarifakmId; + } + + public void setTarifakmId(Integer tarifakmId) { + this.tarifakmId = tarifakmId; + } + + public OrgaoConcedente getOrgaoconcedenteId() { + return orgaoconcedenteId; + } + + public void setOrgaoconcedenteId(OrgaoConcedente orgaoconcedenteId) { + this.orgaoconcedenteId = orgaoconcedenteId; + } + + public Integer getKmate() { + return kmate; + } + + public void setKmate(Integer kmate) { + this.kmate = kmate; + } + + public BigDecimal getValortaxa() { + return valortaxa; + } + + public void setValortaxa(BigDecimal valortaxa) { + this.valortaxa = valortaxa; + } + + public ClaseServicio getClaseServicio() { + return claseServicio; + } + + public void setClaseServicio(ClaseServicio claseServicio) { + this.claseServicio = claseServicio; + } + + 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 compareTo(TarifaKm tkm) { + return this.getKmate() - tkm.getKmate(); + } + +} diff --git a/src/com/rjconsultores/ventaboletos/service/TarifaKmService.java b/src/com/rjconsultores/ventaboletos/service/TarifaKmService.java new file mode 100644 index 000000000..15a9772c5 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/TarifaKmService.java @@ -0,0 +1,12 @@ +package com.rjconsultores.ventaboletos.service; + +import java.util.List; + +import com.rjconsultores.ventaboletos.entidad.ClaseServicio; +import com.rjconsultores.ventaboletos.entidad.OrgaoConcedente; +import com.rjconsultores.ventaboletos.entidad.TarifaKm; + +public interface TarifaKmService extends GenericService{ + + public List buscarPorOrgaoAndClasse(OrgaoConcedente orgaoconcedenteId, ClaseServicio claseId); +} diff --git a/src/com/rjconsultores/ventaboletos/service/impl/TarifaKmServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/TarifaKmServiceImpl.java new file mode 100644 index 000000000..3ce0f5415 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/impl/TarifaKmServiceImpl.java @@ -0,0 +1,60 @@ +package com.rjconsultores.ventaboletos.service.impl; + +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; + +import com.rjconsultores.ventaboletos.dao.TarifaKmDAO; +import com.rjconsultores.ventaboletos.dao.TaxaEmbarqueKmDAO; +import com.rjconsultores.ventaboletos.entidad.ClaseServicio; +import com.rjconsultores.ventaboletos.entidad.OrgaoConcedente; +import com.rjconsultores.ventaboletos.entidad.TarifaKm; +import com.rjconsultores.ventaboletos.entidad.TaxaEmbarqueKm; +import com.rjconsultores.ventaboletos.service.TarifaKmService; +import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; + +@Service("tarifaKmService") +public class TarifaKmServiceImpl implements TarifaKmService { + + @Autowired + private TarifaKmDAO tarifaKmDAO; + + public List buscarPorOrgaoAndClasse(OrgaoConcedente orgaoconcedenteId, ClaseServicio claseId) { + return tarifaKmDAO.buscarPorOrgaoAndClasse( orgaoconcedenteId, claseId); + + } + + public List obtenerTodos() { + return tarifaKmDAO.obtenerTodos(); + } + + public TarifaKm obtenerID(Integer id) { + return tarifaKmDAO.obtenerID(id); + } + + @Transactional + public TarifaKm actualizacion(TarifaKm entidad) { + return tarifaKmDAO.actualizacion(entidad); + } + + @Transactional + public TarifaKm suscribir(TarifaKm entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.TRUE); + + return tarifaKmDAO.suscribir(entidad); + } + + @Transactional + public void borrar(TarifaKm entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.FALSE); + + tarifaKmDAO.borrar(entidad); + } +}