diff --git a/src/com/rjconsultores/ventaboletos/constantes/ConstantesVendaEmbarcada.java b/src/com/rjconsultores/ventaboletos/constantes/ConstantesVendaEmbarcada.java new file mode 100644 index 000000000..12de64bc3 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/constantes/ConstantesVendaEmbarcada.java @@ -0,0 +1,11 @@ +package com.rjconsultores.ventaboletos.constantes; + +public class ConstantesVendaEmbarcada { + + public static final int VENDA_GERADA = 0; + public static final int VENDA_BOLETO_ERROR = 1; + public static final int VENDA_BOLETO_FORMAPAGO_ERROR = 2; + public static final int VENDA_CAJA_ERROR = 3; + public static final int VENDA_CAJA_FORMAPAGO_ERROR = 4; + +} diff --git a/src/com/rjconsultores/ventaboletos/dao/CajaDAO.java b/src/com/rjconsultores/ventaboletos/dao/CajaDAO.java index 23040d48a..f21033526 100644 --- a/src/com/rjconsultores/ventaboletos/dao/CajaDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/CajaDAO.java @@ -3,6 +3,10 @@ package com.rjconsultores.ventaboletos.dao; import java.util.Date; import java.util.List; +import com.rjconsultores.ventaboletos.exception.VendaEmbarcadaBoletoException; +import com.rjconsultores.ventaboletos.exception.VendaEmbarcadaBoletoFormapagoException; +import com.rjconsultores.ventaboletos.exception.VendaEmbarcadaCajaException; +import com.rjconsultores.ventaboletos.exception.VendaEmbarcadaCajaFormapagoException; import com.rjconsultores.ventaboletos.vo.caja.CajaVO; import com.rjconsultores.ventaboletos.vo.caja.UsuarioVO; import com.rjconsultores.ventaboletos.vo.caja.VendaEmbarcadaVO; @@ -11,5 +15,5 @@ public interface CajaDAO { public List buscarCajaFecha(boolean yaCerrado, Date fechaDesde, Date fechaHasta); public List buscarCajaCerrado(Date fecha, String cveusuario, String turnoid); List buscarUsuarioCerrado(Date fecha); - public Integer gerarVendaEmbarcada(VendaEmbarcadaVO vendaEmbarcada); + public void gerarVendaEmbarcada(VendaEmbarcadaVO vendaEmbarcada) throws VendaEmbarcadaBoletoException, VendaEmbarcadaBoletoFormapagoException, VendaEmbarcadaCajaException, VendaEmbarcadaCajaFormapagoException; } diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/CajaHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/CajaHibernateDAO.java index 2177a7e23..65e481d99 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/CajaHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/CajaHibernateDAO.java @@ -18,9 +18,15 @@ import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; import com.rjconsultores.ventaboletos.dao.CajaDAO; import com.rjconsultores.ventaboletos.dao.sqlbuilder.SQLBuilder; +import com.rjconsultores.ventaboletos.exception.BusinessException; +import com.rjconsultores.ventaboletos.exception.VendaEmbarcadaBoletoException; +import com.rjconsultores.ventaboletos.exception.VendaEmbarcadaBoletoFormapagoException; +import com.rjconsultores.ventaboletos.exception.VendaEmbarcadaCajaException; +import com.rjconsultores.ventaboletos.exception.VendaEmbarcadaCajaFormapagoException; import com.rjconsultores.ventaboletos.vo.caja.CajaCerradoVO; import com.rjconsultores.ventaboletos.vo.caja.CajaVO; import com.rjconsultores.ventaboletos.vo.caja.ReceitaDespesaVO; @@ -29,16 +35,12 @@ import com.rjconsultores.ventaboletos.vo.caja.VendaEmbarcadaVO; @Repository("cajaDAO") public class CajaHibernateDAO extends GenericHibernateDAO implements CajaDAO { + private static Logger log = org.slf4j.LoggerFactory.getLogger(CajaHibernateDAO.class); + @Autowired private SQLBuilder sqlBuilder; - private final int VENDA_GERADA = 0; - private final int VENDA_BOLETO_ERROR = 1; - private final int VENDA_BOLETO_FORMAPAGO_ERROR = 2; - private final int VENDA_CAJA_ERROR = 3; - private final int VENDA_CAJA_FORMAPAGO_ERROR = 4; - @Autowired public CajaHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) { setSessionFactory(factory); @@ -183,130 +185,156 @@ public class CajaHibernateDAO extends GenericHibernateDAO implemen } @Override - public Integer gerarVendaEmbarcada(VendaEmbarcadaVO vendaEmbarcada) { - boolean statusBoleto = inserirBoletoVendaEmbarcada(vendaEmbarcada); - boolean statusBoletoFormaPago = inserirBoletoFormaPagoVendaEmbarcada(vendaEmbarcada); - boolean statusCaja = inserirCajaVendaEmbarcada(vendaEmbarcada); - boolean statusCajaFormaPago = inserirCajaFormaPagoVendaEmbarcada(vendaEmbarcada); - - if (!statusBoleto){ - return VENDA_BOLETO_ERROR; - } - - if (!statusBoletoFormaPago){ - return VENDA_BOLETO_FORMAPAGO_ERROR; - } - - if (!statusCaja){ - return VENDA_CAJA_ERROR; - } - - if (!statusCajaFormaPago){ - return VENDA_CAJA_FORMAPAGO_ERROR; - } - - return VENDA_GERADA; + @Transactional(rollbackFor={BusinessException.class,VendaEmbarcadaBoletoException.class,VendaEmbarcadaBoletoFormapagoException.class,VendaEmbarcadaCajaException.class,VendaEmbarcadaCajaFormapagoException.class}) + public void gerarVendaEmbarcada(VendaEmbarcadaVO vendaEmbarcada) throws VendaEmbarcadaBoletoException, VendaEmbarcadaBoletoFormapagoException, VendaEmbarcadaCajaException, VendaEmbarcadaCajaFormapagoException { + inserirBoletoVendaEmbarcada(vendaEmbarcada); + inserirBoletoFormaPagoVendaEmbarcada(vendaEmbarcada); + inserirCajaVendaEmbarcada(vendaEmbarcada); + inserirCajaFormaPagoVendaEmbarcada(vendaEmbarcada); } - private boolean inserirCajaVendaEmbarcada(VendaEmbarcadaVO vendaEmbarcada){ + private void inserirCajaVendaEmbarcada(VendaEmbarcadaVO vendaEmbarcada) throws VendaEmbarcadaCajaException{ - SQLQuery query = getSession().createSQLQuery(sqlBuilder.getSQLInserirCajaVendaEmbarcada()); + try { - vendaEmbarcada.setCajaId(obterIdCaja().longValue()); + SQLQuery query = getSession().createSQLQuery(sqlBuilder.getSQLInserirCajaVendaEmbarcada()); + + vendaEmbarcada.setCajaId(obterIdCaja().longValue()); + + query.setLong("cajaId", vendaEmbarcada.getCajaId()); + query.setString("numAsiento", vendaEmbarcada.getNumAsiento()); + query.setInteger("categoriaId", vendaEmbarcada.getCategoriaId()); + query.setInteger("claseServicioId", vendaEmbarcada.getClaseServicioId()); + query.setInteger("marcaId",vendaEmbarcada.getMarcaId()); + query.setInteger("origemId",vendaEmbarcada.getOrigemId()); + query.setInteger("destinoId",vendaEmbarcada.getDestinoId()); + query.setInteger("corridaId",vendaEmbarcada.getCorridaId()); + query.setDate("fecCorrida",vendaEmbarcada.getFecCorrida()); + query.setBigDecimal("precioBase",vendaEmbarcada.getPrecio()); + query.setBigDecimal("precioPagado",vendaEmbarcada.getPrecio()); + query.setInteger("tipoVentaId",vendaEmbarcada.getTipoVentaId()); + query.setDate("fechorViaje",vendaEmbarcada.getFechorViaje()); + query.setDate("fechorVenta",vendaEmbarcada.getFechorVenta()); + query.setInteger("puntoVentaId",vendaEmbarcada.getPuntoVentaId()); + query.setString("numOperacion",vendaEmbarcada.getNumOperacion()); + query.setBigInteger("empresaPuntoVentaId",vendaEmbarcada.getEmpresaId()); + query.setBigInteger("empresaCorridaId",vendaEmbarcada.getEmpresaId()); + query.setInteger("estacionId",vendaEmbarcada.getEstacionId()); + query.setInteger("usuarioId",vendaEmbarcada.getUsuarioId()); + query.setBigDecimal("importeTaxaEmbarque",vendaEmbarcada.getImporteTaxaEmbarque()); + query.setBigDecimal("importePedagio",vendaEmbarcada.getImportePedagio()); + query.setBigDecimal("importeOutros",vendaEmbarcada.getImporteOutros()); + query.setBigDecimal("importeSeguro",vendaEmbarcada.getImporteSeguro()); + query.setDate("fecCreacion", vendaEmbarcada.getFechorVenta()); + query.setInteger("rutaId", vendaEmbarcada.getRutaId()); + query.setTimestamp("fecModIf", vendaEmbarcada.getFecModIf()); - query.setLong("cajaId", vendaEmbarcada.getCajaId()); - query.setString("numAsiento", vendaEmbarcada.getNumAsiento()); - query.setInteger("categoriaId", vendaEmbarcada.getCategoriaId()); - query.setInteger("claseServicioId", vendaEmbarcada.getClaseServicioId()); - query.setInteger("marcaId",vendaEmbarcada.getMarcaId()); - query.setInteger("origemId",vendaEmbarcada.getOrigemId()); - query.setInteger("destinoId",vendaEmbarcada.getDestinoId()); - query.setInteger("corridaId",vendaEmbarcada.getCorridaId()); - query.setDate("fecCorrida",vendaEmbarcada.getFecCorrida()); - query.setBigDecimal("precioBase",vendaEmbarcada.getPrecio()); - query.setBigDecimal("precioPagado",vendaEmbarcada.getPrecio()); - query.setInteger("tipoVentaId",vendaEmbarcada.getTipoVentaId()); - query.setDate("fechorViaje",vendaEmbarcada.getFechorViaje()); - query.setDate("fechorVenta",vendaEmbarcada.getFechorVenta()); - query.setInteger("puntoVentaId",vendaEmbarcada.getPuntoVentaId()); - query.setString("numOperacion",vendaEmbarcada.getNumOperacion()); - query.setBigInteger("empresaPuntoVentaId",vendaEmbarcada.getEmpresaId()); - query.setBigInteger("empresaCorridaId",vendaEmbarcada.getEmpresaId()); - query.setInteger("estacionId",vendaEmbarcada.getEstacionId()); - query.setInteger("usuarioId",vendaEmbarcada.getUsuarioId()); - query.setBigDecimal("importeTaxaEmbarque",vendaEmbarcada.getImporteTaxaEmbarque()); - query.setBigDecimal("importePedagio",vendaEmbarcada.getImportePedagio()); - query.setBigDecimal("importeOutros",vendaEmbarcada.getImporteOutros()); - query.setBigDecimal("importeSeguro",vendaEmbarcada.getImporteSeguro()); - query.setDate("fecCreacion", vendaEmbarcada.getFechorVenta()); - query.setInteger("rutaId", vendaEmbarcada.getRutaId()); - query.setDate("fecModIf", vendaEmbarcada.getFecModIf()); + if (query.executeUpdate() != 1) { + throw new VendaEmbarcadaCajaException("Erro ao gerar caixa venda embarcada"); + } + + } catch (VendaEmbarcadaCajaException e) { + throw e; + } catch (Exception e) { + log.error(e.getMessage(), e); + throw new VendaEmbarcadaCajaException(e.getMessage(), e); + } - return (query.executeUpdate() == 1); } - private boolean inserirCajaFormaPagoVendaEmbarcada(VendaEmbarcadaVO vendaEmbarcada){ - SQLQuery query = getSession().createSQLQuery(sqlBuilder.getSQLInserirCajaFormaPagoVendaEmbarcada()); + private void inserirCajaFormaPagoVendaEmbarcada(VendaEmbarcadaVO vendaEmbarcada) throws VendaEmbarcadaCajaFormapagoException { + try { + SQLQuery query = getSession().createSQLQuery(sqlBuilder.getSQLInserirCajaFormaPagoVendaEmbarcada()); + + query.setInteger("formaPagoId", vendaEmbarcada.getFormaPagoId()); + query.setLong("cajaId", vendaEmbarcada.getCajaId()); + query.setBigDecimal("importe", vendaEmbarcada.getPrecio()); + query.setInteger("usuarioId", vendaEmbarcada.getUsuarioId()); + query.setLong("cajaFormaPagoId", obterIdCajaFormaPago().longValue()); + query.setTimestamp("fecModIf", vendaEmbarcada.getFecModIf()); + + if (query.executeUpdate() != 1) { + throw new VendaEmbarcadaCajaFormapagoException("Erro ao gerar forma de pagamento do caixa venda embarcada"); + } - query.setInteger("formaPagoId", vendaEmbarcada.getFormaPagoId()); - query.setLong("cajaId", vendaEmbarcada.getCajaId()); - query.setBigDecimal("importe", vendaEmbarcada.getPrecio()); - query.setInteger("usuarioId", vendaEmbarcada.getUsuarioId()); - query.setInteger("cajaFormaPagoId", obterIdCajaFormaPago().intValue()); - query.setDate("fecModIf", vendaEmbarcada.getFecModIf()); - - return (query.executeUpdate() == 1); + } catch (VendaEmbarcadaCajaFormapagoException e) { + throw e; + } catch (Exception e) { + log.error(e.getMessage(), e); + throw new VendaEmbarcadaCajaFormapagoException(e.getMessage(), e); + } } - private boolean inserirBoletoVendaEmbarcada(VendaEmbarcadaVO vendaEmbarcada) { - SQLQuery query = getSession().createSQLQuery(sqlBuilder.getSQLInserirBoletoVendaEmbarcada()); - - vendaEmbarcada.setBoletoId(obterIdBoleto().longValue()); - vendaEmbarcada.setNumOperacion(obterNumOperacion().toString()); + private void inserirBoletoVendaEmbarcada(VendaEmbarcadaVO vendaEmbarcada) throws VendaEmbarcadaBoletoException { + try { + + SQLQuery query = getSession().createSQLQuery(sqlBuilder.getSQLInserirBoletoVendaEmbarcada()); + + vendaEmbarcada.setBoletoId(obterIdBoleto().longValue()); + vendaEmbarcada.setNumOperacion(obterNumOperacion().toString()); + + query.setBigInteger("empresaCorridaId", vendaEmbarcada.getEmpresaId()); + query.setInteger("destinoId", vendaEmbarcada.getDestinoId()); + query.setInteger("tipoVentaId",vendaEmbarcada.getTipoVentaId()); + query.setInteger("categoriaId",vendaEmbarcada.getCategoriaId()); + query.setInteger("corridaId", vendaEmbarcada.getCorridaId()); + query.setInteger("claseServicioId", vendaEmbarcada.getClaseServicioId()); + query.setDate("fecCorrida", vendaEmbarcada.getFecCorrida()); + query.setInteger("puntoVentaId", vendaEmbarcada.getPuntoVentaId()); + query.setBigInteger("empresaPuntoVentaId", vendaEmbarcada.getEmpresaId()); + query.setInteger("origemId", vendaEmbarcada.getOrigemId()); + query.setInteger("marcaId", vendaEmbarcada.getMarcaId()); + query.setString("numAsiento", vendaEmbarcada.getNumAsiento()); + query.setBigDecimal("precioPagado", vendaEmbarcada.getPrecio()); + query.setDate("fechorViaje", vendaEmbarcada.getFechorViaje()); + query.setDate("fechorVenta", vendaEmbarcada.getFechorVenta()); + query.setString("numOperacion", vendaEmbarcada.getNumOperacion()); + query.setInteger("usuarioId",vendaEmbarcada.getUsuarioId()); + query.setBigDecimal("precioBase", vendaEmbarcada.getPrecio()); + query.setInteger("estacionId", vendaEmbarcada.getEstacionId()); + query.setBigDecimal("importeTaxaEmbarque", vendaEmbarcada.getImporteTaxaEmbarque()); + query.setBigDecimal("importePedagio", vendaEmbarcada.getImportePedagio()); + query.setBigDecimal("importeOutros", vendaEmbarcada.getImporteOutros()); + query.setBigDecimal("importeSeguro", vendaEmbarcada.getImporteSeguro()); + query.setInteger("rutaId", vendaEmbarcada.getRutaId()); + query.setLong("boletoId", vendaEmbarcada.getBoletoId()); + query.setTimestamp("fecModIf", vendaEmbarcada.getFecModIf()); + query.setBigDecimal("precioPricing", vendaEmbarcada.getPrecio()); + + if (query.executeUpdate() != 1) { + throw new VendaEmbarcadaBoletoException("Erro ao gerar boleto venda embarcada"); + } - query.setBigInteger("empresaCorridaId", vendaEmbarcada.getEmpresaId()); - query.setInteger("destinoId", vendaEmbarcada.getDestinoId()); - query.setInteger("tipoVentaId",vendaEmbarcada.getTipoVentaId()); - query.setInteger("categoriaId",vendaEmbarcada.getCategoriaId()); - query.setInteger("corridaId", vendaEmbarcada.getCorridaId()); - query.setInteger("claseServicioId", vendaEmbarcada.getClaseServicioId()); - query.setDate("fecCorrida", vendaEmbarcada.getFecCorrida()); - query.setInteger("puntoVentaId", vendaEmbarcada.getPuntoVentaId()); - query.setBigInteger("empresaPuntoVentaId", vendaEmbarcada.getEmpresaId()); - query.setInteger("origemId", vendaEmbarcada.getOrigemId()); - query.setInteger("marcaId", vendaEmbarcada.getMarcaId()); - query.setString("numAsiento", vendaEmbarcada.getNumAsiento()); - query.setBigDecimal("precioPagado", vendaEmbarcada.getPrecio()); - query.setDate("fechorViaje", vendaEmbarcada.getFechorViaje()); - query.setDate("fechorVenta", vendaEmbarcada.getFechorVenta()); - query.setString("numOperacion", vendaEmbarcada.getNumOperacion()); - query.setInteger("usuarioId",vendaEmbarcada.getUsuarioId()); - query.setBigDecimal("precioBase", vendaEmbarcada.getPrecio()); - query.setInteger("estacionId", vendaEmbarcada.getEstacionId()); - query.setBigDecimal("importeTaxaEmbarque", vendaEmbarcada.getImporteTaxaEmbarque()); - query.setBigDecimal("importePedagio", vendaEmbarcada.getImportePedagio()); - query.setBigDecimal("importeOutros", vendaEmbarcada.getImporteOutros()); - query.setBigDecimal("importeSeguro", vendaEmbarcada.getImporteSeguro()); - query.setInteger("rutaId", vendaEmbarcada.getRutaId()); - query.setLong("boletoId", vendaEmbarcada.getBoletoId()); - query.setDate("fecModIf", vendaEmbarcada.getFecModIf()); - query.setBigDecimal("precioPricing", vendaEmbarcada.getPrecio()); - - return (query.executeUpdate() == 1); + } catch (VendaEmbarcadaBoletoException e) { + throw e; + } catch (Exception e) { + log.error(e.getMessage(), e); + throw new VendaEmbarcadaBoletoException(e.getMessage(), e); + } } - private boolean inserirBoletoFormaPagoVendaEmbarcada(VendaEmbarcadaVO vendaEmbarcada){ - SQLQuery query = getSession().createSQLQuery(sqlBuilder.getSQLInserirBoletoFormaPagoVendaEmbarcada()); + private void inserirBoletoFormaPagoVendaEmbarcada(VendaEmbarcadaVO vendaEmbarcada) throws VendaEmbarcadaBoletoFormapagoException{ + try { - query.setInteger("formaPagoId", vendaEmbarcada.getFormaPagoId()); - query.setLong("boletoId", vendaEmbarcada.getBoletoId()); - query.setBigDecimal("importe", vendaEmbarcada.getPrecio()); - query.setDate("fecModIf", vendaEmbarcada.getFecModIf()); - query.setInteger("usuarioId", vendaEmbarcada.getUsuarioId()); - query.setBigDecimal("boletoFormaPagoId", obterIdBoletoFormaPago()); + SQLQuery query = getSession().createSQLQuery(sqlBuilder.getSQLInserirBoletoFormaPagoVendaEmbarcada()); + + query.setInteger("formaPagoId", vendaEmbarcada.getFormaPagoId()); + query.setLong("boletoId", vendaEmbarcada.getBoletoId()); + query.setBigDecimal("importe", vendaEmbarcada.getPrecio()); + query.setTimestamp("fecModIf", vendaEmbarcada.getFecModIf()); + query.setInteger("usuarioId", vendaEmbarcada.getUsuarioId()); + query.setBigDecimal("boletoFormaPagoId", obterIdBoletoFormaPago()); + + if (query.executeUpdate() != 1) { + throw new VendaEmbarcadaBoletoFormapagoException("Erro ao gerar forma de pagamento do boleto venda embarcada"); + } - - return (query.executeUpdate() == 1); + } catch (VendaEmbarcadaBoletoFormapagoException e) { + throw e; + } catch (Exception e) { + log.error(e.getMessage(), e); + throw new VendaEmbarcadaBoletoFormapagoException(e.getMessage(), e); + } } private BigDecimal obterIdBoletoFormaPago(){ diff --git a/src/com/rjconsultores/ventaboletos/dao/sqlbuilder/impl/SQLBuilderOracle.java b/src/com/rjconsultores/ventaboletos/dao/sqlbuilder/impl/SQLBuilderOracle.java index 83978a1b6..96fbf3bc0 100644 --- a/src/com/rjconsultores/ventaboletos/dao/sqlbuilder/impl/SQLBuilderOracle.java +++ b/src/com/rjconsultores/ventaboletos/dao/sqlbuilder/impl/SQLBuilderOracle.java @@ -997,11 +997,11 @@ public class SQLBuilderOracle implements SQLBuilder { sb.append(":cajaId,:numAsiento,:categoriaId,null,:claseServicioId,:marcaId,:origemId,:destinoId,:corridaId,:fecCorrida,null,:precioBase,"); sb.append(":precioPagado,null, :tipoVentaId, null, null, :fechorViaje, :fechorVenta, :puntoVentaId,null, :numOperacion,"); sb.append("'F',null, null, null, :empresaPuntoVentaId, :empresaCorridaId, null, null,"); - sb.append("'V',null, null, null, null, null, null, :fecCreacion, null, null, :estacionId,"); - sb.append("null, null, null, null,null, null, null, null, null,"); + sb.append("'V', 0, 0, 0, null, 0, null, :fecCreacion, null, null, :estacionId,"); + sb.append("0, null, null, null,null, null, null, null, null,"); sb.append("null, null, null, null, null, null, 1, :fecModIf, :usuarioId, 1,"); sb.append("null, null, null, null, null, :importeTaxaEmbarque, :importePedagio, :importeOutros,"); - sb.append(":importeSeguro, null, null, :rutaId, null, null, null, null, null)"); + sb.append(":importeSeguro, 0, null, :rutaId, null, null, null, 0, null)"); return sb.toString(); } @@ -1034,10 +1034,10 @@ public class SQLBuilderOracle implements SQLBuilder { sb.append("(:empresaCorridaId, :destinoId, :tipoVentaId, :categoriaId, null, :claseServicioId, :corridaId, :fecCorrida, :puntoVentaId, "); sb.append(":empresaPuntoVentaId, null, null, :origemId, :marcaId, null, null, :numAsiento, null,"); sb.append("null,null,:precioPagado,null,null, null, :fechorViaje, :fechorVenta, null, :numOperacion,"); - sb.append("'F', null, null, 'V', 0, 0, null, null, 1,"); - sb.append("null, :fecModIf, :usuarioId,null, null, null, null, :precioBase, null,"); + sb.append("'F', null, null, 'V', 0, 0, 0, null, 1,"); + sb.append("0, :fecModIf, :usuarioId,null, null, null, 0, :precioBase, null,"); sb.append("null,null, null, null, null, :estacionId, null, null, null,1,"); - sb.append("null, null, null, null, :precioPricing, null, null, :importeTaxaEmbarque,"); + sb.append("0, null, null, null, :precioPricing, null, null, :importeTaxaEmbarque,"); sb.append(":importePedagio, :importeOutros, :importeSeguro, null, null, null, null, null, null,"); sb.append("null, null, null, null, :rutaId, null, null, null,null, :boletoId)"); diff --git a/src/com/rjconsultores/ventaboletos/exception/VendaEmbarcadaBoletoException.java b/src/com/rjconsultores/ventaboletos/exception/VendaEmbarcadaBoletoException.java new file mode 100644 index 000000000..9f0b9d4b5 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/exception/VendaEmbarcadaBoletoException.java @@ -0,0 +1,19 @@ +package com.rjconsultores.ventaboletos.exception; + +public class VendaEmbarcadaBoletoException extends BusinessException { + + private static final long serialVersionUID = 1L; + + public VendaEmbarcadaBoletoException(String message) { + super(message); + } + + public VendaEmbarcadaBoletoException(String message, Boolean label) { + super(message, label); + } + + public VendaEmbarcadaBoletoException(String message, Object oMsg) { + super(message, oMsg); + } + +} diff --git a/src/com/rjconsultores/ventaboletos/exception/VendaEmbarcadaBoletoFormapagoException.java b/src/com/rjconsultores/ventaboletos/exception/VendaEmbarcadaBoletoFormapagoException.java new file mode 100644 index 000000000..9cb4e1c6b --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/exception/VendaEmbarcadaBoletoFormapagoException.java @@ -0,0 +1,19 @@ +package com.rjconsultores.ventaboletos.exception; + +public class VendaEmbarcadaBoletoFormapagoException extends BusinessException { + + private static final long serialVersionUID = 1L; + + public VendaEmbarcadaBoletoFormapagoException(String message) { + super(message); + } + + public VendaEmbarcadaBoletoFormapagoException(String message, Boolean label) { + super(message, label); + } + + public VendaEmbarcadaBoletoFormapagoException(String message, Object oMsg) { + super(message, oMsg); + } + +} diff --git a/src/com/rjconsultores/ventaboletos/exception/VendaEmbarcadaCajaException.java b/src/com/rjconsultores/ventaboletos/exception/VendaEmbarcadaCajaException.java new file mode 100644 index 000000000..a8aac1755 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/exception/VendaEmbarcadaCajaException.java @@ -0,0 +1,19 @@ +package com.rjconsultores.ventaboletos.exception; + +public class VendaEmbarcadaCajaException extends BusinessException { + + private static final long serialVersionUID = 1L; + + public VendaEmbarcadaCajaException(String message) { + super(message); + } + + public VendaEmbarcadaCajaException(String message, Boolean label) { + super(message, label); + } + + public VendaEmbarcadaCajaException(String message, Object oMsg) { + super(message, oMsg); + } + +} diff --git a/src/com/rjconsultores/ventaboletos/exception/VendaEmbarcadaCajaFormapagoException.java b/src/com/rjconsultores/ventaboletos/exception/VendaEmbarcadaCajaFormapagoException.java new file mode 100644 index 000000000..292d74544 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/exception/VendaEmbarcadaCajaFormapagoException.java @@ -0,0 +1,19 @@ +package com.rjconsultores.ventaboletos.exception; + +public class VendaEmbarcadaCajaFormapagoException extends BusinessException { + + private static final long serialVersionUID = 1L; + + public VendaEmbarcadaCajaFormapagoException(String message) { + super(message); + } + + public VendaEmbarcadaCajaFormapagoException(String message, Boolean label) { + super(message, label); + } + + public VendaEmbarcadaCajaFormapagoException(String message, Object oMsg) { + super(message, oMsg); + } + +} diff --git a/src/com/rjconsultores/ventaboletos/service/VendaEmbarcadaService.java b/src/com/rjconsultores/ventaboletos/service/VendaEmbarcadaService.java new file mode 100644 index 000000000..cf76608ab --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/VendaEmbarcadaService.java @@ -0,0 +1,10 @@ +package com.rjconsultores.ventaboletos.service; + +import com.rjconsultores.ventaboletos.exception.BusinessException; +import com.rjconsultores.ventaboletos.vo.caja.VendaEmbarcadaVO; + +public interface VendaEmbarcadaService { + + public int gerarVendaEmbarcada(VendaEmbarcadaVO vendaEmbarcada) throws BusinessException; + +} diff --git a/src/com/rjconsultores/ventaboletos/service/impl/VendaEmbarcadaServiceImpl.java b/src/com/rjconsultores/ventaboletos/service/impl/VendaEmbarcadaServiceImpl.java new file mode 100644 index 000000000..dc84a7730 --- /dev/null +++ b/src/com/rjconsultores/ventaboletos/service/impl/VendaEmbarcadaServiceImpl.java @@ -0,0 +1,51 @@ +package com.rjconsultores.ventaboletos.service.impl; + +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.rjconsultores.ventaboletos.constantes.ConstantesVendaEmbarcada; +import com.rjconsultores.ventaboletos.dao.CajaDAO; +import com.rjconsultores.ventaboletos.dao.hibernate.CajaHibernateDAO; +import com.rjconsultores.ventaboletos.exception.BusinessException; +import com.rjconsultores.ventaboletos.exception.VendaEmbarcadaBoletoException; +import com.rjconsultores.ventaboletos.exception.VendaEmbarcadaBoletoFormapagoException; +import com.rjconsultores.ventaboletos.exception.VendaEmbarcadaCajaException; +import com.rjconsultores.ventaboletos.exception.VendaEmbarcadaCajaFormapagoException; +import com.rjconsultores.ventaboletos.service.VendaEmbarcadaService; +import com.rjconsultores.ventaboletos.vo.caja.VendaEmbarcadaVO; + +@Service("VendaEmbarcadaService") +public class VendaEmbarcadaServiceImpl implements VendaEmbarcadaService { + + private static Logger log = org.slf4j.LoggerFactory.getLogger(CajaHibernateDAO.class); + + @Autowired + CajaDAO cajaDao; + + @Override + public int gerarVendaEmbarcada(VendaEmbarcadaVO vendaEmbarcada) throws BusinessException { + try { + cajaDao.gerarVendaEmbarcada(vendaEmbarcada); + + return ConstantesVendaEmbarcada.VENDA_GERADA; + } catch (VendaEmbarcadaBoletoException e) { + log.error(e.getMessage(), e); + return ConstantesVendaEmbarcada.VENDA_BOLETO_ERROR; + } catch (VendaEmbarcadaBoletoFormapagoException e) { + log.error(e.getMessage(), e); + return ConstantesVendaEmbarcada.VENDA_BOLETO_FORMAPAGO_ERROR; + } catch (VendaEmbarcadaCajaException e) { + log.error(e.getMessage(), e); + return ConstantesVendaEmbarcada.VENDA_CAJA_ERROR; + } catch (VendaEmbarcadaCajaFormapagoException e) { + log.error(e.getMessage(), e); + return ConstantesVendaEmbarcada.VENDA_CAJA_FORMAPAGO_ERROR; + } catch (Exception e) { + log.error(e.getMessage(), e); + throw new BusinessException(e.getMessage(), e); + } + + } + +} diff --git a/src/com/rjconsultores/ventaboletos/ws/rs/VendaEmbarcadaRS.java b/src/com/rjconsultores/ventaboletos/ws/rs/VendaEmbarcadaRS.java index da3e6bdf8..fb943b6ef 100644 --- a/src/com/rjconsultores/ventaboletos/ws/rs/VendaEmbarcadaRS.java +++ b/src/com/rjconsultores/ventaboletos/ws/rs/VendaEmbarcadaRS.java @@ -13,16 +13,21 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; -import com.rjconsultores.ventaboletos.dao.CajaDAO; +import org.slf4j.Logger; + +import com.rjconsultores.ventaboletos.dao.hibernate.CajaHibernateDAO; +import com.rjconsultores.ventaboletos.service.VendaEmbarcadaService; import com.rjconsultores.ventaboletos.vo.caja.VendaEmbarcadaVO; import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext; @Path("vendaEmbarcada") public class VendaEmbarcadaRS { + private static Logger log = org.slf4j.LoggerFactory.getLogger(VendaEmbarcadaRS.class); private final int CATEGORIA_NAO_SUPORTADA = 5; private final int DATA_COM_FORMATO_INVALIDO = 6; + private final int ERROR_NAO_SUPORTADO_INVALIDO = 7; @POST @Path("/gerarVenda/{numeroAssento}/{categoria}/{origemId}/{destinoId}/{servicoId}/{dataCorrida}/{dataVenda}/{preco}/{tipoVendaId}/{pontoVendaId}/{empresaCorridaId}/{estacaoId}/{usuarioId}/{empresaId}/{taxaEmbarque}/{pedagio}/{outros}/{seguro}/{rutaId}/{formaPagoId}/{classeServicoId}") @@ -81,14 +86,17 @@ public class VendaEmbarcadaRS { vendaEmbarcada.setImporteOutros(importeOutros); vendaEmbarcada.setImporteSeguro(importeSeguro); - CajaDAO cajaDAO = (CajaDAO) AppContext.getApplicationContext().getBean("cajaDAO"); + VendaEmbarcadaService vendaEmbarcadaService = (VendaEmbarcadaService) AppContext.getApplicationContext().getBean("VendaEmbarcadaService"); - int retornoVenda = cajaDAO.gerarVendaEmbarcada(vendaEmbarcada); + int retornoVenda = vendaEmbarcadaService.gerarVendaEmbarcada(vendaEmbarcada); return retornoJson.concat(retornoVenda + "'}"); } catch (ParseException e) { - e.printStackTrace(); + log.error(e.getMessage(), e); return retornoJson.concat(DATA_COM_FORMATO_INVALIDO + "'}"); + } catch (Exception e) { + log.error(e.getMessage(), e); + return retornoJson.concat(ERROR_NAO_SUPORTADO_INVALIDO + "'}"); } } } \ No newline at end of file