SISDAP Relatório ANTT (fixed bug #5247)

git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@35248 d1611594-4594-4d17-8e1d-87c2c4800839
master
julio 2014-05-02 21:32:08 +00:00
parent 5a4182e360
commit 6a8b00198e
2 changed files with 49 additions and 36 deletions

View File

@ -11,6 +11,7 @@ import java.util.zip.Deflater;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
@ -32,6 +33,9 @@ import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer;
public class RelatorioSisdapController extends MyGenericForwardComposer { public class RelatorioSisdapController extends MyGenericForwardComposer {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static Logger log = Logger.getLogger(RelatorioSisdapController.class);
private Integer MAX_BUFFER_ZIP = Integer.valueOf(18024);
private Datebox datInicio; private Datebox datInicio;
private Datebox datFinal; private Datebox datFinal;
@ -40,6 +44,7 @@ public class RelatorioSisdapController extends MyGenericForwardComposer {
@Autowired @Autowired
private EmpresaService empresaService; private EmpresaService empresaService;
@Autowired @Autowired
private SisdapService sisdapService; private SisdapService sisdapService;
@ -59,64 +64,75 @@ public class RelatorioSisdapController extends MyGenericForwardComposer {
Messagebox.OK, Messagebox.INFORMATION); Messagebox.OK, Messagebox.INFORMATION);
return; return;
} }
export(datInicio.getValue(), datFinal.getValue()); processarRelatorioSisdap(datInicio.getValue(), datFinal.getValue());
closeWindow(); closeWindow();
} }
private void zipFiles(String[] filesToZip, String fileOutputName) { private void zipFiles(String[] filesToZip, String fileOutputName) {
byte[] buffer = new byte[18024]; byte[] buffer = new byte[MAX_BUFFER_ZIP];
try try {
{
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(fileOutputName)); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(fileOutputName));
// Ajusta modo de compressão // Ajusta modo de compressão
out.setLevel(Deflater.DEFAULT_COMPRESSION); out.setLevel(Deflater.DEFAULT_COMPRESSION);
// faz a iteração sobre os arquivos, adicionando-os ao arquivo ZIP // faz a iteração sobre os arquivos, adicionando-os ao arquivo ZIP
for (int i = 0; i < filesToZip.length; i++) for (int i = 0; i < filesToZip.length; i++) {
{
System.out.println(i);
FileInputStream in = new FileInputStream(filesToZip[i]); FileInputStream in = new FileInputStream(filesToZip[i]);
// Add ZIP entry to output stream. // Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(filesToZip[i])); out.putNextEntry(new ZipEntry(filesToZip[i]));
// Transfer bytes from the current file to the ZIP file // Transfer bytes from the current file to the ZIP file
int len; int len;
while ((len = in.read(buffer)) > 0) while ((len = in.read(buffer)) > 0) {
{
out.write(buffer, 0, len); out.write(buffer, 0, len);
} }
// Close the current entry // Close the current entry
out.closeEntry(); out.closeEntry();
// Close the current file input stream // Close the current file input stream
in.close(); in.close();
} }
// Close the ZipOutPutStream // Close the ZipOutPutStream
out.close(); out.close();
} catch (IllegalArgumentException iae) { } catch (IllegalArgumentException iae) {
iae.printStackTrace(); log.error("", iae);
} catch (FileNotFoundException fnfe) { } catch (FileNotFoundException fnfe) {
fnfe.printStackTrace(); log.error("", fnfe);
} catch (IOException ioe) { } catch (IOException ioe) {
ioe.printStackTrace(); log.error("", ioe);
} }
} }
public void export(Date fecInicio, Date fecFinal) { private void processarRelatorioSisdap(Date fecInicio, Date fecFinal) {
try{
List<String> movimentoLinhas = sisdapService.getMovimentoLinhas(fecInicio, fecFinal, empresa.getEmpresaId()); List<String> movimentoLinhas = sisdapService.getMovimentoLinhas(fecInicio, fecFinal, empresa.getEmpresaId());
List<String> movimentoSecoes = sisdapService.getMovimentoSecoes(fecInicio, fecFinal, empresa.getEmpresaId()); List<String> movimentoSecoes = sisdapService.getMovimentoSecoes(fecInicio, fecFinal, empresa.getEmpresaId());
if (movimentoLinhas.size() <= 1 && movimentoSecoes.size() <= 1) { if (movimentoLinhas.size() <= 1 && movimentoSecoes.size() <= 1) {
// Não retornou dados // Não retornou dados
try {
Messagebox.show(Labels.getLabel("relatorioSisdapController.MSG.nenhumRegistro"), Messagebox.show(Labels.getLabel("relatorioSisdapController.MSG.nenhumRegistro"),
Labels.getLabel("filtroRelatorioSisdap.window.title"), Labels.getLabel("filtroRelatorioSisdap.window.title"),
Messagebox.OK, Messagebox.INFORMATION); Messagebox.OK, Messagebox.INFORMATION);
} catch (InterruptedException e) {
log.error("", e);
}
return; return;
} }
exportarZip(movimentoLinhas, movimentoSecoes);
}
private void exportarZip(List<String> movimentoLinhas, List<String> movimentoSecoes) {
try {
FileWriter writer = new FileWriter("movimentoLinhas.txt"); FileWriter writer = new FileWriter("movimentoLinhas.txt");
for (String str : movimentoLinhas) { for (String str : movimentoLinhas) {
writer.write(str + "\r\n"); writer.write(str + "\r\n");
@ -134,12 +150,9 @@ public class RelatorioSisdapController extends MyGenericForwardComposer {
FileInputStream is = new FileInputStream("sisdap.zip"); FileInputStream is = new FileInputStream("sisdap.zip");
Filedownload.save(is, "application/zip", "sisdap.zip"); Filedownload.save(is, "application/zip", "sisdap.zip");
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block log.error("", e);
e.printStackTrace();
} }
} }
public Empresa getEmpresa() { public Empresa getEmpresa() {

View File

@ -7,7 +7,7 @@
<zk xmlns="http://www.zkoss.org/2005/zul"> <zk xmlns="http://www.zkoss.org/2005/zul">
<window id="winFiltroRelatorioSisdap" <window id="winFiltroRelatorioSisdap"
apply="${relatorioSisdapController}" apply="${relatorioSisdapController}"
contentStyle="overflow:auto" height="260px" width="550px" contentStyle="overflow:auto" height="165px" width="550px"
border="normal" closable="true"> border="normal" closable="true">
<grid fixedLayout="true"> <grid fixedLayout="true">
<columns> <columns>