fixes bug#22225

dev: Celio
qua:

git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@107840 d1611594-4594-4d17-8e1d-87c2c4800839
master
fabio 2021-07-15 14:57:44 +00:00
parent 6bdc1cbe5d
commit 715870cb89
9 changed files with 558 additions and 40 deletions

View File

@ -0,0 +1,14 @@
package com.rjconsultores.ventaboletos.dao;
import java.util.Date;
import java.util.List;
import com.rjconsultores.ventaboletos.entidad.Empresa;
import com.rjconsultores.ventaboletos.entidad.FechamentoCntcorrente;
import com.rjconsultores.ventaboletos.vo.integracao.FechamentoCntCorrenteVO;
public interface SapDAO extends GenericDAO<FechamentoCntcorrente, Long> {
public List<FechamentoCntCorrenteVO> obtenerTodosParaRemessa(Empresa empresa, Date dataDe, Date dataAte, Boolean reenviar);
}

View File

@ -0,0 +1,103 @@
package com.rjconsultores.ventaboletos.dao.hibernate;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
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 com.rjconsultores.ventaboletos.dao.SapDAO;
import com.rjconsultores.ventaboletos.entidad.Empresa;
import com.rjconsultores.ventaboletos.entidad.FechamentoCntcorrente;
import com.rjconsultores.ventaboletos.vo.integracao.FechamentoCntCorrenteVO;
@Repository("sapDAO")
public class SapHibernateDAO extends GenericHibernateDAO<FechamentoCntcorrente, Long> implements SapDAO {
@Autowired
public SapHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
setSessionFactory(factory);
}
@Override
public List<FechamentoCntCorrenteVO> obtenerTodosParaRemessa(Empresa empresa, Date dataDe, Date dataAte, Boolean reenviar) {
StringBuilder sb = new StringBuilder();
sb.append(" SELECT ");
sb.append(" fc.fechamentocntcorrente_id, ");
sb.append(" to_char(fc.fecfechamento, 'yyyy-mm-DD'), ");
sb.append(" fc.total, ");
sb.append(" es.cveestado, ");
sb.append(" pv.numpuntoventa, ");
sb.append(" pv.nombpuntoventa, ");
sb.append(" fc.empresa_id, ");
sb.append(" emp.nombempresa, ");
sb.append(" fc.indintegradosap, ");
sb.append(" to_char(fc.fecfechamento, 'yyyy'), ");
sb.append(" to_char(fc.fecfechamento, 'mm'), ");
sb.append(" CASE to_char(fc.fecfechamento, 'D') ");
sb.append(" WHEN '6' THEN to_char(fc.fecfechamento+3, 'yyyy-mm-DD') ");
sb.append(" WHEN '7' THEN to_char(fc.fecfechamento+2, 'yyyy-mm-DD') ");
sb.append(" ELSE to_char(fc.fecfechamento+1, 'yyyy-mm-DD') END as feclancamento ");
sb.append(" FROM ");
sb.append(" fechamento_cntcorrente fc ");
sb.append(" INNER JOIN punto_venta pv ON pv.puntoventa_id = fc.puntoventa_id AND pv.activo = 1 ");
sb.append(" INNER JOIN empresa emp ON emp.empresa_id = fc.empresa_id AND emp.activo = 1 ");
sb.append(" LEFT JOIN ciudad ci ON ci.ciudad_id = emp.ciudad_id AND ci.activo = 1 ");
sb.append(" LEFT JOIN plaza pl ON pl.plaza_id = ci.plaza_id AND pl.activo = 1 ");
sb.append(" LEFT JOIN estado es ON es.estado_id = ci.estado_id AND es.activo = 1 ");
sb.append(" WHERE ");
sb.append(" fc.activo = 1 ");
sb.append(" AND fc.fecfechamento BETWEEN :dataDe AND :dataAte ");
sb.append(" AND fc.EMPRESA_ID = :empresaId ");
if(!reenviar){
sb.append(" AND ( fc.indintegradosap IS NULL OR fc.indintegradosap = 0) ");
}
sb.append(" ORDER BY ");
sb.append(" pv.nombpuntoventa, fc.fecfechamento ");
Query query = getSession().createSQLQuery(sb.toString());
query.setInteger("empresaId", empresa.getEmpresaId());
if(dataDe != null && dataAte != null){
query.setDate("dataDe", dataDe);
query.setDate("dataAte", dataAte);
}
@SuppressWarnings("unchecked")
List<Object[]> list = query.list();
List<FechamentoCntCorrenteVO> retorno = new ArrayList<FechamentoCntCorrenteVO>();
for(Object[] tupla : list){
FechamentoCntCorrenteVO fcc = new FechamentoCntCorrenteVO();
fcc.setFechamentocntcorrenteId( Long.valueOf(tupla[0].toString()));
fcc.setFecfechamento( tupla[1].toString() );
fcc.setTotal( (BigDecimal)tupla[2] );
fcc.setUfEmpresa(tupla[3].toString());
fcc.setNumPuntoVenta(tupla[4].toString());
fcc.setNombpuntoventa(tupla[5].toString());
fcc.setEmpresaId( Integer.valueOf( tupla[6].toString() ) );
fcc.setNombEmpresa( tupla[7].toString());
fcc.setIntegradoSap( tupla[8]==null?false:tupla[8].toString().equals("1")?true:false );
fcc.setAnofechamento(tupla[9].toString());
fcc.setMesfechamento(tupla[10].toString());
fcc.setFeclancamento(tupla[11].toString());
retorno.add(fcc);
}
return retorno;
}
}

View File

@ -65,6 +65,9 @@ public class FechamentoCntcorrente {
@Column(name = "INDEMAILENVIADO") @Column(name = "INDEMAILENVIADO")
private Boolean indemailenviado; private Boolean indemailenviado;
@Column(name = "INDINTEGRADOSAP")
private Boolean integradoSap;
public Long getFechamentocntcorrenteId() { public Long getFechamentocntcorrenteId() {
return fechamentocntcorrenteId; return fechamentocntcorrenteId;
@ -161,6 +164,14 @@ public class FechamentoCntcorrente {
public void setIndemailenviado(Boolean indemailenviado) { public void setIndemailenviado(Boolean indemailenviado) {
this.indemailenviado = indemailenviado; this.indemailenviado = indemailenviado;
} }
public Boolean getIntegradoSap() {
return integradoSap;
}
public void setIntegradoSap(Boolean integradoSap) {
this.integradoSap = integradoSap;
}

View File

@ -20,47 +20,47 @@ import javax.persistence.TemporalType;
public class FechamentoParamgeral implements java.io.Serializable { public class FechamentoParamgeral implements java.io.Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@SequenceGenerator(name = "FECHAMENTO_PARAMGERAL_SEQ", sequenceName = "FECHAMENTO_PARAMGERAL_SEQ", allocationSize = 1) @SequenceGenerator(name = "FECHAMENTO_PARAMGERAL_SEQ", sequenceName = "FECHAMENTO_PARAMGERAL_SEQ", allocationSize = 1)
@Id @Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "FECHAMENTO_PARAMGERAL_SEQ") @GeneratedValue(strategy = GenerationType.AUTO, generator = "FECHAMENTO_PARAMGERAL_SEQ")
@Column(name = "FECHAMENTOPARAMGERAL_ID", unique = true, nullable = false, precision = 15, scale = 0) @Column(name = "FECHAMENTOPARAMGERAL_ID", unique = true, nullable = false, precision = 15, scale = 0)
private Long fechamentoparamgeralId; private Long fechamentoparamgeralId;
@JoinColumn(name = "EMPRESA_ID") @JoinColumn(name = "EMPRESA_ID")
@ManyToOne @ManyToOne
private Empresa empresa; private Empresa empresa;
@Column(name = "BOLETO_BANCO_COD", length = 4) @Column(name = "BOLETO_BANCO_COD", length = 4)
private String boletoBancoCod; private String boletoBancoCod;
@Column(name = "BOLETO_BANCO_AGENCIA", length = 10) @Column(name = "BOLETO_BANCO_AGENCIA", length = 10)
private String boletoBancoAgencia; private String boletoBancoAgencia;
@Column(name = "BOLETO_BANCO_AGENCIA_DIGITO", length = 10) @Column(name = "BOLETO_BANCO_AGENCIA_DIGITO", length = 10)
private String boletoBancoAgenciaDigito; private String boletoBancoAgenciaDigito;
@Column(name = "BOLETO_BANCO_CONTA", length = 10) @Column(name = "BOLETO_BANCO_CONTA", length = 10)
private String boletoBancoConta; private String boletoBancoConta;
@Column(name = "BOLETO_BANCO_CONTA_DIGITO", length = 1) @Column(name = "BOLETO_BANCO_CONTA_DIGITO", length = 1)
private String boletoBancoContaDigito; private String boletoBancoContaDigito;
@Column(name = "BOLETO_BANCO_CARTEIRA", length = 3) @Column(name = "BOLETO_BANCO_CARTEIRA", length = 3)
private String boletoBancoCarteira; private String boletoBancoCarteira;
@Column(name = "BOLETO_BANCO_CARTEIRA_VARIAVEL", length = 3) @Column(name = "BOLETO_BANCO_CARTEIRA_VARIAVEL", length = 3)
private String boletoBancoCarteiraVariavel; private String boletoBancoCarteiraVariavel;
@Column(name = "BOLETO_DIAS_VENC", length = 3) @Column(name = "BOLETO_DIAS_VENC", length = 3)
private Integer boletoDiasVenc; private Integer boletoDiasVenc;
@Column(name = "BOLETO_JUROS", precision = 5, scale = 2) @Column(name = "BOLETO_JUROS", precision = 5, scale = 2)
private BigDecimal boletoJuros; private BigDecimal boletoJuros;
@Column(name = "BOLETO_MULTA", precision = 5, scale = 2) @Column(name = "BOLETO_MULTA", precision = 5, scale = 2)
private BigDecimal boletoMulta; private BigDecimal boletoMulta;
@Column(name = "COD_EMP_BANCO", precision = 7, scale = 0) @Column(name = "COD_EMP_BANCO", precision = 7, scale = 0)
private String codConvenio; private String codConvenio;
@ -74,21 +74,21 @@ public class FechamentoParamgeral implements java.io.Serializable {
private String boletoBancoInstrucao3; private String boletoBancoInstrucao3;
@Column(name = "BOLETO_BANCO_INSTRUCAO_SACADO", precision = 255) @Column(name = "BOLETO_BANCO_INSTRUCAO_SACADO", precision = 255)
private String boletoBancoInstrucaoSacado; private String boletoBancoInstrucaoSacado;
@Column(name = "COUNT_REMESSA", precision = 15, scale = 0) @Column(name = "COUNT_REMESSA", precision = 15, scale = 0)
private Long countRemessa; private Long countRemessa;
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
@Column(name = "FECMODIF", length = 7) @Column(name = "FECMODIF", length = 7)
private Date fecmodif; private Date fecmodif;
@Column(name = "USUARIO_ID", precision = 7, scale = 0) @Column(name = "USUARIO_ID", precision = 7, scale = 0)
private Integer usuarioId; private Integer usuarioId;
@Column(name = "ACTIVO", precision = 1, scale = 0) @Column(name = "ACTIVO", precision = 1, scale = 0)
private Boolean activo; private Boolean activo;
public FechamentoParamgeral() { public FechamentoParamgeral() {
super(); super();
} }
@ -106,18 +106,18 @@ public class FechamentoParamgeral implements java.io.Serializable {
this.boletoBancoContaDigito = boletoBancoContaDigito; this.boletoBancoContaDigito = boletoBancoContaDigito;
this.boletoBancoCarteira = boletoBancoCarteira; this.boletoBancoCarteira = boletoBancoCarteira;
this.boletoDiasVenc = boletoDiasVenc; this.boletoDiasVenc = boletoDiasVenc;
this.fecmodif = fecmodif; this.fecmodif = fecmodif;
this.usuarioId = usuarioId; this.usuarioId = usuarioId;
this.activo = activo; this.activo = activo;
} }
public FechamentoParamgeral(Long fechamentoparamgeralId, Empresa empresa, String boletoBancoCod, public FechamentoParamgeral(Long fechamentoparamgeralId, Empresa empresa, String boletoBancoCod,
String boletoBancoAgencia, String boletoBancoAgenciaDigito, String boletoBancoConta, String boletoBancoAgencia, String boletoBancoAgenciaDigito, String boletoBancoConta,
String boletoBancoContaDigito, String boletoBancoCarteira, String boletoBancoCarteiraVariavel, String boletoBancoContaDigito, String boletoBancoCarteira, String boletoBancoCarteiraVariavel,
Integer boletoDiasVenc, BigDecimal boletoJuros, BigDecimal boletoMulta, Integer boletoDiasVenc, BigDecimal boletoJuros, BigDecimal boletoMulta,
String codConvenio, String boletoBancoInstrucao, String boletoBancoInstrucao2, String codConvenio, String boletoBancoInstrucao, String boletoBancoInstrucao2,
String boletoBancoInstrucao3, String boletoBancoInstrucaoSacado, Long countRemessa, String boletoBancoInstrucao3, String boletoBancoInstrucaoSacado, Long countRemessa,
Date fecmodif, Integer usuarioId, Boolean activo) { Date fecmodif, Integer usuarioId, Boolean activo) {
super(); super();
this.fechamentoparamgeralId = fechamentoparamgeralId; this.fechamentoparamgeralId = fechamentoparamgeralId;
@ -155,22 +155,24 @@ public class FechamentoParamgeral implements java.io.Serializable {
this.boletoBancoContaDigito = boletoBancoContaDigito; this.boletoBancoContaDigito = boletoBancoContaDigito;
this.boletoBancoCarteira = boletoBancoCarteira; this.boletoBancoCarteira = boletoBancoCarteira;
this.boletoDiasVenc = boletoDiasVenc; this.boletoDiasVenc = boletoDiasVenc;
this.fecmodif = new Date(); this.fecmodif = new Date();
this.usuarioId = usuarioId; this.usuarioId = usuarioId;
this.activo = true; this.activo = true;
} }
public Long getFechamentoparamgeralId() { public Long getFechamentoparamgeralId() {
return fechamentoparamgeralId; return fechamentoparamgeralId;
} }
public void setFechamentoparamgeralId(Long fechamentoparamgeralId) { public void setFechamentoparamgeralId(Long fechamentoparamgeralId) {
this.fechamentoparamgeralId = fechamentoparamgeralId; this.fechamentoparamgeralId = fechamentoparamgeralId;
} }
public Empresa getEmpresa() { public Empresa getEmpresa() {
return empresa; return empresa;
} }
public void setEmpresa(Empresa empresa) { public void setEmpresa(Empresa empresa) {
this.empresa = empresa; this.empresa = empresa;
} }
@ -178,7 +180,7 @@ public class FechamentoParamgeral implements java.io.Serializable {
public String getBoletoBancoCod() { public String getBoletoBancoCod() {
return boletoBancoCod; return boletoBancoCod;
} }
public void setBoletoBancoCod(String boletoBancoCod) { public void setBoletoBancoCod(String boletoBancoCod) {
this.boletoBancoCod = boletoBancoCod; this.boletoBancoCod = boletoBancoCod;
} }
@ -186,6 +188,7 @@ public class FechamentoParamgeral implements java.io.Serializable {
public String getBoletoBancoAgencia() { public String getBoletoBancoAgencia() {
return boletoBancoAgencia; return boletoBancoAgencia;
} }
public void setBoletoBancoAgencia(String boletoBancoAgencia) { public void setBoletoBancoAgencia(String boletoBancoAgencia) {
this.boletoBancoAgencia = boletoBancoAgencia; this.boletoBancoAgencia = boletoBancoAgencia;
} }
@ -193,7 +196,7 @@ public class FechamentoParamgeral implements java.io.Serializable {
public String getBoletoBancoAgenciaDigito() { public String getBoletoBancoAgenciaDigito() {
return boletoBancoAgenciaDigito; return boletoBancoAgenciaDigito;
} }
public void setBoletoBancoAgenciaDigito(String boletoBancoAgenciaDigito) { public void setBoletoBancoAgenciaDigito(String boletoBancoAgenciaDigito) {
this.boletoBancoAgenciaDigito = boletoBancoAgenciaDigito; this.boletoBancoAgenciaDigito = boletoBancoAgenciaDigito;
} }
@ -201,7 +204,7 @@ public class FechamentoParamgeral implements java.io.Serializable {
public String getBoletoBancoConta() { public String getBoletoBancoConta() {
return boletoBancoConta; return boletoBancoConta;
} }
public void setBoletoBancoConta(String boletoBancoConta) { public void setBoletoBancoConta(String boletoBancoConta) {
this.boletoBancoConta = boletoBancoConta; this.boletoBancoConta = boletoBancoConta;
} }
@ -209,7 +212,7 @@ public class FechamentoParamgeral implements java.io.Serializable {
public String getBoletoBancoContaDigito() { public String getBoletoBancoContaDigito() {
return boletoBancoContaDigito; return boletoBancoContaDigito;
} }
public void setBoletoBancoContaDigito(String boletoBancoContaDigito) { public void setBoletoBancoContaDigito(String boletoBancoContaDigito) {
this.boletoBancoContaDigito = boletoBancoContaDigito; this.boletoBancoContaDigito = boletoBancoContaDigito;
} }
@ -217,7 +220,7 @@ public class FechamentoParamgeral implements java.io.Serializable {
public String getBoletoBancoCarteira() { public String getBoletoBancoCarteira() {
return boletoBancoCarteira; return boletoBancoCarteira;
} }
public void setBoletoBancoCarteira(String boletoBancoCarteira) { public void setBoletoBancoCarteira(String boletoBancoCarteira) {
this.boletoBancoCarteira = boletoBancoCarteira; this.boletoBancoCarteira = boletoBancoCarteira;
} }
@ -225,7 +228,7 @@ public class FechamentoParamgeral implements java.io.Serializable {
public String getBoletoBancoCarteiraVariavel() { public String getBoletoBancoCarteiraVariavel() {
return boletoBancoCarteiraVariavel; return boletoBancoCarteiraVariavel;
} }
public void setBoletoBancoCarteiraVariavel(String boletoBancoCarteiraVariavel) { public void setBoletoBancoCarteiraVariavel(String boletoBancoCarteiraVariavel) {
this.boletoBancoCarteiraVariavel = boletoBancoCarteiraVariavel; this.boletoBancoCarteiraVariavel = boletoBancoCarteiraVariavel;
} }
@ -233,7 +236,7 @@ public class FechamentoParamgeral implements java.io.Serializable {
public Integer getBoletoDiasVenc() { public Integer getBoletoDiasVenc() {
return boletoDiasVenc; return boletoDiasVenc;
} }
public void setBoletoDiasVenc(Integer boletoDiasVenc) { public void setBoletoDiasVenc(Integer boletoDiasVenc) {
this.boletoDiasVenc = boletoDiasVenc; this.boletoDiasVenc = boletoDiasVenc;
} }
@ -241,7 +244,7 @@ public class FechamentoParamgeral implements java.io.Serializable {
public Date getFecmodif() { public Date getFecmodif() {
return fecmodif; return fecmodif;
} }
public void setFecmodif(Date fecmodif) { public void setFecmodif(Date fecmodif) {
this.fecmodif = fecmodif; this.fecmodif = fecmodif;
} }
@ -249,7 +252,7 @@ public class FechamentoParamgeral implements java.io.Serializable {
public Integer getUsuarioId() { public Integer getUsuarioId() {
return usuarioId; return usuarioId;
} }
public void setUsuarioId(Integer usuarioId) { public void setUsuarioId(Integer usuarioId) {
this.usuarioId = usuarioId; this.usuarioId = usuarioId;
} }
@ -321,7 +324,7 @@ public class FechamentoParamgeral implements java.io.Serializable {
public Boolean getActivo() { public Boolean getActivo() {
return activo; return activo;
} }
public void setActivo(Boolean activo) { public void setActivo(Boolean activo) {
this.activo = activo; this.activo = activo;
} }

View File

@ -0,0 +1,6 @@
package com.rjconsultores.ventaboletos.enums;
public enum TipoEnvioRest {
GET,
POST;
}

View File

@ -0,0 +1,110 @@
package com.rjconsultores.ventaboletos.rest;
import java.io.IOException;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;
import com.rjconsultores.ventaboletos.enums.TipoEnvioRest;
import com.rjconsultores.ventaboletos.vo.integracao.FechamentoCntCorrenteVO;
public class IntegracaoSapRest {
private static Logger log = Logger.getLogger(IntegracaoSapRest.class);
private static IntegracaoSapRest instance;
public static synchronized IntegracaoSapRest getInstance() {
if(instance == null) {
instance = new IntegracaoSapRest();
}
return instance;
}
public JSONObject enviarIntegracaoSap( FechamentoCntCorrenteVO fechamento, String url, String credenciais ) {
try {
HttpClient client = new DefaultHttpClient();
HttpUriRequest request = getRequest( url, TipoEnvioRest.POST, credenciais, fechamtoToJson(fechamento));
HttpResponse response = client.execute(request);
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK
&& response.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED) {
throw new IllegalStateException("Ocorreu um erro na requisição." + response.getStatusLine() !=null ? response.getStatusLine().getReasonPhrase() : "");
}
return getRetornoJSON(response);
} catch (IOException e) {
log.error(e);
} catch (JSONException e) {
log.error(e);
} catch (Exception e) {
log.error("Erro no envio/retorno da requisicao para integração SAP", e);
}
return null;
}
private JSONObject getRetornoJSON(HttpResponse response) throws IOException, JSONException {
HttpEntity entity = response.getEntity();
if (entity != null) {
String rest = EntityUtils.toString(entity);
JSONObject result = new JSONObject(rest);
JSONObject boleto = result.getJSONObject("MT_Boleto_RES");
return boleto.getJSONArray("ReturnERP").getJSONObject(0);
}
return null;
}
private String fechamtoToJson( FechamentoCntCorrenteVO fcc){
StringBuilder json = new StringBuilder();
json.append("{");
json.append(" \"ID_LEGADO\": \"010\",");
json.append(" \"AGENCIA\": {");
json.append(" \"KUNNR\": \"").append(fcc.getNumPuntoVenta()).append("\"");
json.append(" },");
json.append(" \"BOLETO\": [{");
json.append(" \"ZBUKRS\": \"").append(fcc.getEmpresaId()).append("\",");
json.append(" \"ZZFCAIXA\": \"").append(fcc.getFechamentocntcorrenteId()).append("\",");
json.append(" \"FILIAL\": {");
json.append(" \"UF\": \"").append(fcc.getUfEmpresa()).append("\",");
json.append(" },");
json.append(" \"GJAHR\": \"").append(fcc.getAnofechamento()).append("\",");
json.append(" \"MONAT\": \"").append(fcc.getMesfechamento()).append("\",");
json.append(" \"BLDAT\": \"").append(fcc.getFecfechamento()).append("\",");
json.append(" \"BUDAT\": \"").append(fcc.getFeclancamento()).append("\",");
json.append(" \"XBLNR\": \"").append(fcc.getNumPuntoVenta()).append("\",");
json.append(" \"WRBTR\": \"").append( fcc.getTotal().toString().replace(",", ".") ).append("\",");
json.append(" }]");
json.append("}");
return json.toString();
}
private HttpUriRequest getRequest(String uri, TipoEnvioRest tipoEnvio, String credenciais, String json) throws Exception {
HttpPost request = new HttpPost(uri);
StringEntity entity = new StringEntity(json);
request.addHeader("Authorization", getAuthorization(credenciais));
request.setHeader("Accept", "application/json");
request.setHeader("Content-type", "application/json");
request.setEntity(entity);
// request.addHeader(new BasicScheme().authenticate(creds, httpPost, null));
return request;
}
private String getAuthorization( String credenciais ) {
return "Basic " + new String(Base64.encodeBase64(credenciais.getBytes()));
}
}

View File

@ -0,0 +1,16 @@
package com.rjconsultores.ventaboletos.service;
import java.util.Date;
import java.util.List;
import com.rjconsultores.ventaboletos.entidad.Empresa;
import com.rjconsultores.ventaboletos.entidad.FechamentoCntcorrente;
import com.rjconsultores.ventaboletos.vo.integracao.FechamentoCntCorrenteVO;
public interface SapService extends GenericService<FechamentoCntcorrente, Long> {
public int remessa(List<FechamentoCntCorrenteVO> fechamentos) throws Exception ;
public List<FechamentoCntCorrenteVO> obtenerTodosParaRemessa(Empresa empresa, Date dataDe, Date dataAte, Boolean reenviar);
}

View File

@ -0,0 +1,109 @@
package com.rjconsultores.ventaboletos.service.impl;
import java.util.Date;
import java.util.List;
import org.codehaus.jettison.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.rjconsultores.ventaboletos.dao.ConstanteDAO;
import com.rjconsultores.ventaboletos.dao.SapDAO;
import com.rjconsultores.ventaboletos.entidad.Constante;
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.vo.integracao.FechamentoCntCorrenteVO;
@Service("sapService")
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";
@Autowired
private SapDAO sapDAO;
@Autowired
private ConstanteDAO constanteDAO;
@Override
public List<FechamentoCntcorrente> obtenerTodos() {
return sapDAO.obtenerTodos();
}
@Override
public FechamentoCntcorrente obtenerID(Long id) {
return sapDAO.obtenerID(id);
}
@Override
@Transactional
public FechamentoCntcorrente suscribir(FechamentoCntcorrente entidad) {
return sapDAO.suscribir(entidad);
}
@Override
@Transactional
public FechamentoCntcorrente actualizacion(FechamentoCntcorrente entidad) {
return sapDAO.actualizacion(entidad);
}
@Override
@Transactional
public void borrar(FechamentoCntcorrente entidad) {
sapDAO.borrar(entidad);
}
@Override
public List<FechamentoCntCorrenteVO> obtenerTodosParaRemessa(Empresa empresa, Date dataDe, Date dataAte, Boolean reenviar) {
return sapDAO.obtenerTodosParaRemessa(empresa, dataDe, dataAte, reenviar);
}
@Override
public int remessa(List<FechamentoCntCorrenteVO> fechamentos) throws Exception {
try {
int contador = 0;
IntegracaoSapRest integracaoSapRest = IntegracaoSapRest.getInstance();
String credenciais = buscaConstante(INTEGRACAO_SAP_CREDENCIAL);
String url = buscaConstante(INTEGRACAO_SAP_URL);
for (FechamentoCntCorrenteVO fechamentoCntcorrente : fechamentos) {
if( fechamentoCntcorrente.isEnviar()) {
JSONObject integrado = integracaoSapRest.enviarIntegracaoSap(fechamentoCntcorrente, url, credenciais);
if(integrado == null) {
throw new RuntimeException("Erro no envio/retorno da requisicao para integração SAP");
}else if(integrado.getString("Integration").equals("S")) {
FechamentoCntcorrente registro = obtenerID(fechamentoCntcorrente.getFechamentocntcorrenteId());
registro.setIntegradoSap(true);
suscribir(registro);
contador++;
}else if(integrado.getString("Integration").equals("E")) {
throw new RuntimeException(integrado.getString("Message"));
}
}
}
return contador;
}catch(RuntimeException re){
throw re;
}catch(Exception e){
throw e;
}
}
private String buscaConstante(String constanteString) {
Constante constante = constanteDAO.buscarPorNomeConstante(constanteString);
if( constante == null || constante.getValorconstante() == null || constante.getValorconstante().isEmpty() ) {
throw new RuntimeException("Constante "+constanteString+" não cadastrada");
}
return constante.getValorconstante();
}
}

View File

@ -0,0 +1,146 @@
package com.rjconsultores.ventaboletos.vo.integracao;
import java.math.BigDecimal;
public class FechamentoCntCorrenteVO {
public FechamentoCntCorrenteVO() {
super();
// TODO Auto-generated constructor stub
}
private Long fechamentocntcorrenteId;
private String fecfechamento;
private String feclancamento;
private String anofechamento;
private String mesfechamento;
private BigDecimal total;
private String nombpuntoventa;
private String numPuntoVenta;
private Integer empresaId;
private String nombEmpresa;
private String ufEmpresa;
private Boolean integradoSap;
private boolean enviar;
public FechamentoCntCorrenteVO(Long fechamentocntcorrenteId, String fecfechamento, String feclancamento, String anofechamento, String mesfechamento, BigDecimal total, String nombpuntoventa, String numPuntoVenta, Integer empresaId, String nombEmpresa, String ufEmpresa, Boolean integradoSap) {
super();
this.fechamentocntcorrenteId = fechamentocntcorrenteId;
this.fecfechamento = fecfechamento;
this.feclancamento = feclancamento;
this.anofechamento = anofechamento;
this.mesfechamento = mesfechamento;
this.total = total;
this.nombpuntoventa = nombpuntoventa;
this.numPuntoVenta = numPuntoVenta;
this.empresaId = empresaId;
this.nombEmpresa = nombEmpresa;
this.ufEmpresa = ufEmpresa;
this.integradoSap = integradoSap;
}
public Long getFechamentocntcorrenteId() {
return fechamentocntcorrenteId;
}
public void setFechamentocntcorrenteId(Long fechamentocntcorrenteId) {
this.fechamentocntcorrenteId = fechamentocntcorrenteId;
}
public String getFecfechamento() {
return fecfechamento;
}
public void setFecfechamento(String fecfechamento) {
this.fecfechamento = fecfechamento;
}
public BigDecimal getTotal() {
return total;
}
public void setTotal(BigDecimal total) {
this.total = total;
}
public String getNombpuntoventa() {
return nombpuntoventa;
}
public void setNombpuntoventa(String nombpuntoventa) {
this.nombpuntoventa = nombpuntoventa;
}
public String getNumPuntoVenta() {
return numPuntoVenta;
}
public void setNumPuntoVenta(String numPuntoVenta) {
this.numPuntoVenta = numPuntoVenta;
}
public Integer getEmpresaId() {
return empresaId;
}
public void setEmpresaId(Integer empresaId) {
this.empresaId = empresaId;
}
public String getNombEmpresa() {
return nombEmpresa;
}
public void setNombEmpresa(String nombEmpresa) {
this.nombEmpresa = nombEmpresa;
}
public String getUfEmpresa() {
return ufEmpresa;
}
public void setUfEmpresa(String ufEmpresa) {
this.ufEmpresa = ufEmpresa;
}
public boolean isIntegradoSap() {
return Boolean.TRUE.equals(integradoSap);
}
public void setIntegradoSap(boolean integradoSap) {
this.integradoSap = integradoSap;
}
public String getFeclancamento() {
return feclancamento;
}
public void setFeclancamento(String feclancamento) {
this.feclancamento = feclancamento;
}
public String getMesfechamento() {
return mesfechamento;
}
public void setMesfechamento(String mesfechamento) {
this.mesfechamento = mesfechamento;
}
public String getAnofechamento() {
return anofechamento;
}
public void setAnofechamento(String anofechamento) {
this.anofechamento = anofechamento;
}
public Boolean isEnviar() {
return enviar;
}
public void setEnviar(Boolean enviar) {
this.enviar = enviar;
}
}