diff --git a/src/com/rjconsultores/ventaboletos/dao/EstacionDAO.java b/src/com/rjconsultores/ventaboletos/dao/EstacionDAO.java index 3aa3b19c4..ed58a6ed9 100644 --- a/src/com/rjconsultores/ventaboletos/dao/EstacionDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/EstacionDAO.java @@ -39,4 +39,12 @@ public interface EstacionDAO extends GenericDAO { public Boolean temEstoque(PuntoVenta puntoVenta, Estacion estacion); public List buscarEstacionesStockCentral(PuntoVenta puntoVenta); + + /** + * Retorna a estação duplicada pelo MAC + * @param descMac + * @param estacionId + * @return + */ + public Estacion buscarEstacionDuplicada(String descMac, Integer estacionId); } diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/EstacionHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/EstacionHibernateDAO.java index 553a77827..77af646e1 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/EstacionHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/EstacionHibernateDAO.java @@ -4,12 +4,14 @@ */ package com.rjconsultores.ventaboletos.dao.hibernate; -import java.math.BigDecimal; import java.util.List; +import org.apache.commons.lang.StringUtils; import org.hibernate.Criteria; +import org.hibernate.Query; import org.hibernate.SQLQuery; import org.hibernate.SessionFactory; +import org.hibernate.criterion.MatchMode; import org.hibernate.criterion.Order; import org.hibernate.criterion.Projections; import org.hibernate.criterion.Property; @@ -48,10 +50,20 @@ public class EstacionHibernateDAO extends GenericHibernateDAO Criteria c = getSession().createCriteria(getPersistentClass()); c.add(Restrictions.eq("activo", Boolean.TRUE)); - c.add(Restrictions.eq("descestacion", descEstacion)); - c.add(Restrictions.eq("descmac", descMac)); - c.add(Restrictions.eq("numcaja", nunCaja)); - c.add(Restrictions.eq("puntoVenta", pv)); + if(StringUtils.isNotBlank(descEstacion)) { + c.add(Restrictions.like("descestacion", descEstacion, MatchMode.START)); + } + if(StringUtils.isNotBlank(descMac)) { + c.add(Restrictions.eq("descmac", descMac)); + } + if(nunCaja != null) { + c.add(Restrictions.eq("numcaja", nunCaja)); + } + if(pv != null) { + c.add(Restrictions.eq("puntoVenta", pv)); + } + + c.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return c.list(); } @@ -70,6 +82,7 @@ public class EstacionHibernateDAO extends GenericHibernateDAO c.add(Restrictions.eq("activo", Boolean.TRUE)); c.add(Restrictions.eq("numcaja", numCaja)); c.add(Restrictions.eq("puntoVenta", puntoVenta)); + c.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); return c.list(); } @@ -200,6 +213,32 @@ public class EstacionHibernateDAO extends GenericHibernateDAO return c.list(); } - + + @SuppressWarnings("unchecked") + public Estacion buscarEstacionDuplicada(String descMac, Integer estacionId) { + StringBuilder sQuery = new StringBuilder(); + sQuery.append("SELECT e ") + .append("FROM Estacion e ") + .append("WHERE e.activo = 1") + .append("AND e.descmac = :descmac "); + + if(estacionId != null) { + sQuery.append("AND e.estacionId <> :estacionId "); + } + + Query qr = getSession().createQuery(sQuery.toString()); + qr.setParameter("descmac", descMac); + if(estacionId != null) { + qr.setParameter("estacionId", estacionId); + } + qr.setMaxResults(1); + + List lsEstacions = qr.list(); + if(lsEstacions != null && !lsEstacions.isEmpty()) { + return lsEstacions.iterator().next(); + } + + return null; + } } diff --git a/src/com/rjconsultores/ventaboletos/entidad/Estacion.java b/src/com/rjconsultores/ventaboletos/entidad/Estacion.java index b9a77eea9..65382b0e3 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/Estacion.java +++ b/src/com/rjconsultores/ventaboletos/entidad/Estacion.java @@ -25,6 +25,8 @@ import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import org.hibernate.annotations.Where; + /** * * @author Administrador @@ -88,17 +90,29 @@ public class Estacion implements Serializable { private String nomeImpressoraBPe; @Column(name = "INDSTOCKCENTRAL") private Boolean indStockCentral; + @OneToMany(mappedBy = "estacion", cascade = CascadeType.ALL, fetch = FetchType.EAGER) + @Where(clause="activo=1") private List estacionSitefList; + @OneToMany(mappedBy = "estacion", cascade = CascadeType.ALL) + @Where(clause="activo=1") private List estacionRioCardList; + @OneToMany(mappedBy = "estacion", cascade = CascadeType.ALL) + @Where(clause="activo=1") private List lsEstacionImpresora; + @OneToMany(mappedBy = "estacion", cascade = CascadeType.ALL) + @Where(clause="activo=1") private List abastoBoletoList; + @OneToMany(mappedBy = "estacion", cascade = CascadeType.ALL) + @Where(clause="activo=1") private List requisicionBoletoList; + @OneToMany(mappedBy = "estacion", cascade = CascadeType.ALL) + @Where(clause="activo=1") private List folioPreimpresoList; public Estacion() { diff --git a/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java index 5e0bd8f8c..e2bb7748d 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java @@ -54,15 +54,11 @@ public class EstacionServiceImpl implements EstacionService { validarEstoqueUpdate(estacion); Boolean esMacDuplicado = Boolean.FALSE; - List lsEstacionMac = estacionDAO.buscar(estacion.getDescmac()); - if (!lsEstacionMac.isEmpty()) { - for (Estacion est : lsEstacionMac) { - if (!est.getEstacionId().equals(estacion.getEstacionId())) { - nomeEstacao = est.getDescestacion(); - numeroCaixa = est.getNumcaja(); - esMacDuplicado = Boolean.TRUE; - } - } + Estacion estacionDuplicada = estacionDAO.buscarEstacionDuplicada(estacion.getDescmac(), estacion.getEstacionId()); + if (estacionDuplicada != null) { + nomeEstacao = estacionDuplicada.getDescestacion(); + numeroCaixa = estacionDuplicada.getNumcaja(); + esMacDuplicado = Boolean.TRUE; } if (esMacDuplicado) { throw new BusinessException(Labels.getLabel("estacionServiceImpl.msg.macDuplicado") + "\n" @@ -99,11 +95,11 @@ public class EstacionServiceImpl implements EstacionService { String errorNoChequeFolio = null; for (EstacionImpresora ei : estacion.getLsEstacionImpresora()) { + boolean isImpressoraFiscal = validacionImpressoraFiscal(ei); if (ApplicationProperties.getInstance().generarRotinaFolios()) { errorNoChequeFolio = autorizaFolioService.noChequeFolioPreimpresos(ei, false); - } else if (validacionImpressoraFiscal(ei) && isNuevaFiscal) { - errorNoChequeFolio = autorizaFolioService.noChequeFolioPreimpresos(ei, true); - }else if(estacion.getIndStockCentral() != null && estacion.getIndStockCentral()){ + } else if ((isImpressoraFiscal && isNuevaFiscal) || + (estacion.getIndStockCentral() != null && estacion.getIndStockCentral() && isImpressoraFiscal)) { errorNoChequeFolio = autorizaFolioService.noChequeFolioPreimpresos(ei, true); } }