julio 2017-02-24 14:00:50 +00:00
parent 9385592dca
commit 07865102ee
1 changed files with 50 additions and 27 deletions

View File

@ -1,21 +1,21 @@
package com.rjconsultores.ventaboletos.service.impl; package com.rjconsultores.ventaboletos.service.impl;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.rmi.RemoteException; import java.rmi.RemoteException;
import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.text.Normalizer; import java.text.Normalizer;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
import javax.sql.DataSource; import javax.sql.DataSource;
import javax.xml.rpc.ServiceException;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.brazilutils.br.cpfcnpj.CpfCnpj; import org.brazilutils.br.cpfcnpj.CpfCnpj;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.tempuri.IAG; import org.tempuri.IAG;
@ -168,9 +168,13 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
} }
private void integrarFornecedorAG(PuntoVenta entidad) { private void integrarFornecedorAG(PuntoVenta entidad) {
try{
Connection connection = null;
try {
connection = getConnection();
IAGservice service = new IAGserviceLocator(); IAGservice service = new IAGserviceLocator();
DaoAG.getInstance().setDBConnection(dataSource.getConnection()); DaoAG.getInstance().setDBConnection(connection);
IAG iag = service.getIAGPort(new URL(DaoAG.getInstance().obterConstante(Constantes.URL_WS_AG))); IAG iag = service.getIAGPort(new URL(DaoAG.getInstance().obterConstante(Constantes.URL_WS_AG)));
TFornecedor fornecedor = null; TFornecedor fornecedor = null;
String strFornecedor = ""; String strFornecedor = "";
@ -232,23 +236,32 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
entidad.setMotivoNaoIntegradoAG(e.getMessage()); entidad.setMotivoNaoIntegradoAG(e.getMessage());
} }
} }
} catch (ServiceException se){ } catch (Exception e) {
wslog.error(se.toString()); wslog.error(e.getMessage(), e);
} catch (MalformedURLException me){ } finally {
wslog.error(me.toString()); try {
} catch (SQLException me){ if (connection != null && !connection.isClosed()) {
wslog.error(me.toString()); connection.close();
}
} catch (SQLException e) {
log.error("error fechar conexão", e);
throw new RuntimeException(e);
}
} }
} }
private void integrarClienteAG(PuntoVenta entidad) { private void integrarClienteAG(PuntoVenta entidad) {
try{
Connection connection = null;
try {
connection = getConnection();
IAGservice service = new IAGserviceLocator(); IAGservice service = new IAGserviceLocator();
DaoAG.getInstance().setDBConnection(dataSource.getConnection()); DaoAG.getInstance().setDBConnection(connection);
IAG iag = service.getIAGPort(new URL(DaoAG.getInstance().obterConstante(Constantes.URL_WS_AG))); IAG iag = service.getIAGPort(new URL(DaoAG.getInstance().obterConstante(Constantes.URL_WS_AG)));
TCliente cli = null; TCliente cli = null;
String cliStr = ""; String cliStr = "";
try{ try {
cliStr = iag.getClienteWithIDWS(entidad.getNumPuntoVenta().toString()); cliStr = iag.getClienteWithIDWS(entidad.getNumPuntoVenta().toString());
wslog.debug("Retorno consulta cliente ws: " + cliStr); wslog.debug("Retorno consulta cliente ws: " + cliStr);
} catch (RemoteException e) { } catch (RemoteException e) {
@ -257,8 +270,8 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
entidad.setMotivoNaoIntegradoAG("Erro ao conectar com o WS: " + e.toString()); entidad.setMotivoNaoIntegradoAG("Erro ao conectar com o WS: " + e.toString());
return; return;
} }
if (!cliStr.contains("ERRO")){ if (!cliStr.contains("ERRO")) {
// retornar msg a informação de registro já cadastrado // retornar msg a informação de registro já cadastrado
entidad.setIndIntegradoAG(false); entidad.setIndIntegradoAG(false);
entidad.setMotivoNaoIntegradoAG("Cliente já cadastrado"); entidad.setMotivoNaoIntegradoAG("Cliente já cadastrado");
} else { } else {
@ -272,10 +285,10 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
cli.setVencimento(0); cli.setVencimento(0);
cli.setContaContabil(""); cli.setContaContabil("");
cli.setCep(entidad.getCep()); cli.setCep(entidad.getCep());
cli.setLogradouro(""+entidad.getLogradouro()); cli.setLogradouro("" + entidad.getLogradouro());
cli.setBairro(entidad.getBairro()); cli.setBairro(entidad.getBairro());
cli.setNumero(""+entidad.getNumero()); cli.setNumero("" + entidad.getNumero());
cli.setComplemento(""+entidad.getComplemento()); cli.setComplemento("" + entidad.getComplemento());
cli.setUf(entidad.getUF()); cli.setUf(entidad.getUF());
cli.setCidade(entidad.getCidade()); cli.setCidade(entidad.getCidade());
cli.setDdd(""); cli.setDdd("");
@ -319,7 +332,7 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
cli.getServicosCliente().setDtCancelamento(Calendar.getInstance()); cli.getServicosCliente().setDtCancelamento(Calendar.getInstance());
cli.getServicosCliente().setObsCancelamento(""); cli.getServicosCliente().setObsCancelamento("");
cli.getServicosCliente().setCRS_Codigo(""); cli.getServicosCliente().setCRS_Codigo("");
try{ try {
String retornoAG = iag.incluiCliente(cli); String retornoAG = iag.incluiCliente(cli);
entidad.setIndIntegradoAG(true); entidad.setIndIntegradoAG(true);
wslog.debug(retornoAG); wslog.debug(retornoAG);
@ -328,15 +341,25 @@ public class PuntoVentaServiceImpl implements PuntoVentaService {
entidad.setMotivoNaoIntegradoAG(e.getMessage()); entidad.setMotivoNaoIntegradoAG(e.getMessage());
} }
} }
} catch (ServiceException se){
wslog.error(se.toString()); } catch (Exception e) {
} catch (MalformedURLException me){ wslog.error(e.getMessage(), e);
wslog.error(me.toString()); } finally {
} catch (SQLException me){ try {
wslog.error(me.toString()); if (connection != null && !connection.isClosed()) {
connection.close();
}
} catch (SQLException e) {
log.error("error fechar conexão", e);
throw new RuntimeException(e);
}
} }
} }
private Connection getConnection() {
return DataSourceUtils.getConnection(dataSource);
}
@Transactional(noRollbackFor = { IntegracionException.class, ValidacionCampoException.class}) @Transactional(noRollbackFor = { IntegracionException.class, ValidacionCampoException.class})
public PuntoVenta actualizacion(PuntoVenta entidad) throws IntegracionException, ValidacionCampoException { public PuntoVenta actualizacion(PuntoVenta entidad) throws IntegracionException, ValidacionCampoException {
entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId()); entidad.setUsuarioId(UsuarioLogado.getUsuarioLogado().getUsuarioId());