ADM perde conexão (fixed bug #5145)

git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@34579 d1611594-4594-4d17-8e1d-87c2c4800839
master
julio 2014-04-04 19:18:43 +00:00
parent b211f940d4
commit 05a8a7b40f
7 changed files with 85 additions and 67 deletions

View File

@ -326,9 +326,9 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio {
row.put("IMPOSTOS", ((BigDecimal) row.get("IMPOSTOS")).add(getValorImposto(idEstado, empresaId, this.resultSet.getString("INTERESTADUAL"), this.resultSet.getBigDecimal("PRECIOPAGADO"), this.resultSet.getBigDecimal("IMPORTESEGURO"), this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE"), this.resultSet.getBigDecimal("IMPORTEPEDAGIO"), BigDecimal.ZERO)));
}
//Deduz imposto
if(( tipoVentaId != 18 && motivoCancelacionId != 0 ) || (tipoVentaId == 18 && this.resultSet.getInt("INDREIMPRESION") == 1 && this.resultSet.getInt("POSSUI_CANC") == 1 )){
row.put("IMPOSTOS", ((BigDecimal) row.get("IMPOSTOS")).subtract( getValorImposto(idEstado, empresaId, this.resultSet.getString("INTERESTADUAL"), this.resultSet.getBigDecimal("PRECIOPAGADO"), this.resultSet.getBigDecimal("IMPORTESEGURO"), this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE"), this.resultSet.getBigDecimal("IMPORTEPEDAGIO"), BigDecimal.ZERO)));
// Deduz imposto
if ((tipoVentaId != 18 && motivoCancelacionId != 0) || (tipoVentaId == 18 && this.resultSet.getInt("INDREIMPRESION") == 1 && this.resultSet.getInt("POSSUI_CANC") == 1)) {
row.put("IMPOSTOS", ((BigDecimal) row.get("IMPOSTOS")).subtract(getValorImposto(idEstado, empresaId, this.resultSet.getString("INTERESTADUAL"), this.resultSet.getBigDecimal("PRECIOPAGADO"), this.resultSet.getBigDecimal("IMPORTESEGURO"), this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE"), this.resultSet.getBigDecimal("IMPORTEPEDAGIO"), BigDecimal.ZERO)));
}
@ -498,8 +498,7 @@ public class RelatorioReceitaDiariaAgencia extends Relatorio {
Boolean indBaseEmbarque = (tipoBaseCalculo == 1 || tipoBaseCalculo == 4 ? true : false);
Boolean indBasePedagio = (tipoBaseCalculo == 1 || tipoBaseCalculo == 5 ? true : false);
Boolean indBaseBagagem = (tipoBaseCalculo == 1 || tipoBaseCalculo == 6 ? true : false);
System.out.println("Valores:");
System.out.println(tarifa+" - "+ seguro+" - "+ embarque+" - "+ pedagio+" - "+ bagagem);
return CalculoImposto.getValorImpostoRelatorioReceitaDiaria(this.getConexao(), estadoId, empresaId, indInterestadual, tarifa, seguro, embarque, pedagio, bagagem, indBaseTarifa, indBaseSeguro, indBaseEmbarque, indBasePedagio, indBaseBagagem);
} catch (Exception e) {
if (e instanceof ExceptionConfiguracao)

View File

@ -5,13 +5,14 @@ package com.rjconsultores.ventaboletos.relatorios.impl;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import com.rjconsultores.ventaboletos.relatorios.negocio.CalculoImposto;
import com.rjconsultores.ventaboletos.relatorios.utilitarios.DataSource;
import com.rjconsultores.ventaboletos.relatorios.utilitarios.ArrayDataSource;
import com.rjconsultores.ventaboletos.relatorios.utilitarios.ExceptionConfiguracao;
import com.rjconsultores.ventaboletos.relatorios.utilitarios.Relatorio;
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
@ -32,7 +33,7 @@ public class RelatorioTaxasLinha extends Relatorio {
super(parametros, conexao);
CalculoImposto.limpaCache();
this.setCustomDataSource(new DataSource(this) {
this.setCustomDataSource(new ArrayDataSource(this) {
public void initDados() throws Exception {
Connection conexao = this.relatorio.getConexao();
@ -62,7 +63,35 @@ public class RelatorioTaxasLinha extends Relatorio {
else
stmt.setNull("DESTINO_ID", java.sql.Types.INTEGER);
this.resultSet = stmt.executeQuery();
ResultSet rset = stmt.executeQuery();
while (rset.next()) {
Map<String, Object> dataResult = new HashMap<String, Object>();
dataResult.put("PREFIXO", rset.getString("PREFIXO"));
dataResult.put("CIDADE_ORIGEM", rset.getString("CIDADE_ORIGEM"));
dataResult.put("CIDADE_DESTINO", rset.getString("CIDADE_DESTINO"));
dataResult.put("IMPORTETAXAEMBARQUE", rset.getBigDecimal("IMPORTETAXAEMBARQUE"));
dataResult.put("IMPORTEPEDAGIO", rset.getBigDecimal("IMPORTEPEDAGIO"));
dataResult.put("IMPORTESEGURO", rset.getBigDecimal("IMPORTESEGURO"));
dataResult.put("NOMBEMPRESA", rset.getString("NOMBEMPRESA"));
dataResult.put("NOMBPUNTOVENTA", rset.getString("NOMBPUNTOVENTA"));
dataResult.put("EMBARQUE_VENDIDOS", rset.getBigDecimal("EMBARQUE_VENDIDOS"));
dataResult.put("PEDAGIO_VENDIDOS", rset.getBigDecimal("PEDAGIO_VENDIDOS"));
dataResult.put("SEGURO_VENDIDOS", rset.getBigDecimal("SEGURO_VENDIDOS"));
dataResult.put("ORIGEM_ESTADO_ID", rset.getInt("ORIGEM_ESTADO_ID"));
dataResult.put("DESTINO_ESTADO_ID", rset.getInt("DESTINO_ESTADO_ID"));
dataResult.put("INTERESTADUAL", rset.getString("INTERESTADUAL"));
dataResult.put("TOTAL_EMBARQUE", rset.getBigDecimal("TOTAL_EMBARQUE"));
dataResult.put("TOTAL_PEDAGIO", rset.getBigDecimal("TOTAL_PEDAGIO"));
dataResult.put("TOTAL_SEGURO", rset.getBigDecimal("TOTAL_SEGURO"));
this.dados.add(dataResult);
}
this.resultSet = rset;
}
public Object valueCustomFields(String fieldName) throws Exception {
@ -73,7 +102,6 @@ public class RelatorioTaxasLinha extends Relatorio {
String indInterestadual = this.resultSet.getString("INTERESTADUAL");
Integer idEstado = this.resultSet.getInt("ORIGEM_ESTADO_ID");
try {
if (fieldName.equals("IMPORTETAXAEMBARQUE") && this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE") != null && !this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE").equals(BigDecimal.ZERO)) {
valorIcms = CalculoImposto.getValorImposto(this.relatorio.getConexao(), idEstado, this.resultSet.getInt("EMPRESA_ID"), indInterestadual, BigDecimal.ZERO, BigDecimal.ZERO, this.resultSet.getBigDecimal("IMPORTETAXAEMBARQUE"), BigDecimal.ZERO);
@ -208,7 +236,7 @@ public class RelatorioTaxasLinha extends Relatorio {
sql.append(" EM.EMPRESA_ID, ");
sql.append(" CJ.PUNTOVENTA_ID, ");
sql.append(" PV.NOMBPUNTOVENTA ");
sql.append(" ORDER BY EM.NOMBEMPRESA, PO.DESCPARADA ");
sql.append(" ORDER BY EM.NOMBEMPRESA, PO.DESCPARADA, PD.DESCPARADA, PV.NOMBPUNTOVENTA ");
return sql.toString();
}

View File

@ -8,6 +8,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;
@ -18,10 +19,11 @@ import net.sf.jasperreports.engine.JRField;
*/
public class ArrayDataSource implements IDataSource {
private static Logger log = Logger.getLogger(ArrayDataSource.class);
protected Relatorio relatorio;
protected ResultSet resultSet;
private Integer rowNum;
protected List<Map<String, Object>> dados;
public ArrayDataSource(Relatorio relatorio) throws Exception {
@ -40,14 +42,20 @@ public class ArrayDataSource implements IDataSource {
return (valueCustomField != null) ? valueCustomField : getByName(field.getName());
} catch (Exception e) {
e.printStackTrace();
log.error("", e);
throw new JRException(e);
}
}
protected Object getByName(String name){
protected Object getByName(String name) {
try {
return this.dados.get(this.rowNum).get(name);
} catch (Exception e) {
log.error("", e);
}
return null;
}
/*
@ -58,10 +66,14 @@ public class ArrayDataSource implements IDataSource {
@Override
public boolean next() {
try {
this.rowNum++;
if ( this.dados != null && this.rowNum < this.dados.size()) {
if (this.dados != null && this.rowNum < this.dados.size()) {
return true;
}
} catch (Exception e) {
log.error("", e);
}
return false;
@ -77,7 +89,6 @@ public class ArrayDataSource implements IDataSource {
*
* @see com.rjconsultores.ventaboletos.relatorios.utilitarios.IDataSource#valueCustomFields(java.lang.String)
*/
@Override
public Object valueCustomFields(String fieldName) throws Exception {
// TODO Auto-generated method stub
return null;

View File

@ -9,12 +9,16 @@ import java.sql.SQLException;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;
import org.apache.log4j.Logger;
/**
* @author Bruno H. G. Gouvêa <bruno@rjconsultores.com.br>
*
*/
public class DataSource implements IDataSource {
private static Logger log = Logger.getLogger(DataSource.class);
protected Relatorio relatorio;
protected ResultSet resultSet;
protected Integer rowNum;
@ -28,11 +32,9 @@ public class DataSource implements IDataSource {
@Override
public Object getFieldValue(JRField field) throws JRException {
try {
Object valueCustomField = this.valueCustomFields(field.getName());
return (valueCustomField != null) ? valueCustomField : this.resultSet.getObject(field.getName());
return this.resultSet.getObject(field.getName());
} catch (Exception e) {
e.printStackTrace();
log.error("", e);
throw new JRException(e);
}
@ -49,6 +51,7 @@ public class DataSource implements IDataSource {
this.rowNum++;
return this.resultSet != null && this.resultSet.next();
} catch (SQLException e) {
log.error("", e);
return false;
}
}
@ -58,13 +61,4 @@ public class DataSource implements IDataSource {
}
/*
* (non-Javadoc)
*
* @see com.rjconsultores.ventaboletos.relatorios.utilitarios.IDataSource#valueCustomFields(java.lang.String)
*/
@Override
public Object valueCustomFields(String fieldName) throws Exception {
return null;
}
}

View File

@ -1,6 +1,5 @@
package com.rjconsultores.ventaboletos.relatorios.utilitarios;
import net.sf.jasperreports.engine.JRDataSource;
/**
@ -13,5 +12,4 @@ public interface IDataSource extends JRDataSource {
public void initDados() throws Exception;
public Object valueCustomFields(String fieldName) throws Exception;
}

View File

@ -1,32 +1,26 @@
package com.rjconsultores.ventaboletos.relatorios.utilitarios;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import org.apache.log4j.Logger;
import com.rjconsultores.ventaboletos.relatorios.render.RenderRelatorioJasper;
/**
*
* Enum complexo contendo as configurações dos relatórios disponíveis no sistema.
*
* @author Bruno H. G. Gouvêa <bruno@rjconsultores.com.br>
*
*/
/**
* @author Bruno H. G. Gouvêa <bruno@rjconsultores.com.br>
*
*/
public abstract class Relatorio {
/*
* RELATORIO_APROVEITAMENTO(1, "RelatorioAproveitamento", "Relatório de Aproveitamento",new RendimentoParamsImpl(), null); RELATORIO_RECEITA_DIARIA_AGENCIA(2, "RelatorioReceitaDiariaAgencia", "Relatório de Receita Diária por Agência", null, null), RELATORIO_EXEMPLO(99, "ExemploFoo", "Relatório Foo", null, null);
*/
private Connection conexao;
private static Logger log = Logger.getLogger(Relatorio.class);
private Connection conexao;
private Map<String, Object> parametros;
protected RenderRelatorioJasper render;
private IDataSource customDataSource;
@ -87,6 +81,13 @@ public abstract class Relatorio {
*/
public void setCustomDataSource(IDataSource iDataSource) {
this.customDataSource = iDataSource;
try {
if (!this.conexao.isClosed())
this.conexao.close();
} catch (SQLException e) {
log.error("Erro ao fechar a conexion", e);
}
}
public IParametros getProcessadorParametros() {
@ -108,7 +109,7 @@ public abstract class Relatorio {
byte[] conteudo = null;
try {
if (this.render == null){
if (this.render == null) {
this.processaParametros();
this.render = new RenderRelatorioJasper(this);
}

View File

@ -4,7 +4,6 @@
*/
package com.rjconsultores.ventaboletos.web.gui.controladores.relatorios;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@ -341,19 +340,7 @@ public class RelatorioReceitaDiariaAgenciaController extends MyGenericForwardCom
parametros.put("FILTROS", filtro.toString());
Connection conexao = null;
Relatorio relatorio = null;
try {
conexao = dataSource.getConnection();
relatorio = new RelatorioReceitaDiariaAgencia(parametros, conexao);
} catch (Exception e) {
if (!conexao.isClosed())
conexao.close();
throw e;
} finally {
if (!conexao.isClosed())
conexao.close();
}
Relatorio relatorio = new RelatorioReceitaDiariaAgencia(parametros, dataSource.getConnection());
Map args = new HashMap();
args.put("relatorio", relatorio);