171 lines
5.7 KiB
Java
171 lines
5.7 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.PrecioVentajaDAO;
|
|
import com.rjconsultores.ventaboletos.entidad.PrecioVentaja;
|
|
import com.rjconsultores.ventaboletos.exception.BusinessException;
|
|
import com.rjconsultores.ventaboletos.service.PrecioVentajaService;
|
|
import com.rjconsultores.ventaboletos.service.RutaService;
|
|
import com.rjconsultores.ventaboletos.utilerias.UsuarioLogado;
|
|
|
|
/**
|
|
*
|
|
* @author Igor
|
|
*/
|
|
@Service("precioVentajaService")
|
|
public class PrecioVentajaServiceImpl implements PrecioVentajaService {
|
|
|
|
@Autowired
|
|
private PrecioVentajaDAO precioVentajaDAO;
|
|
|
|
@Autowired
|
|
private RutaService rutaService;
|
|
|
|
public List<PrecioVentaja> obtenerTodos() {
|
|
return null;
|
|
}
|
|
|
|
public PrecioVentaja obtenerID(Integer id) {
|
|
return null;
|
|
}
|
|
|
|
@Transactional
|
|
public PrecioVentaja suscribirActualizacion(PrecioVentaja entidad) throws BusinessException {
|
|
|
|
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
|
entidad.setFecmodif(Calendar.getInstance().getTime());
|
|
entidad.setActivo(Boolean.TRUE);
|
|
|
|
|
|
if(!verificarPreenhimentoLinhaOriginal(entidad)){
|
|
throw new BusinessException("editarPrecioVentajaController.MSG.linha.original");
|
|
}
|
|
|
|
if(!verificarPreenchimentoOrigemDestinoOriginais(entidad)){
|
|
throw new BusinessException("editarPrecioVentajaController.MSG.origem.destino.originais");
|
|
}
|
|
|
|
if(!verificarPreenhimentoLinhaASerCopiada(entidad)){
|
|
throw new BusinessException("editarPrecioVentajaController.MSG.linhaASerCopiada");
|
|
}
|
|
|
|
if(!verificarPreenchimentoOrigemDestinoASeremCopiados(entidad)){
|
|
throw new BusinessException("editarPrecioVentajaController.MSG.origem.destinoASeremCopiados");
|
|
}
|
|
|
|
if(!verificarPreenchimentoDataInicioFim(entidad)){
|
|
throw new BusinessException("editarPrecioVentajaController.MSG.data.InicioFim");
|
|
}
|
|
|
|
if(!verificarRutaOrigemDestinoOriginal(entidad)){
|
|
throw new BusinessException("editarPrecioVentajaController.MSG.destinoOuOrigemNaoExistemOriginal");
|
|
}
|
|
|
|
if(!verificarRutaOrigemDestinoASerCopiado(entidad)){
|
|
throw new BusinessException("editarPrecioVentajaController.MSG.destinoOuOrigemNaoExistemDestino");
|
|
}
|
|
|
|
Boolean precioVentajaDuplicado = validarDuplicidade(entidad);
|
|
|
|
if (precioVentajaDuplicado) {
|
|
throw new BusinessException("editarPrecioVentajaController.MSG.data.existeIgual", new Object[] { entidad.getOrigenOriginalId().getDescparada(),
|
|
entidad.getDestinoOriginalId().getDescparada(), entidad.getRutaOriginalId().getDescruta() });
|
|
}
|
|
|
|
|
|
|
|
if (entidad.getPrecioVentajaId() == null) {
|
|
return precioVentajaDAO.suscribir(entidad);
|
|
} else {
|
|
return precioVentajaDAO.actualizacion(entidad);
|
|
}
|
|
}
|
|
|
|
private Boolean validarDuplicidade(PrecioVentaja entidad) {
|
|
List<PrecioVentaja> lsPrecioVentaja = precioVentajaDAO.buscarPrecioVentaja(entidad.getOrigenOriginalId().getParadaId(), entidad.getDestinoOriginalId().getParadaId(), entidad.getRutaOriginalId().getRutaId(), entidad.getCorridaId() );
|
|
Boolean precioVentajaDuplicado = false;
|
|
|
|
if (!lsPrecioVentaja.isEmpty()) {
|
|
|
|
if (entidad.getPrecioVentajaId() == null){
|
|
precioVentajaDuplicado = Boolean.TRUE;
|
|
}else{
|
|
for (PrecioVentaja est : lsPrecioVentaja) {
|
|
if (!est.getPrecioVentajaId().equals(entidad.getPrecioVentajaId())) {
|
|
precioVentajaDuplicado = Boolean.TRUE;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return precioVentajaDuplicado;
|
|
}
|
|
|
|
private Boolean verificarPreenchimentoDataInicioFim(PrecioVentaja entidad){
|
|
if(entidad.getFechaInicio() == null || entidad.getFechaFinal() == null){
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private Boolean verificarPreenchimentoOrigemDestinoASeremCopiados(PrecioVentaja entidad){
|
|
if(entidad.getOrigenPrecioId() == null || entidad.getDestinoPrecioId() == null){
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private Boolean verificarPreenhimentoLinhaASerCopiada(PrecioVentaja entidad) {
|
|
if(entidad.getRutaPrecioId() == null){
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private Boolean verificarPreenchimentoOrigemDestinoOriginais(PrecioVentaja entidad){
|
|
if(entidad.getOrigenOriginalId() == null || entidad.getDestinoOriginalId() == null){
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private Boolean verificarPreenhimentoLinhaOriginal(PrecioVentaja entidad) {
|
|
if(entidad.getRutaOriginalId() == null){
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private Boolean verificarRutaOrigemDestinoOriginal(PrecioVentaja entidad) {
|
|
Boolean existeOrigemOriginal = rutaService.paradaExisteEnLaRuta(entidad.getOrigenOriginalId(), entidad.getRutaOriginalId());
|
|
Boolean exiteDestinoOriginal = rutaService.paradaExisteEnLaRuta(entidad.getDestinoOriginalId(), entidad.getRutaOriginalId());
|
|
return existeOrigemOriginal && exiteDestinoOriginal;
|
|
}
|
|
|
|
private Boolean verificarRutaOrigemDestinoASerCopiado(PrecioVentaja entidad) {
|
|
Boolean exiteOrigemASerCopiado = rutaService.paradaExisteEnLaRuta(entidad.getOrigenPrecioId(), entidad.getRutaPrecioId());
|
|
Boolean exiteDestinoASerCopiado = rutaService.paradaExisteEnLaRuta(entidad.getDestinoPrecioId(), entidad.getRutaPrecioId());
|
|
return exiteOrigemASerCopiado && exiteDestinoASerCopiado;
|
|
}
|
|
|
|
|
|
@Transactional
|
|
public void borrar(PrecioVentaja entidad) {
|
|
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());
|
|
entidad.setFecmodif(Calendar.getInstance().getTime());
|
|
entidad.setActivo(Boolean.FALSE);
|
|
precioVentajaDAO.actualizacion(entidad);
|
|
}
|
|
}
|