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-87c2c4800839master
parent
5a4182e360
commit
6a8b00198e
|
@ -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,91 +33,106 @@ 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;
|
||||
private Empresa empresa;
|
||||
private Combobox cmbEmpresa;
|
||||
|
||||
|
||||
@Autowired
|
||||
private EmpresaService empresaService;
|
||||
|
||||
@Autowired
|
||||
private SisdapService sisdapService;
|
||||
|
||||
private List<Empresa> lsEmpresa;
|
||||
|
||||
|
||||
@Override
|
||||
public void doAfterCompose(Component comp) throws Exception {
|
||||
lsEmpresa = empresaService.obtenerTodos();
|
||||
|
||||
|
||||
super.doAfterCompose(comp);
|
||||
}
|
||||
|
||||
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);
|
||||
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){
|
||||
// Não retornou dados
|
||||
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) {
|
||||
// Não retornou dados
|
||||
try {
|
||||
Messagebox.show(Labels.getLabel("relatorioSisdapController.MSG.nenhumRegistro"),
|
||||
Labels.getLabel("filtroRelatorioSisdap.window.title"),
|
||||
Messagebox.OK, Messagebox.INFORMATION);
|
||||
return;
|
||||
} 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");
|
||||
|
@ -131,15 +147,12 @@ public class RelatorioSisdapController extends MyGenericForwardComposer {
|
|||
|
||||
String[] files = new String[] { "movimentoLinhas.txt", "movimentoSecoes.txt" };
|
||||
zipFiles(files, "sisdap.zip");
|
||||
|
||||
|
||||
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() {
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue