AdmMono/src/com/rjconsultores/ventaboletos/ws/rs/VendaEmbarcadaRS.java

103 lines
4.8 KiB
Java

package com.rjconsultores.ventaboletos.ws.rs;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.slf4j.Logger;
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}/{numFolioPreImpresso}/{serieImpFiscal}")
@Produces({MediaType.APPLICATION_JSON})
public String gerarVenda(@PathParam("numeroAssento") String numeroAssento, @PathParam("categoria") String categoria, @PathParam("origemId") Integer origemId,
@PathParam("destinoId") Integer destinoId, @PathParam("servicoId") Integer servicoId, @PathParam("dataCorrida") String dataCorrida, @PathParam("dataVenda") String dataVenda,
@PathParam("preco") BigDecimal preco, @PathParam("tipoVendaId") Integer tipoVendaId, @PathParam("pontoVendaId") Integer pontoVendaId,
@PathParam("empresaCorridaId") Integer empresaCorridaId, @PathParam("estacaoId") Integer estacaoId, @PathParam("usuarioId") Integer usuarioId,
@PathParam("empresaId") BigInteger empresaId, @PathParam("taxaEmbarque") BigDecimal importeTaxaEmbarque, @PathParam("pedagio") BigDecimal importePedagio,
@PathParam("outros") BigDecimal importeOutros, @PathParam("seguro") BigDecimal importeSeguro, @PathParam("rutaId") Integer rutaId, @PathParam("formaPagoId") Integer formaPagoId,
@PathParam("classeServicoId") Integer classeServicoId, @PathParam("numFolioPreImpresso") String numFolioPreImpresso, @PathParam("serieImpFiscal") String serieImpFiscal ){
String retornoJson = "{'response':'";
try {
int categoriaId = 1;
if (!categoria.equalsIgnoreCase("normal")){
return retornoJson.concat(CATEGORIA_NAO_SUPORTADA + "'}");
}
VendaEmbarcadaVO vendaEmbarcada = new VendaEmbarcadaVO();
vendaEmbarcada.setUsuarioId(usuarioId);
vendaEmbarcada.setClienteId(vendaEmbarcada.getUsuarioId());
vendaEmbarcada.setCategoriaId(categoriaId);
vendaEmbarcada.setCorridaId(servicoId);
vendaEmbarcada.setDestinoId(destinoId);
vendaEmbarcada.setOrigemId(origemId);
vendaEmbarcada.setEmpresaCorridaId(empresaCorridaId);
vendaEmbarcada.setTipoVentaId(tipoVendaId);
vendaEmbarcada.setEmpresaId(empresaId);
vendaEmbarcada.setPrecio(preco);
vendaEmbarcada.setNumAsiento(numeroAssento);
vendaEmbarcada.setPuntoVentaId(pontoVendaId);
vendaEmbarcada.setEmpresaPuntoVentaId(empresaId.intValue());
vendaEmbarcada.setEstacionId(estacaoId);
vendaEmbarcada.setRutaId(rutaId);
vendaEmbarcada.setClaseServicioId(classeServicoId);
vendaEmbarcada.setFormaPagoId(formaPagoId);
String data[] = dataCorrida.split("__");
if (data.length != 2){
return retornoJson.concat(DATA_COM_FORMATO_INVALIDO + "'}");
}
vendaEmbarcada.setFecCorrida(new Date(new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").parse(data[0].replace("_", "/").concat(" ").concat(data[1].replace("_", ":"))).getTime()));
vendaEmbarcada.setFechorViaje(vendaEmbarcada.getFecCorrida());
vendaEmbarcada.setFechorVenta(vendaEmbarcada.getFecCorrida());
vendaEmbarcada.setMarcaId(empresaId.intValue());
vendaEmbarcada.setImporteTaxaEmbarque(importeTaxaEmbarque);
vendaEmbarcada.setImportePedagio(importePedagio);
vendaEmbarcada.setImporteOutros(importeOutros);
vendaEmbarcada.setImporteSeguro(importeSeguro);
vendaEmbarcada.setNumFolioPreimpresso(numFolioPreImpresso);
vendaEmbarcada.setSerieImpFiscal(serieImpFiscal);
VendaEmbarcadaService vendaEmbarcadaService = (VendaEmbarcadaService) AppContext.getApplicationContext().getBean("VendaEmbarcadaService");
int retornoVenda = vendaEmbarcadaService.gerarVendaEmbarcada(vendaEmbarcada);
return retornoJson.concat(retornoVenda + "'}");
} catch (ParseException e) {
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 + "'}");
}
}
}