From 421ee652faece55a6aef41f19de9e804f83b736b Mon Sep 17 00:00:00 2001 From: Frederico Palma Date: Mon, 26 Jan 2009 17:06:03 +0000 Subject: [PATCH] git-svn-id: https://svn.coded.pt/svn/SIPRP@922 bb69d46d-e84e-40c8-a05a-06db0d633741 --- .../print/PlanoActuacaoPrintDataProvider.java | 223 ++++++++++++------ 1 file changed, 157 insertions(+), 66 deletions(-) diff --git a/trunk/SIPRPSoft/src/siprp/planoactuacao/print/PlanoActuacaoPrintDataProvider.java b/trunk/SIPRPSoft/src/siprp/planoactuacao/print/PlanoActuacaoPrintDataProvider.java index 1c88c252..3d9ceb7b 100644 --- a/trunk/SIPRPSoft/src/siprp/planoactuacao/print/PlanoActuacaoPrintDataProvider.java +++ b/trunk/SIPRPSoft/src/siprp/planoactuacao/print/PlanoActuacaoPrintDataProvider.java @@ -1,6 +1,7 @@ package siprp.planoactuacao.print; import java.util.Date; +import java.util.HashMap; import java.util.Vector; import siprp.planoactuacao.SingletonConstants; @@ -12,13 +13,11 @@ import com.evolute.utils.data.Mappable; import com.evolute.utils.data.MappableObject; import com.evolute.utils.db.DBManager; import com.evolute.utils.db.Executer; -import com.evolute.utils.sql.Assignment; import com.evolute.utils.sql.BlobUpdate; import com.evolute.utils.sql.Expression; import com.evolute.utils.sql.Field; import com.evolute.utils.sql.Select; import com.evolute.utils.sql.Select2; -import com.evolute.utils.sql.Update; public class PlanoActuacaoPrintDataProvider @@ -146,7 +145,7 @@ public class PlanoActuacaoPrintDataProvider null, null ); Virtual2DArray array = LOCAL_EXECUTER.executeQuery( select ); - return ( Integer ) array.get( 0, 0 ); + return array.columnLength() > 0 ? ( Integer ) array.get( 0, 0 ) : null; } public LegislacaoAplicavelToPrint getLegislacaoAplicavel( Integer empresaId, Integer estabelecimentoId ) @@ -196,7 +195,11 @@ public class PlanoActuacaoPrintDataProvider { Integer areaId = ( Integer ) array.get( n, 0 ); String areaDescricao = ( String ) array.get( n, 1 ); - areas.add( new AreaToPrint( areaDescricao, getRiscosToPrintByAreaId( areaId, validacaoDl, validacaoDns ) ) ); + Vector riscos = getRiscosToPrintByAreaId( areaId, validacaoDl, validacaoDns ); + if( riscos.size() > 0 ) + { + areas.add( new AreaToPrint( areaDescricao, riscos ) ); + } } return areas; } @@ -223,6 +226,41 @@ public class PlanoActuacaoPrintDataProvider null, null ); array = WEB_EXECUTER.executeQuery( select ); + for( int n = 0; n < array.columnLength(); n++ ) + { + Integer id = ( Integer ) array.get( n, 0 ); + String descricao = ( String ) array.get( n, 1 ); + Integer valor = ( Integer ) array.get( n, 2 ); + String responsavelExecucao = ( String ) array.get( n, 3 ); + String recursosNecessarios = ( String ) array.get( n, 4 ); + Date dataInicio = ( Date ) array.get( n, 5 ); + Date dataFim = ( Date ) array.get( n, 6 ); + String parecerDl = ( String ) array.get( n, 7 ); + if( ( parecerDl == null || parecerDl.trim().length() == 0 ) + && validacaoDl ) + { + parecerDl = "De acordo"; + } + String parecerDns = ( String ) array.get( n, 8 ); + if( ( parecerDns == null || parecerDns.trim().length() == 0 ) + && validacaoDns ) + { + parecerDns = "De acordo"; + } + String verificacaoSiprp = ( String ) array.get( n, 9 ); + riscos.add( + new RiscoToPrint( + descricao, + valor, + getMedidasToPrintByRiscoId( id ), + responsavelExecucao, + recursosNecessarios, + dataInicio != null ? new DataToPrint( "data-prevista-inicio", dataInicio ) : null, + dataFim != null ? new DataToPrint( "data-prevista-conclusao", dataFim ) : null, + parecerDl, + parecerDns, + verificacaoSiprp ) ); + } } else { @@ -243,51 +281,62 @@ public class PlanoActuacaoPrintDataProvider "null", "null", "null", - "verificacao_siprp" }, - new Field( "hs_relatorio_area.area_id" ).isEqual( areaId ).and( + "null" }, + new Field( "hs_relatorio_posto.area_id" ).isEqual( areaId ).and( new Field( "hs_relatorio_risco.deleted_date" ).isEqual( null ) ).and( new Field( "hs_relatorio_posto.deleted_date" ).isEqual( null ) ), - new String[]{ "id" }, + new String[]{ "hs_relatorio_risco.id" }, null, null, null ); array = LOCAL_EXECUTER.executeQuery( select ); - } - for( int n = 0; n < array.columnLength(); n++ ) - { - Integer id = ( Integer ) array.get( n, 0 ); - String descricao = ( String ) array.get( n, 1 ); - Integer valor = ( Integer ) array.get( n, 2 ); - String responsavelExecucao = ( String ) array.get( n, 3 ); - String recursosNecessarios = ( String ) array.get( n, 4 ); - Date dataInicio = ( Date ) array.get( n, 5 ); - Date dataFim = ( Date ) array.get( n, 6 ); - String parecerDl = ( String ) array.get( n, 7 ); - if( ( parecerDl == null || parecerDl.trim().length() == 0 ) - && validacaoDl ) + Vector riscosVector = new Vector(); + HashMap> riscosIdMap = new HashMap>(); + for( int n = 0; n < array.columnLength(); n++ ) { - parecerDl = "De acordo"; + Integer id = ( Integer ) array.get( n, 0 ); + String descricao = ( String ) array.get( n, 1 ); + Integer risco = ( Integer ) array.get( n, 2 ); + if( risco == null ) + { + continue; + } + String key = descricao + "_" + risco; + if( !riscosIdMap.containsKey( key ) ) + { + riscosIdMap.put( key, new Vector() ); + riscosVector.add( key ); + } + riscosIdMap.get( key ).add( id ); } - String parecerDns = ( String ) array.get( n, 8 ); - if( ( parecerDns == null || parecerDns.trim().length() == 0 ) - && validacaoDns ) + for( String risco : riscosVector ) { - parecerDns = "De acordo"; + int index = risco.lastIndexOf( "_" ); + String descricao = risco.substring( 0, index ); + Integer valor = new Integer( risco.substring( index + 1, risco.length() ) ); + Vector medidas = new Vector(); + for( Integer id : riscosIdMap.get( risco ) ) + { + medidas.addAll( getMedidasToPrintByRiscoId( id ) ); + } + if( medidas.size() > 0 ) + { + riscos.add( + new RiscoToPrint( + descricao, + valor, + medidas, + null, + null, + null, + null, + null, + null, + null ) ); + } } - String verificacaoSiprp = ( String ) array.get( n, 9 ); - riscos.add( - new RiscoToPrint( - descricao, - valor, - getMedidasToPrintByRiscoId( id ), - responsavelExecucao, - recursosNecessarios, - dataInicio != null ? new DataToPrint( "data-prevista-inicio", dataInicio ) : null, - dataFim != null ? new DataToPrint( "data-prevista-conclusao", dataFim ) : null, - parecerDl, - parecerDns, - verificacaoSiprp ) ); } + return riscos; } @@ -295,26 +344,47 @@ public class PlanoActuacaoPrintDataProvider throws Exception { Vector medidas = new Vector(); - Select select = - new Select2( - new String[]{ "plano_medidas" }, - new Integer[]{}, - new Expression[]{}, - new String[]{ "id", "descricao" }, - new Field( "risco_id" ).isEqual( riscoId ), - new String[]{ "id" }, - null, - null, - null ); - Virtual2DArray array = WEB_EXECUTER.executeQuery( select ); + Virtual2DArray array; + if( web ) + { + Select select = + new Select2( + new String[]{ "plano_medidas" }, + new Integer[]{}, + new Expression[]{}, + new String[]{ "id", "descricao" }, + new Field( "risco_id" ).isEqual( riscoId ), + new String[]{ "id" }, + null, + null, + null ); + array = WEB_EXECUTER.executeQuery( select ); + } + else + { + Select select = + new Select2( + new String[]{ "hs_relatorio_medida" }, + new Integer[]{}, + new Expression[]{}, + new String[]{ "hs_relatorio_medida.id", "hs_relatorio_medida.description" }, + new Field( "hs_relatorio_medida.risco_id" ).isEqual( riscoId ).and( + new Field( "hs_relatorio_medida.deleted_date" ).isEqual( null ) ), + new String[]{ "hs_relatorio_medida.id" }, + null, + null, + null ); + array = LOCAL_EXECUTER.executeQuery( select ); + } for( int n = 0; n < array.columnLength(); n++ ) { Integer id = ( Integer ) array.get( n, 0 ); String descricao = ( String ) array.get( n, 1 ); - medidas.add( - new MedidaToPrint( - descricao, - getPostosToPrintByMedidaId( id ) ) ); + Vector postos = getPostosToPrintByMedidaId( id ); + if( postos.size() > 0 ) + { + medidas.add( new MedidaToPrint( descricao, postos ) ); + } } return medidas; } @@ -323,18 +393,39 @@ public class PlanoActuacaoPrintDataProvider throws Exception { Vector postos = new Vector(); - Select select = - new Select2( - new String[]{ "plano_postos_trabalho" }, - new Integer[]{}, - new Expression[]{}, - new String[]{ "id", "descricao" }, - new Field( "medida_id" ).isEqual( medidaId ), - new String[]{ "id" }, - null, - null, - null ); - Virtual2DArray array = WEB_EXECUTER.executeQuery( select ); + Virtual2DArray array; + if( web ) + { + Select select = + new Select2( + new String[]{ "plano_postos_trabalho" }, + new Integer[]{}, + new Expression[]{}, + new String[]{ "id", "descricao" }, + new Field( "medida_id" ).isEqual( medidaId ), + new String[]{ "id" }, + null, + null, + null ); + array = WEB_EXECUTER.executeQuery( select ); + } + else + { + Select select = + new Select2( + new String[]{ "hs_relatorio_posto", "hs_relatorio_posto_medida" }, + new Integer[]{ Select2.JOIN_INNER }, + new Expression[]{ + new Field( "hs_relatorio_posto.id" ).isEqual( new Field( "hs_relatorio_posto_medida.posto_id" ) ) + }, + new String[]{ "hs_relatorio_posto.id", "hs_relatorio_posto.description" }, + new Field( "hs_relatorio_posto_medida.medida_id" ).isEqual( medidaId ), + new String[]{ "hs_relatorio_posto.id" }, + null, + null, + null ); + array = LOCAL_EXECUTER.executeQuery( select ); + } for( int n = 0; n < array.columnLength(); n++ ) { String descricao = ( String ) array.get( n, 1 );