bug#AL-1726

Modificações dos metodos de integraçao para melhoria junto ao banco de
dados
master
Fabio Faria 2022-12-15 14:30:13 -03:00
parent 9ec6f09ad5
commit 0532d002d4
5 changed files with 55 additions and 24 deletions

19
pom.xml
View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>br.com.rjconsultores</groupId> <groupId>br.com.rjconsultores</groupId>
<artifactId>ModelWeb</artifactId> <artifactId>ModelWeb</artifactId>
<version>1.0.9</version> <version>1.0.10</version>
<distributionManagement> <distributionManagement>
<repository> <repository>
@ -133,7 +133,22 @@
<dependency> <dependency>
<groupId>org.jboss.resteasy</groupId> <groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId> <artifactId>resteasy-jaxrs</artifactId>
<version>3.15.3.Final</version> <version>3.14.0.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.14</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
<scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View File

@ -3,9 +3,12 @@ package com.rjconsultores.ventaboletos.dao.hibernate;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType; import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import com.rjconsultores.ventaboletos.dao.GenericDAO;
import org.hibernate.Criteria; import org.hibernate.Criteria;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
import org.hibernate.Session; import org.hibernate.Session;
@ -21,8 +24,6 @@ import org.hibernate.loader.criteria.CriteriaLoader;
import org.hibernate.persister.entity.OuterJoinLoadable; import org.hibernate.persister.entity.OuterJoinLoadable;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport; import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.rjconsultores.ventaboletos.dao.GenericDAO;
/** /**
* *
* @author gleimar * @author gleimar
@ -158,4 +159,13 @@ public class GenericHibernateDAO<T, ID extends Serializable> extends HibernateDa
return info; return info;
} }
public static <T> List<T> castList(Class<? extends T> clazz, Collection<?> rawCollection)
throws ClassCastException {
List<T> result = new ArrayList<T>(rawCollection.size());
for (Object o : rawCollection) {
result.add(clazz.cast(o));
}
return result;
}
} }

View File

@ -7,6 +7,15 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import javax.sql.DataSource;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
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.SapDAO; import com.rjconsultores.ventaboletos.dao.SapDAO;
import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.Empresa;
import com.rjconsultores.ventaboletos.entidad.FechamentoCntcorrente; import com.rjconsultores.ventaboletos.entidad.FechamentoCntcorrente;
@ -15,12 +24,6 @@ import com.rjconsultores.ventaboletos.enums.StatusIntegracaoSap;
import com.rjconsultores.ventaboletos.utilerias.DateUtil; import com.rjconsultores.ventaboletos.utilerias.DateUtil;
import com.rjconsultores.ventaboletos.vo.integracao.FechamentoCntCorrenteVO; import com.rjconsultores.ventaboletos.vo.integracao.FechamentoCntCorrenteVO;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;
@Repository("sapDAO") @Repository("sapDAO")
public class SapHibernateDAO extends GenericHibernateDAO<FechamentoCntcorrente, Long> implements SapDAO { public class SapHibernateDAO extends GenericHibernateDAO<FechamentoCntcorrente, Long> implements SapDAO {
@ -29,13 +32,18 @@ public class SapHibernateDAO extends GenericHibernateDAO<FechamentoCntcorrente,
setSessionFactory(factory); setSessionFactory(factory);
} }
@Autowired
@Qualifier("dataSourceWrite")
DataSource scoDs;
@Override @Override
@Transactional
public List<FechamentoCntCorrenteVO> obtenerTodosParaRemessa(Empresa empresa, Date dataDe, Date dataAte, String status) { public List<FechamentoCntCorrenteVO> obtenerTodosParaRemessa(Empresa empresa, Date dataDe, Date dataAte, String status) {
return obtenerTodosParaRemessa(empresa, dataDe, dataAte, status, null); return obtenerTodosParaRemessa(empresa, dataDe, dataAte, status, null);
} }
@SuppressWarnings("unchecked")
@Override @Override
@Transactional
public List<FechamentoCntCorrenteVO> obtenerTodosParaRemessa(Empresa empresa, Date dataDe, Date dataAte, String status, PuntoVenta puntoVenta) { public List<FechamentoCntCorrenteVO> obtenerTodosParaRemessa(Empresa empresa, Date dataDe, Date dataAte, String status, PuntoVenta puntoVenta) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -142,6 +150,7 @@ public class SapHibernateDAO extends GenericHibernateDAO<FechamentoCntcorrente,
} }
@Override @Override
@Transactional
public boolean atualizaFechamento(Long fechamentocntcorrenteId, int status) throws Exception { public boolean atualizaFechamento(Long fechamentocntcorrenteId, int status) throws Exception {
if(fechamentocntcorrenteId == null ) { if(fechamentocntcorrenteId == null ) {
@ -149,17 +158,13 @@ public class SapHibernateDAO extends GenericHibernateDAO<FechamentoCntcorrente,
} }
//é feito update manualmente porque o hibernate utiliza sco_read e nao tem permissao de escrita no banco //é feito update manualmente porque o hibernate utiliza sco_read e nao tem permissao de escrita no banco
@SuppressWarnings("deprecation") try(Connection con = scoDs.getConnection();
Connection con = getSession().connection(); Statement stmt = con.createStatement()){
Statement stmt = con.createStatement();
con.setAutoCommit(false);
stmt.addBatch("UPDATE FECHAMENTO_CNTCORRENTE SET INDINTEGRADOSAP = "+ status stmt.addBatch("UPDATE FECHAMENTO_CNTCORRENTE SET INDINTEGRADOSAP = "+ status
+" WHERE FECHAMENTOCNTCORRENTE_ID = " + fechamentocntcorrenteId); +" WHERE FECHAMENTOCNTCORRENTE_ID = " + fechamentocntcorrenteId);
stmt.executeBatch(); stmt.executeBatch();
con.commit(); }
stmt.close();
return Boolean.TRUE; return Boolean.TRUE;
} }

View File

@ -8,7 +8,7 @@ import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
@ -31,7 +31,7 @@ public class IntegracaoSapRest {
public JSONObject enviarIntegracaoSap( FechamentoCntCorrenteVO fechamento, String url, String credenciais ) { public JSONObject enviarIntegracaoSap( FechamentoCntCorrenteVO fechamento, String url, String credenciais ) {
try { try {
HttpClient client = new DefaultHttpClient(); HttpClient client = HttpClientBuilder.create().build();
HttpUriRequest request = getRequest( url, TipoEnvioRest.POST, credenciais, fechamtoToJson(fechamento)); HttpUriRequest request = getRequest( url, TipoEnvioRest.POST, credenciais, fechamtoToJson(fechamento));
HttpResponse response = client.execute(request); HttpResponse response = client.execute(request);

View File

@ -83,6 +83,7 @@ public class SapServiceImpl implements SapService{
for (FechamentoCntCorrenteVO fechamentoCntcorrente : fechamentos) { for (FechamentoCntCorrenteVO fechamentoCntcorrente : fechamentos) {
if( fechamentoCntcorrente.isEnviar()) { if( fechamentoCntcorrente.isEnviar()) {
log.debug("Enviando fechamento:"+ fechamentoCntcorrente.getFechamentocntcorrenteId());
JSONObject integrado = integracaoSapRest.enviarIntegracaoSap(fechamentoCntcorrente, url, credenciais); JSONObject integrado = integracaoSapRest.enviarIntegracaoSap(fechamentoCntcorrente, url, credenciais);
if(integrado == null) { if(integrado == null) {