From 3529bc704e7b9a13721cdd2e03bf405f39d6420a Mon Sep 17 00:00:00 2001 From: leonardo Date: Mon, 28 Mar 2016 13:47:47 +0000 Subject: [PATCH] fixes bug #7288 fixes bug #7287 git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@54283 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../RelatorioArquivoBGMController.java | 66 +++++++++++-------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioArquivoBGMController.java b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioArquivoBGMController.java index d610720d3..da120eb5e 100644 --- a/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioArquivoBGMController.java +++ b/src/java/com/rjconsultores/ventaboletos/web/gui/controladores/relatorios/RelatorioArquivoBGMController.java @@ -6,6 +6,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.sql.Connection; import java.util.ArrayList; import java.util.Calendar; import java.util.List; @@ -26,6 +27,7 @@ import org.zkoss.zul.Filedownload; import com.rjconsultores.integracaoreceitadespesa.Arquivo; import com.rjconsultores.integracaoreceitadespesa.dao.Totalbus; +import com.rjconsultores.integracaoreceitadespesa.entidades.DespesaReceita; import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.PuntoVenta; import com.rjconsultores.ventaboletos.web.utilerias.MyComboboxEmpresa; @@ -73,36 +75,44 @@ public class RelatorioArquivoBGMController extends MyGenericForwardComposer { // seta dia e mês finais para limite da iteração int diaFinal = calFinal.get(Calendar.DAY_OF_MONTH); int mesFinal = calFinal.get(Calendar.MONTH); - while (cal.get(Calendar.DAY_OF_MONTH) <= diaFinal && cal.get(Calendar.MONTH) <= mesFinal) { - String fileName = System.getProperty("jboss.server.log.dir") + "/BGM-" + cal.get(Calendar.YEAR) + "" + (cal.get(Calendar.MONTH) + 1) + "" + cal.get(Calendar.DAY_OF_MONTH) + ".txt"; - File file = new File(fileName); - - Totalbus totalbus = new Totalbus(dataSource.getConnection()); - - log.debug("gerando arquivo..."); - Arquivo.GravaArquivo(file.getAbsolutePath(), totalbus.getDespesasReceitas( - cmbPuntoVenta.getSelectedItem() == null ? null : ((PuntoVenta)cmbPuntoVenta.getSelectedItem().getValue()).getPuntoventaId(), - cmbEmpresa.getSelectedItem() == null ? null : ((Empresa)cmbEmpresa.getSelectedItem().getValue()).getEmpresaId(), - cal.getTime())); - // adiciona um dia para iteração - cal.add(Calendar.DAY_OF_MONTH, 1); - files.add(file); - } + Connection con = null; + try{ + con = dataSource.getConnection(); - - String fileZip = System.getProperty("jboss.server.log.dir") + "/ArquivosBGM.zip"; - log.debug("nome arquivo: " + fileZip); - FileInputStream inputStream; - - compactarArquivos(files, fileZip); - File filez = new File(fileZip); - log.info(filez.exists()); - if (filez.exists()) { - log.debug("download dos arquivos"); - inputStream = new FileInputStream(filez); - Filedownload.save(inputStream, new MimetypesFileTypeMap().getContentType(filez), filez.getName()); + while (cal.get(Calendar.DAY_OF_MONTH) <= diaFinal && cal.get(Calendar.MONTH) <= mesFinal) { + String fileName = System.getProperty("jboss.server.log.dir") + "/BGM-" + cal.get(Calendar.YEAR) + "" + DespesaReceita.lpad(Integer.toString(cal.get(Calendar.MONTH) + 1), "0", 2) + "" + DespesaReceita.lpad(Integer.toString(cal.get(Calendar.DAY_OF_MONTH)), "0", 2) + ".txt"; + File file = new File(fileName); + + Totalbus totalbus = new Totalbus(con); + + log.debug("gerando arquivo..."); + Arquivo.GravaArquivo(file.getAbsolutePath(), totalbus.getDespesasReceitas( + cmbPuntoVenta.getSelectedItem() == null ? null : ((PuntoVenta)cmbPuntoVenta.getSelectedItem().getValue()).getPuntoventaId(), + cmbEmpresa.getSelectedItem() == null ? null : ((Empresa)cmbEmpresa.getSelectedItem().getValue()).getEmpresaId(), + cal.getTime())); + // adiciona um dia para iteração + cal.add(Calendar.DAY_OF_MONTH, 1); + files.add(file); + } + + + String fileZip = System.getProperty("jboss.server.log.dir") + "/ArquivosBGM.zip"; + log.debug("nome arquivo: " + fileZip); + FileInputStream inputStream; + + compactarArquivos(files, fileZip); + File filez = new File(fileZip); + log.info(filez.exists()); + if (filez.exists()) { + log.debug("download dos arquivos"); + inputStream = new FileInputStream(filez); + Filedownload.save(inputStream, new MimetypesFileTypeMap().getContentType(filez), filez.getName()); + } + filez.delete(); + + } finally { + con.close(); } - filez.delete(); } public static void compactarArquivo(String arqSaida,String arqEntrada) throws IOException{