fixes bug#18256
dev:thiago qua: git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@100186 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
788407f620
commit
fde19520b2
|
@ -21,4 +21,6 @@ public interface BpeDAO {
|
|||
public List<BPeVO> buscarBPeRejeitadosContingencia(Integer empresaId, String numBpe, String chbpe, Date dtVendaInicio, Date dtVendaFim, List<Integer> estados, List<String> codigosRejeicoes);
|
||||
|
||||
public void definirBPeRejeitadoSefazReenvio(Integer bpeId, String codstat) throws BusinessException;
|
||||
|
||||
public List<BPeVO> buscarBPeVendaEEventosAutorizados(Integer empresaId, Date dtVendaInicio, Date dtVendaFim, Integer estadoId);
|
||||
}
|
||||
|
|
|
@ -1641,4 +1641,64 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BPeVO> buscarBPeVendaEEventosAutorizados(Integer empresaId, Date dtVendaInicio, Date dtVendaFim, Integer estadoId) {
|
||||
StringBuilder sQuery = new StringBuilder();
|
||||
sQuery.append("select bpe.chbpe, bpe.tipoevento, b.num_bpe numBpe, b.numserie_bpe numserieBpe, b.fechorventa, ")
|
||||
.append("case when bpe.xmlcontingencia is not null and bpe.indcontingencia = 1 then bpe.xmlcontingencia else bpe.xmlregular end xmlEnvio, ")
|
||||
.append("bpe.xmlresposta xmlResposta ")
|
||||
.append("from bpe bpe ")
|
||||
.append("join boleto b on b.boleto_id = bpe.boleto_id ")
|
||||
.append("join marca m on m.marca_id = b.marca_id ")
|
||||
.append("left join estado e on e.codibge = bpe.uf ")
|
||||
.append("where bpe.activo = 1 ")
|
||||
.append("and bpe.tipoamb = :tipoamb ")
|
||||
.append("and bpe.codstat in ('100','101','102','135','150') ");
|
||||
|
||||
if(empresaId != null) {
|
||||
sQuery.append("and m.empresa_id = :empresaId ");
|
||||
}
|
||||
if(dtVendaInicio != null && dtVendaFim != null) {
|
||||
sQuery.append("and b.fechorventa between to_date(:dtVendaInicio,'dd/mm/yyyy hh24:mi') and to_date(:dtVendaFim,'dd/mm/yyyy hh24:mi') ");
|
||||
}
|
||||
if(estadoId != null) {
|
||||
sQuery.append("and e.estado_id = :estadoId ");
|
||||
}
|
||||
|
||||
Query qr = getSession().createSQLQuery(sQuery.toString())
|
||||
.addScalar("chbpe", StringType.INSTANCE)
|
||||
.addScalar("tipoevento", StringType.INSTANCE)
|
||||
.addScalar("chbpe", StringType.INSTANCE)
|
||||
.addScalar("numBpe", StringType.INSTANCE)
|
||||
.addScalar("numserieBpe", StringType.INSTANCE)
|
||||
.addScalar("xmlEnvio", StringType.INSTANCE)
|
||||
.addScalar("xmlResposta", StringType.INSTANCE)
|
||||
.addScalar("fechorventa", TimestampType.INSTANCE)
|
||||
.setResultTransformer(new AliasToBeanResultTransformer(BPeVO.class));
|
||||
|
||||
qr.setParameter("tipoamb", getAmbiente());
|
||||
if(empresaId != null) {
|
||||
qr.setParameter("empresaId", empresaId);
|
||||
}
|
||||
if(dtVendaInicio != null && dtVendaFim != null) {
|
||||
qr.setParameter("dtVendaInicio", DateUtil.getStringDate(DateUtil.inicioFecha(dtVendaInicio), "dd/MM/yyyy HH:mm"));
|
||||
qr.setParameter("dtVendaFim", DateUtil.getStringDate(DateUtil.fimFecha(dtVendaFim), "dd/MM/yyyy HH:mm"));
|
||||
}
|
||||
if(estadoId != null) {
|
||||
qr.setParameter("estadoId", estadoId);
|
||||
}
|
||||
|
||||
return qr.list();
|
||||
}
|
||||
|
||||
public String getAmbiente() {
|
||||
ConstanteService constanteService = (ConstanteService) AppContext.getApplicationContext().getBean("constanteService");
|
||||
Constante contante = constanteService.buscarPorNomeConstante("BPE_AMBIENTE");
|
||||
String valorConstante = contante == null ? null : contante.getValorconstante();
|
||||
if(valorConstante != null) {
|
||||
return valorConstante;
|
||||
}
|
||||
return "1";
|
||||
}
|
||||
|
||||
}
|
|
@ -20,5 +20,9 @@ public interface BpeService {
|
|||
public List<BPeVO> buscarBPeRejeitadosContingencia(Integer empresaId, String numBpe, String chbpe, Date dtVendaInicio, Date dtVendaFim, List<Integer> estados, List<String> codigosRejeicoes);
|
||||
|
||||
public void definirBPeRejeitadoSefazReenvio(List<BPeVO> bpesReenvio) throws BusinessException;
|
||||
|
||||
public List<BPeVO> buscarBPeVendaEEventosAutorizados(Integer empresaId, Date dtVendaInicio, Date dtVendaFim, Integer estadoId);
|
||||
|
||||
public byte[] extrairXmlsBPe(List<BPeVO> bpes);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
package com.rjconsultores.ventaboletos.service.impl;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.datasource.DataSourceUtils;
|
||||
|
@ -20,6 +24,7 @@ import com.rjconsultores.ventaboletos.exception.BusinessException;
|
|||
import com.rjconsultores.ventaboletos.service.BpeService;
|
||||
import com.rjconsultores.ventaboletos.utilerias.exportacao.ExportacaoBpe;
|
||||
import com.rjconsultores.ventaboletos.utilerias.exportacao.bpe.ExportacaoBPEVo;
|
||||
import com.rjconsultores.ventaboletos.utilerias.exportacao.bpe.xml.BPeUtil;
|
||||
import com.rjconsultores.ventaboletos.utilerias.fiscal.vo.FiscalRdi;
|
||||
import com.rjconsultores.ventaboletos.vo.bpe.BPeVO;
|
||||
|
||||
|
@ -118,4 +123,32 @@ public class BpeServiceImpl implements BpeService {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BPeVO> buscarBPeVendaEEventosAutorizados(Integer empresaId, Date dtVendaInicio, Date dtVendaFim, Integer estadoId) {
|
||||
return bpeDAO.buscarBPeVendaEEventosAutorizados(empresaId, dtVendaInicio, dtVendaFim, estadoId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] extrairXmlsBPe(List<BPeVO> bpes) {
|
||||
if(bpes != null && !bpes.isEmpty()) {
|
||||
Map<String, InputStream> arquivos = new HashMap<String, InputStream>();
|
||||
for (BPeVO bpe : bpes) {
|
||||
Map<String, InputStream> arquivo = null;
|
||||
if(StringUtils.isNotBlank(bpe.getTipoevento())) {
|
||||
arquivo = BPeUtil.convertBPeXmlRegularEventoToArquivoXml(bpe);
|
||||
arquivos.put(arquivo.entrySet().iterator().next().getKey(), arquivo.entrySet().iterator().next().getValue());
|
||||
arquivo = BPeUtil.convertBPeXmlRepostaEventoToArquivoXml(bpe);
|
||||
arquivos.put(arquivo.entrySet().iterator().next().getKey(), arquivo.entrySet().iterator().next().getValue());
|
||||
} else {
|
||||
arquivo = BPeUtil.convertBPeXmlRegularToArquivoXml(bpe);
|
||||
arquivos.put(arquivo.entrySet().iterator().next().getKey(), arquivo.entrySet().iterator().next().getValue());
|
||||
arquivo = BPeUtil.convertBPeXmlRepostaToArquivoXml(bpe);
|
||||
arquivos.put(arquivo.entrySet().iterator().next().getKey(), arquivo.entrySet().iterator().next().getValue());
|
||||
}
|
||||
}
|
||||
return BPeUtil.zipFiles(arquivos);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,18 +1,28 @@
|
|||
package com.rjconsultores.ventaboletos.utilerias.exportacao.bpe.xml;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.rjconsultores.ventaboletos.constantes.Constantes;
|
||||
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||
import com.rjconsultores.ventaboletos.utilerias.exportacao.bpe.ExportacaoBPEVo;
|
||||
import com.rjconsultores.ventaboletos.vo.bpe.BPeVO;
|
||||
|
||||
import br.inf.portalfiscal.bpe.TBPe;
|
||||
|
||||
|
@ -37,5 +47,118 @@ public class BPeUtil {
|
|||
}
|
||||
return objeto;
|
||||
}
|
||||
|
||||
public static Map<String, InputStream> convertBPeXmlRegularToArquivoXml(BPeVO bpe) {
|
||||
try {
|
||||
String complemento = "BPeRecepacao_E";
|
||||
String nomeArquivo = getNomeArquivo(bpe, complemento);
|
||||
return gerarArquivo(bpe.getXmlEnvio(), nomeArquivo);
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Map<String, InputStream> convertBPeXmlRepostaToArquivoXml(BPeVO bpe) {
|
||||
try {
|
||||
String complemento = "BPeRecepacao_R";
|
||||
String nomeArquivo = getNomeArquivo(bpe, complemento);
|
||||
return gerarArquivo(bpe.getXmlResposta(), nomeArquivo);
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Map<String, InputStream> convertBPeXmlRegularEventoToArquivoXml(BPeVO bpe) {
|
||||
try {
|
||||
String complemento = "BPeRecepacaoEvento_" + bpe.getTipoevento() + "_E";
|
||||
String nomeArquivo = getNomeArquivo(bpe, complemento);
|
||||
return gerarArquivo(bpe.getXmlEnvio(), nomeArquivo);
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Map<String, InputStream> convertBPeXmlRepostaEventoToArquivoXml(BPeVO bpe) {
|
||||
try {
|
||||
String complemento = "BPeRecepacaoEvento_" + bpe.getTipoevento() + "_R";
|
||||
String nomeArquivo = getNomeArquivo(bpe, complemento);
|
||||
return gerarArquivo(bpe.getXmlResposta(), nomeArquivo);
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Map<String, InputStream> gerarArquivo(String xml, String nomeArquivo) throws IOException {
|
||||
InputStream file = IOUtils.toInputStream(xml, Constantes.UTF_8);
|
||||
Map<String, InputStream> arquivo = new HashMap<String, InputStream>();
|
||||
arquivo.put(nomeArquivo, file);
|
||||
return arquivo;
|
||||
}
|
||||
|
||||
private static String getNomeArquivo(BPeVO bpe, String complemento) {
|
||||
StringBuilder nomeArquivo = new StringBuilder();
|
||||
nomeArquivo.append(DateUtil.getStringDate(bpe.getFechorventa(), "yyyyMMddHHmmss"))
|
||||
.append("_")
|
||||
.append(bpe.getChbpe())
|
||||
.append("_")
|
||||
.append(bpe.getNumserieBpe())
|
||||
.append("_")
|
||||
.append(bpe.getNumBpe())
|
||||
.append("_")
|
||||
.append(complemento)
|
||||
.append(".xml");
|
||||
|
||||
return nomeArquivo.toString();
|
||||
|
||||
}
|
||||
|
||||
public static byte[] zipFiles(Map<String, InputStream> arquivos) {
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ZipOutputStream outputStream = new ZipOutputStream(baos);
|
||||
InputStream inputStream = null;
|
||||
|
||||
try {
|
||||
for (Entry<String, InputStream> arquivo : arquivos.entrySet()) {
|
||||
outputStream.putNextEntry(new ZipEntry(arquivo.getKey()));
|
||||
byte[] readBuff = new byte[4096];
|
||||
int readLen = -1;
|
||||
|
||||
while ((readLen = arquivo.getValue().read(readBuff)) != -1) {
|
||||
outputStream.write(readBuff, 0, readLen);
|
||||
}
|
||||
outputStream.closeEntry();
|
||||
arquivo.getValue().close();
|
||||
}
|
||||
|
||||
outputStream.finish();
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
|
||||
} finally {
|
||||
if (outputStream != null) {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,9 @@ public class BPeVO {
|
|||
private String errocontingencia;
|
||||
private Date fechorventa;
|
||||
private String nombempresa;
|
||||
private String xmlEnvio;
|
||||
private String xmlResposta;
|
||||
private String tipoevento;
|
||||
|
||||
public Integer getBpeId() {
|
||||
return bpeId;
|
||||
|
@ -107,5 +110,29 @@ public class BPeVO {
|
|||
public void setNombempresa(String nombempresa) {
|
||||
this.nombempresa = nombempresa;
|
||||
}
|
||||
|
||||
|
||||
public String getXmlResposta() {
|
||||
return xmlResposta;
|
||||
}
|
||||
|
||||
public void setXmlResposta(String xmlResposta) {
|
||||
this.xmlResposta = xmlResposta;
|
||||
}
|
||||
|
||||
public String getTipoevento() {
|
||||
return tipoevento;
|
||||
}
|
||||
|
||||
public void setTipoevento(String tipoevento) {
|
||||
this.tipoevento = tipoevento;
|
||||
}
|
||||
|
||||
public String getXmlEnvio() {
|
||||
return xmlEnvio;
|
||||
}
|
||||
|
||||
public void setXmlEnvio(String xmlEnvio) {
|
||||
this.xmlEnvio = xmlEnvio;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue