diff --git a/src/com/rjconsultores/ventaboletos/entidad/Estacion.java b/src/com/rjconsultores/ventaboletos/entidad/Estacion.java index c55b57983..20fc2b843 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/Estacion.java +++ b/src/com/rjconsultores/ventaboletos/entidad/Estacion.java @@ -5,16 +5,21 @@ package com.rjconsultores.ventaboletos.entidad; import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; import java.util.Date; +import java.util.List; + 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.ManyToOne; +import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.SequenceGenerator; import javax.persistence.Table; @@ -70,15 +75,14 @@ public class Estacion implements Serializable { private String nomeArquivoLayout; @Column(name = "NOMEIMPRESSORARELATORIO") private String nomeImpressoraRelatorio; + @OneToMany(mappedBy = "estacion", cascade = CascadeType.ALL,fetch=FetchType.EAGER) + private List estacionSitefList; - @JoinColumn(name = "ESTACIONSITEF_ID") - @ManyToOne(cascade=CascadeType.ALL) - private EstacionSitef estacionSitefId; public Estacion() { - this.estacionSitefId = new EstacionSitef(); - } + } + public Estacion(Integer estacionId) { this.estacionId = estacionId; @@ -196,14 +200,6 @@ public class Estacion implements Serializable { this.nomeImpressoraRelatorio = nomeImpressoraRelatorio; } - - public EstacionSitef getEstacionSitefId() { - return estacionSitefId; - } - - public void setEstacionSitefId(EstacionSitef estacionSitefId) { - this.estacionSitefId = estacionSitefId; - } @Override public int hashCode() { @@ -228,4 +224,21 @@ public class Estacion implements Serializable { public String toString() { return "com.rjconsultores.ventaboletos.entidad.Estacion[estacionId=" + estacionId + "]"; } + + public List getEstacionSitefList() { + List tmp = new ArrayList(); + + if(estacionSitefList != null){ + for(EstacionSitef es:estacionSitefList){ + if (es.getActivo()){ + tmp.add(es); + } + } + } + return tmp; + } + + public void setEstacionSitefList(List estacionSitefList) { + this.estacionSitefList = estacionSitefList; + } } diff --git a/src/com/rjconsultores/ventaboletos/entidad/EstacionSitef.java b/src/com/rjconsultores/ventaboletos/entidad/EstacionSitef.java index b18269a10..9edae397a 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/EstacionSitef.java +++ b/src/com/rjconsultores/ventaboletos/entidad/EstacionSitef.java @@ -9,20 +9,18 @@ import java.util.Date; import java.util.List; 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.NamedQueries; -import javax.persistence.NamedQuery; -import javax.persistence.OneToMany; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +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; /** * @@ -45,6 +43,12 @@ public class EstacionSitef implements Serializable { private Integer numfilial; @Column(name = "NUMPDV") private Integer numpdv; + @OneToOne + @JoinColumn(name = "EMPRESA_ID") + private Empresa empresa; + @ManyToOne + @JoinColumn(name = "ESTACION_ID", referencedColumnName = "ESTACION_ID") + private Estacion estacion; @Column(name = "USUARIO_ID") private Integer usuarioId; @Column(name = "ACTIVO") @@ -53,8 +57,6 @@ public class EstacionSitef implements Serializable { @Temporal(TemporalType.TIMESTAMP) private Date fecmodif; - @OneToMany(cascade = CascadeType.ALL, mappedBy = "estacionSitefId") - private List estacionList; public EstacionSitef() { } @@ -118,15 +120,7 @@ public class EstacionSitef implements Serializable { public void setFecmodif(Date fecmodif) { this.fecmodif = fecmodif; } - - - public List getEstacionList() { - return estacionList; - } - - public void setEstacionList(List estacionList) { - this.estacionList = estacionList; - } + @Override public int hashCode() { @@ -152,5 +146,21 @@ public class EstacionSitef implements Serializable { public String toString() { return "com.rjconsultores.ventaboletos.entidad.EstacionSitef[ estacionsitefId=" + estacionsitefId + " ]"; } + + public Empresa getEmpresa() { + return empresa; + } + + public void setEmpresa(Empresa empresa) { + this.empresa = empresa; + } + + public Estacion getEstacion() { + return estacion; + } + + public void setEstacion(Estacion estacion) { + this.estacion = estacion; + } } diff --git a/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java index d824601d0..1383447ec 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java @@ -13,6 +13,7 @@ import org.springframework.transaction.annotation.Transactional; import com.rjconsultores.ventaboletos.dao.EstacionDAO; import com.rjconsultores.ventaboletos.entidad.Estacion; +import com.rjconsultores.ventaboletos.entidad.EstacionSitef; import com.rjconsultores.ventaboletos.entidad.PuntoVenta; import com.rjconsultores.ventaboletos.exception.BusinessException; import com.rjconsultores.ventaboletos.service.EstacionService; @@ -25,89 +26,77 @@ import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado; @Service("estacionService") public class EstacionServiceImpl implements EstacionService { - @Autowired - private EstacionDAO estacionDAO; + @Autowired + private EstacionDAO estacionDAO; - public List obtenerTodos() { - return estacionDAO.obtenerTodos(); - } + public List obtenerTodos() { + return estacionDAO.obtenerTodos(); + } - public Estacion obtenerID(Integer id) { - return estacionDAO.obtenerID(id); - } + public Estacion obtenerID(Integer id) { + return estacionDAO.obtenerID(id); + } - @Transactional(rollbackFor=BusinessException.class) - public Estacion suscribirActualizar(Estacion estacion) throws BusinessException { - List lsEstacion = estacionDAO.buscar(estacion.getDescmac()); - boolean esDuplicado = false; + @Transactional(rollbackFor = BusinessException.class) + public Estacion suscribirActualizar(Estacion estacion) throws BusinessException { + List lsEstacion = estacionDAO.buscar(estacion.getDescmac()); - if (!lsEstacion.isEmpty()) { - if (estacion.getEstacionId() == null) { - esDuplicado = true; - } else { - esDuplicado = !lsEstacion.get(0).getEstacionId().equals(estacion.getEstacionId()); - } - } + boolean esCajaDuplicado = false; + lsEstacion = estacionDAO.buscar(estacion.getNumcaja(), estacion.getPuntoVenta()); - if (esDuplicado) { - throw new BusinessException("MSG.Registro.Existe"); - } + if (!lsEstacion.isEmpty()) { + if (estacion.getEstacionId() == null) { + esCajaDuplicado = true; + } else { + esCajaDuplicado = !lsEstacion.get(0).getEstacionId().equals(estacion.getEstacionId()); + } + } - boolean esCajaDuplicado = false; - lsEstacion = estacionDAO.buscar(estacion.getNumcaja(), estacion.getPuntoVenta()); + if (esCajaDuplicado) { + throw new BusinessException("estacionServiceImpl.msg.cajaDuplicado"); + } - if (!lsEstacion.isEmpty()) { - if (estacion.getEstacionId() == null) { - esCajaDuplicado = true; - } else { - esCajaDuplicado = !lsEstacion.get(0).getEstacionId().equals(estacion.getEstacionId()); - } - } + estacion.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + estacion.setFecmodif(Calendar.getInstance().getTime()); + estacion.setActivo(Boolean.TRUE); + if (estacion.getEstacionId() == null) { + return estacionDAO.suscribir(estacion); + } else { - if (esCajaDuplicado) { - throw new BusinessException("estacionServiceImpl.msg.cajaDuplicado"); - } + return estacionDAO.actualizacion(estacion); + } + } - estacion.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); - estacion.setFecmodif(Calendar.getInstance().getTime()); - estacion.setActivo(Boolean.TRUE); + @Transactional + public void borrar(Estacion entidad) { + entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + entidad.setFecmodif(Calendar.getInstance().getTime()); + entidad.setActivo(Boolean.FALSE); - if (estacion.getEstacionId() == null) { - return estacionDAO.suscribir(estacion); - } else { + if (entidad.getEstacionSitefList() != null) { + for (EstacionSitef es : entidad.getEstacionSitefList()) { + es.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); + es.setFecmodif(Calendar.getInstance().getTime()); + es.setActivo(Boolean.FALSE); + } + } - return estacionDAO.actualizacion(estacion); - } - } + estacionDAO.actualizacion(entidad); + } - @Transactional - public void borrar(Estacion entidad) { - entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); - entidad.setFecmodif(Calendar.getInstance().getTime()); - entidad.setActivo(Boolean.FALSE); - - if(entidad.getEstacionSitefId() != null){ - entidad.getEstacionSitefId().setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); - entidad.getEstacionSitefId().setFecmodif(Calendar.getInstance().getTime()); - entidad.getEstacionSitefId().setActivo(Boolean.FALSE); - } + public List buscar(String descEstacion, String descMac, Long nunCaja, PuntoVenta pv) { + return estacionDAO.buscar(descEstacion, descMac, nunCaja, pv); + } - estacionDAO.actualizacion(entidad); - } + public List buscar(String descMac) { + return estacionDAO.buscar(descMac); + } - public List buscar(String descEstacion, String descMac, Long nunCaja, PuntoVenta pv) { - return estacionDAO.buscar(descEstacion, descMac, nunCaja, pv); - } - - public List buscar(String descMac) { - return estacionDAO.buscar(descMac); - } - - @Override - public Long getDecimalMAC(String mac) { - mac = mac.trim(); - mac = mac.replace("-", ""); - return Long.parseLong(mac, 16); - } + @Override + public Long getDecimalMAC(String mac) { + mac = mac.trim(); + mac = mac.replace("-", ""); + return Long.parseLong(mac, 16); + } }