fixes bug#9119
git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/Integracion/IntegracaoReceitaDespesa/trunk/IntegracaoReceitaDespesa@69593 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
bb88f3dc8d
commit
9d08163be6
|
@ -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.nio.channels.FileChannel;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
@ -70,7 +71,7 @@ public class BGMApplication {
|
||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String executaExportacao(Date dataInicio, Date dataFinal, String diretorio, Integer empresaId, Integer puntoVentaId, Connection con) throws IllegalArgumentException{
|
public String executaExportacao(Date dataInicio, Date dataFinal, String diretorio, Integer empresaId, Integer puntoVentaId, Connection con,String pathGravacaoExternaArquivos) throws IllegalArgumentException{
|
||||||
if (empresaId == null){
|
if (empresaId == null){
|
||||||
throw new IllegalArgumentException("o parâmetro empesaId é obrigatório!");
|
throw new IllegalArgumentException("o parâmetro empesaId é obrigatório!");
|
||||||
}
|
}
|
||||||
|
@ -100,6 +101,9 @@ public class BGMApplication {
|
||||||
|
|
||||||
log.debug("gerando arquivo...");
|
log.debug("gerando arquivo...");
|
||||||
Arquivo.GravaArquivo(file.getAbsolutePath(), totalbus.getDespesasReceitas(puntoVentaId, empresaId, cal.getTime()));
|
Arquivo.GravaArquivo(file.getAbsolutePath(), totalbus.getDespesasReceitas(puntoVentaId, empresaId, cal.getTime()));
|
||||||
|
|
||||||
|
this.copiarArquivoExternamente(file, pathGravacaoExternaArquivos);
|
||||||
|
|
||||||
// adiciona um dia para iteração
|
// adiciona um dia para iteração
|
||||||
cal.add(Calendar.DAY_OF_MONTH, 1);
|
cal.add(Calendar.DAY_OF_MONTH, 1);
|
||||||
files.add(file);
|
files.add(file);
|
||||||
|
@ -121,7 +125,38 @@ public class BGMApplication {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void copiarArquivoExternamente(File arquivoBGM,String pathGravacaoExternaArquivos){
|
||||||
|
if (pathGravacaoExternaArquivos == null){
|
||||||
|
log.info("Path externo para gravação de arquivos não configurado");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pathGravacaoExternaArquivos.endsWith("/")){
|
||||||
|
pathGravacaoExternaArquivos = pathGravacaoExternaArquivos +"/";
|
||||||
|
}
|
||||||
|
|
||||||
|
File destino = new File(pathGravacaoExternaArquivos + arquivoBGM.getName());
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.copyFileUsingChannel(arquivoBGM, destino);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error(String.format("Erro ao gravar o arquivo %s no diretorio %s", arquivoBGM.getName(),pathGravacaoExternaArquivos) ,e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void copyFileUsingChannel(File source, File dest) throws IOException {
|
||||||
|
|
||||||
|
FileChannel sourceChannel = null;
|
||||||
|
FileChannel destChannel = null;
|
||||||
|
try {
|
||||||
|
sourceChannel = new FileInputStream(source).getChannel();
|
||||||
|
destChannel = new FileOutputStream(dest).getChannel();
|
||||||
|
destChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
|
||||||
|
}finally{
|
||||||
|
sourceChannel.close();
|
||||||
|
destChannel.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
private void excluirArquivosZip(String diretorio){
|
private void excluirArquivosZip(String diretorio){
|
||||||
File pasta = new File(diretorio);
|
File pasta = new File(diretorio);
|
||||||
File[] arquivos = pasta.listFiles();
|
File[] arquivos = pasta.listFiles();
|
||||||
|
|
Loading…
Reference in New Issue