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-87c2c4800839master
parent
bb79902609
commit
9b1c1f8ad8
|
@ -11,6 +11,6 @@ public interface SapDAO extends GenericDAO<FechamentoCntcorrente, Long> {
|
|||
|
||||
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;
|
||||
|
||||
}
|
|
@ -27,6 +27,7 @@ public class SapHibernateDAO extends GenericHibernateDAO<FechamentoCntcorrente,
|
|||
setSessionFactory(factory);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<FechamentoCntCorrenteVO> obtenerTodosParaRemessa(Empresa empresa, Date dataDe, Date dataAte, Boolean reenviar) {
|
||||
|
||||
|
@ -64,7 +65,7 @@ public class SapHibernateDAO extends GenericHibernateDAO<FechamentoCntcorrente,
|
|||
}
|
||||
|
||||
if(!reenviar){
|
||||
sb.append(" AND ( fc.indintegradosap IS NULL OR fc.indintegradosap <> 1) ");
|
||||
sb.append(" AND fc.indintegradosap IS NULL ");
|
||||
}
|
||||
|
||||
sb.append(" ORDER BY ");
|
||||
|
@ -81,7 +82,8 @@ public class SapHibernateDAO extends GenericHibernateDAO<FechamentoCntcorrente,
|
|||
query.setDate("dataAte", DateUtil.normalizarToFecha(dataAte));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
query.setMaxResults(100);
|
||||
|
||||
List<Object[]> list = query.list();
|
||||
List<FechamentoCntCorrenteVO> retorno = new ArrayList<FechamentoCntCorrenteVO>();
|
||||
|
||||
|
@ -123,7 +125,7 @@ public class SapHibernateDAO extends GenericHibernateDAO<FechamentoCntcorrente,
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean atualizaFechamento(Long fechamentocntcorrenteId) throws Exception {
|
||||
public boolean atualizaFechamento(Long fechamentocntcorrenteId, int status) throws Exception {
|
||||
|
||||
if(fechamentocntcorrenteId == null ) {
|
||||
return false;
|
||||
|
@ -135,7 +137,8 @@ public class SapHibernateDAO extends GenericHibernateDAO<FechamentoCntcorrente,
|
|||
Statement stmt = con.createStatement();
|
||||
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();
|
||||
con.commit();
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.rjconsultores.ventaboletos.service.impl;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.codehaus.jettison.json.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.rest.IntegracaoSapRest;
|
||||
import com.rjconsultores.ventaboletos.service.SapService;
|
||||
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||
import com.rjconsultores.ventaboletos.vo.integracao.FechamentoCntCorrenteVO;
|
||||
|
||||
@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_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
|
||||
private SapDAO sapDAO;
|
||||
|
@ -76,12 +81,14 @@ public class SapServiceImpl implements SapService{
|
|||
JSONObject integrado = integracaoSapRest.enviarIntegracaoSap(fechamentoCntcorrente, url, credenciais);
|
||||
|
||||
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")) {
|
||||
atualizaFechamento(fechamentoCntcorrente.getFechamentocntcorrenteId());
|
||||
atualizaFechamento(fechamentoCntcorrente.getFechamentocntcorrenteId(), INTEGRACAO_SAP_OK);
|
||||
contador++;
|
||||
}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 {
|
||||
return sapDAO.atualizaFechamento( fechamentocntcorrenteId);
|
||||
private boolean atualizaFechamento(Long fechamentocntcorrenteId, int status) throws Exception {
|
||||
return sapDAO.atualizaFechamento( fechamentocntcorrenteId, status);
|
||||
}
|
||||
|
||||
private String buscaConstante(String constanteString) {
|
||||
|
@ -110,10 +117,16 @@ public class SapServiceImpl implements SapService{
|
|||
|
||||
@Override
|
||||
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()) {
|
||||
remessa(listaPendente);
|
||||
while(!listaPendente.isEmpty()) {
|
||||
try {
|
||||
remessa(listaPendente);
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
listaPendente = obtenerTodosParaRemessa(null, DateUtil.getYesterdayDate(), new Date(), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue