fixes bug#24329

dev: Celio
qua:

git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@111655 d1611594-4594-4d17-8e1d-87c2c4800839
master
fabio 2022-04-01 20:56:44 +00:00
parent bb79902609
commit 9b1c1f8ad8
3 changed files with 31 additions and 15 deletions

View File

@ -11,6 +11,6 @@ public interface SapDAO extends GenericDAO<FechamentoCntcorrente, Long> {
public List<FechamentoCntCorrenteVO> obtenerTodosParaRemessa(Empresa empresa, Date dataDe, Date dataAte, Boolean reenviar); public List<FechamentoCntCorrenteVO> obtenerTodosParaRemessa(Empresa empresa, Date dataDe, Date dataAte, Boolean reenviar);
public boolean atualizaFechamento(Long fechamentocntcorrenteId) throws Exception; public boolean atualizaFechamento(Long fechamentocntcorrenteId, int status) throws Exception;
} }

View File

@ -27,6 +27,7 @@ public class SapHibernateDAO extends GenericHibernateDAO<FechamentoCntcorrente,
setSessionFactory(factory); setSessionFactory(factory);
} }
@SuppressWarnings("unchecked")
@Override @Override
public List<FechamentoCntCorrenteVO> obtenerTodosParaRemessa(Empresa empresa, Date dataDe, Date dataAte, Boolean reenviar) { public List<FechamentoCntCorrenteVO> obtenerTodosParaRemessa(Empresa empresa, Date dataDe, Date dataAte, Boolean reenviar) {
@ -64,9 +65,9 @@ public class SapHibernateDAO extends GenericHibernateDAO<FechamentoCntcorrente,
} }
if(!reenviar){ if(!reenviar){
sb.append(" AND ( fc.indintegradosap IS NULL OR fc.indintegradosap <> 1) "); sb.append(" AND fc.indintegradosap IS NULL ");
} }
sb.append(" ORDER BY "); sb.append(" ORDER BY ");
sb.append(" pv.nombpuntoventa, fc.fecfechamento "); sb.append(" pv.nombpuntoventa, fc.fecfechamento ");
@ -79,9 +80,10 @@ public class SapHibernateDAO extends GenericHibernateDAO<FechamentoCntcorrente,
if(dataDe != null && dataAte != null){ if(dataDe != null && dataAte != null){
query.setDate("dataDe", DateUtil.normalizarToFecha(dataDe)); query.setDate("dataDe", DateUtil.normalizarToFecha(dataDe));
query.setDate("dataAte", DateUtil.normalizarToFecha(dataAte)); query.setDate("dataAte", DateUtil.normalizarToFecha(dataAte));
} }
@SuppressWarnings("unchecked") query.setMaxResults(100);
List<Object[]> list = query.list(); List<Object[]> list = query.list();
List<FechamentoCntCorrenteVO> retorno = new ArrayList<FechamentoCntCorrenteVO>(); List<FechamentoCntCorrenteVO> retorno = new ArrayList<FechamentoCntCorrenteVO>();
@ -123,7 +125,7 @@ public class SapHibernateDAO extends GenericHibernateDAO<FechamentoCntcorrente,
} }
@Override @Override
public boolean atualizaFechamento(Long fechamentocntcorrenteId) throws Exception { public boolean atualizaFechamento(Long fechamentocntcorrenteId, int status) throws Exception {
if(fechamentocntcorrenteId == null ) { if(fechamentocntcorrenteId == null ) {
return false; return false;
@ -135,7 +137,8 @@ public class SapHibernateDAO extends GenericHibernateDAO<FechamentoCntcorrente,
Statement stmt = con.createStatement(); Statement stmt = con.createStatement();
con.setAutoCommit(false); con.setAutoCommit(false);
stmt.addBatch("UPDATE FECHAMENTO_CNTCORRENTE SET INDINTEGRADOSAP = 1 WHERE FECHAMENTOCNTCORRENTE_ID = " + fechamentocntcorrenteId); stmt.addBatch("UPDATE FECHAMENTO_CNTCORRENTE SET INDINTEGRADOSAP = "+ status
+" WHERE FECHAMENTOCNTCORRENTE_ID = " + fechamentocntcorrenteId);
stmt.executeBatch(); stmt.executeBatch();
con.commit(); con.commit();

View File

@ -3,6 +3,7 @@ package com.rjconsultores.ventaboletos.service.impl;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.apache.log4j.Logger;
import org.codehaus.jettison.json.JSONObject; import org.codehaus.jettison.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -15,6 +16,7 @@ import com.rjconsultores.ventaboletos.entidad.Empresa;
import com.rjconsultores.ventaboletos.entidad.FechamentoCntcorrente; import com.rjconsultores.ventaboletos.entidad.FechamentoCntcorrente;
import com.rjconsultores.ventaboletos.rest.IntegracaoSapRest; import com.rjconsultores.ventaboletos.rest.IntegracaoSapRest;
import com.rjconsultores.ventaboletos.service.SapService; import com.rjconsultores.ventaboletos.service.SapService;
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
import com.rjconsultores.ventaboletos.vo.integracao.FechamentoCntCorrenteVO; import com.rjconsultores.ventaboletos.vo.integracao.FechamentoCntCorrenteVO;
@Service("sapService") @Service("sapService")
@ -22,6 +24,9 @@ public class SapServiceImpl implements SapService{
private static final String INTEGRACAO_SAP_URL = "INTEGRACAO_SAP_URL"; private static final String INTEGRACAO_SAP_URL = "INTEGRACAO_SAP_URL";
private static final String INTEGRACAO_SAP_CREDENCIAL = "INTEGRACAO_SAP_CREDENCIAL"; private static final String INTEGRACAO_SAP_CREDENCIAL = "INTEGRACAO_SAP_CREDENCIAL";
private static final int INTEGRACAO_SAP_OK = 1;
private static final int INTEGRACAO_SAP_ERRO = 2;
private static Logger log = Logger.getLogger(SapServiceImpl.class);
@Autowired @Autowired
private SapDAO sapDAO; private SapDAO sapDAO;
@ -76,12 +81,14 @@ public class SapServiceImpl implements SapService{
JSONObject integrado = integracaoSapRest.enviarIntegracaoSap(fechamentoCntcorrente, url, credenciais); JSONObject integrado = integracaoSapRest.enviarIntegracaoSap(fechamentoCntcorrente, url, credenciais);
if(integrado == null) { if(integrado == null) {
throw new RuntimeException("Erro no envio/retorno da requisicao para integração SAP"); atualizaFechamento(fechamentoCntcorrente.getFechamentocntcorrenteId(), INTEGRACAO_SAP_ERRO);
log.error("Erro no envio/retorno da requisicao para integração SAP do fechamentoID: "+fechamentoCntcorrente.getFechamentocntcorrenteId());
}else if(integrado.getString("Integration").equals("S")) { }else if(integrado.getString("Integration").equals("S")) {
atualizaFechamento(fechamentoCntcorrente.getFechamentocntcorrenteId()); atualizaFechamento(fechamentoCntcorrente.getFechamentocntcorrenteId(), INTEGRACAO_SAP_OK);
contador++; contador++;
}else if(integrado.getString("Integration").equals("E")) { }else if(integrado.getString("Integration").equals("E")) {
throw new RuntimeException("Retorno enviado pelo SAP: \r\n"+integrado.getString("Message")); atualizaFechamento(fechamentoCntcorrente.getFechamentocntcorrenteId(), INTEGRACAO_SAP_ERRO);
log.warn("Retorno enviado pelo SAP: \r\n"+integrado.getString("Message"));
} }
} }
} }
@ -94,8 +101,8 @@ public class SapServiceImpl implements SapService{
} }
} }
private boolean atualizaFechamento(Long fechamentocntcorrenteId) throws Exception { private boolean atualizaFechamento(Long fechamentocntcorrenteId, int status) throws Exception {
return sapDAO.atualizaFechamento( fechamentocntcorrenteId); return sapDAO.atualizaFechamento( fechamentocntcorrenteId, status);
} }
private String buscaConstante(String constanteString) { private String buscaConstante(String constanteString) {
@ -110,10 +117,16 @@ public class SapServiceImpl implements SapService{
@Override @Override
public void integracaoSapAutomatica() throws Exception { public void integracaoSapAutomatica() throws Exception {
List<FechamentoCntCorrenteVO> listaPendente = obtenerTodosParaRemessa(null, new Date(), new Date(), false); List<FechamentoCntCorrenteVO> listaPendente = obtenerTodosParaRemessa(null, DateUtil.getYesterdayDate(), new Date(), false);
if(!listaPendente.isEmpty()) { while(!listaPendente.isEmpty()) {
remessa(listaPendente); try {
remessa(listaPendente);
} catch (Exception e) {
throw e;
}
listaPendente = obtenerTodosParaRemessa(null, DateUtil.getYesterdayDate(), new Date(), false);
} }
} }