AdmMono/src/com/rjconsultores/ventaboletos/service/impl/EstacionServiceImpl.java

142 lines
4.3 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.EstacionSitef;
import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
import com.rjconsultores.ventaboletos.entidad.Usuario;
import com.rjconsultores.ventaboletos.exception.BusinessException;
import com.rjconsultores.ventaboletos.service.AutorizaFolioService;
import com.rjconsultores.ventaboletos.service.EstacionService;
import com.rjconsultores.ventaboletos.utilerias.ApplicationProperties;
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
/**
*
* @author Administrador
*/
@Service("estacionService")
public class EstacionServiceImpl implements EstacionService {
@Autowired
private EstacionDAO estacionDAO;
@Autowired
private AutorizaFolioService autorizaFolioService;
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 {
if (!ApplicationProperties.getInstance().generarRotinaFolios()){
Estacion estacionPuntoVentaAnterior = estacionDAO.obtenerID(estacion.getEstacionId());
if (!estacionPuntoVentaAnterior.getPuntoVenta().equals(estacion.getPuntoVenta())){
if (estacionDAO.temEstoque(estacionPuntoVentaAnterior.getPuntoVenta(), estacion)){
throw new BusinessException("estacionServiceImpl.msg.hayStock");
}
}
}
Boolean esMacDuplicado = Boolean.FALSE;
List<Estacion> lsEstacionMac = estacionDAO.buscar(estacion.getDescmac());
if (!lsEstacionMac.isEmpty()) {
for (Estacion est : lsEstacionMac) {
if (!est.getEstacionId().equals(estacion.getEstacionId())) {
esMacDuplicado = Boolean.TRUE;
}
}
}
if (esMacDuplicado) {
throw new BusinessException("estacionServiceImpl.msg.macDuplicado");
}
boolean esCajaDuplicado = false;
List<Estacion> 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) {
estacion = estacionDAO.suscribir(estacion);
} else {
estacion = estacionDAO.actualizacion(estacion);
}
if (ApplicationProperties.getInstance().generarRotinaFolios()) {
autorizaFolioService.noChequeFolioPreimpresos(estacion);
}
return estacion;
}
@Transactional
public void borrar(Estacion entidad) {
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
entidad.setFecmodif(Calendar.getInstance().getTime());
entidad.setActivo(Boolean.FALSE);
if (entidad.getEstacionSitefList() != null) {
for (EstacionSitef es : entidad.getEstacionSitefList()) {
es.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
es.setFecmodif(Calendar.getInstance().getTime());
es.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);
}
@Override
public List<Estacion> buscarEstaciones(PuntoVenta puntoVenta) {
List<Estacion> estaciones = estacionDAO.buscarEstaciones(puntoVenta);
return estaciones;
}
}