diff --git a/src/com/rjconsultores/ventaboletos/dao/EstacionDAO.java b/src/com/rjconsultores/ventaboletos/dao/EstacionDAO.java index ed58a6ed9..641aff86a 100644 --- a/src/com/rjconsultores/ventaboletos/dao/EstacionDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/EstacionDAO.java @@ -21,6 +21,8 @@ public interface EstacionDAO extends GenericDAO { public List buscar(String descMac); + public Estacion buscarPorIMEI(String imei); + /** * Hace la búsqueda de las estciones ativas por el numCaja y puntoVenta * @@ -46,5 +48,7 @@ public interface EstacionDAO extends GenericDAO { * @param estacionId * @return */ - public Estacion buscarEstacionDuplicada(String descMac, Integer estacionId); + public Estacion buscarEstacionDuplicadaPorMAC(String descMac, Integer estacionId); + + public Estacion buscarEstacionDuplicadaPorIMEI(String imei, Integer estacionId); } diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/EstacionHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/EstacionHibernateDAO.java index bdefe6687..2be743d2e 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/EstacionHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/EstacionHibernateDAO.java @@ -77,6 +77,14 @@ public class EstacionHibernateDAO extends GenericHibernateDAO return c.list(); } + public Estacion buscarPorIMEI(String imei) { + Criteria c = getSession().createCriteria(getPersistentClass()); + c.add(Restrictions.eq("activo", Boolean.TRUE)); + c.add(Restrictions.eq("imei", imei)); + + return (Estacion) c.uniqueResult(); + } + @Override public List buscar(Long numCaja, PuntoVenta puntoVenta) { Criteria c = getSession().createCriteria(getPersistentClass()); @@ -214,7 +222,7 @@ public class EstacionHibernateDAO extends GenericHibernateDAO return c.list(); } - public Estacion buscarEstacionDuplicada(String descMac, Integer estacionId) { + public Estacion buscarEstacionDuplicadaPorMAC(String descMac, Integer estacionId) { StringBuilder sQuery = new StringBuilder(); sQuery.append("SELECT e ") .append("FROM Estacion e ") @@ -227,17 +235,48 @@ public class EstacionHibernateDAO extends GenericHibernateDAO 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; + } + + public Estacion buscarEstacionDuplicadaPorIMEI(String imei, Integer estacionId) { + StringBuilder sQuery = new StringBuilder(); + sQuery.append("SELECT e ") + .append("FROM Estacion e ") + .append("WHERE e.activo = 1") + .append("AND e.imei = :imei "); + + if(estacionId != null) { + sQuery.append("AND e.estacionId <> :estacionId "); + } + + Query qr = getSession().createQuery(sQuery.toString()); + qr.setParameter("imei", imei); + + 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 0116ab859..4b0826ab4 100644 --- a/src/com/rjconsultores/ventaboletos/entidad/Estacion.java +++ b/src/com/rjconsultores/ventaboletos/entidad/Estacion.java @@ -96,6 +96,8 @@ public class Estacion implements Serializable { private Integer tipoImpressoraRelatorio; @Column(name = "INDMAPAVIAGEMIMPTERMICA") private Boolean indMapaViagemImpTermica; + @Column(name = "IMEI") + private String imei; @OneToMany(mappedBy = "estacion", cascade = CascadeType.ALL, fetch = FetchType.EAGER) @Where(clause="activo=1") @@ -434,4 +436,11 @@ public class Estacion implements Serializable { this.indMapaViagemImpTermica = indMapaViagemImpTermica; } + public String getImei() { + return imei; + } + + public void setImei(String imei) { + this.imei = imei; + } } diff --git a/src/com/rjconsultores/ventaboletos/service/EstacionService.java b/src/com/rjconsultores/ventaboletos/service/EstacionService.java index 5d1c76f4a..ded2801aa 100644 --- a/src/com/rjconsultores/ventaboletos/service/EstacionService.java +++ b/src/com/rjconsultores/ventaboletos/service/EstacionService.java @@ -37,6 +37,8 @@ public interface EstacionService { public List buscar(String descMac); + public Estacion buscarPorIMEI(String imei); + public Long getDecimalMAC(String mac); public List buscarEstaciones(PuntoVenta puntoVenta); diff --git a/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java index cfc805ff9..a133e81ae 100644 --- a/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java +++ b/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java @@ -49,31 +49,13 @@ public class EstacionServiceImpl implements EstacionService { @Transactional(rollbackFor = BusinessException.class) public Estacion suscribirActualizar(Estacion estacion) throws BusinessException { - String nomeEstacao = ""; - Long numeroCaixa = 0l; - validarEstoqueUpdate(estacion); - Boolean esMacDuplicado = Boolean.FALSE; - Estacion estacionDuplicada = estacionDAO.buscarEstacionDuplicada(estacion.getDescmac(), estacion.getEstacionId()); - if (estacionDuplicada != null) { - nomeEstacao = estacionDuplicada.getDescestacion(); - numeroCaixa = estacionDuplicada.getNumcaja(); - esMacDuplicado = Boolean.TRUE; - } - if (esMacDuplicado) { - - StringBuilder msg = new StringBuilder(); - msg.append( Labels.getLabel("estacionServiceImpl.msg.macDuplicado") ); - msg.append( "\n" ); - msg.append( Labels.getLabel("estacionServiceImpl.msg.macDuplicado.descricaoEstacao") ); - msg.append( nomeEstacao ); - msg.append( "\n" ); - msg.append( Labels.getLabel("estacionServiceImpl.msg.macDuplicado.numeroCaixa") ); - msg.append( numeroCaixa.toString() ); - - throw new BusinessException( msg.toString()); - } + if (estacion.getDescmac() != null && !estacion.getDescmac().isEmpty()) + validarDuplicidade(estacionDAO.buscarEstacionDuplicadaPorMAC(estacion.getDescmac(), estacion.getEstacionId())); + + if (estacion.getImei() != null && !estacion.getImei().isEmpty()) + validarDuplicidade(estacionDAO.buscarEstacionDuplicadaPorIMEI(estacion.getImei(), estacion.getEstacionId())); boolean esCajaDuplicado = false; List lsEstacion = estacionDAO.buscar(estacion.getNumcaja(), estacion.getPuntoVenta()); @@ -120,6 +102,32 @@ public class EstacionServiceImpl implements EstacionService { return estacion; } + private void validarDuplicidade(Estacion estacionValidacao) throws BusinessException { + Boolean esMacDuplicado = Boolean.FALSE; + + String nomeEstacao = ""; + Long numeroCaixa = 0l; + + if (estacionValidacao != null) { + nomeEstacao = estacionValidacao.getDescestacion(); + numeroCaixa = estacionValidacao.getNumcaja(); + esMacDuplicado = Boolean.TRUE; + } + + if (esMacDuplicado) { + StringBuilder msg = new StringBuilder(); + msg.append( Labels.getLabel("estacionServiceImpl.msg.macDuplicado") ); + msg.append( "\n" ); + msg.append( Labels.getLabel("estacionServiceImpl.msg.macDuplicado.descricaoEstacao") ); + msg.append( nomeEstacao ); + msg.append( "\n" ); + msg.append( Labels.getLabel("estacionServiceImpl.msg.macDuplicado.numeroCaixa") ); + msg.append( numeroCaixa.toString() ); + + throw new BusinessException( msg.toString()); + } + } + private boolean validacionNuevaImpressoraFiscal(final Estacion e) { for (EstacionImpresora ei : e.getLsEstacionImpresora()) { if(TipoImpressora.getTipoImpressoraFiscal(ei.getTipoImpressora())!=null && ei.getEstacionImpresoraId() == null){ @@ -198,6 +206,10 @@ public class EstacionServiceImpl implements EstacionService { return estacionDAO.buscar(descMac); } + public Estacion buscarPorIMEI(String imei) { + return estacionDAO.buscarPorIMEI(imei); + } + @Override public Long getDecimalMAC(String mac) { mac = mac.trim();