forked from Coded/SIPRP
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1070 lines
38 KiB
1070 lines
38 KiB
/*
|
|
* To change this template, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
|
|
package db.providers;
|
|
|
|
import com.evolute.utils.arrays.Virtual2DArray;
|
|
import com.evolute.utils.data.Mappable;
|
|
import com.evolute.utils.data.MappableObject;
|
|
import com.evolute.utils.error.ErrorLogger;
|
|
import com.evolute.utils.sql.Assignment;
|
|
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;
|
|
import com.evolute.utils.sql.expression.Par;
|
|
import com.evolute.utils.strings.StringPlainer;
|
|
import db.data.siprp.outer.EstadoMedidasData;
|
|
import db.data.siprp.outer.PlanoAreasData;
|
|
import db.data.siprp.outer.PlanoMedidasData;
|
|
import db.data.siprp.outer.PlanoPostosTrabalhoData;
|
|
import db.data.siprp.outer.PlanoRiscosData;
|
|
import db.data.siprp.outer.PlanoValoresQualitativosData;
|
|
import db.data.siprp.outer.PlanosActuacaoData;
|
|
import db.entidades.Area;
|
|
import db.entidades.EstadoMedida;
|
|
import db.entidades.LinhaEstatistica;
|
|
import db.entidades.Medida;
|
|
import db.entidades.PlanoActuacao;
|
|
import db.entidades.PostoTrabalho;
|
|
import db.entidades.Risco;
|
|
import db.entidades.Utilizador;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Comparator;
|
|
import utils.Global;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
import utils.Utils;
|
|
|
|
|
|
public class PlanosDataProvider extends GenericDataProvider
|
|
{
|
|
private static PlanosDataProvider INSTANCE = null;
|
|
protected static final String UNCONTROLLED = "Incontrolado";
|
|
protected static final String CONTROLLED = "Controlado";
|
|
protected static final String INDETERMINATE = "Indeterminado";
|
|
protected static final String MUITO_ALTO = "Muito Alto";
|
|
protected static final String ALTO = "Alto";
|
|
protected static final String MEDIO = "M\u00e9dio";
|
|
protected static final String BAIXO = "Baixo";
|
|
|
|
protected HashMap<Integer, PlanoValoresQualitativosData> VALORES_QUALITATIVOS_BY_ID = new HashMap<Integer, PlanoValoresQualitativosData>();
|
|
|
|
private PlanosDataProvider() throws Exception
|
|
{
|
|
super();
|
|
}
|
|
|
|
public static synchronized PlanosDataProvider getInstance() throws Exception
|
|
{
|
|
if ( INSTANCE == null )
|
|
{
|
|
INSTANCE = new PlanosDataProvider();
|
|
}
|
|
return INSTANCE;
|
|
}
|
|
|
|
public void updatePlano( PlanoActuacao p ) throws Exception
|
|
{
|
|
if ( p.getConcluidoPorDesactivacao() == null )
|
|
{
|
|
p.setConcluidoPorDesactivacao( false );
|
|
}
|
|
if ( p.getObs_correcao() == null )
|
|
{
|
|
p.setObs_correcao( "" );
|
|
}
|
|
if ( p.getObservacoes_dl() == null )
|
|
{
|
|
p.setObservacoes_dl( "" );
|
|
}
|
|
if ( p.getObservacoes_dns() == null )
|
|
{
|
|
p.setObservacoes_dns( "" );
|
|
}
|
|
if ( p.getUser_dir_loja() != null && p.getUser_dir_loja() == 0 )
|
|
{
|
|
p.setUser_dir_loja( null );
|
|
}
|
|
if ( p.getUser_dns() != null && p.getUser_dns() == 0 )
|
|
{
|
|
p.setUser_dns( null );
|
|
}
|
|
if ( p.getUser_hs() != null && p.getUser_hs() == 0 )
|
|
{
|
|
p.setUser_hs( null );
|
|
}
|
|
if ( p.getUser_seg() != null && p.getUser_seg() == 0 )
|
|
{
|
|
p.setUser_seg( null );
|
|
}
|
|
|
|
Expression where = new Field( "id" ).isEqual( p.getId() );
|
|
|
|
Update upd = new Update( "planos_actuacao", new Assignment[]
|
|
{
|
|
new Assignment( new Field( "fase" ), p.getFase() ),
|
|
new Assignment( new Field( "validacao_director_loja" ), p.getValidacao_director_loja() ),
|
|
new Assignment( new Field( "validacao_dns" ), p.getValidacao_dns() ),
|
|
new Assignment( new Field( "validacao_hs" ), p.getValidacao_hs() ),
|
|
new Assignment( new Field( "observacoes_dl" ), p.getObservacoes_dl() ),
|
|
new Assignment( new Field( "observacoes_dns" ), p.getObservacoes_dns() ),
|
|
new Assignment( new Field( "obs_correcao" ), p.getObs_correcao() ),
|
|
new Assignment( new Field( "correcao" ), p.getCorrecao() ),
|
|
new Assignment( new Field( "fase_antes_correcao" ), p.getFase_antes_correcao() ),
|
|
new Assignment( new Field( "concluido_por_desactivacao" ), ( p.getConcluidoPorDesactivacao() == null ? Boolean.FALSE : p.getConcluidoPorDesactivacao() ) ),
|
|
new Assignment( new Field( "data_desactivacao" ), p.getDataDesactivacao() ),
|
|
new Assignment( new Field( "data_validacao_dir_loja" ), p.getData_validacao_dir_loja() ),
|
|
new Assignment( new Field( "user_dir_loja" ), p.getUser_dir_loja() ),
|
|
new Assignment( new Field( "data_validacao_dns" ), p.getData_validacao_dns() ),
|
|
new Assignment( new Field( "user_dns" ), p.getUser_dns() ),
|
|
new Assignment( new Field( "data_validacao_hs" ), p.getData_validacao_hs() ),
|
|
new Assignment( new Field( "user_hs" ), p.getUser_hs() ),
|
|
new Assignment( new Field( "data_controlo" ), p.getData_controlo() ),
|
|
new Assignment( new Field( "data_email_controlo" ), p.getData_email_controlo() ),
|
|
new Assignment( new Field( "data_validacao_seg" ), p.getData_validacao_seg() ),
|
|
new Assignment( new Field( "user_seg" ), p.getUser_seg() )
|
|
}, where );
|
|
|
|
System.out.println( "SQL UPDATE PLANO : " + upd.toString() );
|
|
|
|
ErrorLogger.log( "SAVE : PlanosDataProvider.updatePlano( " + p.getId() + " ) : " + upd.toString() );
|
|
getExecuter().executeQuery( upd );
|
|
}
|
|
|
|
public void updateRisco( Risco r ) throws Exception
|
|
{
|
|
if ( r.getResponsavel_execucao() == null )
|
|
{
|
|
r.setResponsavel_execucao( "" );
|
|
}
|
|
if ( r.getPor() == null )
|
|
{
|
|
r.setPor( "" );
|
|
}
|
|
if ( r.getRecursos_necessarios() == null )
|
|
{
|
|
r.setRecursos_necessarios( "" );
|
|
}
|
|
if ( r.getParecer_dl() == null )
|
|
{
|
|
r.setParecer_dl( "" );
|
|
}
|
|
if ( r.getParecer_dns() == null )
|
|
{
|
|
r.setParecer_dns( "" );
|
|
}
|
|
if ( r.getVerificacao_siprp() == null )
|
|
{
|
|
r.setVerificacao_siprp( "" );
|
|
}
|
|
|
|
Expression where = new Field( "id" ).isEqual( r.getId() );
|
|
|
|
Update upd = new Update( PlanoRiscosData.TABLENAME, new Assignment[] {
|
|
new Assignment( new Field( PlanoRiscosData.RESPONSAVEL_EXECUCAO ), r.getResponsavel_execucao() ),
|
|
new Assignment( new Field( PlanoRiscosData.POR ), r.getPor() ),
|
|
new Assignment( new Field( PlanoRiscosData.RECURSOS_NECESSARIOS ), r.getRecursos_necessarios() ),
|
|
new Assignment( new Field( PlanoRiscosData.DATA_INICIO ), r.getData_inicio() ),
|
|
new Assignment( new Field( PlanoRiscosData.DATA_FIM ), r.getData_fim() ),
|
|
new Assignment( new Field( PlanoRiscosData.PARECER_DNS ), r.getParecer_dns() ),
|
|
new Assignment( new Field( PlanoRiscosData.PARECER_DL ), r.getParecer_dl() ),
|
|
new Assignment( new Field( PlanoRiscosData.VERIFICACAO_SIPRP ), r.getVerificacao_siprp() )
|
|
}, where );
|
|
|
|
ErrorLogger.log( "\nSAVE : PlanosDataProvider.updateRisco( " + r.getId() + " ) : " + upd.toString() );
|
|
getExecuter().executeQuery( upd );
|
|
System.out.println( "\n\tUPDATE RISCO SUCCESS !" );
|
|
}
|
|
|
|
public void updateMedidas( Risco risco ) throws Exception
|
|
{
|
|
List< Medida > medidas = risco.getMedidas();
|
|
for ( Medida m : medidas )
|
|
{
|
|
Integer emID = null;
|
|
if ( m.getValidarMedidaId() != null && m.getValidarMedidaId() != 0 )
|
|
{
|
|
emID = m.getValidarMedidaId();
|
|
}
|
|
|
|
Expression where = new Field( "id" ).isEqual( m.getId() ).and( new Field( "risco_id" ).isEqual( risco.getId() ) );
|
|
|
|
Update upd = new Update( PlanoMedidasData.TABLENAME, new Assignment[] {
|
|
new Assignment( new Field( PlanoMedidasData.ESTADO_MEDIDAS_ID ), emID )
|
|
}, where );
|
|
|
|
System.out.println( "SQL UPDATE MEDIDAS : " + upd.toString() );
|
|
ErrorLogger.log( "SAVE : PlanosDataProvider.updateMedidas( " + risco.getId() + " ) : " + upd.toString() );
|
|
getExecuter().executeQuery( upd );
|
|
}
|
|
}
|
|
|
|
private enum SECTION { ACTIVOS, SEGUIMENTO, CONCLUIDOS }
|
|
|
|
private Select2 getExpression( SECTION section, Utilizador u, String nome, String estabelecimento, String dataVisita, Integer ano )
|
|
{
|
|
Expression where = getWhereExpression( nome, estabelecimento, dataVisita );
|
|
Expression faseExpression = null;
|
|
switch ( section )
|
|
{
|
|
case ACTIVOS :
|
|
faseExpression = getFaseActivos( u );
|
|
break;
|
|
case SEGUIMENTO :
|
|
faseExpression = getFaseSeguimento( u );
|
|
break;
|
|
case CONCLUIDOS :
|
|
faseExpression = getFaseConcluidos( u );
|
|
break;
|
|
}
|
|
if ( faseExpression != null )
|
|
{
|
|
where = where.and( faseExpression );
|
|
}
|
|
if( ano != null && ano > 0 && dataVisita == null )
|
|
{
|
|
where = where.and( new Field( "EXTRACT( year FROM " + PlanosActuacaoData.DATA_VISITA_FULL + " )" ).isEqual( ano) );
|
|
}
|
|
Select2 query = new Select2(
|
|
new String[] { PlanosActuacaoData.TABLENAME, PlanoAreasData.TABLENAME, PlanoRiscosData.TABLENAME },
|
|
new Integer[] { Select2.JOIN_INNER, Select2.JOIN_INNER },
|
|
new Expression[] {
|
|
new Field( PlanosActuacaoData.ID_FULL ).isEqual( new Field( PlanoAreasData.PLANO_ID_FULL ) ) ,
|
|
new Field( PlanoAreasData.ID_FULL ).isEqual( new Field( PlanoRiscosData.AREA_ID_FULL ) )
|
|
},
|
|
new String[] {
|
|
PlanosActuacaoData.ESTABELECIMENTO_ID_FULL,
|
|
PlanosActuacaoData.FASE_FULL,
|
|
PlanosActuacaoData.DATA_VISITA_FULL,
|
|
"trim( " + PlanosActuacaoData.NOME_ESTABELECIMENTO_FULL +" )",
|
|
PlanosActuacaoData.VALIDACAO_DIRECTOR_LOJA_FULL,
|
|
PlanosActuacaoData.VALIDACAO_DNS_FULL,
|
|
PlanosActuacaoData.VALIDACAO_HS_FULL,
|
|
"trim( " + PlanosActuacaoData.PARECER_DNS_FULL + " )",
|
|
"trim( " + PlanosActuacaoData.OBS_CORRECAO_FULL + " )",
|
|
PlanosActuacaoData.DATA_VALIDACAO_DIR_LOJA_FULL,
|
|
PlanosActuacaoData.USER_DIR_LOJA_FULL,
|
|
PlanosActuacaoData.DATA_VALIDACAO_DNS_FULL,
|
|
PlanosActuacaoData.USER_DNS_FULL,
|
|
PlanosActuacaoData.DATA_VALIDACAO_HS_FULL,
|
|
PlanosActuacaoData.USER_HS_FULL,
|
|
PlanosActuacaoData.FASE_ANTES_CORRECAO_FULL,
|
|
PlanosActuacaoData.CORRECAO_FULL,
|
|
"trim( " + PlanosActuacaoData.OBSERVACOES_DL_FULL + " )",
|
|
"trim( " + PlanosActuacaoData.OBSERVACOES_DNS_FULL + " )",
|
|
"trim( " + PlanosActuacaoData.VERIFICACAO_SIPRP_FULL + " )",
|
|
PlanosActuacaoData.DATA_CONTROLO_FULL,
|
|
PlanosActuacaoData.DATA_EMAIL_CONTROLO_FULL,
|
|
PlanosActuacaoData.EMPRESA_ID_FULL,
|
|
"trim( " + PlanosActuacaoData.NOME_EMPRESA_FULL + " )",
|
|
PlanosActuacaoData.TECNICO_HS_ID_FULL,
|
|
"trim( " + PlanosActuacaoData.TECNICO_HS_NOME_FULL + " )",
|
|
PlanosActuacaoData.ID_FULL,
|
|
PlanosActuacaoData.DATA_RELATORIO_FULL,
|
|
PlanosActuacaoData.DELETED_DATE_FULL,
|
|
PlanosActuacaoData.CONCLUIDO_POR_DESACTIVACAO_FULL,
|
|
PlanosActuacaoData.TECNICO_SUPERIOR_HS_ID_FULL,
|
|
"trim( " + PlanosActuacaoData.TECNICO_SUPERIOR_HS_NOME_FULL + " )",
|
|
PlanosActuacaoData.DATA_DESACTIVACAO_FULL,
|
|
PlanosActuacaoData.DATA_DISPONIBILIZACAO_FULL,
|
|
PlanosActuacaoData.DATA_VALIDACAO_SEG_FULL,
|
|
PlanosActuacaoData.USER_SEG_FULL,
|
|
PlanosActuacaoData.HS_RELATORIO_ID_FULL,
|
|
"COUNT( DISTINCT " + PlanoRiscosData.IS_PATRIMONIAL_FULL + " ) > 1"
|
|
},
|
|
where,
|
|
null, new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11",
|
|
"12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24",
|
|
"25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37" },
|
|
null, null
|
|
);
|
|
query.disableOrderFieldsVerification();
|
|
return query;
|
|
}
|
|
|
|
private Expression getWhereExpression( String nome, String estabelecimento, String dataVisita )
|
|
{
|
|
Expression result = new Field( PlanosActuacaoData.DELETED_DATE_FULL ).isEqual( null );
|
|
if ( nome != null )
|
|
{
|
|
nome = StringPlainer.convertString( nome.trim() );
|
|
nome = nome.replaceAll( " ", "%" );
|
|
result = result.and( new Par(
|
|
new Field( "plain_utf8( " + PlanosActuacaoData.TECNICO_HS_NOME_FULL + " )" ).isLike( "%" + nome + "%" )
|
|
.or( new Field( "plain_utf8( " + PlanosActuacaoData.TECNICO_SUPERIOR_HS_NOME_FULL + " )" ).isLike( "%" + nome + "%" ) )
|
|
) );
|
|
}
|
|
if ( estabelecimento != null )
|
|
{
|
|
estabelecimento = StringPlainer.convertString( estabelecimento.trim() );
|
|
estabelecimento = estabelecimento.replaceAll( " ", "%" );
|
|
result = result.and( new Field( "plain_utf8( " + PlanosActuacaoData.NOME_ESTABELECIMENTO_FULL + " )" ).isLike( "%" + estabelecimento + "%" ) );
|
|
}
|
|
if ( dataVisita != null )
|
|
{
|
|
result = result.and( new Field( PlanosActuacaoData.DATA_VISITA_FULL ).isEqual( dataVisita ) );
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
public List< PlanoActuacao > searchPlanosActivos( Utilizador u, String nome, String estabelecimento, String dataVisita, Integer ano )
|
|
throws Exception
|
|
{
|
|
System.out.println( "\nPlanosDataProvider . searchPlanosActivos() : " );
|
|
|
|
Select2 query = getExpression( SECTION.ACTIVOS, u, nome, estabelecimento, dataVisita, ano );
|
|
System.out.println( "\tSQL : " + query );
|
|
|
|
Virtual2DArray array = getExecuter().executeQuery( query );
|
|
return getFullPlanos( array );
|
|
|
|
}
|
|
|
|
public List< PlanoActuacao > searchPlanosSeguimento( Utilizador u, String nome, String estabelecimento, String dataVisita, Integer ano )
|
|
throws Exception
|
|
{
|
|
System.out.println( "\nPlanosDataProvider . searchPlanosSeguimento() : " );
|
|
|
|
Select2 query = getExpression( SECTION.SEGUIMENTO, u, nome, estabelecimento, dataVisita, ano );
|
|
System.out.println( "\tSQL : " + query );
|
|
|
|
Virtual2DArray array = getExecuter().executeQuery( query );
|
|
return getFullPlanos( array );
|
|
}
|
|
|
|
public List< PlanoActuacao > searchPlanosConcluidos( Utilizador u, String nome, String estabelecimento, String dataVisita, Integer ano )
|
|
throws Exception
|
|
{
|
|
System.out.println( "\nPlanosDataProvider . searchPlanosConcluidos() : " );
|
|
|
|
Select2 query = getExpression( SECTION.CONCLUIDOS, u, nome, estabelecimento, dataVisita, ano );
|
|
System.out.println( "\tSQL : " + query );
|
|
|
|
Virtual2DArray array = getExecuter().executeQuery( query );
|
|
return getFullPlanos( array );
|
|
}
|
|
|
|
|
|
|
|
private Expression getFaseActivos( Utilizador u )
|
|
{
|
|
Expression result = null;
|
|
int userType = u.getTipo();
|
|
switch ( userType )
|
|
{
|
|
case Global.TECNICO_HS :
|
|
result = new Par(
|
|
new Field( "fase" ).isEqual( 1 )
|
|
.or( new Field( "fase" ).isEqual( 5 ) )
|
|
);
|
|
break;
|
|
case Global.RESPONSAVEL_SEGURANCA :
|
|
result = new Field( "fase" ).isEqual( 2 );
|
|
break;
|
|
case Global.DIRECTOR_LOJA :
|
|
result = new Field( "fase" ).isEqual( 3 );
|
|
break;
|
|
case Global.DIRECTOR_NACIONAL_SEGURANCA :
|
|
result = new Field( "fase" ).isEqual( 4 );
|
|
break;
|
|
}
|
|
if ( userType != Global.DIRECTOR_SIPRP && userType != Global.TECNICO_HS && userType != Global.DIRECTOR_NACIONAL_SEGURANCA )
|
|
{
|
|
Expression expr = new Field( "estabelecimento_id" ).isEqual( u.getEstabelecimento_id() );
|
|
result = result == null ? expr : result.and( expr );
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private Expression getFaseSeguimento( Utilizador u )
|
|
{
|
|
Expression result = null;
|
|
int userType = u.getTipo();
|
|
switch ( userType )
|
|
{
|
|
case Global.TECNICO_HS :
|
|
result = new Par(
|
|
new Field( "fase" ).isDifferent( 1 )
|
|
.and( new Field( "fase" ).isDifferent( 5 ) )
|
|
.and( new Field( "fase" ).isDifferent( 6 ) )
|
|
);
|
|
break;
|
|
case Global.RESPONSAVEL_SEGURANCA :
|
|
result = new Par(
|
|
new Field( "fase" ).isDifferent( 2 )
|
|
.and( new Field( "fase" ).isDifferent( 6 ) )
|
|
);
|
|
break;
|
|
case Global.DIRECTOR_LOJA :
|
|
result = new Par(
|
|
new Field( "fase" ).isDifferent( 3 )
|
|
.and( new Field( "fase" ).isDifferent( 6 ) )
|
|
);
|
|
break;
|
|
case Global.DIRECTOR_NACIONAL_SEGURANCA :
|
|
result = new Par(
|
|
new Field( "fase" ).isDifferent( 4 )
|
|
.and( new Field( "fase" ).isDifferent( 6 ) )
|
|
);
|
|
break;
|
|
case Global.DIRECTOR_SIPRP :
|
|
case Global.RH :
|
|
case Global.DIRECTOR_GERAL_RH :
|
|
case Global.GESTOR :
|
|
result = new Par(
|
|
new Field( "fase" ).isGreater( 1 )
|
|
.and( new Field( "fase" ).isLess( 6 ) )
|
|
);
|
|
break;
|
|
}
|
|
|
|
if ( userType != Global.DIRECTOR_SIPRP && userType != Global.TECNICO_HS
|
|
&& userType != Global.DIRECTOR_NACIONAL_SEGURANCA && userType != Global.DIRECTOR_GERAL_RH
|
|
&& userType != Global.GESTOR )
|
|
{
|
|
Expression expr = new Field( "estabelecimento_id" ).isEqual( u.getEstabelecimento_id() );
|
|
result = result == null ? expr : result.and( expr );
|
|
}
|
|
if ( userType == Global.GESTOR )
|
|
{
|
|
if ( u.getEstabelecimento_gestor() > 0 )
|
|
{
|
|
Expression expr = new Field( "estabelecimento_id" ).isEqual( u.getEstabelecimento_gestor() );
|
|
result = result.and( expr );
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private Expression getFaseConcluidos( Utilizador u )
|
|
{
|
|
Expression result = new Field( "fase" ).isEqual( 6 );
|
|
int userType = u.getTipo();
|
|
if ( userType != Global.DIRECTOR_SIPRP && userType != Global.TECNICO_HS
|
|
&& userType != Global.DIRECTOR_NACIONAL_SEGURANCA && userType != Global.DIRECTOR_GERAL_RH
|
|
&& userType != Global.GESTOR )
|
|
{
|
|
result = result.and( new Field( "estabelecimento_id" ).isEqual( u.getEstabelecimento_id() ) );
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private List< PlanoActuacao > getFullPlanos( Virtual2DArray array )
|
|
{
|
|
List< PlanoActuacao > result = new LinkedList< PlanoActuacao >();
|
|
if ( array != null )
|
|
{
|
|
for ( int i = 0; i < array.rowCount(); i++ )
|
|
{
|
|
Integer estabelecimentoID = array.get( i, 0 );
|
|
Integer fase = array.get( i, 1 );
|
|
Date dataVisita = array.get( i, 2 );
|
|
String nomeEstabelecimento = array.get( i, 3 );
|
|
Boolean validacaoDirectorLoja = array.get( i, 4 );
|
|
Boolean validacaoDNS = array.get( i, 5 );
|
|
Boolean validacaoHS = array.get( i, 6 );
|
|
String observacaoCorreccao = array.get( i, 8 );
|
|
Date dataValidacaoDirectorLoja = array.get( i, 9 );
|
|
Integer userDirectorLoja = array.get( i, 10 );
|
|
Date dataValidacaoDNS = array.get( i, 11 );
|
|
Integer userDNS = array.get( i, 12 );
|
|
Date dataValidacaoHS = array.get( i, 13 );
|
|
Integer userHS = array.get( i, 14 );
|
|
Integer faseAntesCorreccao = array.get( i, 15 );
|
|
String correccao = array.get( i, 16 );
|
|
String observacoesDL = array.get( i, 17 );
|
|
String observacoesDNS = array.get( i, 18 );
|
|
String nomeEmpresa = array.get( i, 23 );
|
|
Integer tecnicoHSID = array.get( i, 24 );
|
|
String tecnicoHSNome = array.get( i, 25 );
|
|
Integer id = array.get( i, 26 );
|
|
Boolean concluidoPorDesactivacao = array.get( i, 29 );
|
|
Integer tecnicoSuperiorHSID = array.get( i, 30 );
|
|
String tecnicoSuperiorHSNome = array.get( i, 31 );
|
|
Date dataDesactivacao = array.get( i, 32 );
|
|
Date dataDisponibilizacao = array.get( i, 33 );
|
|
Date dataValidacaoSeg = array.get( i, 34 );
|
|
Integer userSeg = array.get( i, 35 );
|
|
Integer hsRelatorioID = array.get( i, 36 );
|
|
Boolean temPatrimoniais = array.get( i, 37 );
|
|
|
|
PlanoActuacao pa = new PlanoActuacao();
|
|
pa.setId( id );
|
|
pa.setEstabelecimento_id( estabelecimentoID );
|
|
pa.setNome_estabelecimento( Utils.unicodeToHTML( nomeEstabelecimento ) );
|
|
pa.setNome_empresa( Utils.unicodeToHTML( nomeEmpresa ) );
|
|
pa.setFase( fase );
|
|
pa.setData_visita( dataVisita );
|
|
pa.setValidacao_director_loja( validacaoDirectorLoja );
|
|
pa.setValidacao_dns( validacaoDNS );
|
|
pa.setValidacao_hs( validacaoHS );
|
|
pa.setObservacoes_dl( Utils.unicodeToHTML( observacoesDL ) );
|
|
pa.setObservacoes_dns( Utils.unicodeToHTML( observacoesDNS ) );
|
|
pa.setObs_correcao( Utils.unicodeToHTML( observacaoCorreccao ) );
|
|
pa.setAreas( getAreasByPlanoID( id ) );
|
|
pa.setTotal_riscos( getTotalRiscosByPlanoID( id ) );
|
|
pa.setCorrecao( Utils.unicodeToHTML( correccao ) );
|
|
pa.setFase_antes_correcao( faseAntesCorreccao );
|
|
pa.setData_validacao_dir_loja( dataValidacaoDirectorLoja );
|
|
pa.setUser_dir_loja( userDirectorLoja );
|
|
pa.setData_validacao_dns( dataValidacaoDNS );
|
|
pa.setUser_dns( userDNS );
|
|
pa.setData_validacao_hs( dataValidacaoHS );
|
|
pa.setUser_hs( userHS );
|
|
pa.setTecnico_hs_id( tecnicoHSID );
|
|
pa.setTecnico_hs_nome( Utils.unicodeToHTML( tecnicoHSNome ) );
|
|
pa.setConcluidoPorDesactivacao( concluidoPorDesactivacao );
|
|
pa.setDataDesactivacao( dataDesactivacao );
|
|
pa.setTecnico_superior_hs_id( tecnicoSuperiorHSID );
|
|
pa.setTecnico_superior_hs_nome( Utils.unicodeToHTML( tecnicoSuperiorHSNome ) );
|
|
pa.setData_disponibilizacao( dataDisponibilizacao );
|
|
pa.setData_validacao_seg( dataValidacaoSeg );
|
|
pa.setUser_seg( userSeg );
|
|
pa.setHs_relatorio_id( hsRelatorioID );
|
|
pa.setTem_patrimoniais( temPatrimoniais );
|
|
|
|
result.add( pa );
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
private List< Area > getAreasByPlanoID( final Integer planoID )
|
|
{
|
|
List< Area > list = new LinkedList< Area >();
|
|
try
|
|
{
|
|
Select2 query = new Select2( PlanoAreasData.TABLENAME,
|
|
new Field( PlanoAreasData.PLANO_ID_FULL ).isEqual( planoID ),
|
|
new String[] { PlanoAreasData.ID_FULL, PlanoAreasData.PLANO_ID_FULL, PlanoAreasData.DESCRICAO_FULL,
|
|
PlanoAreasData.ORDEM_FULL, PlanoAreasData.IS_PRINCIPAL_FULL },
|
|
new String[] { PlanoAreasData.DESCRICAO_FULL }
|
|
);
|
|
Virtual2DArray array = getExecuter().executeQuery( query );
|
|
if ( array != null && array.rowCount() > 0 )
|
|
{
|
|
for ( int i = 0; i < array.rowCount(); i++ )
|
|
{
|
|
Integer areaID = array.get( i, 0 );
|
|
Integer pID = array.get( i, 1 );
|
|
String descricao = array.get( i, 2 );
|
|
Integer ordem = array.get( i, 3 );
|
|
Boolean isPrincipal = array.get( i, 4 );
|
|
|
|
Area area = new Area();
|
|
area.setId( areaID );
|
|
area.setPlano_id( pID );
|
|
area.setDescricao( Utils.unicodeToHTML( descricao ) );
|
|
area.setOrdem( ordem );
|
|
area.setIs_principal( isPrincipal );
|
|
area.setRiscos( getRiscosByArea( area ) );
|
|
list.add( area );
|
|
}
|
|
}
|
|
}
|
|
catch ( Exception e )
|
|
{
|
|
ErrorLogger.logException( e );
|
|
}
|
|
Collections.sort( list );
|
|
return list;
|
|
}
|
|
|
|
/**
|
|
* FIXME : ORDER BY patrimonial em ultimo !
|
|
*/
|
|
private List< Risco > getRiscosByArea( Area a ) throws Exception
|
|
{
|
|
List< Risco > list = new LinkedList< Risco >();
|
|
|
|
Select2 query = new Select2(
|
|
PlanoRiscosData.TABLENAME,
|
|
new Field( PlanoRiscosData.AREA_ID_FULL ).isEqual( a.getId() ),
|
|
new String[] {
|
|
PlanoRiscosData.ID_FULL, PlanoRiscosData.AREA_ID_FULL, PlanoRiscosData.DESCRICAO_FULL, PlanoRiscosData.RESPONSAVEL_EXECUCAO_FULL,
|
|
PlanoRiscosData.POR_FULL, PlanoRiscosData.RECURSOS_NECESSARIOS_FULL, PlanoRiscosData.DATA_INICIO_FULL, PlanoRiscosData.DATA_FIM_FULL,
|
|
PlanoRiscosData.PARECER_DL_FULL, PlanoRiscosData.PARECER_DNS_FULL, PlanoRiscosData.VERIFICACAO_SIPRP_FULL, PlanoRiscosData.VALOR_FULL,
|
|
PlanoRiscosData.IS_PATRIMONIAL_FULL, PlanoRiscosData.VALOR_QUALITATIVO_ID, "coalesce( valor, -1 ) AS ordem_valor",
|
|
},
|
|
new String[] { "ordem_valor DESC", PlanoRiscosData.AREA_ID_FULL, PlanoRiscosData.RISCO_ID_FULL }
|
|
);
|
|
query.disableOrderFieldsVerification();
|
|
|
|
Virtual2DArray array = getExecuter().executeQuery( query );
|
|
if ( array != null && array.rowCount() > 0 )
|
|
{
|
|
for ( int i = 0; i < array.rowCount(); i++ )
|
|
{
|
|
Integer riscoID = array.get( i, 0 );
|
|
Integer areaID = array.get( i, 1 );
|
|
String descricao = array.get( i, 2 );
|
|
String responsavelExecucao = array.get( i, 3 );
|
|
String por = array.get( i, 4 );
|
|
String recursosNecessarios = array.get( i, 5 );
|
|
Date dataInicio = array.get( i, 6 );
|
|
Date dataFim = array.get( i, 7 );
|
|
String parecerDL = array.get( i, 8 );
|
|
String parecerDNS = array.get( i, 9 );
|
|
String verificacaoSiprp = array.get( i, 10 );
|
|
Integer valor = array.get( i, 11 );
|
|
Boolean isPatrimonial = array.get( i, 12 );
|
|
Integer valorQualitativoID = array.get( i, 13 );
|
|
|
|
Risco r = new Risco();
|
|
r.setId( riscoID );
|
|
r.setArea_id( areaID );
|
|
r.setDescricao( Utils.unicodeToHTML( descricao ) );
|
|
r.setResponsavel_execucao( Utils.unicodeToHTML( responsavelExecucao ) );
|
|
r.setPor( por );
|
|
r.setRecursos_necessarios( Utils.unicodeToHTML( recursosNecessarios ) );
|
|
r.setData_inicio( dataInicio );
|
|
r.setData_fim( dataFim );
|
|
r.setParecer_dl( Utils.unicodeToHTML( parecerDL ) );
|
|
r.setParecer_dns( Utils.unicodeToHTML( parecerDNS ) );
|
|
r.setVerificacao_siprp( Utils.unicodeToHTML( verificacaoSiprp ) );
|
|
r.setValorQuantitativo( valor );
|
|
r.setMedidas( getMedidasByRisco( r ) );
|
|
r.setIsPatrimonial( isPatrimonial );
|
|
r.setValorQualitativoID( valorQualitativoID );
|
|
if( valorQualitativoID != null )
|
|
{
|
|
r.setValorQualitativo( loadValorQualitativoByID( valorQualitativoID ).getDescricao() );
|
|
}
|
|
list.add( r );
|
|
}
|
|
}
|
|
Collections.sort( list, new Comparator<Risco>(){
|
|
|
|
@Override
|
|
public int compare( Risco o1, Risco o2 )
|
|
{
|
|
Integer o1Value = 1000;
|
|
Integer o2Value = 1000;
|
|
if( o1.getValorQuantitativo() != null )
|
|
{
|
|
o1Value = -o1.getValorQuantitativo();
|
|
}
|
|
else if(o1.getValorQualitativo() == null)
|
|
{
|
|
o1Value = 300;
|
|
}
|
|
else if(o1.getValorQualitativo().equals(UNCONTROLLED) || o1.getValorQualitativo().equals(MUITO_ALTO))
|
|
{
|
|
o1Value = 100;
|
|
}
|
|
else if(o1.getValorQualitativo().equals(CONTROLLED) || o1.getValorQualitativo().equals(ALTO))
|
|
{
|
|
o1Value = 200;
|
|
}
|
|
else if(o1.getValorQualitativo().equals(INDETERMINATE) || o1.getValorQualitativo().equals(MEDIO))
|
|
{
|
|
o1Value = 300;
|
|
}
|
|
else if(o1.getValorQualitativo().equals(BAIXO))
|
|
{
|
|
o1Value = 400;
|
|
}
|
|
if( o2.getValorQuantitativo() != null )
|
|
{
|
|
o2Value = -o2.getValorQuantitativo();
|
|
}
|
|
else if(o2.getValorQualitativo() == null )
|
|
{
|
|
o2Value = 300;
|
|
}
|
|
else if(o2.getValorQualitativo().equals(UNCONTROLLED) || o2.getValorQualitativo().equals(MUITO_ALTO))
|
|
{
|
|
o2Value = 100;
|
|
}
|
|
else if(o2.getValorQualitativo().equals(CONTROLLED) || o2.getValorQualitativo().equals(ALTO))
|
|
{
|
|
o2Value = 200;
|
|
}
|
|
else if(o2.getValorQualitativo().equals(INDETERMINATE) || o2.getValorQualitativo().equals(MEDIO))
|
|
{
|
|
o2Value = 300;
|
|
}
|
|
else if(o2.getValorQualitativo().equals(BAIXO))
|
|
{
|
|
o2Value = 400;
|
|
}
|
|
return o1Value.compareTo(o2Value);
|
|
}
|
|
|
|
} );
|
|
return list;
|
|
}
|
|
|
|
|
|
private List< Medida > getMedidasByRisco( Risco r ) throws Exception
|
|
{
|
|
List< Medida > list = new LinkedList< Medida >();
|
|
|
|
Select2 query = new Select2( PlanoMedidasData.TABLENAME,
|
|
new Field( PlanoMedidasData.RISCO_ID_FULL ).isEqual( r.getId() ),
|
|
new String[] {
|
|
PlanoMedidasData.ID_FULL, PlanoMedidasData.DESCRICAO_FULL, PlanoMedidasData.ESTADO_MEDIDAS_ID_FULL
|
|
},
|
|
new String[] { PlanoMedidasData.ID_FULL }
|
|
);
|
|
Virtual2DArray array = getExecuter().executeQuery( query );
|
|
if ( array != null )
|
|
{
|
|
for ( int i = 0; i < array.rowCount(); i++ )
|
|
{
|
|
Integer planoMedidaID = array.get( i, 0 );
|
|
String descricao = array.get( i, 1 );
|
|
Integer estado = array.get( i, 2 );
|
|
|
|
Medida m = new Medida();
|
|
m.setId( planoMedidaID );
|
|
m.setDescricao( Utils.unicodeToHTML( descricao ) );
|
|
m.setValidarMedidaId( estado );
|
|
m.setPostos( getPostosByMedida( m ) );
|
|
|
|
list.add( m );
|
|
}
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
private List< PostoTrabalho > getPostosByMedida( Medida m ) throws Exception
|
|
{
|
|
List< PostoTrabalho > list = new LinkedList< PostoTrabalho >();
|
|
|
|
Select2 query = new Select2( PlanoPostosTrabalhoData.TABLENAME,
|
|
new Field( PlanoPostosTrabalhoData.MEDIDA_ID_FULL ).isEqual( m.getId() ),
|
|
new String[] { PlanoPostosTrabalhoData.ID_FULL, PlanoPostosTrabalhoData.MEDIDA_ID_FULL,
|
|
PlanoPostosTrabalhoData.DESCRICAO_FULL, PlanoPostosTrabalhoData.IS_PRINCIPAL_FULL },
|
|
new String[] { PlanoPostosTrabalhoData.ID_FULL }
|
|
);
|
|
Virtual2DArray array = getExecuter().executeQuery( query );
|
|
if ( array != null )
|
|
{
|
|
for ( int i = 0; i < array.rowCount(); i++ )
|
|
{
|
|
Integer planoPostoTrabalhoID = array.get( i, 0 );
|
|
Integer medidaID = array.get( i, 1 );
|
|
String descricao = array.get( i, 2 );
|
|
Boolean isPrincipal = array.get( i, 3 );
|
|
|
|
PostoTrabalho p = new PostoTrabalho();
|
|
p.setId( planoPostoTrabalhoID );
|
|
p.setMedida_id( medidaID );
|
|
p.setDescricao( Utils.unicodeToHTML( descricao ) );
|
|
p.setIs_principal( isPrincipal );
|
|
list.add( p );
|
|
}
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
private int getTotalRiscosByPlanoID( Integer planoID )
|
|
{
|
|
int count = 0;
|
|
try
|
|
{
|
|
Select2 query = new Select2(
|
|
new String[] { PlanoRiscosData.TABLENAME, PlanoAreasData.TABLENAME, PlanosActuacaoData.TABLENAME },
|
|
new Integer[] { Select2.JOIN_INNER, Select2.JOIN_INNER },
|
|
new Expression[] {
|
|
new Field( PlanoRiscosData.AREA_ID_FULL ).isEqual( new Field( PlanoAreasData.ID_FULL ) ),
|
|
new Field( PlanoAreasData.PLANO_ID_FULL ).isEqual( new Field( PlanosActuacaoData.ID_FULL ) )
|
|
},
|
|
new String[] {
|
|
"COUNT( " + PlanoRiscosData.ID_FULL + " ) AS total_riscos"
|
|
},
|
|
new Field( PlanosActuacaoData.ID_FULL ).isEqual( planoID ).and(
|
|
new Field( PlanosActuacaoData.DELETED_DATE_FULL ).isEqual( null )
|
|
),
|
|
new String[] {},
|
|
null,
|
|
null,
|
|
null
|
|
);
|
|
Virtual2DArray array = getExecuter().executeQuery( query );
|
|
if ( array != null && array.rowCount() > 0 )
|
|
{
|
|
Long countL = array.get( 0, 0 );
|
|
count = countL == null ? 0 : countL.intValue();
|
|
}
|
|
}
|
|
catch ( Exception e )
|
|
{
|
|
ErrorLogger.logException( e );
|
|
}
|
|
return count;
|
|
}
|
|
|
|
public List< EstadoMedida > getEstadoMedidas() throws Exception
|
|
{
|
|
List< EstadoMedida > list = new LinkedList< EstadoMedida >();
|
|
|
|
Select2 query = new Select2( EstadoMedidasData.TABLENAME,
|
|
new Field( EstadoMedidasData.ACTIVO_FULL ).isEqual( "y" ),
|
|
new String[] {
|
|
EstadoMedidasData.ID_FULL, EstadoMedidasData.DESCRICAO_FULL, EstadoMedidasData.ORDEM_FULL,
|
|
EstadoMedidasData.ACTIVO_FULL
|
|
},
|
|
new String[] { EstadoMedidasData.ORDEM_FULL + " ASC" }
|
|
);
|
|
Virtual2DArray array = getExecuter().executeQuery( query );
|
|
if ( array != null )
|
|
{
|
|
for ( int i = 0; i < array.rowCount(); i++ )
|
|
{
|
|
Integer estadoID = array.get( i, 0 );
|
|
String descricao = array.get( i, 1 );
|
|
|
|
EstadoMedida estado = new EstadoMedida();
|
|
estado.setId( estadoID );
|
|
estado.setDescricao( Utils.unicodeToHTML( descricao ) );
|
|
list.add( estado );
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public void loadValoresQualitativos() throws Exception
|
|
{
|
|
VALORES_QUALITATIVOS_BY_ID.clear();
|
|
List<PlanoValoresQualitativosData> valores = getAllValoresQualitativos();
|
|
for( PlanoValoresQualitativosData valor : valores )
|
|
{
|
|
VALORES_QUALITATIVOS_BY_ID.put( valor.getId(), valor);
|
|
}
|
|
}
|
|
|
|
public List<PlanoValoresQualitativosData> getAllValoresQualitativos() throws Exception
|
|
{
|
|
return getProvider().listLoad( PlanoValoresQualitativosData.class, PlanoValoresQualitativosData.ID );
|
|
}
|
|
|
|
public PlanoValoresQualitativosData loadValorQualitativoByID( Integer valorID ) throws Exception
|
|
{
|
|
if( !VALORES_QUALITATIVOS_BY_ID.containsKey( valorID) )
|
|
{
|
|
loadValoresQualitativos();
|
|
}
|
|
return VALORES_QUALITATIVOS_BY_ID.get( valorID );
|
|
}
|
|
|
|
public List<Integer> getDistinctYears( Integer excludeYear ) throws Exception
|
|
{
|
|
List<Integer> result = new LinkedList<Integer>();
|
|
|
|
Expression where = new Field( "deleted_date" ).isEqual( null );
|
|
if ( excludeYear != null )
|
|
{
|
|
where = where.and( new Field( "EXTRACT( year FROM data_visita )" ).notIn( new Integer[] { excludeYear } ) );
|
|
}
|
|
Select2 query = new Select2(
|
|
new String[] { "planos_actuacao" },
|
|
new Integer[] { },
|
|
new Expression[] { },
|
|
new String[] { "DISTINCT( cast( EXTRACT( year FROM data_visita ) as integer ) ) AS ano" },
|
|
where,
|
|
new String[] { "ano DESC" },
|
|
null, null, null );
|
|
query.disableOrderFieldsVerification();
|
|
Virtual2DArray array = getExecuter().executeQuery( query );
|
|
for ( int i = 0; i < array.rowCount(); i++ )
|
|
{
|
|
Integer ano = array.get( i, 0 );
|
|
result.add( ano );
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public List<LinhaEstatistica> getEstatisticaForPlanoId( Integer planoId )
|
|
throws Exception
|
|
{
|
|
Select select =
|
|
new Select2( new String[]{ PlanoAreasData.TABLENAME, PlanoRiscosData.TABLENAME, PlanoMedidasData.TABLENAME,
|
|
EstadoMedidasData.TABLENAME, PlanoValoresQualitativosData.TABLENAME },
|
|
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_LEFT_OUTER, Select2.JOIN_LEFT_OUTER },
|
|
new Expression[]{
|
|
new Field( PlanoAreasData.ID_FULL ).isEqual( new Field( PlanoRiscosData.AREA_ID_FULL ) ),
|
|
new Field( PlanoRiscosData.ID_FULL ).isEqual( new Field( PlanoMedidasData.RISCO_ID_FULL ) ),
|
|
new Field( EstadoMedidasData.ID_FULL ).isEqual( new Field( PlanoMedidasData.ESTADO_MEDIDAS_ID_FULL ) ),
|
|
new Field( PlanoValoresQualitativosData.ID_FULL ).isEqual( new Field( PlanoRiscosData.VALOR_QUALITATIVO_ID_FULL ) ),
|
|
},
|
|
new String[]{ "COALESCE( " + EstadoMedidasData.DESCRICAO_FULL + ", 'n.d.' )",
|
|
"COALESCE( ''|| " + PlanoRiscosData.VALOR_FULL + "," + PlanoValoresQualitativosData.DESCRICAO_FULL + " )",
|
|
"COUNT( * )",
|
|
EstadoMedidasData.ORDEM_FULL,
|
|
PlanoRiscosData.VALOR_FULL },
|
|
new Field( PlanoAreasData.PLANO_ID_FULL ).isEqual( planoId),
|
|
new String[]{ "4", "5", "2" },
|
|
new String[]{ "1", "4", "2", "5" },
|
|
null,
|
|
null ) ;
|
|
select.disableOrderFieldsVerification();
|
|
Virtual2DArray array = getExecuter().executeQuery( select );
|
|
List<LinhaEstatistica> linhas = new ArrayList<LinhaEstatistica>();
|
|
int total = 0;
|
|
String last = null;
|
|
int totalEstado = 0;
|
|
for( int n = 0; n < array.rowCount(); n++ )
|
|
{
|
|
String estado = array.get( n, 0 );
|
|
if( last == null ? estado != null : !last.equals( estado ) )
|
|
{
|
|
if( totalEstado > 0 )
|
|
{
|
|
linhas.add( new LinhaEstatistica( "", "TOTAL", 0, totalEstado ) );
|
|
}
|
|
last = estado;
|
|
totalEstado = 0;
|
|
}
|
|
else
|
|
{
|
|
estado = "";
|
|
}
|
|
String valoracao = array.get( n, 1 );
|
|
Integer count = ( ( Number ) array.get( n, 2 ) ).intValue();
|
|
total += count;
|
|
totalEstado += count;
|
|
linhas.add( new LinhaEstatistica( estado, valoracao, 0, count) );
|
|
}
|
|
linhas.add( new LinhaEstatistica( "", "TOTAL", 0, totalEstado ) );
|
|
for( LinhaEstatistica linha : linhas )
|
|
{
|
|
linha.setPercentagem( ( int ) Math.round( linha.getQuantidade().doubleValue() * 100.0 / (double) total ) );
|
|
}
|
|
linhas.add( new LinhaEstatistica( "TOTAL", "", 100, total ) );
|
|
return linhas;
|
|
}
|
|
|
|
public List<LinhaEstatistica> getEstatisticaForEstabelecimentoIdAndDateInterval( Integer estabelecimentoId, Date dataInicio, Date dataFim )
|
|
throws Exception
|
|
{
|
|
Expression expr = null;
|
|
if( estabelecimentoId != null )
|
|
{
|
|
expr = new Field( PlanosActuacaoData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimentoId);
|
|
}
|
|
if( dataInicio != null )
|
|
{
|
|
Expression diExpr = new Field( PlanosActuacaoData.DATA_VISITA_FULL ).isGreaterOrEqual( dataInicio);
|
|
if( expr != null )
|
|
{
|
|
expr = expr.and( diExpr);
|
|
}
|
|
else
|
|
{
|
|
expr = diExpr;
|
|
}
|
|
}
|
|
if( dataFim != null )
|
|
{
|
|
Expression dfExpr = new Field( PlanosActuacaoData.DATA_VISITA_FULL ).isLessOrEqual( dataFim);
|
|
if( expr != null )
|
|
{
|
|
expr = expr.and( dfExpr);
|
|
}
|
|
else
|
|
{
|
|
expr = dfExpr;
|
|
}
|
|
}
|
|
Select select =
|
|
new Select2( new String[]{ PlanosActuacaoData.TABLENAME, PlanoAreasData.TABLENAME, PlanoRiscosData.TABLENAME,
|
|
PlanoMedidasData.TABLENAME, EstadoMedidasData.TABLENAME, PlanoValoresQualitativosData.TABLENAME },
|
|
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_LEFT_OUTER, Select2.JOIN_LEFT_OUTER },
|
|
new Expression[]{
|
|
new Field( PlanosActuacaoData.ID_FULL ).isEqual( new Field( PlanoAreasData.PLANO_ID_FULL ) ),
|
|
new Field( PlanoAreasData.ID_FULL ).isEqual( new Field( PlanoRiscosData.AREA_ID_FULL ) ),
|
|
new Field( PlanoRiscosData.ID_FULL ).isEqual( new Field( PlanoMedidasData.RISCO_ID_FULL ) ),
|
|
new Field( EstadoMedidasData.ID_FULL ).isEqual( new Field( PlanoMedidasData.ESTADO_MEDIDAS_ID_FULL ) ),
|
|
new Field( PlanoValoresQualitativosData.ID_FULL ).isEqual( new Field( PlanoRiscosData.VALOR_QUALITATIVO_ID_FULL ) ),
|
|
},
|
|
new String[]{ "COALESCE( " + EstadoMedidasData.DESCRICAO_FULL + ", 'n.d.' )",
|
|
"COALESCE( ''|| " + PlanoRiscosData.VALOR_FULL + "," + PlanoValoresQualitativosData.DESCRICAO_FULL + " )",
|
|
"COUNT( * )",
|
|
EstadoMedidasData.ORDEM_FULL,
|
|
PlanoRiscosData.VALOR_FULL },
|
|
expr,
|
|
new String[]{ "4", "5", "2" },
|
|
new String[]{ "1", "4", "2", "5" },
|
|
null,
|
|
null ) ;
|
|
select.disableOrderFieldsVerification();
|
|
Virtual2DArray array = getExecuter().executeQuery( select );
|
|
List<LinhaEstatistica> linhas = new ArrayList<LinhaEstatistica>();
|
|
int total = 0;
|
|
String last = null;
|
|
int totalEstado = 0;
|
|
for( int n = 0; n < array.rowCount(); n++ )
|
|
{
|
|
String estado = array.get( n, 0 );
|
|
if( last == null ? estado != null : !last.equals( estado ) )
|
|
{
|
|
if( totalEstado > 0 )
|
|
{
|
|
linhas.add( new LinhaEstatistica( "", "TOTAL", 0, totalEstado ) );
|
|
}
|
|
last = estado;
|
|
totalEstado = 0;
|
|
}
|
|
else
|
|
{
|
|
estado = "";
|
|
}
|
|
String valoracao = array.get( n, 1 );
|
|
Integer count = ( ( Number ) array.get( n, 2 ) ).intValue();
|
|
total += count;
|
|
totalEstado += count;
|
|
linhas.add( new LinhaEstatistica( estado, valoracao, 0, count) );
|
|
}
|
|
linhas.add( new LinhaEstatistica( "", "TOTAL", 0, totalEstado ) );
|
|
for( LinhaEstatistica linha : linhas )
|
|
{
|
|
linha.setPercentagem( ( int ) Math.round( linha.getQuantidade().doubleValue() * 100.0 / (double) total ) );
|
|
}
|
|
linhas.add( new LinhaEstatistica( "TOTAL", "", 100, total ) );
|
|
return linhas;
|
|
}
|
|
|
|
public List<Mappable> getEstabelecimentosForEstatistica( Utilizador u )
|
|
throws Exception
|
|
{
|
|
Expression exp = new Field( db.data.siprp_local.outer.EstabelecimentosData.EMPRESA_ID_FULL ).isEqual( 32 ).and(
|
|
new Field( db.data.siprp_local.outer.EstabelecimentosData.INACTIVO_FULL ).isDifferent( "y" ) );
|
|
int userType = u.getTipo();
|
|
if ( userType != Global.DIRECTOR_SIPRP && userType != Global.TECNICO_HS
|
|
&& userType != Global.DIRECTOR_NACIONAL_SEGURANCA && userType != Global.DIRECTOR_GERAL_RH
|
|
&& userType != Global.GESTOR )
|
|
{
|
|
exp = exp.and( new Field( db.data.siprp_local.outer.EstabelecimentosData.ID_FULL ).isEqual( u.getEstabelecimento_id() ) );
|
|
}
|
|
Select select =
|
|
new Select2( new String[]{ db.data.siprp_local.outer.EstabelecimentosData.TABLENAME },
|
|
new Integer[]{},
|
|
new Expression[]{},
|
|
new String[]{ db.data.siprp_local.outer.EstabelecimentosData.ID_FULL, db.data.siprp_local.outer.EstabelecimentosData.NOME_FULL },
|
|
exp,
|
|
new String[]{ db.data.siprp_local.outer.EstabelecimentosData.NOME_FULL },
|
|
null,
|
|
null,
|
|
null);
|
|
Virtual2DArray array = getLocalExecuter().executeQuery( select );
|
|
List<Mappable> estabelecimentos = new ArrayList<Mappable>();
|
|
for( int n = 0; n < array.rowCount(); n++ )
|
|
{
|
|
estabelecimentos.add( new MappableObject( ( Integer ) array.get( n, 0), array.get( n, 1 ) ) );
|
|
}
|
|
return estabelecimentos;
|
|
}
|
|
}
|