leonardo 2016-03-28 13:47:47 +00:00
parent 134cf97d5e
commit 3529bc704e
1 changed files with 38 additions and 28 deletions

View File

@ -6,6 +6,7 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.sql.Connection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
@ -26,6 +27,7 @@ import org.zkoss.zul.Filedownload;
import com.rjconsultores.integracaoreceitadespesa.Arquivo; import com.rjconsultores.integracaoreceitadespesa.Arquivo;
import com.rjconsultores.integracaoreceitadespesa.dao.Totalbus; import com.rjconsultores.integracaoreceitadespesa.dao.Totalbus;
import com.rjconsultores.integracaoreceitadespesa.entidades.DespesaReceita;
import com.rjconsultores.ventaboletos.entidad.Empresa; import com.rjconsultores.ventaboletos.entidad.Empresa;
import com.rjconsultores.ventaboletos.entidad.PuntoVenta; import com.rjconsultores.ventaboletos.entidad.PuntoVenta;
import com.rjconsultores.ventaboletos.web.utilerias.MyComboboxEmpresa; 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 // seta dia e mês finais para limite da iteração
int diaFinal = calFinal.get(Calendar.DAY_OF_MONTH); int diaFinal = calFinal.get(Calendar.DAY_OF_MONTH);
int mesFinal = calFinal.get(Calendar.MONTH); int mesFinal = calFinal.get(Calendar.MONTH);
while (cal.get(Calendar.DAY_OF_MONTH) <= diaFinal && cal.get(Calendar.MONTH) <= mesFinal) { Connection con = null;
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"; try{
File file = new File(fileName); con = dataSource.getConnection();
Totalbus totalbus = new Totalbus(dataSource.getConnection()); 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);
log.debug("gerando arquivo..."); Totalbus totalbus = new Totalbus(con);
Arquivo.GravaArquivo(file.getAbsolutePath(), totalbus.getDespesasReceitas(
cmbPuntoVenta.getSelectedItem() == null ? null : ((PuntoVenta)cmbPuntoVenta.getSelectedItem().getValue()).getPuntoventaId(), log.debug("gerando arquivo...");
cmbEmpresa.getSelectedItem() == null ? null : ((Empresa)cmbEmpresa.getSelectedItem().getValue()).getEmpresaId(), Arquivo.GravaArquivo(file.getAbsolutePath(), totalbus.getDespesasReceitas(
cal.getTime())); cmbPuntoVenta.getSelectedItem() == null ? null : ((PuntoVenta)cmbPuntoVenta.getSelectedItem().getValue()).getPuntoventaId(),
// adiciona um dia para iteração cmbEmpresa.getSelectedItem() == null ? null : ((Empresa)cmbEmpresa.getSelectedItem().getValue()).getEmpresaId(),
cal.add(Calendar.DAY_OF_MONTH, 1); cal.getTime()));
files.add(file); // 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"; String fileZip = System.getProperty("jboss.server.log.dir") + "/ArquivosBGM.zip";
log.debug("nome arquivo: " + fileZip); log.debug("nome arquivo: " + fileZip);
FileInputStream inputStream; FileInputStream inputStream;
compactarArquivos(files, fileZip); compactarArquivos(files, fileZip);
File filez = new File(fileZip); File filez = new File(fileZip);
log.info(filez.exists()); log.info(filez.exists());
if (filez.exists()) { if (filez.exists()) {
log.debug("download dos arquivos"); log.debug("download dos arquivos");
inputStream = new FileInputStream(filez); inputStream = new FileInputStream(filez);
Filedownload.save(inputStream, new MimetypesFileTypeMap().getContentType(filez), filez.getName()); 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{ public static void compactarArquivo(String arqSaida,String arqEntrada) throws IOException{