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