From 32ad62a7de830457b515befba7881a76a697abb1 Mon Sep 17 00:00:00 2001 From: julio Date: Sun, 9 Jun 2019 21:41:44 +0000 Subject: [PATCH] bug#14533 -- teste de performance dev: julio qua: git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@94314 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../dao/hibernate/BpeHibernateDAO.java | 90 ++++++++++++------- 1 file changed, 60 insertions(+), 30 deletions(-) diff --git a/src/com/rjconsultores/ventaboletos/dao/hibernate/BpeHibernateDAO.java b/src/com/rjconsultores/ventaboletos/dao/hibernate/BpeHibernateDAO.java index b288456bf..ca9d2e599 100644 --- a/src/com/rjconsultores/ventaboletos/dao/hibernate/BpeHibernateDAO.java +++ b/src/com/rjconsultores/ventaboletos/dao/hibernate/BpeHibernateDAO.java @@ -47,7 +47,7 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO { public ExportacaoBPEVo buscarRegistroExportacaoBpe(Connection connection, Date inicio, Date fim, Integer empresaId, String cveestado) { log.info("Inicio da consulta buscarRegistroExportacaoBpe: " + new Date()); - + ExportacaoBPEVo exportacaoBPEVo = new ExportacaoBPEVo(); List registros = new ArrayList(); @@ -59,13 +59,25 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO { sql.append(" c.numfoliosistema as numfoliosistema, "); sql.append(" coalesce(c.preciopagado,0) + coalesce(c.importetaxaembarque,0) + coalesce(c.importeseguro,0) + coalesce(c.importepedagio,0) + coalesce(c.importeoutros,0) as valortotal, "); sql.append(" bpe.codstat as codstatus, "); - sql.append(" DBMS_LOB.substr(coalesce(bpe.xmlregular, bpe.xmlcontingencia), 3000) as xml_bpe, "); - sql.append(" DBMS_LOB.substr(coalesce(bpe.xmlregular, bpe.xmlcontingencia), 3000, 3001) as xml_bpe_2, "); - sql.append(" DBMS_LOB.substr(coalesce(bpe.xmlregular, bpe.xmlcontingencia), 3000, 6001) as xml_bpe_3, "); + + sql.append(" COALESCE(bpe_cancel.xml_bpe, bpe.xml_bpe) as xml_bpe, "); + sql.append(" COALESCE(bpe_cancel.xml_bpe_2, bpe.xml_bpe_2) as xml_bpe_2, "); + sql.append(" COALESCE(bpe_cancel.xml_bpe_3, bpe.xml_bpe_3) as xml_bpe_3, "); + sql.append(" COALESCE(bpe_cancel.xml_bpe_4, bpe.xml_bpe_4) as xml_bpe_4, "); + sql.append(" COALESCE(bpe_cancel.xml_bpe_5, bpe.xml_bpe_5) as xml_bpe_5, "); + + // sql.append(" DBMS_LOB.substr(COALESCE(bpe_cancel.xmlregular, bpe_cancel.xmlcontingencia, bpe.xmlregular, bpe.xmlcontingencia), 3000) AS xml_bpe, "); + // sql.append(" DBMS_LOB.substr(COALESCE(bpe_cancel.xmlregular, bpe_cancel.xmlcontingencia, bpe.xmlregular, bpe.xmlcontingencia), 3000, 3001) AS xml_bpe_2, "); + // sql.append(" DBMS_LOB.substr(COALESCE(bpe_cancel.xmlregular, bpe_cancel.xmlcontingencia, bpe.xmlregular, bpe.xmlcontingencia), 3000, 6001) AS xml_bpe_3, "); + + // sql.append(" DBMS_LOB.substr(coalesce(bpe.xmlregular, bpe.xmlcontingencia), 3000) as xml_bpe, "); + // sql.append(" DBMS_LOB.substr(coalesce(bpe.xmlregular, bpe.xmlcontingencia), 3000, 3001) as xml_bpe_2, "); + // sql.append(" DBMS_LOB.substr(coalesce(bpe.xmlregular, bpe.xmlcontingencia), 3000, 6001) as xml_bpe_3, "); + sql.append(" bpe.tipoevento as tipoevento, "); sql.append(" bpe.desconto as v_desconto, "); sql.append(" bpe.chbpe, "); - sql.append(" coalesce(chbpe_substituicao, ' ') as chbpe_sub, "); + sql.append(" coalesce(bpe.chbpe_substituicao, ' ') as chbpe_sub, "); sql.append(" to_char(c.feccreacion, 'yyyymmdd') as dh_emisao, "); sql.append(" to_char(c.fechorviaje, 'yyyymmdd') as dhrecbto, "); sql.append(" coalesce(bpe.tiposubstituicao, '0') as tp_bpe, "); @@ -75,10 +87,10 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO { sql.append(" c.categoria_id, "); sql.append(" e.codestabelecimento as cod_estabelecimento, "); sql.append(" ep.crtbpe as crt, "); - sql.append(" co.codibge as municipio_origem, "); - sql.append(" eo.cveestado as estado_origem, "); - sql.append(" cd.codibge as municipio_destino, "); - sql.append(" ed.cveestado as estado_destino, "); + // sql.append(" co.codibge as municipio_origem, "); + // sql.append(" eo.cveestado as estado_origem, "); + // sql.append(" cd.codibge as municipio_destino, "); + // sql.append(" ed.cveestado as estado_destino, "); sql.append(" ((case when coalesce(r.indtribtarifa,0) = 1 then c.preciopagado else 0 end) + (case when coalesce(r.indtribtaxaembarque,0) = 1 then c.importetaxaembarque else 0 end) + (case when coalesce(r.indtribpedagio,0) = 1 then c.importepedagio else 0 end)) as valortributado, "); sql.append(" ei.porcredbaseicms as red_base_calc_estadual, "); sql.append(" ei.porcredbaseicmsim as red_base_calc_municipal, "); @@ -98,19 +110,22 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO { sql.append("from boleto c "); sql.append(" join bpe bpe on c.boleto_id = bpe.boleto_id "); sql.append(" and bpe.activo = (case when c.motivocancelacion_id = 17 and c.boletooriginal_id is null then 0 else 1 end) "); + + sql.append(" left join bpe bpe_cancel on bpe.chbpe = bpe_cancel.chbpe and bpe.codstat in ('135') and bpe_cancel.codstat in ('100','150') "); + sql.append(" join estado e on e.codibge = bpe.uf "); sql.append(" join marca ma on c.marca_id = ma.marca_id "); sql.append(" join empresa ep on ma.empresa_id = ep.empresa_id "); sql.append(" join ruta r on r.ruta_id = c.ruta_id "); - sql.append(" left join alias_servico ase on ase.origen_id = c.origen_id "); - sql.append(" and ase.destino_id = c.destino_id and ase.ruta_id = c.ruta_id and ase.activo = 1 and ase.corrida_id is null "); - sql.append(" inner join parada o on coalesce(ase.aliasorigen_id, c.origen_id) = o.parada_id "); - sql.append(" inner join ciudad co on o.ciudad_id = co.ciudad_id "); - sql.append(" inner join estado eo on eo.estado_id = co.estado_id "); - sql.append(" inner join parada d on coalesce(ase.aliasdestino_id, c.destino_id) = d.parada_id "); - sql.append(" inner join ciudad cd on d.ciudad_id = cd.ciudad_id "); - sql.append(" inner join estado ed on ed.estado_id = cd.estado_id "); - sql.append(" left join empresa_imposto ei on ei.empresa_id = ep.empresa_id and ei.estado_id = e.estado_id "); + // sql.append(" left join alias_servico ase on ase.origen_id = c.origen_id "); + // sql.append(" and ase.destino_id = c.destino_id and ase.ruta_id = c.ruta_id and ase.activo = 1 and ase.corrida_id is null "); + // sql.append(" inner join parada o on coalesce(ase.aliasorigen_id, c.origen_id) = o.parada_id "); + // sql.append(" inner join ciudad co on o.ciudad_id = co.ciudad_id "); + // sql.append(" inner join estado eo on eo.estado_id = co.estado_id "); + // sql.append(" inner join parada d on coalesce(ase.aliasdestino_id, c.destino_id) = d.parada_id "); + // sql.append(" inner join ciudad cd on d.ciudad_id = cd.ciudad_id "); + // sql.append(" inner join estado ed on ed.estado_id = cd.estado_id "); + sql.append(" inner join empresa_imposto ei on ei.empresa_id = ep.empresa_id and ei.estado_id = e.estado_id "); sql.append("where c.activo = 1 and e.activo = 1 and ei.activo = 1 "); sql.append(" and bpe.tipoamb = 1 and ep.activo = 1 "); sql.append(" and bpe.codstat in ('-1','100','101','102','135','150') "); @@ -121,13 +136,16 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO { sql.append(" and e.cveestado = ? "); sql.append("order by to_number(c.numfoliosistema), to_number(num_bpe), dh_emisao "); +// ResultSet rs = null; +// PreparedStatement ps = null; try { PreparedStatement ps = connection.prepareStatement(sql.toString()); ps.setString(1, DateUtil.getStringDate(inicio, DATE_FORMAT_DMY) + " 00:00:00"); ps.setString(2, DateUtil.getStringDate(fim, DATE_FORMAT_DMY) + " 23:59:59"); ps.setLong(3, Long.valueOf(empresaId)); ps.setString(4, cveestado); - + + ps.setFetchSize(9999); ResultSet rs = ps.executeQuery(); while (rs.next()) { @@ -165,10 +183,10 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO { registro.setTipoevento(rs.getString("tipoevento")); registro.setCodigoContabilEstadual(rs.getString("codigocontabil_estadual")); registro.setCodigocontabilMunicipal(rs.getString("codigocontabil_municipal")); - registro.setMunicipioOrigem(rs.getString("municipio_origem")); - registro.setEstadoOrigem(rs.getString("estado_origem")); - registro.setMunicipioDestino(rs.getString("municipio_destino")); - registro.setEstadoDestino(rs.getString("estado_destino")); + // registro.setMunicipioOrigem(rs.getString("municipio_origem")); + // registro.setEstadoOrigem(rs.getString("estado_origem")); + // registro.setMunicipioDestino(rs.getString("municipio_destino")); + // registro.setEstadoDestino(rs.getString("estado_destino")); registro.setCrt(rs.getInt("crt")); registro.setIndPedagioMunicipal(rs.getInt("indpedagiomunicipal") == 1); registro.setIndSeguroMunicipal(rs.getInt("indseguromunicipal") == 1); @@ -181,14 +199,24 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO { registro.setValortributado(valortributado); registro.setValortotal(valortotal); - String xml_bpe = rs.getNString("xml_bpe"); - String xml_bpe_2 = rs.getNString("xml_bpe_2"); - String xml_bpe_3 = rs.getNString("xml_bpe_3"); - registro.setXml(StringUtils.join(new String[] { xml_bpe, xml_bpe_2, xml_bpe_3 })); + // String xml_bpe = rs.getNString("xml_bpe"); + // String xml_bpe_2 = rs.getNString("xml_bpe_2"); + // String xml_bpe_3 = rs.getNString("xml_bpe_3"); + + String xml_bpe = rs.getString("xml_bpe"); + String xml_bpe_2 = rs.getString("xml_bpe_2"); + String xml_bpe_3 = rs.getString("xml_bpe_3"); + String xml_bpe_4 = rs.getString("xml_bpe_4"); + String xml_bpe_5 = rs.getString("xml_bpe_5"); + + String xml = StringUtils.join(new String[] { xml_bpe, xml_bpe_2, xml_bpe_3, xml_bpe_4, xml_bpe_5 }); + + // String xml = StringUtils.join(new String[] { xml_bpe, xml_bpe_2, xml_bpe_3 }); + registro.setXml(xml); if (exportacaoBPEVo.isBpeCanceladoENaoEmbarque(registro)) { - String xmlAnterior = buscarXmlBPE(connection, (StringUtils.isBlank(registro.getChbpeSub()) ? registro.getChbpe() : registro.getChbpeSub())); - registro.setXmlAnterior(xmlAnterior); + // String xmlAnterior = buscarXmlBPE(connection, (StringUtils.isBlank(registro.getChbpeSub()) ? registro.getChbpe() : registro.getChbpeSub())); + registro.setXmlAnterior(xml); registro.setXml(null); } @@ -199,7 +227,7 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO { ps.close(); log.info("Fim buscarRegistroExportacaoBpe: " + new Date()); - + } catch (Exception e) { log.error(e.getMessage(), e); } @@ -234,6 +262,8 @@ public class BpeHibernateDAO extends HibernateDaoSupport implements BpeDAO { exportacaoBPEVo.gerarListas(registro); } + log.info(" !!!! --- Fim preocesso da ExportacaoBpe: " + new Date()); + return exportacaoBPEVo; }