join IntegracaoReceitaDespesa
parent
8bb8c1cb0e
commit
b6fc55a8d5
|
@ -1,3 +1,3 @@
|
|||
Manifest-Version: 1.0
|
||||
Class-Path:
|
||||
|
||||
Manifest-Version: 1.0
|
||||
Class-Path:
|
||||
|
|
@ -1,57 +1,57 @@
|
|||
package com.rjconsultores.integracaoreceitadespesa;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
package com.rjconsultores.integracaoreceitadespesa;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
||||
public class Application {
|
||||
private static Application instance = null;
|
||||
|
||||
private static final Logger log = LogManager.getLogger(Application.class);
|
||||
|
||||
private Application(){
|
||||
|
||||
}
|
||||
|
||||
public Connection getConnection(){
|
||||
try {
|
||||
Properties props = Application.getInstance().getApplicationProperties();
|
||||
|
||||
String DRIVER = "oracle.jdbc.driver.OracleDriver";
|
||||
|
||||
Class.forName(DRIVER);
|
||||
Connection conn = DriverManager.getConnection(
|
||||
props.getProperty("url"),
|
||||
props.getProperty("username").trim(),
|
||||
props.getProperty("password").trim());
|
||||
|
||||
return conn;
|
||||
|
||||
} catch (Exception e){
|
||||
log.error("", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static Application getInstance(){
|
||||
if (instance == null){
|
||||
instance = new Application();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public Properties getApplicationProperties(){
|
||||
Properties props = new Properties();
|
||||
try {
|
||||
props.load(new FileInputStream("db.properties"));
|
||||
} catch (IOException e) {
|
||||
log.error("", e);
|
||||
}
|
||||
return props;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class Application {
|
||||
private static Application instance = null;
|
||||
|
||||
private static final Logger log = LogManager.getLogger(Application.class);
|
||||
|
||||
private Application(){
|
||||
|
||||
}
|
||||
|
||||
public Connection getConnection(){
|
||||
try {
|
||||
Properties props = Application.getInstance().getApplicationProperties();
|
||||
|
||||
String DRIVER = "oracle.jdbc.driver.OracleDriver";
|
||||
|
||||
Class.forName(DRIVER);
|
||||
Connection conn = DriverManager.getConnection(
|
||||
props.getProperty("url"),
|
||||
props.getProperty("username").trim(),
|
||||
props.getProperty("password").trim());
|
||||
|
||||
return conn;
|
||||
|
||||
} catch (Exception e){
|
||||
log.error("", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public static Application getInstance(){
|
||||
if (instance == null){
|
||||
instance = new Application();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public Properties getApplicationProperties(){
|
||||
Properties props = new Properties();
|
||||
try {
|
||||
props.load(new FileInputStream("db.properties"));
|
||||
} catch (IOException e) {
|
||||
log.error("", e);
|
||||
}
|
||||
return props;
|
||||
}
|
||||
}
|
|
@ -1,37 +1,37 @@
|
|||
package com.rjconsultores.integracaoreceitadespesa;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
package com.rjconsultores.integracaoreceitadespesa;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
||||
public class Arquivo {
|
||||
private static final Logger log = LogManager.getLogger(Arquivo.class);
|
||||
|
||||
public static void GravaArquivo(String filename, List<String> rows){
|
||||
try{
|
||||
log.debug("gravando arquivo" + filename + "...");
|
||||
FileWriter writer = new FileWriter(filename);
|
||||
for(String str: rows) {
|
||||
writer.write(str);
|
||||
}
|
||||
writer.close();
|
||||
} catch (Exception e){
|
||||
log.error("", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void close(Closeable c) {
|
||||
if (c == null) return;
|
||||
try {
|
||||
c.close();
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class Arquivo {
|
||||
private static final Logger log = LogManager.getLogger(Arquivo.class);
|
||||
|
||||
public static void GravaArquivo(String filename, List<String> rows){
|
||||
try{
|
||||
log.debug("gravando arquivo" + filename + "...");
|
||||
FileWriter writer = new FileWriter(filename);
|
||||
for(String str: rows) {
|
||||
writer.write(str);
|
||||
}
|
||||
writer.close();
|
||||
} catch (Exception e){
|
||||
log.error("", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void close(Closeable c) {
|
||||
if (c == null) return;
|
||||
try {
|
||||
c.close();
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,270 +1,270 @@
|
|||
package com.rjconsultores.integracaoreceitadespesa;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
package com.rjconsultores.integracaoreceitadespesa;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
|
||||
import com.rjconsultores.integracaoreceitadespesa.dao.Totalbus;
|
||||
|
||||
public class BGMApplication {
|
||||
private static BGMApplication instance = null;
|
||||
|
||||
private static final Logger log = LogManager.getLogger(BGMApplication.class);
|
||||
|
||||
private static final int TAMANHO_BUFFER = 4096; // 4kb
|
||||
|
||||
private boolean isReceitasDespesasComporte;
|
||||
|
||||
private boolean isCodReceitaFixoBgm;
|
||||
|
||||
private boolean isReceitasDespesasOuroPrata;
|
||||
|
||||
private BGMApplication(){
|
||||
|
||||
}
|
||||
|
||||
public Connection getConnection(){
|
||||
try {
|
||||
Properties props = BGMApplication.getInstance().getApplicationProperties();
|
||||
|
||||
String DRIVER = "oracle.jdbc.driver.OracleDriver";
|
||||
|
||||
Class.forName(DRIVER);
|
||||
Connection conn = DriverManager.getConnection(
|
||||
props.getProperty("url"),
|
||||
props.getProperty("username").trim(),
|
||||
props.getProperty("password").trim());
|
||||
|
||||
return conn;
|
||||
|
||||
} catch (Exception e){
|
||||
log.error("", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static BGMApplication getInstance(){
|
||||
if (instance == null){
|
||||
instance = new BGMApplication();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public Properties getApplicationProperties(){
|
||||
Properties props = new Properties();
|
||||
try {
|
||||
props.load(new FileInputStream("db.properties"));
|
||||
} catch (IOException e) {
|
||||
log.error("", e);
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
||||
public String executaExportacao(Date dataInicio, Date dataFinal, String diretorio, Integer empresaId, Integer puntoVentaId, Connection con,String pathGravacaoExternaArquivos, boolean incluiTipoPagamentoTurismoBGM, boolean isReceitasDespesasComporte,boolean isCodReceitaFixoBgm, boolean isReceitasDespesasOuroPrata, boolean layoutNovo) throws IllegalArgumentException, IntegracaoReceitaDespesaException{
|
||||
this.isCodReceitaFixoBgm = isCodReceitaFixoBgm;
|
||||
this.isReceitasDespesasComporte = isReceitasDespesasComporte;
|
||||
this.isReceitasDespesasOuroPrata = isReceitasDespesasOuroPrata;
|
||||
return executaExportacao(dataInicio, dataFinal, diretorio, empresaId, puntoVentaId, con, pathGravacaoExternaArquivos, incluiTipoPagamentoTurismoBGM, layoutNovo);
|
||||
}
|
||||
|
||||
public String executaExportacao(Date dataInicio, Date dataFinal, String diretorio, Integer empresaId, Integer puntoVentaId, Connection con,String pathGravacaoExternaArquivos, boolean incluiTipoPagamentoTurismoBGM, boolean isReceitasDespesasComporte,boolean isCodReceitaFixoBgm, boolean isReceitasDespesasOuroPrata) throws IllegalArgumentException, IntegracaoReceitaDespesaException{
|
||||
this.isCodReceitaFixoBgm = isCodReceitaFixoBgm;
|
||||
this.isReceitasDespesasOuroPrata = isReceitasDespesasOuroPrata;
|
||||
return executaExportacao(dataInicio, dataFinal, diretorio, empresaId, puntoVentaId, con, pathGravacaoExternaArquivos, incluiTipoPagamentoTurismoBGM, false);
|
||||
}
|
||||
|
||||
public String executaExportacao(Date dataInicio, Date dataFinal, String diretorio, Integer empresaId, Integer puntoVentaId, Connection con,String pathGravacaoExternaArquivos, boolean incluiTipoPagamentoTurismoBGM, boolean isReceitasDespesasComporte, boolean isReceitasDespesasOuroPrata) throws IllegalArgumentException, IntegracaoReceitaDespesaException{
|
||||
this.isReceitasDespesasComporte = isReceitasDespesasComporte;
|
||||
return executaExportacao(dataInicio, dataFinal, diretorio, empresaId, puntoVentaId, con, pathGravacaoExternaArquivos, incluiTipoPagamentoTurismoBGM, false);
|
||||
}
|
||||
|
||||
public String executaExportacao(Date dataInicio, Date dataFinal, String diretorio, Integer empresaId, Integer puntoVentaId, Connection con,String pathGravacaoExternaArquivos, boolean incluiTipoPagamentoTurismoBGM, boolean layoutNovo) throws IllegalArgumentException, IntegracaoReceitaDespesaException{
|
||||
if (empresaId == null){
|
||||
throw new IllegalArgumentException("o parâmetro empesaId é obrigatório!");
|
||||
}
|
||||
if (puntoVentaId == null){
|
||||
throw new IllegalArgumentException("o parâmetro puntoVentaId é obrigatório!");
|
||||
}
|
||||
excluirArquivosZip(diretorio);
|
||||
Totalbus totalbus = new Totalbus(con, isReceitasDespesasComporte, isCodReceitaFixoBgm, isReceitasDespesasOuroPrata, layoutNovo );
|
||||
if (totalbus.isConstanteBloqueioMenorQueData(empresaId, dataFinal)){
|
||||
totalbus.updateDataBloqueio(empresaId, dataFinal);
|
||||
}
|
||||
List<File> files = new ArrayList<File>();
|
||||
Calendar cal = Calendar.getInstance();
|
||||
// Seta primeiro dia da iteração
|
||||
cal.setTime(dataInicio);
|
||||
Calendar calFinal = Calendar.getInstance();
|
||||
calFinal.setTime(dataFinal);
|
||||
|
||||
Calendar cf = Calendar.getInstance();
|
||||
cf.setTime(dataFinal);
|
||||
cf.add(Calendar.DATE, 1);
|
||||
try{
|
||||
|
||||
while (cal.before(cf)) {
|
||||
String fileName = diretorio + File.separator + "BGM_" + empresaId + "-" + cal.get(Calendar.YEAR)
|
||||
+ "" + StringUtils.leftPad(Integer.toString(cal.get(Calendar.MONTH) + 1), 2, "0") + ""
|
||||
+ StringUtils.leftPad(Integer.toString(cal.get(Calendar.DAY_OF_MONTH)), 2, "0") + ".txt";
|
||||
File file = new File(fileName);
|
||||
|
||||
log.debug("gerando arquivo...");
|
||||
Arquivo.GravaArquivo(file.getAbsolutePath(), totalbus.getDespesasReceitas(puntoVentaId, empresaId, cal.getTime(), incluiTipoPagamentoTurismoBGM, layoutNovo));
|
||||
|
||||
this.copiarArquivoExternamente(file, pathGravacaoExternaArquivos);
|
||||
|
||||
// adiciona um dia para iteração
|
||||
cal.add(Calendar.DAY_OF_MONTH, 1);
|
||||
files.add(file);
|
||||
}
|
||||
|
||||
String fileZip = diretorio + File.separator + "ArquivosBGM.zip";
|
||||
log.debug("nome arquivo: " + fileZip);
|
||||
|
||||
compactarArquivos(files, fileZip);
|
||||
return fileZip;
|
||||
} catch (IntegracaoReceitaDespesaException e){
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
log.error("", e);
|
||||
return "";
|
||||
} finally{
|
||||
try {
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
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){
|
||||
File pasta = new File(diretorio);
|
||||
File[] arquivos = pasta.listFiles();
|
||||
|
||||
for(File arquivo : arquivos) {
|
||||
if(arquivo.getName().endsWith("zip")) {
|
||||
arquivo.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void compactarArquivo(String arqSaida,String arqEntrada) throws IOException{
|
||||
int cont;
|
||||
byte[] dados = new byte[TAMANHO_BUFFER];
|
||||
BufferedInputStream origem = null;
|
||||
FileInputStream streamDeEntrada = null;
|
||||
FileOutputStream destino = null;
|
||||
ZipOutputStream saida = null;
|
||||
ZipEntry entry = null;
|
||||
try {
|
||||
destino = new FileOutputStream(new File(arqSaida));
|
||||
saida = new ZipOutputStream(new BufferedOutputStream(destino));
|
||||
File file = new File(arqEntrada);
|
||||
streamDeEntrada = new FileInputStream(file);
|
||||
origem = new BufferedInputStream(streamDeEntrada, TAMANHO_BUFFER);
|
||||
entry = new ZipEntry(file.getName());
|
||||
saida.putNextEntry(entry);
|
||||
while((cont = origem.read(dados, 0, TAMANHO_BUFFER)) != -1) {
|
||||
saida.write(dados, 0, cont);
|
||||
}
|
||||
origem.close();
|
||||
saida.close();
|
||||
} catch(IOException e) {
|
||||
log.error(e.getMessage());
|
||||
throw new IOException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void compactarArquivos(List<File> arquivosEOuPastas, String arquivoDeSaida){
|
||||
System.out.println(arquivoDeSaida);
|
||||
log.debug(arquivoDeSaida);
|
||||
|
||||
// Create a buffer for reading the files
|
||||
byte[] buf = new byte[1024];
|
||||
|
||||
try {
|
||||
// Create the ZIP file
|
||||
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(arquivoDeSaida));
|
||||
|
||||
// Compress the files
|
||||
for (File f : arquivosEOuPastas) {
|
||||
FileInputStream in = new FileInputStream(f.getPath());
|
||||
|
||||
// Add ZIP entry to output stream.
|
||||
out.putNextEntry(new ZipEntry(f.getName()));
|
||||
System.out.println(f.getPath());
|
||||
// Transfer bytes from the file to the ZIP file
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
|
||||
// Complete the entry
|
||||
out.closeEntry();
|
||||
in.close();
|
||||
f.delete();
|
||||
}
|
||||
|
||||
// Complete the ZIP file
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(),e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
import com.rjconsultores.integracaoreceitadespesa.dao.Totalbus;
|
||||
|
||||
public class BGMApplication {
|
||||
private static BGMApplication instance = null;
|
||||
|
||||
private static final Logger log = LogManager.getLogger(BGMApplication.class);
|
||||
|
||||
private static final int TAMANHO_BUFFER = 4096; // 4kb
|
||||
|
||||
private boolean isReceitasDespesasComporte;
|
||||
|
||||
private boolean isCodReceitaFixoBgm;
|
||||
|
||||
private boolean isReceitasDespesasOuroPrata;
|
||||
|
||||
private BGMApplication(){
|
||||
|
||||
}
|
||||
|
||||
public Connection getConnection(){
|
||||
try {
|
||||
Properties props = BGMApplication.getInstance().getApplicationProperties();
|
||||
|
||||
String DRIVER = "oracle.jdbc.driver.OracleDriver";
|
||||
|
||||
Class.forName(DRIVER);
|
||||
Connection conn = DriverManager.getConnection(
|
||||
props.getProperty("url"),
|
||||
props.getProperty("username").trim(),
|
||||
props.getProperty("password").trim());
|
||||
|
||||
return conn;
|
||||
|
||||
} catch (Exception e){
|
||||
log.error("", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static BGMApplication getInstance(){
|
||||
if (instance == null){
|
||||
instance = new BGMApplication();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public Properties getApplicationProperties(){
|
||||
Properties props = new Properties();
|
||||
try {
|
||||
props.load(new FileInputStream("db.properties"));
|
||||
} catch (IOException e) {
|
||||
log.error("", e);
|
||||
}
|
||||
return props;
|
||||
}
|
||||
|
||||
public String executaExportacao(Date dataInicio, Date dataFinal, String diretorio, Integer empresaId, Integer puntoVentaId, Connection con,String pathGravacaoExternaArquivos, boolean incluiTipoPagamentoTurismoBGM, boolean isReceitasDespesasComporte,boolean isCodReceitaFixoBgm, boolean isReceitasDespesasOuroPrata, boolean layoutNovo) throws IllegalArgumentException, IntegracaoReceitaDespesaException{
|
||||
this.isCodReceitaFixoBgm = isCodReceitaFixoBgm;
|
||||
this.isReceitasDespesasComporte = isReceitasDespesasComporte;
|
||||
this.isReceitasDespesasOuroPrata = isReceitasDespesasOuroPrata;
|
||||
return executaExportacao(dataInicio, dataFinal, diretorio, empresaId, puntoVentaId, con, pathGravacaoExternaArquivos, incluiTipoPagamentoTurismoBGM, layoutNovo);
|
||||
}
|
||||
|
||||
public String executaExportacao(Date dataInicio, Date dataFinal, String diretorio, Integer empresaId, Integer puntoVentaId, Connection con,String pathGravacaoExternaArquivos, boolean incluiTipoPagamentoTurismoBGM, boolean isReceitasDespesasComporte,boolean isCodReceitaFixoBgm, boolean isReceitasDespesasOuroPrata) throws IllegalArgumentException, IntegracaoReceitaDespesaException{
|
||||
this.isCodReceitaFixoBgm = isCodReceitaFixoBgm;
|
||||
this.isReceitasDespesasOuroPrata = isReceitasDespesasOuroPrata;
|
||||
return executaExportacao(dataInicio, dataFinal, diretorio, empresaId, puntoVentaId, con, pathGravacaoExternaArquivos, incluiTipoPagamentoTurismoBGM, false);
|
||||
}
|
||||
|
||||
public String executaExportacao(Date dataInicio, Date dataFinal, String diretorio, Integer empresaId, Integer puntoVentaId, Connection con,String pathGravacaoExternaArquivos, boolean incluiTipoPagamentoTurismoBGM, boolean isReceitasDespesasComporte, boolean isReceitasDespesasOuroPrata) throws IllegalArgumentException, IntegracaoReceitaDespesaException{
|
||||
this.isReceitasDespesasComporte = isReceitasDespesasComporte;
|
||||
return executaExportacao(dataInicio, dataFinal, diretorio, empresaId, puntoVentaId, con, pathGravacaoExternaArquivos, incluiTipoPagamentoTurismoBGM, false);
|
||||
}
|
||||
|
||||
public String executaExportacao(Date dataInicio, Date dataFinal, String diretorio, Integer empresaId, Integer puntoVentaId, Connection con,String pathGravacaoExternaArquivos, boolean incluiTipoPagamentoTurismoBGM, boolean layoutNovo) throws IllegalArgumentException, IntegracaoReceitaDespesaException{
|
||||
if (empresaId == null){
|
||||
throw new IllegalArgumentException("o parâmetro empesaId é obrigatório!");
|
||||
}
|
||||
if (puntoVentaId == null){
|
||||
throw new IllegalArgumentException("o parâmetro puntoVentaId é obrigatório!");
|
||||
}
|
||||
excluirArquivosZip(diretorio);
|
||||
Totalbus totalbus = new Totalbus(con, isReceitasDespesasComporte, isCodReceitaFixoBgm, isReceitasDespesasOuroPrata, layoutNovo );
|
||||
if (totalbus.isConstanteBloqueioMenorQueData(empresaId, dataFinal)){
|
||||
totalbus.updateDataBloqueio(empresaId, dataFinal);
|
||||
}
|
||||
List<File> files = new ArrayList<File>();
|
||||
Calendar cal = Calendar.getInstance();
|
||||
// Seta primeiro dia da iteração
|
||||
cal.setTime(dataInicio);
|
||||
Calendar calFinal = Calendar.getInstance();
|
||||
calFinal.setTime(dataFinal);
|
||||
|
||||
Calendar cf = Calendar.getInstance();
|
||||
cf.setTime(dataFinal);
|
||||
cf.add(Calendar.DATE, 1);
|
||||
try{
|
||||
|
||||
while (cal.before(cf)) {
|
||||
String fileName = diretorio + File.separator + "BGM_" + empresaId + "-" + cal.get(Calendar.YEAR)
|
||||
+ "" + StringUtils.leftPad(Integer.toString(cal.get(Calendar.MONTH) + 1), 2, "0") + ""
|
||||
+ StringUtils.leftPad(Integer.toString(cal.get(Calendar.DAY_OF_MONTH)), 2, "0") + ".txt";
|
||||
File file = new File(fileName);
|
||||
|
||||
log.debug("gerando arquivo...");
|
||||
Arquivo.GravaArquivo(file.getAbsolutePath(), totalbus.getDespesasReceitas(puntoVentaId, empresaId, cal.getTime(), incluiTipoPagamentoTurismoBGM, layoutNovo));
|
||||
|
||||
this.copiarArquivoExternamente(file, pathGravacaoExternaArquivos);
|
||||
|
||||
// adiciona um dia para iteração
|
||||
cal.add(Calendar.DAY_OF_MONTH, 1);
|
||||
files.add(file);
|
||||
}
|
||||
|
||||
String fileZip = diretorio + File.separator + "ArquivosBGM.zip";
|
||||
log.debug("nome arquivo: " + fileZip);
|
||||
|
||||
compactarArquivos(files, fileZip);
|
||||
return fileZip;
|
||||
} catch (IntegracaoReceitaDespesaException e){
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
log.error("", e);
|
||||
return "";
|
||||
} finally{
|
||||
try {
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
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){
|
||||
File pasta = new File(diretorio);
|
||||
File[] arquivos = pasta.listFiles();
|
||||
|
||||
for(File arquivo : arquivos) {
|
||||
if(arquivo.getName().endsWith("zip")) {
|
||||
arquivo.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void compactarArquivo(String arqSaida,String arqEntrada) throws IOException{
|
||||
int cont;
|
||||
byte[] dados = new byte[TAMANHO_BUFFER];
|
||||
BufferedInputStream origem = null;
|
||||
FileInputStream streamDeEntrada = null;
|
||||
FileOutputStream destino = null;
|
||||
ZipOutputStream saida = null;
|
||||
ZipEntry entry = null;
|
||||
try {
|
||||
destino = new FileOutputStream(new File(arqSaida));
|
||||
saida = new ZipOutputStream(new BufferedOutputStream(destino));
|
||||
File file = new File(arqEntrada);
|
||||
streamDeEntrada = new FileInputStream(file);
|
||||
origem = new BufferedInputStream(streamDeEntrada, TAMANHO_BUFFER);
|
||||
entry = new ZipEntry(file.getName());
|
||||
saida.putNextEntry(entry);
|
||||
while((cont = origem.read(dados, 0, TAMANHO_BUFFER)) != -1) {
|
||||
saida.write(dados, 0, cont);
|
||||
}
|
||||
origem.close();
|
||||
saida.close();
|
||||
} catch(IOException e) {
|
||||
log.error(e.getMessage());
|
||||
throw new IOException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void compactarArquivos(List<File> arquivosEOuPastas, String arquivoDeSaida){
|
||||
System.out.println(arquivoDeSaida);
|
||||
log.debug(arquivoDeSaida);
|
||||
|
||||
// Create a buffer for reading the files
|
||||
byte[] buf = new byte[1024];
|
||||
|
||||
try {
|
||||
// Create the ZIP file
|
||||
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(arquivoDeSaida));
|
||||
|
||||
// Compress the files
|
||||
for (File f : arquivosEOuPastas) {
|
||||
FileInputStream in = new FileInputStream(f.getPath());
|
||||
|
||||
// Add ZIP entry to output stream.
|
||||
out.putNextEntry(new ZipEntry(f.getName()));
|
||||
System.out.println(f.getPath());
|
||||
// Transfer bytes from the file to the ZIP file
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
|
||||
// Complete the entry
|
||||
out.closeEntry();
|
||||
in.close();
|
||||
f.delete();
|
||||
}
|
||||
|
||||
// Complete the ZIP file
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(),e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +1,13 @@
|
|||
package com.rjconsultores.integracaoreceitadespesa;
|
||||
|
||||
public class IntegracaoReceitaDespesaException extends Exception{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -5422391379643449955L;
|
||||
|
||||
public IntegracaoReceitaDespesaException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
package com.rjconsultores.integracaoreceitadespesa;
|
||||
|
||||
public class IntegracaoReceitaDespesaException extends Exception{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -5422391379643449955L;
|
||||
|
||||
public IntegracaoReceitaDespesaException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,223 +1,223 @@
|
|||
package com.rjconsultores.integracaoreceitadespesa.entidades;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class DespesaReceita {
|
||||
protected String dataLancamento; // DD/MM/YYYY
|
||||
protected String codigoEmpresa; // 011 003 Numerico
|
||||
protected final String codigoFilial = "001"; // 014 003 Numerico
|
||||
protected String localArrecadacao; // 017 005 Alfanumerico
|
||||
protected final String numeroDaGuia = " "; // 022 025 Alfanumerico
|
||||
protected String dataMovimento; // 047 010 Alfanumerico
|
||||
protected final String usuarioGlobus = "TOTALBUS ";// 057 015 Alfanumerico
|
||||
protected final String turno = "01";// 072 002 Numerico
|
||||
protected String codigoReceitaDespesa;// 074 010 Numerico CONSTANTE CODIGO_RECEITA_DESPESA_GLOBUS
|
||||
protected String identificadorReceitaDespesa;// 084 001 Alfanumerico
|
||||
protected String valorLancamento;// 085 013 Numerico
|
||||
protected final String numeroContratoTurismo = "0000000000"; // 098 010 Numerico
|
||||
protected final String numeroReciboTurismo = " "; // 108 010 Alfanumerico
|
||||
protected final String formaPagamentoTurismo = " ";// 118 002 Numerico
|
||||
protected String tipoPagamentoTurismo = " ";// 120 002 Numerico
|
||||
protected String descricaoDetalhada = " ";// 122 80 Alfanumerico
|
||||
protected final String documentoVenda = "000000";// 202 6 Numerico
|
||||
protected String tipoDocumentoVenda = " ";// 208 1 Alfanumerico
|
||||
protected final String numerodocumentoCPG = "0000000000";// 209 10 Numerico
|
||||
protected String formaPagamentoId = "0";// 218 Numerico
|
||||
protected String tx_id = " ";
|
||||
protected String numFolioSistema = " ";
|
||||
protected final String finalLinha = "*";// 239 1 Alfanumerico
|
||||
|
||||
protected String numeroEstabelecimento = " ";
|
||||
protected String codigoAutorizacao = " ";
|
||||
protected String cantParcelas = "0000";
|
||||
|
||||
|
||||
protected SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
||||
|
||||
public DespesaReceita() {
|
||||
|
||||
}
|
||||
|
||||
public void preencheLinha(List<String> rows) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(dataLancamento);
|
||||
sb.append(codigoEmpresa);
|
||||
sb.append(codigoFilial);
|
||||
sb.append(localArrecadacao.toUpperCase());
|
||||
sb.append(numeroDaGuia);
|
||||
sb.append(dataMovimento);
|
||||
sb.append(usuarioGlobus);
|
||||
sb.append(turno);
|
||||
sb.append(codigoReceitaDespesa);
|
||||
sb.append(identificadorReceitaDespesa.toUpperCase());
|
||||
sb.append(valorLancamento);
|
||||
sb.append(StringUtils.rightPad("", 10, " "));
|
||||
sb.append(numeroReciboTurismo);
|
||||
sb.append(getFormaPagamentoTurismo());
|
||||
sb.append(getTipoPagamentoTurismo());
|
||||
sb.append(StringUtils.rightPad(StringUtils.isNotEmpty(descricaoDetalhada) ? truncStr(descricaoDetalhada, 100) : "", 100, " "));
|
||||
sb.append(documentoVenda);
|
||||
sb.append(tipoDocumentoVenda);
|
||||
sb.append(StringUtils.rightPad("", 9, "0"));
|
||||
sb.append(formaPagamentoId);
|
||||
sb.append(finalLinha);
|
||||
sb.append(System.getProperty("line.separator"));
|
||||
rows.add(sb.toString());
|
||||
}
|
||||
|
||||
public void preencheLinhaComporte(List<String> rows) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(StringUtils.rightPad(dataLancamento.trim(), 10, " ")); //10
|
||||
sb.append(StringUtils.leftPad(codigoEmpresa.trim(), 3, "0")); //13
|
||||
sb.append(StringUtils.leftPad(codigoFilial.trim(), 3, "0")); //16
|
||||
sb.append(StringUtils.rightPad(truncStr(localArrecadacao.toUpperCase(), 5), 5, " ")); //21
|
||||
sb.append(StringUtils.rightPad(numeroDaGuia.trim(), 25, " ")); //46
|
||||
sb.append(StringUtils.rightPad(dataMovimento.trim(), 10, " ")); //56
|
||||
sb.append(StringUtils.rightPad(usuarioGlobus.trim(), 15, " ")); //71
|
||||
sb.append(StringUtils.leftPad(turno.trim(), 2, "0")); //73
|
||||
sb.append(StringUtils.leftPad(codigoReceitaDespesa.trim(), 10, "0")); //83
|
||||
sb.append(StringUtils.rightPad(identificadorReceitaDespesa.toUpperCase().trim(), 1, " ")); //84
|
||||
sb.append(StringUtils.leftPad(valorLancamento.trim(), 13, "0")); //97
|
||||
sb.append(StringUtils.rightPad(numeroContratoTurismo.trim(), 10, "0")); //107
|
||||
sb.append(StringUtils.rightPad(numeroReciboTurismo.trim(), 10, "0")); //117
|
||||
sb.append(StringUtils.leftPad(getFormaPagamentoId().trim(), 2, "0")); //119
|
||||
sb.append(StringUtils.leftPad(getTipoPagamentoTurismo().trim(), 2, "0")); //121
|
||||
sb.append(StringUtils.rightPad(descricaoDetalhada.trim(), 80, " ")); //201
|
||||
sb.append(StringUtils.rightPad(StringUtils.isNotEmpty(numeroEstabelecimento) ? StringUtils.rightPad(numeroEstabelecimento, 10, "0").substring(0,10) : "", 10, "0"));//211
|
||||
sb.append(codigoAutorizacao != null ? StringUtils.rightPad(codigoAutorizacao, 25, "0") : StringUtils.rightPad("", 25, "0")); //236
|
||||
sb.append(StringUtils.rightPad(formaPagamentoId.trim(), 2, "0")); //238
|
||||
sb.append(StringUtils.leftPad(cantParcelas.trim(), 4, "0")); //242
|
||||
sb.append(StringUtils.leftPad(numFolioSistema.trim(), 16, " ")); //258
|
||||
sb.append(StringUtils.leftPad(tx_id.trim(), 35, " ")); //293
|
||||
sb.append(finalLinha);
|
||||
sb.append(System.getProperty("line.separator"));
|
||||
|
||||
rows.add(sb.toString());
|
||||
}
|
||||
|
||||
public void preencheLinhaLayoutNovo(List<String> rows) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(StringUtils.rightPad(dataLancamento.trim(), 10, " "));
|
||||
sb.append(StringUtils.leftPad(codigoEmpresa.trim(), 3, "0"));
|
||||
sb.append(StringUtils.leftPad(codigoFilial.trim(), 3, "0"));
|
||||
sb.append(StringUtils.rightPad(truncStr(localArrecadacao.toUpperCase(), 5), 5, " "));
|
||||
sb.append(StringUtils.rightPad(numeroDaGuia.trim(), 25, " "));
|
||||
sb.append(StringUtils.rightPad(dataMovimento.trim(), 10, " "));
|
||||
sb.append(StringUtils.rightPad(usuarioGlobus.trim(), 15, " "));
|
||||
sb.append(StringUtils.leftPad(turno.trim(), 2, "0"));
|
||||
sb.append(StringUtils.leftPad(codigoReceitaDespesa.trim(), 10, "0"));
|
||||
sb.append(StringUtils.rightPad(identificadorReceitaDespesa.toUpperCase().trim(), 1, " "));
|
||||
sb.append(StringUtils.leftPad(valorLancamento.trim(), 13, "0"));
|
||||
sb.append(StringUtils.rightPad("", 10, " "));
|
||||
sb.append(StringUtils.rightPad(numeroReciboTurismo.trim(), 10, " "));
|
||||
sb.append(StringUtils.leftPad(getFormaPagamentoId().trim(), 2, "0"));
|
||||
sb.append(StringUtils.leftPad(getTipoPagamentoTurismo().trim(), 2, "0"));
|
||||
sb.append(StringUtils.rightPad(StringUtils.isNotEmpty(descricaoDetalhada) ? truncStr(descricaoDetalhada, 100) : "", 100, " "));
|
||||
sb.append(StringUtils.leftPad(documentoVenda.trim(), 6, "0"));
|
||||
sb.append(StringUtils.rightPad(tipoDocumentoVenda.trim(), 1, " "));
|
||||
sb.append(StringUtils.rightPad("", 10, "0"));
|
||||
sb.append(finalLinha);
|
||||
sb.append(System.getProperty("line.separator"));
|
||||
rows.add(sb.toString());
|
||||
}
|
||||
|
||||
public void setDataLancamento(Date dataLancamento) {
|
||||
this.dataLancamento = sdf.format(dataLancamento);
|
||||
}
|
||||
|
||||
public void setCodigoEmpresa(Integer codigoEmpresa) {
|
||||
this.codigoEmpresa = StringUtils.leftPad(codigoEmpresa.toString(), 3, "0");
|
||||
}
|
||||
|
||||
public void setLocalArrecadacao(Integer localArrecadacao) {
|
||||
this.localArrecadacao = StringUtils.rightPad(localArrecadacao != null ? truncStr(localArrecadacao.toString(), 5) : "", 5, " ");
|
||||
}
|
||||
|
||||
public void setLocalArrecadacao(String localArrecadacao) {
|
||||
this.localArrecadacao = StringUtils.rightPad(localArrecadacao != null ? truncStr(localArrecadacao, 6) : "", 5, "");
|
||||
}
|
||||
|
||||
public void setDataMovimento(Date dataMovimento) {
|
||||
this.dataMovimento = sdf.format(dataMovimento);
|
||||
}
|
||||
|
||||
public void setCodigoReceitaDespesa(String codigoReceitaDespesa) {
|
||||
this.codigoReceitaDespesa = StringUtils.leftPad(codigoReceitaDespesa != null ? codigoReceitaDespesa : "0", 10, "0");
|
||||
}
|
||||
|
||||
public void setIdentificadorReceitaDespesa(String identificadorReceitaDespesa) {
|
||||
this.identificadorReceitaDespesa = identificadorReceitaDespesa.toUpperCase();
|
||||
}
|
||||
|
||||
public void setValorLancamento(String valorLancamento) {
|
||||
this.valorLancamento = StringUtils.leftPad(valorLancamento!=null?truncStr(valorLancamento.replace(",", "").replace(".", ""), 100):"", 13, "0");
|
||||
}
|
||||
|
||||
public void setDescricaoDetalhada(String desc) {
|
||||
this.descricaoDetalhada = StringUtils.rightPad(StringUtils.isNotEmpty(desc) ? truncStr(desc, 100) : "", 100, " ");
|
||||
}
|
||||
|
||||
public String getFormaPagamentoTurismo() {
|
||||
return formaPagamentoTurismo;
|
||||
}
|
||||
|
||||
public String getTipoPagamentoTurismo() {
|
||||
return tipoPagamentoTurismo;
|
||||
}
|
||||
|
||||
public void setTipoPagamentoTurismo(String tipoPagamentoTurismo) {
|
||||
this.tipoPagamentoTurismo = StringUtils.leftPad(StringUtils.isNotEmpty(tipoPagamentoTurismo) ? truncStr(tipoPagamentoTurismo, 2):tipoPagamentoTurismo, 2, " ");
|
||||
}
|
||||
|
||||
public String getFormaPagamentoId() {
|
||||
return formaPagamentoId;
|
||||
}
|
||||
|
||||
public void setFormaPagamentoId(String formaPagamentoId) {
|
||||
this.formaPagamentoId = StringUtils.leftPad(StringUtils.isNotEmpty(formaPagamentoId) ? truncStr(formaPagamentoId.toString(), 2) : "", 1, "0");
|
||||
}
|
||||
|
||||
protected String truncStr(String str, int size) {
|
||||
if (str.length() > size) {
|
||||
return str.substring(0, size - 1);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public String getTipoDocumentoVenda() {
|
||||
return tipoDocumentoVenda;
|
||||
}
|
||||
|
||||
public void setTipoDocumentoVenda(String tipoDocumentoVenda) {
|
||||
this.tipoDocumentoVenda = tipoDocumentoVenda;
|
||||
}
|
||||
|
||||
public String getNumeroEstabelecimento() {
|
||||
return numeroEstabelecimento;
|
||||
}
|
||||
|
||||
public void setNumeroEstabelecimento(String numeroEstabelecimento) {
|
||||
this.numeroEstabelecimento = StringUtils.rightPad(numeroEstabelecimento != null ? numeroEstabelecimento : " ", 10, " ");
|
||||
}
|
||||
|
||||
public String getCodigoAutorizacao() {
|
||||
return codigoAutorizacao;
|
||||
}
|
||||
|
||||
public void setCodigoAutorizacao(String codigoAutorizacao) {
|
||||
this.codigoAutorizacao = StringUtils.rightPad(codigoAutorizacao != null ? truncStr(codigoAutorizacao, 22) : " ", 22, "0");
|
||||
}
|
||||
|
||||
public String getCantParcelas() {
|
||||
return cantParcelas;
|
||||
}
|
||||
|
||||
public void setCantParcelas(String cantParcelas) {
|
||||
this.cantParcelas = StringUtils.isNotEmpty(cantParcelas) ? StringUtils.leftPad(cantParcelas, 4,"0") : " ";
|
||||
}
|
||||
|
||||
}
|
||||
package com.rjconsultores.integracaoreceitadespesa.entidades;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class DespesaReceita {
|
||||
protected String dataLancamento; // DD/MM/YYYY
|
||||
protected String codigoEmpresa; // 011 003 Numerico
|
||||
protected final String codigoFilial = "001"; // 014 003 Numerico
|
||||
protected String localArrecadacao; // 017 005 Alfanumerico
|
||||
protected final String numeroDaGuia = " "; // 022 025 Alfanumerico
|
||||
protected String dataMovimento; // 047 010 Alfanumerico
|
||||
protected final String usuarioGlobus = "TOTALBUS ";// 057 015 Alfanumerico
|
||||
protected final String turno = "01";// 072 002 Numerico
|
||||
protected String codigoReceitaDespesa;// 074 010 Numerico CONSTANTE CODIGO_RECEITA_DESPESA_GLOBUS
|
||||
protected String identificadorReceitaDespesa;// 084 001 Alfanumerico
|
||||
protected String valorLancamento;// 085 013 Numerico
|
||||
protected final String numeroContratoTurismo = "0000000000"; // 098 010 Numerico
|
||||
protected final String numeroReciboTurismo = " "; // 108 010 Alfanumerico
|
||||
protected final String formaPagamentoTurismo = " ";// 118 002 Numerico
|
||||
protected String tipoPagamentoTurismo = " ";// 120 002 Numerico
|
||||
protected String descricaoDetalhada = " ";// 122 80 Alfanumerico
|
||||
protected final String documentoVenda = "000000";// 202 6 Numerico
|
||||
protected String tipoDocumentoVenda = " ";// 208 1 Alfanumerico
|
||||
protected final String numerodocumentoCPG = "0000000000";// 209 10 Numerico
|
||||
protected String formaPagamentoId = "0";// 218 Numerico
|
||||
protected String tx_id = " ";
|
||||
protected String numFolioSistema = " ";
|
||||
protected final String finalLinha = "*";// 239 1 Alfanumerico
|
||||
|
||||
protected String numeroEstabelecimento = " ";
|
||||
protected String codigoAutorizacao = " ";
|
||||
protected String cantParcelas = "0000";
|
||||
|
||||
|
||||
protected SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
|
||||
|
||||
public DespesaReceita() {
|
||||
|
||||
}
|
||||
|
||||
public void preencheLinha(List<String> rows) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(dataLancamento);
|
||||
sb.append(codigoEmpresa);
|
||||
sb.append(codigoFilial);
|
||||
sb.append(localArrecadacao.toUpperCase());
|
||||
sb.append(numeroDaGuia);
|
||||
sb.append(dataMovimento);
|
||||
sb.append(usuarioGlobus);
|
||||
sb.append(turno);
|
||||
sb.append(codigoReceitaDespesa);
|
||||
sb.append(identificadorReceitaDespesa.toUpperCase());
|
||||
sb.append(valorLancamento);
|
||||
sb.append(StringUtils.rightPad("", 10, " "));
|
||||
sb.append(numeroReciboTurismo);
|
||||
sb.append(getFormaPagamentoTurismo());
|
||||
sb.append(getTipoPagamentoTurismo());
|
||||
sb.append(StringUtils.rightPad(StringUtils.isNotEmpty(descricaoDetalhada) ? truncStr(descricaoDetalhada, 100) : "", 100, " "));
|
||||
sb.append(documentoVenda);
|
||||
sb.append(tipoDocumentoVenda);
|
||||
sb.append(StringUtils.rightPad("", 9, "0"));
|
||||
sb.append(formaPagamentoId);
|
||||
sb.append(finalLinha);
|
||||
sb.append(System.getProperty("line.separator"));
|
||||
rows.add(sb.toString());
|
||||
}
|
||||
|
||||
public void preencheLinhaComporte(List<String> rows) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(StringUtils.rightPad(dataLancamento.trim(), 10, " ")); //10
|
||||
sb.append(StringUtils.leftPad(codigoEmpresa.trim(), 3, "0")); //13
|
||||
sb.append(StringUtils.leftPad(codigoFilial.trim(), 3, "0")); //16
|
||||
sb.append(StringUtils.rightPad(truncStr(localArrecadacao.toUpperCase(), 5), 5, " ")); //21
|
||||
sb.append(StringUtils.rightPad(numeroDaGuia.trim(), 25, " ")); //46
|
||||
sb.append(StringUtils.rightPad(dataMovimento.trim(), 10, " ")); //56
|
||||
sb.append(StringUtils.rightPad(usuarioGlobus.trim(), 15, " ")); //71
|
||||
sb.append(StringUtils.leftPad(turno.trim(), 2, "0")); //73
|
||||
sb.append(StringUtils.leftPad(codigoReceitaDespesa.trim(), 10, "0")); //83
|
||||
sb.append(StringUtils.rightPad(identificadorReceitaDespesa.toUpperCase().trim(), 1, " ")); //84
|
||||
sb.append(StringUtils.leftPad(valorLancamento.trim(), 13, "0")); //97
|
||||
sb.append(StringUtils.rightPad(numeroContratoTurismo.trim(), 10, "0")); //107
|
||||
sb.append(StringUtils.rightPad(numeroReciboTurismo.trim(), 10, "0")); //117
|
||||
sb.append(StringUtils.leftPad(getFormaPagamentoId().trim(), 2, "0")); //119
|
||||
sb.append(StringUtils.leftPad(getTipoPagamentoTurismo().trim(), 2, "0")); //121
|
||||
sb.append(StringUtils.rightPad(descricaoDetalhada.trim(), 80, " ")); //201
|
||||
sb.append(StringUtils.rightPad(StringUtils.isNotEmpty(numeroEstabelecimento) ? StringUtils.rightPad(numeroEstabelecimento, 10, "0").substring(0,10) : "", 10, "0"));//211
|
||||
sb.append(codigoAutorizacao != null ? StringUtils.rightPad(codigoAutorizacao, 25, "0") : StringUtils.rightPad("", 25, "0")); //236
|
||||
sb.append(StringUtils.rightPad(formaPagamentoId.trim(), 2, "0")); //238
|
||||
sb.append(StringUtils.leftPad(cantParcelas.trim(), 4, "0")); //242
|
||||
sb.append(StringUtils.leftPad(numFolioSistema.trim(), 16, " ")); //258
|
||||
sb.append(StringUtils.leftPad(tx_id.trim(), 35, " ")); //293
|
||||
sb.append(finalLinha);
|
||||
sb.append(System.getProperty("line.separator"));
|
||||
|
||||
rows.add(sb.toString());
|
||||
}
|
||||
|
||||
public void preencheLinhaLayoutNovo(List<String> rows) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(StringUtils.rightPad(dataLancamento.trim(), 10, " "));
|
||||
sb.append(StringUtils.leftPad(codigoEmpresa.trim(), 3, "0"));
|
||||
sb.append(StringUtils.leftPad(codigoFilial.trim(), 3, "0"));
|
||||
sb.append(StringUtils.rightPad(truncStr(localArrecadacao.toUpperCase(), 5), 5, " "));
|
||||
sb.append(StringUtils.rightPad(numeroDaGuia.trim(), 25, " "));
|
||||
sb.append(StringUtils.rightPad(dataMovimento.trim(), 10, " "));
|
||||
sb.append(StringUtils.rightPad(usuarioGlobus.trim(), 15, " "));
|
||||
sb.append(StringUtils.leftPad(turno.trim(), 2, "0"));
|
||||
sb.append(StringUtils.leftPad(codigoReceitaDespesa.trim(), 10, "0"));
|
||||
sb.append(StringUtils.rightPad(identificadorReceitaDespesa.toUpperCase().trim(), 1, " "));
|
||||
sb.append(StringUtils.leftPad(valorLancamento.trim(), 13, "0"));
|
||||
sb.append(StringUtils.rightPad("", 10, " "));
|
||||
sb.append(StringUtils.rightPad(numeroReciboTurismo.trim(), 10, " "));
|
||||
sb.append(StringUtils.leftPad(getFormaPagamentoId().trim(), 2, "0"));
|
||||
sb.append(StringUtils.leftPad(getTipoPagamentoTurismo().trim(), 2, "0"));
|
||||
sb.append(StringUtils.rightPad(StringUtils.isNotEmpty(descricaoDetalhada) ? truncStr(descricaoDetalhada, 100) : "", 100, " "));
|
||||
sb.append(StringUtils.leftPad(documentoVenda.trim(), 6, "0"));
|
||||
sb.append(StringUtils.rightPad(tipoDocumentoVenda.trim(), 1, " "));
|
||||
sb.append(StringUtils.rightPad("", 10, "0"));
|
||||
sb.append(finalLinha);
|
||||
sb.append(System.getProperty("line.separator"));
|
||||
rows.add(sb.toString());
|
||||
}
|
||||
|
||||
public void setDataLancamento(Date dataLancamento) {
|
||||
this.dataLancamento = sdf.format(dataLancamento);
|
||||
}
|
||||
|
||||
public void setCodigoEmpresa(Integer codigoEmpresa) {
|
||||
this.codigoEmpresa = StringUtils.leftPad(codigoEmpresa.toString(), 3, "0");
|
||||
}
|
||||
|
||||
public void setLocalArrecadacao(Integer localArrecadacao) {
|
||||
this.localArrecadacao = StringUtils.rightPad(localArrecadacao != null ? truncStr(localArrecadacao.toString(), 5) : "", 5, " ");
|
||||
}
|
||||
|
||||
public void setLocalArrecadacao(String localArrecadacao) {
|
||||
this.localArrecadacao = StringUtils.rightPad(localArrecadacao != null ? truncStr(localArrecadacao, 6) : "", 5, "");
|
||||
}
|
||||
|
||||
public void setDataMovimento(Date dataMovimento) {
|
||||
this.dataMovimento = sdf.format(dataMovimento);
|
||||
}
|
||||
|
||||
public void setCodigoReceitaDespesa(String codigoReceitaDespesa) {
|
||||
this.codigoReceitaDespesa = StringUtils.leftPad(codigoReceitaDespesa != null ? codigoReceitaDespesa : "0", 10, "0");
|
||||
}
|
||||
|
||||
public void setIdentificadorReceitaDespesa(String identificadorReceitaDespesa) {
|
||||
this.identificadorReceitaDespesa = identificadorReceitaDespesa.toUpperCase();
|
||||
}
|
||||
|
||||
public void setValorLancamento(String valorLancamento) {
|
||||
this.valorLancamento = StringUtils.leftPad(valorLancamento!=null?truncStr(valorLancamento.replace(",", "").replace(".", ""), 100):"", 13, "0");
|
||||
}
|
||||
|
||||
public void setDescricaoDetalhada(String desc) {
|
||||
this.descricaoDetalhada = StringUtils.rightPad(StringUtils.isNotEmpty(desc) ? truncStr(desc, 100) : "", 100, " ");
|
||||
}
|
||||
|
||||
public String getFormaPagamentoTurismo() {
|
||||
return formaPagamentoTurismo;
|
||||
}
|
||||
|
||||
public String getTipoPagamentoTurismo() {
|
||||
return tipoPagamentoTurismo;
|
||||
}
|
||||
|
||||
public void setTipoPagamentoTurismo(String tipoPagamentoTurismo) {
|
||||
this.tipoPagamentoTurismo = StringUtils.leftPad(StringUtils.isNotEmpty(tipoPagamentoTurismo) ? truncStr(tipoPagamentoTurismo, 2):tipoPagamentoTurismo, 2, " ");
|
||||
}
|
||||
|
||||
public String getFormaPagamentoId() {
|
||||
return formaPagamentoId;
|
||||
}
|
||||
|
||||
public void setFormaPagamentoId(String formaPagamentoId) {
|
||||
this.formaPagamentoId = StringUtils.leftPad(StringUtils.isNotEmpty(formaPagamentoId) ? truncStr(formaPagamentoId.toString(), 2) : "", 1, "0");
|
||||
}
|
||||
|
||||
protected String truncStr(String str, int size) {
|
||||
if (str.length() > size) {
|
||||
return str.substring(0, size - 1);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public String getTipoDocumentoVenda() {
|
||||
return tipoDocumentoVenda;
|
||||
}
|
||||
|
||||
public void setTipoDocumentoVenda(String tipoDocumentoVenda) {
|
||||
this.tipoDocumentoVenda = tipoDocumentoVenda;
|
||||
}
|
||||
|
||||
public String getNumeroEstabelecimento() {
|
||||
return numeroEstabelecimento;
|
||||
}
|
||||
|
||||
public void setNumeroEstabelecimento(String numeroEstabelecimento) {
|
||||
this.numeroEstabelecimento = StringUtils.rightPad(numeroEstabelecimento != null ? numeroEstabelecimento : " ", 10, " ");
|
||||
}
|
||||
|
||||
public String getCodigoAutorizacao() {
|
||||
return codigoAutorizacao;
|
||||
}
|
||||
|
||||
public void setCodigoAutorizacao(String codigoAutorizacao) {
|
||||
this.codigoAutorizacao = StringUtils.rightPad(codigoAutorizacao != null ? truncStr(codigoAutorizacao, 22) : " ", 22, "0");
|
||||
}
|
||||
|
||||
public String getCantParcelas() {
|
||||
return cantParcelas;
|
||||
}
|
||||
|
||||
public void setCantParcelas(String cantParcelas) {
|
||||
this.cantParcelas = StringUtils.isNotEmpty(cantParcelas) ? StringUtils.leftPad(cantParcelas, 4,"0") : " ";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,87 +1,87 @@
|
|||
package com.rjconsultores.integracaoreceitadespesa.entidades;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class DespesaReceitaComporte extends DespesaReceita {
|
||||
|
||||
protected String numeroEstabelecimento;
|
||||
protected String codigoAutorizacao;
|
||||
protected String cantParcelas = "";
|
||||
protected String numfoliosistema = "";
|
||||
protected String txId = "";
|
||||
|
||||
@Override
|
||||
public void preencheLinha(List<String> rows) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(StringUtils.rightPad(dataLancamento.trim(), 10, " ")); //10
|
||||
sb.append(StringUtils.leftPad(codigoEmpresa.trim(), 3, "0")); //13
|
||||
sb.append(StringUtils.leftPad(codigoFilial.trim(), 3, "0")); //16
|
||||
sb.append(StringUtils.rightPad(truncStr(localArrecadacao.toUpperCase(), 5), 5, " ")); //21
|
||||
sb.append(StringUtils.rightPad(numeroDaGuia.trim(), 25, " ")); //46
|
||||
sb.append(StringUtils.rightPad(dataMovimento.trim(), 10, " ")); //56
|
||||
sb.append(StringUtils.rightPad(usuarioGlobus.trim(), 15, " ")); //71
|
||||
sb.append(StringUtils.leftPad(turno.trim(), 2, "0")); //73
|
||||
sb.append(StringUtils.leftPad(codigoReceitaDespesa.trim(), 10, "0")); //83
|
||||
sb.append(StringUtils.rightPad(identificadorReceitaDespesa.toUpperCase().trim(), 1, "0")); //84
|
||||
sb.append(StringUtils.leftPad(valorLancamento.trim(), 13, "0")); //97
|
||||
sb.append(StringUtils.leftPad(numeroContratoTurismo.trim(), 10, "0"));//107
|
||||
sb.append(StringUtils.leftPad(numeroReciboTurismo.trim(), 10, "0"));//117
|
||||
sb.append(StringUtils.leftPad(getFormaPagamentoTurismo().trim(),2,"0"));//119
|
||||
sb.append(StringUtils.leftPad(getTipoPagamentoTurismo().trim(), 2, "0"));//121
|
||||
sb.append(StringUtils.rightPad(StringUtils.isNotEmpty(descricaoDetalhada) ? truncStr(descricaoDetalhada, 80) : "", 80, " ")); //201
|
||||
sb.append(StringUtils.rightPad(StringUtils.isNotEmpty(numeroEstabelecimento) ? StringUtils.rightPad(numeroEstabelecimento, 10, "0").substring(0,10) : "", 10, "0")); //211
|
||||
sb.append(StringUtils.rightPad(StringUtils.isNotEmpty(codigoAutorizacao) ? StringUtils.rightPad(codigoAutorizacao, 22, " ").substring(0,22) : "", 22, " "));//237
|
||||
sb.append(StringUtils.leftPad("0", 2, "0"));//239
|
||||
sb.append(StringUtils.leftPad(" ", 1, " "));//239
|
||||
sb.append(StringUtils.leftPad(formaPagamentoId, 2, "0"));//239
|
||||
sb.append(StringUtils.isNotEmpty(cantParcelas) ? StringUtils.leftPad(cantParcelas, 4,"0") : "0000");//243
|
||||
sb.append(StringUtils.leftPad(numfoliosistema,16, " "));//259
|
||||
sb.append(StringUtils.leftPad(txId,35, " "));//294
|
||||
sb.append(finalLinha);
|
||||
sb.append(System.getProperty("line.separator"));
|
||||
rows.add(sb.toString());
|
||||
}
|
||||
|
||||
public String getNumeroEstabelecimento() {
|
||||
return numeroEstabelecimento;
|
||||
}
|
||||
|
||||
public void setNumeroEstabelecimento(String numeroEstabelecimento) {
|
||||
this.numeroEstabelecimento = StringUtils.rightPad(numeroEstabelecimento != null ? numeroEstabelecimento : " ", 10, " ");
|
||||
}
|
||||
|
||||
public String getCodigoAutorizacao() {
|
||||
return codigoAutorizacao;
|
||||
}
|
||||
|
||||
public void setCodigoAutorizacao(String codigoAutorizacao) {
|
||||
this.codigoAutorizacao = codigoAutorizacao;
|
||||
}
|
||||
|
||||
public String getCantParcelas() {
|
||||
return cantParcelas;
|
||||
}
|
||||
|
||||
public void setCantParcelas(String cantParcelas) {
|
||||
this.cantParcelas = StringUtils.isNotEmpty(cantParcelas) ? StringUtils.leftPad(cantParcelas, 4,"0") : "0000";
|
||||
}
|
||||
|
||||
public String getNumfoliosistema() {
|
||||
return numfoliosistema;
|
||||
}
|
||||
|
||||
public void setNumfoliosistema(String numfoliosistema) {
|
||||
this.numfoliosistema = StringUtils.leftPad(numfoliosistema != null ? numfoliosistema :StringUtils.leftPad(" ", 16) , 16, " ");
|
||||
}
|
||||
|
||||
public String getTxId() {
|
||||
return txId;
|
||||
}
|
||||
|
||||
public void setTxId(String txId) {
|
||||
this.txId = StringUtils.leftPad(txId != null ? truncStr(txId, 36) : StringUtils.leftPad(" ", 35), 35, " ");
|
||||
}
|
||||
|
||||
}
|
||||
package com.rjconsultores.integracaoreceitadespesa.entidades;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
public class DespesaReceitaComporte extends DespesaReceita {
|
||||
|
||||
protected String numeroEstabelecimento;
|
||||
protected String codigoAutorizacao;
|
||||
protected String cantParcelas = "";
|
||||
protected String numfoliosistema = "";
|
||||
protected String txId = "";
|
||||
|
||||
@Override
|
||||
public void preencheLinha(List<String> rows) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(StringUtils.rightPad(dataLancamento.trim(), 10, " ")); //10
|
||||
sb.append(StringUtils.leftPad(codigoEmpresa.trim(), 3, "0")); //13
|
||||
sb.append(StringUtils.leftPad(codigoFilial.trim(), 3, "0")); //16
|
||||
sb.append(StringUtils.rightPad(truncStr(localArrecadacao.toUpperCase(), 5), 5, " ")); //21
|
||||
sb.append(StringUtils.rightPad(numeroDaGuia.trim(), 25, " ")); //46
|
||||
sb.append(StringUtils.rightPad(dataMovimento.trim(), 10, " ")); //56
|
||||
sb.append(StringUtils.rightPad(usuarioGlobus.trim(), 15, " ")); //71
|
||||
sb.append(StringUtils.leftPad(turno.trim(), 2, "0")); //73
|
||||
sb.append(StringUtils.leftPad(codigoReceitaDespesa.trim(), 10, "0")); //83
|
||||
sb.append(StringUtils.rightPad(identificadorReceitaDespesa.toUpperCase().trim(), 1, "0")); //84
|
||||
sb.append(StringUtils.leftPad(valorLancamento.trim(), 13, "0")); //97
|
||||
sb.append(StringUtils.leftPad(numeroContratoTurismo.trim(), 10, "0"));//107
|
||||
sb.append(StringUtils.leftPad(numeroReciboTurismo.trim(), 10, "0"));//117
|
||||
sb.append(StringUtils.leftPad(getFormaPagamentoTurismo().trim(),2,"0"));//119
|
||||
sb.append(StringUtils.leftPad(getTipoPagamentoTurismo().trim(), 2, "0"));//121
|
||||
sb.append(StringUtils.rightPad(StringUtils.isNotEmpty(descricaoDetalhada) ? truncStr(descricaoDetalhada, 80) : "", 80, " ")); //201
|
||||
sb.append(StringUtils.rightPad(StringUtils.isNotEmpty(numeroEstabelecimento) ? StringUtils.rightPad(numeroEstabelecimento, 10, "0").substring(0,10) : "", 10, "0")); //211
|
||||
sb.append(StringUtils.rightPad(StringUtils.isNotEmpty(codigoAutorizacao) ? StringUtils.rightPad(codigoAutorizacao, 22, " ").substring(0,22) : "", 22, " "));//237
|
||||
sb.append(StringUtils.leftPad("0", 2, "0"));//239
|
||||
sb.append(StringUtils.leftPad(" ", 1, " "));//239
|
||||
sb.append(StringUtils.leftPad(formaPagamentoId, 2, "0"));//239
|
||||
sb.append(StringUtils.isNotEmpty(cantParcelas) ? StringUtils.leftPad(cantParcelas, 4,"0") : "0000");//243
|
||||
sb.append(StringUtils.leftPad(numfoliosistema,16, " "));//259
|
||||
sb.append(StringUtils.leftPad(txId,35, " "));//294
|
||||
sb.append(finalLinha);
|
||||
sb.append(System.getProperty("line.separator"));
|
||||
rows.add(sb.toString());
|
||||
}
|
||||
|
||||
public String getNumeroEstabelecimento() {
|
||||
return numeroEstabelecimento;
|
||||
}
|
||||
|
||||
public void setNumeroEstabelecimento(String numeroEstabelecimento) {
|
||||
this.numeroEstabelecimento = StringUtils.rightPad(numeroEstabelecimento != null ? numeroEstabelecimento : " ", 10, " ");
|
||||
}
|
||||
|
||||
public String getCodigoAutorizacao() {
|
||||
return codigoAutorizacao;
|
||||
}
|
||||
|
||||
public void setCodigoAutorizacao(String codigoAutorizacao) {
|
||||
this.codigoAutorizacao = codigoAutorizacao;
|
||||
}
|
||||
|
||||
public String getCantParcelas() {
|
||||
return cantParcelas;
|
||||
}
|
||||
|
||||
public void setCantParcelas(String cantParcelas) {
|
||||
this.cantParcelas = StringUtils.isNotEmpty(cantParcelas) ? StringUtils.leftPad(cantParcelas, 4,"0") : "0000";
|
||||
}
|
||||
|
||||
public String getNumfoliosistema() {
|
||||
return numfoliosistema;
|
||||
}
|
||||
|
||||
public void setNumfoliosistema(String numfoliosistema) {
|
||||
this.numfoliosistema = StringUtils.leftPad(numfoliosistema != null ? numfoliosistema :StringUtils.leftPad(" ", 16) , 16, " ");
|
||||
}
|
||||
|
||||
public String getTxId() {
|
||||
return txId;
|
||||
}
|
||||
|
||||
public void setTxId(String txId) {
|
||||
this.txId = StringUtils.leftPad(txId != null ? truncStr(txId, 36) : StringUtils.leftPad(" ", 35), 35, " ");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
package com.rjconsultores.integracaoreceitadespesa.entidades;
|
||||
|
||||
public class Empresa {
|
||||
public Integer codigo;
|
||||
public String nombempresa;
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return nombempresa;
|
||||
}
|
||||
}
|
||||
package com.rjconsultores.integracaoreceitadespesa.entidades;
|
||||
|
||||
public class Empresa {
|
||||
public Integer codigo;
|
||||
public String nombempresa;
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return nombempresa;
|
||||
}
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
package com.rjconsultores.integracaoreceitadespesa.entidades;
|
||||
|
||||
public class PuntoVenta {
|
||||
public Integer codigo;
|
||||
public String nombpuntoventa;
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return nombpuntoventa;
|
||||
}
|
||||
}
|
||||
package com.rjconsultores.integracaoreceitadespesa.entidades;
|
||||
|
||||
public class PuntoVenta {
|
||||
public Integer codigo;
|
||||
public String nombpuntoventa;
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return nombpuntoventa;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue