@ -1,5 +1,7 @@
package siprp.planoactuacao.print ;
import java.util.Collections ;
import java.util.Comparator ;
import java.util.Date ;
import java.util.HashMap ;
import java.util.Vector ;
@ -24,6 +26,9 @@ public class PlanoActuacaoPrintDataProvider
{
private static final Object LOCK = new Object ( ) ;
private static PlanoActuacaoPrintDataProvider instance = null ;
protected static final Object UNCONTROLLED = "Incontrolado" ;
protected static final Object CONTROLLED = "Controlado" ;
protected static final Object INDETERMINATE = "Indeterminado" ;
protected final Executer WEB_EXECUTER ;
protected final Executer LOCAL_EXECUTER ;
@ -79,7 +84,7 @@ public class PlanoActuacaoPrintDataProvider
null ) ;
Virtual2DArray array = LOCAL_EXECUTER . executeQuery ( select ) ;
return ( ( Boolean ) array . get ( 0 , 0 ) ) . booleanValue ( ) ;
return array . get ( 0 , 0 ) ! = null ? ( ( Boolean ) array . get ( 0 , 0 ) ) . booleanValue ( ) : false ;
}
catch ( Exception ex )
{
@ -207,7 +212,7 @@ public class PlanoActuacaoPrintDataProvider
// return legislacao;
// }
public LegislacaoAplicavelToPrint getLegislacaoAplicavel ( Integer plan oId )
public LegislacaoAplicavelToPrint getLegislacaoAplicavel ( Integer relatori oId )
throws Exception
{
Select select =
@ -215,9 +220,10 @@ public class PlanoActuacaoPrintDataProvider
new String [ ] { "hs_relatorio_legislacao" } ,
new Integer [ ] { } ,
new Expression [ ] { } ,
new String [ ] { "hs_relatorio_legislacao.categoria" , "hs_relatorio_legislacao.descricao" } ,
new Field ( "hs_relatorio_legislacao.hs_relatorio_id" ) . isEqual ( planoId ) ,
new String [ ] { "hs_relatorio_legislacao.categoria DESC" } ,
new String [ ] { "hs_relatorio_legislacao.categoria" , "hs_relatorio_legislacao.descricao" ,
"COALESCE(hs_relatorio_legislacao.categoria,'A')" } ,
new Field ( "hs_relatorio_legislacao.hs_relatorio_id" ) . isEqual ( relatorioId ) ,
new String [ ] { "COALESCE(hs_relatorio_legislacao.categoria,'A')" , "ordem" } ,
null ,
null ,
null ) ;
@ -241,11 +247,13 @@ public class PlanoActuacaoPrintDataProvider
nomes . add ( categoria ) ;
diplomas . add ( new Vector < String > ( ) ) ;
}
last = categoria ;
diplomas . lastElement ( ) . add ( descricao ) ;
}
}
LegislacaoAplicavelToPrint legislacao =
new LegislacaoAplicavelToPrint ( diplomasGerais ) ;
new LegislacaoAplicavelToPrint ( diplomasGerais , nomes . toArray ( new String [ nomes . size ( ) ] ) ,
diplomas . toArray ( new Vector [ diplomas . size ( ) ] ) ) ;
return legislacao ;
}
@ -261,7 +269,7 @@ public class PlanoActuacaoPrintDataProvider
new String [ ] { "plano_areas" } ,
new Integer [ ] { } ,
new Expression [ ] { } ,
new String [ ] { "id" , "descricao" } ,
new String [ ] { "id" , "descricao" , "1" } ,
new Field ( "plano_id" ) . isEqual ( planoId ) ,
new String [ ] { "id" } ,
null ,
@ -276,7 +284,7 @@ public class PlanoActuacaoPrintDataProvider
new String [ ] { "hs_relatorio_area" } ,
new Integer [ ] { } ,
new Expression [ ] { } ,
new String [ ] { "id" , "description" } ,
new String [ ] { "id" , "description" , "ordem" } ,
new Field ( "relatorio_id" ) . isEqual ( planoId ) . and (
new Field ( "deleted_date" ) . isEqual ( null ) ) ,
new String [ ] { "id" } ,
@ -289,12 +297,35 @@ public class PlanoActuacaoPrintDataProvider
{
Integer areaId = ( Integer ) array . get ( n , 0 ) ;
String areaDescricao = ( String ) array . get ( n , 1 ) ;
Integer ordem = ( Integer ) array . get ( n , 2 ) ;
boolean generico = false ;
if ( ! web )
{
Select selectGen =
new Select2 (
new String [ ] { "hs_relatorio_posto" } ,
new Integer [ ] { } ,
new Expression [ ] { } ,
new String [ ] { "COUNT( hs_relatorio_posto.id )" } ,
new Field ( "hs_relatorio_posto.area_id" ) . isEqual ( areaId ) . and (
new Field ( "hs_relatorio_posto.is_principal" ) . isEqual ( true ) ) ,
null ,
null ,
null ,
null ) ;
Virtual2DArray genArray = LOCAL_EXECUTER . executeQuery ( selectGen ) ;
if ( genArray . columnLength ( ) > 0 & & genArray . get ( 0 , 0 ) ! = null )
{
generico = ( ( Number ) genArray . get ( 0 , 0 ) ) . intValue ( ) > 0 ;
}
}
Vector < RiscoToPrint > riscos = getRiscosToPrintByAreaId ( areaId , validacaoDl , validacaoDns ) ;
if ( riscos . size ( ) > 0 )
{
areas . add ( new AreaToPrint ( areaDescricao , riscos ) ) ;
areas . add ( new AreaToPrint ( areaDescricao , riscos , ordem , generico ) ) ;
}
}
Collections . sort ( areas ) ;
return areas ;
}
@ -353,7 +384,7 @@ public class PlanoActuacaoPrintDataProvider
dataFim ! = null ? new DataToPrint ( "data-prevista-conclusao" , dataFim ) : null ,
parecerDl ,
parecerDns ,
verificacaoSiprp ) ) ;
verificacaoSiprp , null , null ) ) ;
}
}
else
@ -388,6 +419,8 @@ public class PlanoActuacaoPrintDataProvider
Vector < String > riscosVector = new Vector < String > ( ) ;
HashMap < String , Vector < Integer > > riscosIdMap = new HashMap < String , Vector < Integer > > ( ) ;
HashMap < Integer , Integer > riscoPostoMap = new HashMap < Integer , Integer > ( ) ;
HashMap < String , Integer > valoresQuantitativos = new HashMap < String , Integer > ( ) ;
HashMap < String , String > valoresQualitativos = new HashMap < String , String > ( ) ;
for ( int n = 0 ; n < array . columnLength ( ) ; n + + )
{
Integer id = ( Integer ) array . get ( n , 0 ) ;
@ -417,6 +450,8 @@ public class PlanoActuacaoPrintDataProvider
}
riscosIdMap . get ( key ) . add ( id ) ;
riscoPostoMap . put ( id , posto ) ;
valoresQuantitativos . put ( key , risco ) ;
valoresQualitativos . put ( key , ( ( String ) array . get ( n , 3 ) ) ) ;
}
for ( String risco : riscosVector )
{
@ -442,11 +477,53 @@ public class PlanoActuacaoPrintDataProvider
null ,
null ,
null ,
null ) ) ;
null ,
valoresQuantitativos . get ( risco ) ,
valoresQualitativos . get ( risco ) ) ) ;
}
}
}
Collections . sort ( riscos , new Comparator < RiscoToPrint > ( ) {
@Override
public int compare ( RiscoToPrint o1 , RiscoToPrint o2 ) {
Integer o1Value = 1000 ;
Integer o2Value = 1000 ;
if ( o1 . valorQuantitativo ! = null )
{
o1Value = - o1 . valorQuantitativo ;
}
else if ( o1 . valorQualitativo . equals ( UNCONTROLLED ) )
{
o1Value = 100 ;
}
else if ( o1 . valorQualitativo . equals ( CONTROLLED ) )
{
o1Value = 200 ;
}
else if ( o1 . valorQualitativo . equals ( INDETERMINATE ) )
{
o1Value = 300 ;
}
if ( o2 . valorQuantitativo ! = null )
{
o2Value = - o2 . valorQuantitativo ;
}
else if ( o2 . valorQualitativo . equals ( UNCONTROLLED ) )
{
o2Value = 100 ;
}
else if ( o2 . valorQualitativo . equals ( CONTROLLED ) )
{
o2Value = 200 ;
}
else if ( o2 . valorQualitativo . equals ( INDETERMINATE ) )
{
o2Value = 300 ;
}
return o1Value . compareTo ( o2Value ) ;
}
} ) ;
return riscos ;
}