diff --git a/src/com/rjconsultores/ventaboletos/dao/ClienteDAO.java b/src/com/rjconsultores/ventaboletos/dao/ClienteDAO.java index 21d78275a..627d83b92 100644 --- a/src/com/rjconsultores/ventaboletos/dao/ClienteDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/ClienteDAO.java @@ -4,13 +4,9 @@ import java.util.List; import com.rjconsultores.ventaboletos.entidad.Cliente; - - - - public interface ClienteDAO extends GenericDAO { - public List buscar(String nombCliente); + public List buscar(String nombCliente); - + public Cliente buscarPorNumeroFidelidade(Integer numeroFidelidade); } diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/ClienteHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/ClienteHibernateDAO.java index 645a68692..3e9c2304e 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/ClienteHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/ClienteHibernateDAO.java @@ -3,7 +3,6 @@ package com.rjconsultores.ventaboletos.dao.hibernate; import java.util.List; import org.hibernate.Criteria; -import org.hibernate.Query; import org.hibernate.SessionFactory; import org.hibernate.criterion.Order; import org.hibernate.criterion.Restrictions; @@ -14,37 +13,46 @@ import org.springframework.stereotype.Repository; import com.rjconsultores.ventaboletos.dao.ClienteDAO; import com.rjconsultores.ventaboletos.entidad.Cliente; - - - @Repository("clienteDAO") public class ClienteHibernateDAO extends GenericHibernateDAO - implements ClienteDAO { + implements ClienteDAO { - @Autowired - public ClienteHibernateDAO( - @Qualifier("sessionFactory") SessionFactory factory) { - setSessionFactory(factory); - } + @Autowired + public ClienteHibernateDAO( + @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("id")); - - return c.list(); - } + @Override + public List obtenerTodos() { + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + c.addOrder(Order.asc("id")); - public List buscar(String nombCliente) { - Criteria c = getSession().createCriteria(getPersistentClass()); - c.add(Restrictions.eq("activo", Boolean.TRUE)); - c.add(Restrictions.eq("nombcliente", nombCliente)); - + return c.list(); + } - return c.list(); - } + public List buscar(String nombCliente) { + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + c.add(Restrictions.eq("nombcliente", nombCliente)); - + return c.list(); + } + + @Override + public Cliente buscarPorNumeroFidelidade(Integer numeroFidelidade) { + Criteria c = getSession().createCriteria(getPersistentClass()); + + Criteria clienteFidelidad = null; + clienteFidelidad = c.createCriteria("listClienteFidelidad"); + clienteFidelidad.add(Restrictions.eq("activo", Boolean.TRUE)); + + Criteria tarjetaFidelidad = null; + tarjetaFidelidad = clienteFidelidad.createCriteria("tarjetaFidelidad"); + tarjetaFidelidad.add(Restrictions.eq("numTarjeta", numeroFidelidade)); + tarjetaFidelidad.add(Restrictions.eq("activo", Boolean.TRUE)); + + return (Cliente) c.uniqueResult(); + } } - diff --git a/src/com/rjconsultores/ventaboletos/entidad/Cliente.java b/src/com/rjconsultores/ventaboletos/entidad/Cliente.java index 38eec228d..59ddba1a6 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/Cliente.java +++ b/src/com/rjconsultores/ventaboletos/entidad/Cliente.java @@ -12,364 +12,332 @@ import javax.persistence.Basic; import javax.persistence.CascadeType; 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.NamedQueries; -import javax.persistence.NamedQuery; import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.SequenceGenerator; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; -import javax.xml.bind.annotation.XmlRootElement; /** - * + * * @author RJ */ @Entity @SequenceGenerator(name = "CLIENTE_SEQ", sequenceName = "CLIENTE_SEQ", allocationSize = 1) @Table(name = "CLIENTE") - public class Cliente implements Serializable { - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.AUTO, generator = "CLIENTE_SEQ") - @Column(name = "CLIENTE_ID") - private Integer clienteId; - - @Column(name = "NOMBCLIENTE") - private String nombcliente; - - @Column(name = "APELLIDOPATERNO") - private String apellidopaterno; - - @Column(name = "APELLIDOMATERNO") - private String apellidomaterno; - - @Column(name = "FECNACIMIENTO") - @Temporal(TemporalType.TIMESTAMP) - private Date fecnacimiento; - - @Column(name = "NUMRFC") - private String numrfc; - - @Column(name = "NUMTELEFONO") - private String numtelefono; - - @Column(name = "NUMTELEFONODOS") - private String numtelefonodos; - - @Column(name = "NUMFAX") - private String numfax; - - @Column(name = "NUMEXTENSION") - private String numextension; - - @Column(name = "NUMEXTENSIONDOS") - private String numextensiondos; - - - @JoinColumn(name = "TIPOOCUPACION_ID") - @OneToOne(cascade=CascadeType.ALL) - private TipoOcupacion tipoocupacionId; - - @Column(name = "MEDIOINFORMATIVO_ID") - private Integer medioinformativoId; - - - @JoinColumn(name = "MOTIVOVIAJE_ID") - @OneToOne(cascade=CascadeType.ALL) - private MotivoViaje motivoviajeId; - - @Column(name = "INDSEXO") - private String indsexo; - - @Column(name = "NUMCURP") - private String numcurp; - - @Column(name = "CANTHIJOS") - private Integer canthijos; - - @Column(name = "DESCCORREO") - private String desccorreo; - - @Column(name = "EDAD") - private Integer edad; - - @Column(name = "ESTADOCIVIL_ID") - private Integer estadocivilId; - - @Column(name = "GRADOESTUDIO_ID") - private Integer gradoestudioId; - - @Column(name = "EQUIVALENCIA_ID") - private String equivalenciaId; - - @Column(name = "ACTIVO") - private Boolean activo; - - @Column(name = "FECMODIF") - @Temporal(TemporalType.TIMESTAMP) - private Date fecmodif; - - @Column(name = "USUARIO_ID") - private Integer usuarioId; - - @Column(name = "DESCCONTRASENA") - private String desccontrasena; - - @Column(name = "NUMLADA") - private String numlada; - - @Column(name = "INDCAMBIOCONTRASENA") - private Integer indcambiocontrasena; - - @OneToMany(cascade = CascadeType.ALL, mappedBy = "clienteId") - private List lsClienteDireccion; - - - + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.AUTO, generator = "CLIENTE_SEQ") + @Column(name = "CLIENTE_ID") + private Integer clienteId; + @Column(name = "NOMBCLIENTE") + private String nombcliente; + @Column(name = "APELLIDOPATERNO") + private String apellidopaterno; + @Column(name = "APELLIDOMATERNO") + private String apellidomaterno; + @Column(name = "FECNACIMIENTO") + @Temporal(TemporalType.TIMESTAMP) + private Date fecnacimiento; + @Column(name = "NUMRFC") + private String numrfc; + @Column(name = "NUMTELEFONO") + private String numtelefono; + @Column(name = "NUMTELEFONODOS") + private String numtelefonodos; + @Column(name = "NUMFAX") + private String numfax; + @Column(name = "NUMEXTENSION") + private String numextension; + @Column(name = "NUMEXTENSIONDOS") + private String numextensiondos; + @JoinColumn(name = "TIPOOCUPACION_ID") + @OneToOne(cascade = CascadeType.ALL) + private TipoOcupacion tipoocupacionId; + @Column(name = "MEDIOINFORMATIVO_ID") + private Integer medioinformativoId; + @JoinColumn(name = "MOTIVOVIAJE_ID") + @OneToOne(cascade = CascadeType.ALL) + private MotivoViaje motivoviajeId; + @Column(name = "INDSEXO") + private String indsexo; + @Column(name = "NUMCURP") + private String numcurp; + @Column(name = "CANTHIJOS") + private Integer canthijos; + @Column(name = "DESCCORREO") + private String desccorreo; + @Column(name = "EDAD") + private Integer edad; + @Column(name = "ESTADOCIVIL_ID") + private Integer estadocivilId; + @Column(name = "GRADOESTUDIO_ID") + private Integer gradoestudioId; + @Column(name = "EQUIVALENCIA_ID") + private String equivalenciaId; + @Column(name = "ACTIVO") + private Boolean activo; + @Column(name = "FECMODIF") + @Temporal(TemporalType.TIMESTAMP) + private Date fecmodif; + @Column(name = "USUARIO_ID") + private Integer usuarioId; + @Column(name = "DESCCONTRASENA") + private String desccontrasena; + @Column(name = "NUMLADA") + private String numlada; + @Column(name = "INDCAMBIOCONTRASENA") + private Integer indcambiocontrasena; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "clienteId") + private List lsClienteDireccion; + @OneToMany(cascade = CascadeType.ALL) + @JoinColumn(name = "CLIENTE_ID", referencedColumnName = "CLIENTE_ID") + private List listClienteFidelidad; + @Column(name = "NUMIDENTIFICAUNO") + private String numIdentificaUno; + @Column(name = "NUMIDENTIFICADOS") + private String numIdentificaDos; - public Cliente() { - } + public Cliente() { + } - public Cliente(Integer clienteId) { - this.clienteId = clienteId; - } + public Cliente(Integer clienteId) { + this.clienteId = clienteId; + } - public Integer getClienteId() { - return clienteId; - } + public Integer getClienteId() { + return clienteId; + } - public void setClienteId(Integer clienteId) { - this.clienteId = clienteId; - } + public void setClienteId(Integer clienteId) { + this.clienteId = clienteId; + } - public String getNombcliente() { - return nombcliente; - } + public String getNombcliente() { + return nombcliente; + } - public void setNombcliente(String nombcliente) { - this.nombcliente = nombcliente; - } + public void setNombcliente(String nombcliente) { + this.nombcliente = nombcliente; + } - public String getApellidopaterno() { - return apellidopaterno; - } + public String getApellidopaterno() { + return apellidopaterno; + } - public void setApellidopaterno(String apellidopaterno) { - this.apellidopaterno = apellidopaterno; - } + public void setApellidopaterno(String apellidopaterno) { + this.apellidopaterno = apellidopaterno; + } - public String getApellidomaterno() { - return apellidomaterno; - } + public String getApellidomaterno() { + return apellidomaterno; + } - public void setApellidomaterno(String apellidomaterno) { - this.apellidomaterno = apellidomaterno; - } + public void setApellidomaterno(String apellidomaterno) { + this.apellidomaterno = apellidomaterno; + } - public Date getFecnacimiento() { - return fecnacimiento; - } + public Date getFecnacimiento() { + return fecnacimiento; + } - public void setFecnacimiento(Date fecnacimiento) { - this.fecnacimiento = fecnacimiento; - } + public void setFecnacimiento(Date fecnacimiento) { + this.fecnacimiento = fecnacimiento; + } - public String getNumrfc() { - return numrfc; - } + public String getNumrfc() { + return numrfc; + } - public void setNumrfc(String numrfc) { - this.numrfc = numrfc; - } + public void setNumrfc(String numrfc) { + this.numrfc = numrfc; + } - public String getNumtelefono() { - return numtelefono; - } + public String getNumtelefono() { + return numtelefono; + } - public void setNumtelefono(String numtelefono) { - this.numtelefono = numtelefono; - } + public void setNumtelefono(String numtelefono) { + this.numtelefono = numtelefono; + } - public String getNumtelefonodos() { - return numtelefonodos; - } + public String getNumtelefonodos() { + return numtelefonodos; + } - public void setNumtelefonodos(String numtelefonodos) { - this.numtelefonodos = numtelefonodos; - } + public void setNumtelefonodos(String numtelefonodos) { + this.numtelefonodos = numtelefonodos; + } - public String getNumfax() { - return numfax; - } + public String getNumfax() { + return numfax; + } - public void setNumfax(String numfax) { - this.numfax = numfax; - } + public void setNumfax(String numfax) { + this.numfax = numfax; + } - public String getNumextension() { - return numextension; - } + public String getNumextension() { + return numextension; + } - public void setNumextension(String numextension) { - this.numextension = numextension; - } + public void setNumextension(String numextension) { + this.numextension = numextension; + } - public String getNumextensiondos() { - return numextensiondos; - } + public String getNumextensiondos() { + return numextensiondos; + } - public void setNumextensiondos(String numextensiondos) { - this.numextensiondos = numextensiondos; - } + public void setNumextensiondos(String numextensiondos) { + this.numextensiondos = numextensiondos; + } - public TipoOcupacion getTipoocupacionId() { - return tipoocupacionId; - } + public TipoOcupacion getTipoocupacionId() { + return tipoocupacionId; + } - public void setTipoocupacionId(TipoOcupacion tipoocupacionId) { - this.tipoocupacionId = tipoocupacionId; - } + public void setTipoocupacionId(TipoOcupacion tipoocupacionId) { + this.tipoocupacionId = tipoocupacionId; + } - public Integer getMedioinformativoId() { - return medioinformativoId; - } + public Integer getMedioinformativoId() { + return medioinformativoId; + } - public void setMedioinformativoId(Integer medioinformativoId) { - this.medioinformativoId = medioinformativoId; - } + public void setMedioinformativoId(Integer medioinformativoId) { + this.medioinformativoId = medioinformativoId; + } - public MotivoViaje getMotivoviajeId() { - return motivoviajeId; - } + public MotivoViaje getMotivoviajeId() { + return motivoviajeId; + } - public void setMotivoviajeId(MotivoViaje motivoviajeId) { - this.motivoviajeId = motivoviajeId; - } + public void setMotivoviajeId(MotivoViaje motivoviajeId) { + this.motivoviajeId = motivoviajeId; + } - public String getIndsexo() { - return indsexo; - } + public String getIndsexo() { + return indsexo; + } - public void setIndsexo(String indsexo) { - this.indsexo = indsexo; - } + public void setIndsexo(String indsexo) { + this.indsexo = indsexo; + } - public String getNumcurp() { - return numcurp; - } + public String getNumcurp() { + return numcurp; + } - public void setNumcurp(String numcurp) { - this.numcurp = numcurp; - } + public void setNumcurp(String numcurp) { + this.numcurp = numcurp; + } - public Integer getCanthijos() { - return canthijos; - } + public Integer getCanthijos() { + return canthijos; + } - public void setCanthijos(Integer canthijos) { - this.canthijos = canthijos; - } + public void setCanthijos(Integer canthijos) { + this.canthijos = canthijos; + } - public String getDesccorreo() { - return desccorreo; - } + public String getDesccorreo() { + return desccorreo; + } - public void setDesccorreo(String desccorreo) { - this.desccorreo = desccorreo; - } + public void setDesccorreo(String desccorreo) { + this.desccorreo = desccorreo; + } - public Integer getEdad() { - return edad; - } + public Integer getEdad() { + return edad; + } - public void setEdad(Integer edad) { - this.edad = edad; - } + public void setEdad(Integer edad) { + this.edad = edad; + } - public Integer getEstadocivilId() { - return estadocivilId; - } + public Integer getEstadocivilId() { + return estadocivilId; + } - public void setEstadocivilId(Integer estadocivilId) { - this.estadocivilId = estadocivilId; - } + public void setEstadocivilId(Integer estadocivilId) { + this.estadocivilId = estadocivilId; + } - public Integer getGradoestudioId() { - return gradoestudioId; - } + public Integer getGradoestudioId() { + return gradoestudioId; + } - public void setGradoestudioId(Integer gradoestudioId) { - this.gradoestudioId = gradoestudioId; - } + public void setGradoestudioId(Integer gradoestudioId) { + this.gradoestudioId = gradoestudioId; + } - public String getEquivalenciaId() { - return equivalenciaId; - } + public String getEquivalenciaId() { + return equivalenciaId; + } - public void setEquivalenciaId(String equivalenciaId) { - this.equivalenciaId = equivalenciaId; - } + public void setEquivalenciaId(String equivalenciaId) { + this.equivalenciaId = equivalenciaId; + } - public Boolean getActivo() { - return activo; - } + public Boolean getActivo() { + return activo; + } - public void setActivo(Boolean activo) { - this.activo = activo; - } + public void setActivo(Boolean activo) { + this.activo = activo; + } - public Date getFecmodif() { - return fecmodif; - } + public Date getFecmodif() { + return fecmodif; + } - public void setFecmodif(Date fecmodif) { - this.fecmodif = fecmodif; - } + public void setFecmodif(Date fecmodif) { + this.fecmodif = fecmodif; + } - public Integer getUsuarioId() { - return usuarioId; - } + public Integer getUsuarioId() { + return usuarioId; + } - public void setUsuarioId(Integer usuarioId) { - this.usuarioId = usuarioId; - } + public void setUsuarioId(Integer usuarioId) { + this.usuarioId = usuarioId; + } - public String getDesccontrasena() { - return desccontrasena; - } + public String getDesccontrasena() { + return desccontrasena; + } - public void setDesccontrasena(String desccontrasena) { - this.desccontrasena = desccontrasena; - } + public void setDesccontrasena(String desccontrasena) { + this.desccontrasena = desccontrasena; + } - public String getNumlada() { - return numlada; - } + public String getNumlada() { + return numlada; + } - public void setNumlada(String numlada) { - this.numlada = numlada; - } + public void setNumlada(String numlada) { + this.numlada = numlada; + } - public Integer getIndcambiocontrasena() { - return indcambiocontrasena; - } + public Integer getIndcambiocontrasena() { + return indcambiocontrasena; + } - public void setIndcambiocontrasena(Integer indcambiocontrasena) { - this.indcambiocontrasena = indcambiocontrasena; - } - + public void setIndcambiocontrasena(Integer indcambiocontrasena) { + this.indcambiocontrasena = indcambiocontrasena; + } - public List getLsClienteDireccion() { + public List getLsClienteDireccion() { return lsClienteDireccion; } @@ -377,29 +345,51 @@ public class Cliente implements Serializable { this.lsClienteDireccion = lsClienteDireccion; } + public List getListClienteFidelidad() { + return listClienteFidelidad; + } + + public void setListClienteFidelidad(List listClienteFidelidad) { + this.listClienteFidelidad = listClienteFidelidad; + } + + public String getNumIdentificaUno() { + return numIdentificaUno; + } + + public void setNumIdentificaUno(String numIdentificaUno) { + this.numIdentificaUno = numIdentificaUno; + } + + public String getNumIdentificaDos() { + return numIdentificaDos; + } + + public void setNumIdentificaDos(String numIdentificaDos) { + this.numIdentificaDos = numIdentificaDos; + } + @Override - public int hashCode() { - int hash = 0; - hash += (clienteId != null ? clienteId.hashCode() : 0); - return hash; - } + public int hashCode() { + int hash = 0; + hash += (clienteId != null ? clienteId.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 Cliente)) { - return false; - } - Cliente other = (Cliente) object; - if ((this.clienteId == null && other.clienteId != null) || (this.clienteId != null && !this.clienteId.equals(other.clienteId))) { - return false; - } - return true; - } + @Override + public boolean equals(Object object) { + if (!(object instanceof Cliente)) { + return false; + } + Cliente other = (Cliente) object; + if ((this.clienteId == null && other.clienteId != null) || (this.clienteId != null && !this.clienteId.equals(other.clienteId))) { + return false; + } + return true; + } - @Override - public String toString() { - return "com.rjconsultores.ventaboletos.entidad.Cliente[ clienteId=" + clienteId + " ]"; - } - + @Override + public String toString() { + return "com.rjconsultores.ventaboletos.entidad.Cliente[ clienteId=" + clienteId + " ]"; + } } diff --git a/src/com/rjconsultores/ventaboletos/entidad/ClienteFidelidad.java b/src/com/rjconsultores/ventaboletos/entidad/ClienteFidelidad.java new file mode 100644 index 000000000..a9ac7cbd9 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/entidad/ClienteFidelidad.java @@ -0,0 +1,128 @@ +package com.rjconsultores.ventaboletos.entidad; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Basic; +import javax.persistence.CascadeType; +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.OneToOne; +import javax.persistence.SequenceGenerator; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +@Entity +@SequenceGenerator(name = "CLIENTE_FIDELIDAD_SEQ", sequenceName = "CLIENTE_FIDELIDAD_SEQ", allocationSize = 1) +@Table(name = "CLIENTE_FIDELIDAD") +public class ClienteFidelidad implements Serializable { + + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.AUTO, generator = "CLIENTE_FIDELIDAD_SEQ") + @Column(name = "CLIENTEFIDELIDAD_ID") + private Integer clienteFidelidadId; + @OneToOne + @JoinColumn(name = "CLIENTE_ID") + private Cliente cliente; + @OneToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "TARJETAFIDELIDAD_ID") + private TarjetaFidelidad tarjetaFidelidad; + @OneToOne + @JoinColumn(name = "EMPRESA_ID") + private Empresa empresa; + @Column(name = "ACTIVO") + private Boolean activo; + @Column(name = "FECMODIF") + @Temporal(TemporalType.TIMESTAMP) + private Date fecmodif; + @Column(name = "USUARIO_ID") + private Integer usuarioId; + + public Integer getClienteFidelidadId() { + return clienteFidelidadId; + } + + public void setClienteFidelidadId(Integer clienteFidelidadId) { + this.clienteFidelidadId = clienteFidelidadId; + } + + public TarjetaFidelidad getTarjetaFidelidad() { + return tarjetaFidelidad; + } + + public void setTarjetaFidelidad(TarjetaFidelidad tarjetaFidelidad) { + this.tarjetaFidelidad = tarjetaFidelidad; + } + + public Empresa getEmpresa() { + return empresa; + } + + public void setEmpresa(Empresa empresa) { + this.empresa = empresa; + } + + 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; + } + + public Cliente getCliente() { + return cliente; + } + + public void setCliente(Cliente cliente) { + this.cliente = cliente; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((clienteFidelidadId == null) ? 0 : clienteFidelidadId.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; + ClienteFidelidad other = (ClienteFidelidad) obj; + if (clienteFidelidadId == null) { + if (other.clienteFidelidadId != null) + return false; + } else if (!clienteFidelidadId.equals(other.clienteFidelidadId)) + return false; + return true; + } +} diff --git a/src/com/rjconsultores/ventaboletos/entidad/TarjetaFidelidad.java b/src/com/rjconsultores/ventaboletos/entidad/TarjetaFidelidad.java index 0d5c173ee..8267cc770 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/TarjetaFidelidad.java +++ b/src/com/rjconsultores/ventaboletos/entidad/TarjetaFidelidad.java @@ -18,7 +18,7 @@ import javax.persistence.Temporal; import javax.persistence.TemporalType; /** - * + * * @author Shiro */ @Entity @@ -26,95 +26,94 @@ import javax.persistence.TemporalType; @Table(name = "TARJETA_FIDELIDAD") public class TarjetaFidelidad implements Serializable { - private static final long serialVersionUID = 1L; - @Id - @Basic(optional = false) - @GeneratedValue(strategy = GenerationType.AUTO, generator = "TARJETA_FIDELIDAD_SEQ") - @Column(name = "TARJETAFIDELIDAD_ID") - private Integer tarjetaFidelidadId; - @Column(name = "NUMTARJETA") - private String numTarjeta; - @Column(name = "DESCGENERACION") - private String descGeneracion; - @Column(name = "ACTIVO") - private Boolean activo; - @Column(name = "FECMODIF") - @Temporal(TemporalType.TIMESTAMP) - private Date fecmodif; - @Column(name = "USUARIO_ID") - private Integer usuarioId; + private static final long serialVersionUID = 1L; + @Id + @Basic(optional = false) + @GeneratedValue(strategy = GenerationType.AUTO, generator = "TARJETA_FIDELIDAD_SEQ") + @Column(name = "TARJETAFIDELIDAD_ID") + private Integer tarjetaFidelidadId; + @Column(name = "NUMTARJETA") + private Integer numTarjeta; + @Column(name = "DESCGENERACION") + private String descGeneracion; + @Column(name = "ACTIVO") + private Boolean activo; + @Column(name = "FECMODIF") + @Temporal(TemporalType.TIMESTAMP) + private Date fecmodif; + @Column(name = "USUARIO_ID") + private Integer usuarioId; - public Boolean getActivo() { - return activo; - } + public Boolean getActivo() { + return activo; + } - public void setActivo(Boolean activo) { - this.activo = activo; - } + public void setActivo(Boolean activo) { + this.activo = activo; + } - public String getDescGeneracion() { - return descGeneracion; - } + public String getDescGeneracion() { + return descGeneracion; + } - public void setDescGeneracion(String descGeneracion) { - this.descGeneracion = descGeneracion; - } + public void setDescGeneracion(String descGeneracion) { + this.descGeneracion = descGeneracion; + } - public Date getFecmodif() { - return fecmodif; - } + public Date getFecmodif() { + return fecmodif; + } - public void setFecmodif(Date fecmodif) { - this.fecmodif = fecmodif; - } + public void setFecmodif(Date fecmodif) { + this.fecmodif = fecmodif; + } - public String getNumTarjeta() { - return numTarjeta; - } + public Integer getNumTarjeta() { + return numTarjeta; + } - public void setNumTarjeta(String numTarjeta) { - this.numTarjeta = numTarjeta; - } + public void setNumTarjeta(Integer numTarjeta) { + this.numTarjeta = numTarjeta; + } - public Integer getTarjetaFidelidadId() { - return tarjetaFidelidadId; - } + public Integer getTarjetaFidelidadId() { + return tarjetaFidelidadId; + } - public void setTarjetaFidelidadId(Integer tarjetaFidelidadId) { - this.tarjetaFidelidadId = tarjetaFidelidadId; - } + public void setTarjetaFidelidadId(Integer tarjetaFidelidadId) { + this.tarjetaFidelidadId = tarjetaFidelidadId; + } - public Integer getUsuarioId() { - return usuarioId; - } + public Integer getUsuarioId() { + return usuarioId; + } - public void setUsuarioId(Integer usuarioId) { - this.usuarioId = usuarioId; - } + public void setUsuarioId(Integer usuarioId) { + this.usuarioId = usuarioId; + } - @Override - public int hashCode() { - int hash = 0; - hash += (tarjetaFidelidadId != null ? tarjetaFidelidadId.hashCode() : 0); - return hash; - } + @Override + public int hashCode() { + int hash = 0; + hash += (tarjetaFidelidadId != null ? tarjetaFidelidadId.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 TarjetaFidelidad)) { - return false; - } - TarjetaFidelidad other = (TarjetaFidelidad) object; - if ((this.tarjetaFidelidadId == null && other.tarjetaFidelidadId != null) || (this.tarjetaFidelidadId != null && !this.tarjetaFidelidadId.equals(other.tarjetaFidelidadId))) { - return false; - } - return true; - } + @Override + public boolean equals(Object object) { + if (!(object instanceof TarjetaFidelidad)) { + return false; + } + TarjetaFidelidad other = (TarjetaFidelidad) object; + if ((this.tarjetaFidelidadId == null && other.tarjetaFidelidadId != null) || (this.tarjetaFidelidadId != null && !this.tarjetaFidelidadId.equals(other.tarjetaFidelidadId))) { + return false; + } + return true; + } - @Override - public String toString() { - //return "com.rjconsultores.ventaboletos.entidad.TarjetaFidelidad[tarjetaFidelidadId=" + tarjetaFidelidadId + "]"; - return this.getDescGeneracion(); - } + @Override + public String toString() { + // return "com.rjconsultores.ventaboletos.entidad.TarjetaFidelidad[tarjetaFidelidadId=" + tarjetaFidelidadId + "]"; + return this.getDescGeneracion(); + } } diff --git a/src/com/rjconsultores/ventaboletos/service/ClienteService.java b/src/com/rjconsultores/ventaboletos/service/ClienteService.java index 669119d8c..9a7104cc3 100644 --- a/src/com/rjconsultores/ventaboletos/service/ClienteService.java +++ b/src/com/rjconsultores/ventaboletos/service/ClienteService.java @@ -8,10 +8,9 @@ import java.util.List; import com.rjconsultores.ventaboletos.entidad.Cliente; - - public interface ClienteService extends GenericService { - public List buscar(String numCliente); - + public List buscar(String numCliente); + + public Cliente buscarPorNumeroFidelidade(Integer numeroFidelidade); } diff --git a/src/com/rjconsultores/ventaboletos/service/ImportacaoClientesService.java b/src/com/rjconsultores/ventaboletos/service/ImportacaoClientesService.java new file mode 100644 index 000000000..44f822d9f --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/ImportacaoClientesService.java @@ -0,0 +1,10 @@ +package com.rjconsultores.ventaboletos.service; + +import java.io.Reader; +import java.util.List; + +public interface ImportacaoClientesService { + public List lerArquivo(Reader reader); + + public String[] salvarClientes(List clientes); +} diff --git a/src/com/rjconsultores/ventaboletos/service/impl/ClienteServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/ClienteServiceImpl.java index 352306ef5..d5c6338f0 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/ClienteServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/ClienteServiceImpl.java @@ -16,55 +16,56 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; /** - * + * * @author Desenvolvimento */ @Service("clienteService") public class ClienteServiceImpl implements ClienteService { - @Autowired - private ClienteDAO clienteDAO; + @Autowired + private ClienteDAO clienteDAO; - public List obtenerTodos() { - return clienteDAO.obtenerTodos(); - } + public List obtenerTodos() { + return clienteDAO.obtenerTodos(); + } - public Cliente obtenerID(Integer id) { - return clienteDAO.obtenerID(id); - } + public Cliente obtenerID(Integer id) { + return clienteDAO.obtenerID(id); + } - @Transactional - public Cliente suscribir(Cliente entidad) { - entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); - entidad.setFecmodif(Calendar.getInstance().getTime()); - entidad.setActivo(Boolean.TRUE); + @Transactional + public Cliente suscribir(Cliente entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.TRUE); - return clienteDAO.suscribir(entidad); - } + return clienteDAO.suscribir(entidad); + } - @Transactional - public Cliente actualizacion(Cliente entidad) { - entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); - entidad.setFecmodif(Calendar.getInstance().getTime()); - entidad.setActivo(Boolean.TRUE); + @Transactional + public Cliente actualizacion(Cliente entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.TRUE); - return clienteDAO.actualizacion(entidad); - } + return clienteDAO.actualizacion(entidad); + } - - @Transactional - public void borrar(Cliente entidad) { - entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); - entidad.setFecmodif(Calendar.getInstance().getTime()); - entidad.setActivo(Boolean.FALSE); + @Transactional + public void borrar(Cliente entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.FALSE); - clienteDAO.actualizacion(entidad); - } - - - public List buscar(String numbCliente) { - return clienteDAO.buscar(numbCliente); - } + clienteDAO.actualizacion(entidad); + } - + public List buscar(String numbCliente) { + return clienteDAO.buscar(numbCliente); + } + + @Override + public Cliente buscarPorNumeroFidelidade(Integer numeroFidelidade) { + return clienteDAO.buscarPorNumeroFidelidade(numeroFidelidade); + } } diff --git a/src/com/rjconsultores/ventaboletos/service/impl/ImportacaoClientesServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/ImportacaoClientesServiceImpl.java new file mode 100644 index 000000000..3106a9f1d --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/impl/ImportacaoClientesServiceImpl.java @@ -0,0 +1,109 @@ +package com.rjconsultores.ventaboletos.service.impl; + +import java.io.BufferedReader; +import java.io.Reader; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; + +import org.apache.log4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.rjconsultores.ventaboletos.entidad.Cliente; +import com.rjconsultores.ventaboletos.entidad.ClienteFidelidad; +import com.rjconsultores.ventaboletos.entidad.TarjetaFidelidad; +import com.rjconsultores.ventaboletos.service.ClienteService; +import com.rjconsultores.ventaboletos.service.ImportacaoClientesService; +import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; + +@Service("importacaoClientesService") +public class ImportacaoClientesServiceImpl implements ImportacaoClientesService { + + @Autowired + private ClienteService clienteService; + private static Logger log = Logger.getLogger(ImportacaoClientesServiceImpl.class); + + @Override + public List lerArquivo(Reader reader) { + String linha = null; + List listaClientes = new ArrayList(); + try { + BufferedReader leitor = new BufferedReader(reader); + + while ((linha = leitor.readLine()) != null) { + String[] dados = linha.split(","); + listaClientes.add(dados); + } + + leitor.close(); + } catch (Exception e) { + log.error(e); + } + + return listaClientes; + } + + @Override + public String[] salvarClientes(List clientes) { + StringBuilder qtdeGravados = new StringBuilder(); + StringBuilder erros = new StringBuilder(); + + Integer inseridos = 0; + Integer atualizados = 0; + for (int i = 0; i < clientes.size(); i++) { + String[] cliente = clientes.get(i); + try { + String nomeCliente = cliente[1].replace("\"", "").toUpperCase(); + if (nomeCliente.length() > 60) { + nomeCliente = nomeCliente.substring(0, 59); + } + + Cliente clienteGravar = clienteService.buscarPorNumeroFidelidade(Integer.parseInt(cliente[0])); + if (clienteGravar == null) { + clienteGravar = new Cliente(); + clienteGravar.setNombcliente(nomeCliente); + clienteGravar.setNumIdentificaUno(cliente[3]); + + TarjetaFidelidad tarjetaFidelidad = new TarjetaFidelidad(); + tarjetaFidelidad.setActivo(Boolean.TRUE); + tarjetaFidelidad.setFecmodif(Calendar.getInstance().getTime()); + tarjetaFidelidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + // cast para Integer para remover 0 a esquedas: + tarjetaFidelidad.setNumTarjeta(Integer.parseInt(cliente[0])); + + ClienteFidelidad clienteFidelidad = new ClienteFidelidad(); + clienteFidelidad.setTarjetaFidelidad(tarjetaFidelidad); + clienteFidelidad.setActivo(Boolean.TRUE); + clienteFidelidad.setFecmodif(Calendar.getInstance().getTime()); + clienteFidelidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + clienteFidelidad.setCliente(clienteGravar); + List ls = new ArrayList(); + ls.add(clienteFidelidad); + clienteGravar.setListClienteFidelidad(ls); + + clienteService.suscribir(clienteGravar); + inseridos = inseridos + 1; + } else { + clienteGravar.setNombcliente(nomeCliente); + clienteGravar.setNumIdentificaUno(cliente[3]); + clienteService.actualizacion(clienteGravar); + + atualizados = atualizados + 1; + } + } catch (Exception e) { + erros.append("Linha ").append(i).append(" do arquivo de clientes, erro: ").append(e.getCause().getCause()).append("\n"); + + log.error(e); + } + } + + qtdeGravados.append("Gravados ").append(inseridos + atualizados).append(" clientes de ").append(clientes.size()).append(" importados.\n"); + qtdeGravados.append("Atualizados ").append(atualizados).append(" clientes.\n"); + qtdeGravados.append("Inseridos ").append(inseridos).append(" novos clientes."); + + String[] resultado = { qtdeGravados.toString(), erros.toString() }; + + return resultado; + } +} diff --git a/src/hibernate.cfg.xml b/src/hibernate.cfg.xml index 918aae759..7ee63aa7f 100644 --- a/src/hibernate.cfg.xml +++ b/src/hibernate.cfg.xml @@ -1,207 +1,200 @@ - - - - - - - oracle.jdbc.OracleDriver - - jdbc:oracle:thin:@sistema.grupoguanabara.net.br:1521:ORCL - - vtabol - - vtax05 - - - - - - - org.hibernate.dialect.Oracle10gDialect - - true - - true 1, false 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + oracle.jdbc.OracleDriver + jdbc:oracle:thin:@sistema.grupoguanabara.net.br:1521:ORCL + vtabol + vtax05 + + org.hibernate.dialect.Oracle10gDialect + true + true 1, false 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -