114 lines
3.6 KiB
Java
114 lines
3.6 KiB
Java
/*
|
|
* To change this template, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
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.EstacionDAO;
|
|
import com.rjconsultores.ventaboletos.entidad.Estacion;
|
|
import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
|
|
import com.rjconsultores.ventaboletos.exception.BusinessException;
|
|
import com.rjconsultores.ventaboletos.service.EstacionService;
|
|
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
|
|
|
/**
|
|
*
|
|
* @author Administrador
|
|
*/
|
|
@Service("estacionService")
|
|
public class EstacionServiceImpl implements EstacionService {
|
|
|
|
@Autowired
|
|
private EstacionDAO estacionDAO;
|
|
|
|
public List<Estacion> obtenerTodos() {
|
|
return estacionDAO.obtenerTodos();
|
|
}
|
|
|
|
public Estacion obtenerID(Integer id) {
|
|
return estacionDAO.obtenerID(id);
|
|
}
|
|
|
|
@Transactional(rollbackFor=BusinessException.class)
|
|
public Estacion suscribirActualizar(Estacion estacion) throws BusinessException {
|
|
List<Estacion> lsEstacion = estacionDAO.buscar(estacion.getDescmac());
|
|
boolean esDuplicado = false;
|
|
|
|
if (!lsEstacion.isEmpty()) {
|
|
if (estacion.getEstacionId() == null) {
|
|
esDuplicado = true;
|
|
} else {
|
|
esDuplicado = !lsEstacion.get(0).getEstacionId().equals(estacion.getEstacionId());
|
|
}
|
|
}
|
|
|
|
if (esDuplicado) {
|
|
throw new BusinessException("MSG.Registro.Existe");
|
|
}
|
|
|
|
boolean esCajaDuplicado = false;
|
|
lsEstacion = estacionDAO.buscar(estacion.getNumcaja(), estacion.getPuntoVenta());
|
|
|
|
if (!lsEstacion.isEmpty()) {
|
|
if (estacion.getEstacionId() == null) {
|
|
esCajaDuplicado = true;
|
|
} else {
|
|
esCajaDuplicado = !lsEstacion.get(0).getEstacionId().equals(estacion.getEstacionId());
|
|
}
|
|
}
|
|
|
|
|
|
if (esCajaDuplicado) {
|
|
throw new BusinessException("estacionServiceImpl.msg.cajaDuplicado");
|
|
}
|
|
|
|
estacion.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
|
estacion.setFecmodif(Calendar.getInstance().getTime());
|
|
estacion.setActivo(Boolean.TRUE);
|
|
|
|
if (estacion.getEstacionId() == null) {
|
|
return estacionDAO.suscribir(estacion);
|
|
} else {
|
|
|
|
return estacionDAO.actualizacion(estacion);
|
|
}
|
|
}
|
|
|
|
@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);
|
|
}
|
|
|
|
estacionDAO.actualizacion(entidad);
|
|
}
|
|
|
|
public List<Estacion> buscar(String descEstacion, String descMac, Long nunCaja, PuntoVenta pv) {
|
|
return estacionDAO.buscar(descEstacion, descMac, nunCaja, pv);
|
|
}
|
|
|
|
public List<Estacion> buscar(String descMac) {
|
|
return estacionDAO.buscar(descMac);
|
|
}
|
|
|
|
@Override
|
|
public Long getDecimalMAC(String mac) {
|
|
mac = mac.trim();
|
|
mac = mac.replace("-", "");
|
|
return Long.parseLong(mac, 16);
|
|
}
|
|
}
|