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.ZipOutputStream;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
@ -32,6 +33,9 @@ import com.rjconsultores.ventaboletos.web.utilerias.MyGenericForwardComposer;
public class RelatorioSisdapController extends MyGenericForwardComposer {
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 datFinal;
@ -40,6 +44,7 @@ public class RelatorioSisdapController extends MyGenericForwardComposer {
@Autowired
private EmpresaService empresaService;
@Autowired
private SisdapService sisdapService;
@ -53,70 +58,81 @@ public class RelatorioSisdapController extends MyGenericForwardComposer {
}
public void onClick$btnExecutarRelatorio(Event ev) throws Exception {
if (cmbEmpresa.getSelectedIndex() < 0){
if (cmbEmpresa.getSelectedIndex() < 0) {
Messagebox.show(Labels.getLabel("relatorioSisdapController.MSG.empresaErro"),
Labels.getLabel("filtroRelatorioSisdap.window.title"),
Messagebox.OK, Messagebox.INFORMATION);
return;
}
export(datInicio.getValue(), datFinal.getValue());
processarRelatorioSisdap(datInicio.getValue(), datFinal.getValue());
closeWindow();
}
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));
// Ajusta modo de compressão
out.setLevel(Deflater.DEFAULT_COMPRESSION);
// faz a iteração sobre os arquivos, adicionando-os ao arquivo ZIP
for (int i = 0; i < filesToZip.length; i++)
{
System.out.println(i);
for (int i = 0; i < filesToZip.length; i++) {
FileInputStream in = new FileInputStream(filesToZip[i]);
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(filesToZip[i]));
// Transfer bytes from the current file to the ZIP file
int len;
while ((len = in.read(buffer)) > 0)
{
while ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
// Close the current entry
out.closeEntry();
// Close the current file input stream
in.close();
}
// Close the ZipOutPutStream
out.close();
} catch (IllegalArgumentException iae){
iae.printStackTrace();
} catch (FileNotFoundException fnfe){
fnfe.printStackTrace();
} catch (IOException ioe){
ioe.printStackTrace();
} catch (IllegalArgumentException iae) {
log.error("", iae);
} catch (FileNotFoundException fnfe) {
log.error("", fnfe);
} catch (IOException ioe) {
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> 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
try {
Messagebox.show(Labels.getLabel("relatorioSisdapController.MSG.nenhumRegistro"),
Labels.getLabel("filtroRelatorioSisdap.window.title"),
Messagebox.OK, Messagebox.INFORMATION);
} catch (InterruptedException e) {
log.error("", e);
}
return;
}
exportarZip(movimentoLinhas, movimentoSecoes);
}
private void exportarZip(List<String> movimentoLinhas, List<String> movimentoSecoes) {
try {
FileWriter writer = new FileWriter("movimentoLinhas.txt");
for (String str : movimentoLinhas) {
writer.write(str + "\r\n");
@ -134,12 +150,9 @@ public class RelatorioSisdapController extends MyGenericForwardComposer {
FileInputStream is = new FileInputStream("sisdap.zip");
Filedownload.save(is, "application/zip", "sisdap.zip");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
log.error("", e);
}
}
public Empresa getEmpresa() {

View File

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