From efa63453021b0529b4fe08ed619ddb1e01404ba9 Mon Sep 17 00:00:00 2001 From: Frederico Palma Date: Mon, 19 Jun 2006 16:42:01 +0000 Subject: [PATCH] no message git-svn-id: https://svn.coded.pt/svn/SIPRP@530 bb69d46d-e84e-40c8-a05a-06db0d633741 --- .../doGetListaTrabalhadoresPendentes.java | 152 ++++++++++++++---- 1 file changed, 122 insertions(+), 30 deletions(-) diff --git a/trunk/WEB-INF/classes/siprp/pagina/doGetListaTrabalhadoresPendentes.java b/trunk/WEB-INF/classes/siprp/pagina/doGetListaTrabalhadoresPendentes.java index 508a4ac0..22202ea9 100644 --- a/trunk/WEB-INF/classes/siprp/pagina/doGetListaTrabalhadoresPendentes.java +++ b/trunk/WEB-INF/classes/siprp/pagina/doGetListaTrabalhadoresPendentes.java @@ -26,7 +26,17 @@ import com.evolute.utils.strings.*; public class doGetListaTrabalhadoresPendentes extends siprpServlet { - protected java.util.Date today; + protected static final int ESTADO_NAO_SE_APLICA = 0; + protected static final int ESTADO_PENDENTE = 1; + protected static final int ESTADO_MARCADO = 2; + protected static final int ESTADO_TRATADO = 3; + + protected static int MOTIVO_ADMISSAO = 1; + protected static int MOTIVO_PERIODICA = 2; + protected static int MOTIVO_OCASIONAL = 3; + protected static int MOTIVO_PERIODICA_INICIAL = 5; + + protected java.sql.Date today; protected long todayMillis; /** Creates a new instance of doGetListaTrabalhadores */ @@ -42,11 +52,17 @@ public class doGetListaTrabalhadoresPendentes Vector links = new Vector(); Vector desc = new Vector(); Vector descAdicional = new Vector(); - today = new java.util.Date(); - todayMillis = today.getTime(); +// today = new java.util.Date(); +// todayMillis = today.getTime(); try { + stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); + rs = new ResultSet2DArray( stmt.executeQuery( "SELECT CURRENT_DATE" ) ); + today = ( java.sql.Date ) rs.get( 0, 0 ); + stmt.close(); + todayMillis = today.getTime(); + userRole = (String)session.getAttribute(super.sessionUserRole); empresaId = (String)session.getAttribute(super.sessionEmpresaId); estabelecimentoId = (String)session.getAttribute(super.sessionEstabelecimentoId); @@ -61,11 +77,12 @@ public class doGetListaTrabalhadoresPendentes //con = DriverManager.getConnection( super.bdUrl, super.bdUsername, super.bdPassword ); dbQuery = new StringBuffer(); dbQuery.append( "SELECT trabalhadores.id, trabalhadores.nome, " - + "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.realizada, " - + " trabalhadores.nome_plain " + + "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.estado, " + + " trabalhadores.nome_plain, marcacoes_trabalhador.motivo " + "FROM trabalhadores LEFT JOIN marcacoes_trabalhador ON ( marcacoes_trabalhador.trabalhador_id = trabalhadores.id )" + "WHERE estabelecimento_id = " + estabelecimentoId + " AND trabalhadores.inactivo <> 'y' AND data_demissao IS NULL " + + " AND marcacoes_trabalhador.estado NOT IN ( 3, 4, 5) " + "ORDER BY 6, 3, 4 DESC " ); // dbQuery.append( "SELECT id, nome, ( ultima_consulta IS NOT NULL AND realizada = 'y' )," // + " ( ultimo_exame IS NOT NULL AND realizado = 'y' )," @@ -94,8 +111,8 @@ public class doGetListaTrabalhadoresPendentes Integer id = index < max ? ( Integer ) rs.get( index, 0 ) : new Integer( -1 ); if( !id.equals( trabalhadorID ) ) { - Object listaConsultas[][] = ( Object[][] ) consultas.toArray( new Object[consultas.size()][2] ); - Object listaExames[][] = ( Object[][] ) exames.toArray( new Object[exames.size()][2] ); + Object listaConsultas[][] = ( Object[][] ) consultas.toArray( new Object[consultas.size()][3] ); + Object listaExames[][] = ( Object[][] ) exames.toArray( new Object[exames.size()][3] ); if( trabalhadorID.intValue() > -1 && verificarTrabalhador( listaConsultas, listaExames ) ) { @@ -116,10 +133,11 @@ public class doGetListaTrabalhadoresPendentes String nome = ( String ) rs.get( index, 1 ); java.util.Date data = ( java.util.Date ) rs.get( index, 3 ); - String realizada = ( String ) rs.get( index, 4 ); + Integer estado = ( Integer ) rs.get( index, 4 ); + Integer motivo = ( Integer ) rs.get( index, 6 ); trabalhadorID = id; nomeTrabalhador = nome; - Object marcacao[] = new Object[]{ data, realizada }; + Object marcacao[] = new Object[]{ data, estado, motivo }; if( tipo == null ) { continue; @@ -187,37 +205,111 @@ public class doGetListaTrabalhadoresPendentes } } -protected boolean verificarTrabalhador( Object consultas[][], Object exames[][] ) -{ - boolean estadoConsultas = false; - boolean estadoExames = ( exames.length == 0 ) || ( ( java.util.Date )exames[ 0 ][ 0 ] ).before(today) || - ( ( ( ( java.util.Date )exames[ 0 ][ 0 ] ).getTime() - todayMillis ) / 86400000 > 14 ); - if( consultas.length > 0 ) + protected int[] classificarTrabalhador( Object consultas[][], Object exames[][] ) { - int anterior; - int proxima; - if( ( (java.util.Date) consultas[ 0 ][ 0 ] ).after( today ) ) + int estado[] = new int[ 2 ]; + int indiceProximaConsulta = -1; + int indiceProximaConsultaPeriodica = -1; + int indiceConsultaAnterior = -1; + int indiceConsultaAnteriorPeriodica = -1; + int indiceProximoExame = -1; + int indiceExameAnterior = -1; + + if( consultas == null ) + { + estado[ 0 ] = ESTADO_NAO_SE_APLICA; + } + else if( consultas.length > 0 ) { - proxima = 0; - if( consultas.length >= 2 ) + if( !today.after( (java.util.Date) consultas[ 0 ][ 0 ] ) ) { - anterior = 1; + indiceProximaConsulta = 0; + if( ( ( Integer ) consultas[ 0 ][ 2 ] ).intValue() != MOTIVO_OCASIONAL ) + { + indiceProximaConsultaPeriodica = 0; + } } - else + for( int n = indiceProximaConsulta + 1; n < consultas.length; n++ ) { - anterior = -1; + if( today.after( (java.util.Date) consultas[ 0 ][ 0 ] ) && + ( ( Integer ) consultas[ 0 ][ 1 ] ).intValue() == 2 ) + { + if( indiceConsultaAnterior == -1 ) + { + indiceConsultaAnterior = n; + } + if( ( ( Integer ) consultas[ 0 ][ 2 ] ).intValue() != MOTIVO_OCASIONAL ) + { + indiceConsultaAnteriorPeriodica = n; + break; + } + } } +// estadoConsultas = anterior >= 0 && "y".equals( consultas[ anterior ][ 1 ] ) && +// ( proxima == -1 || ( ( ( java.util.Date )consultas[ proxima ][ 0 ] ).getTime() - todayMillis ) / 86400000 > 14 ); } - else + if( exames == null ) { - proxima = -1; - anterior = 0; + estado[ 1 ] = ESTADO_NAO_SE_APLICA; } - estadoConsultas = anterior >= 0 && "y".equals( consultas[ anterior ][ 1 ] ) && - ( proxima == -1 || ( ( ( java.util.Date )consultas[ proxima ][ 0 ] ).getTime() - todayMillis ) / 86400000 > 14 ); + else if( exames.length > 0 ) + { + if( !today.after( (java.util.Date) exames[ 0 ][ 0 ] ) ) + { + indiceProximoExame = 0; + } + for( int n = indiceProximoExame + 1; n < exames.length; n++ ) + { + if( today.after( (java.util.Date) exames[ 0 ][ 0 ] ) && + ( ( Integer ) exames[ 0 ][ 1 ] ).intValue() == 2 ) + { + indiceExameAnterior = n; + break; + } + } +// estadoConsultas = anterior >= 0 && "y".equals( consultas[ anterior ][ 1 ] ) && +// ( proxima == -1 || ( ( ( java.util.Date )consultas[ proxima ][ 0 ] ).getTime() - todayMillis ) / 86400000 > 14 ); + } + +// else +// { +// estado[ 0 ] = ESTADO_PENDENTE; +// } + + return estado; + } + + protected boolean verificarTrabalhador( Object consultas[][], Object exames[][] ) + { + boolean estadoConsultas = false; + boolean estadoExames = ( exames.length == 0 ) || ( ( java.util.Date )exames[ 0 ][ 0 ] ).before(today) || + ( ( ( ( java.util.Date )exames[ 0 ][ 0 ] ).getTime() - todayMillis ) / 86400000 > 14 ); + if( consultas.length > 0 ) + { + int anterior; + int proxima; + if( ( (java.util.Date) consultas[ 0 ][ 0 ] ).after( today ) ) + { + proxima = 0; + if( consultas.length >= 2 ) + { + anterior = 1; + } + else + { + anterior = -1; + } + } + else + { + proxima = -1; + anterior = 0; + } + estadoConsultas = anterior >= 0 && "y".equals( consultas[ anterior ][ 1 ] ) && + ( proxima == -1 || ( ( ( java.util.Date )consultas[ proxima ][ 0 ] ).getTime() - todayMillis ) / 86400000 > 14 ); + } + return !(estadoConsultas && estadoExames); } - return !(estadoConsultas && estadoExames); -} protected HashMap criarDadosTrabalhador( Connection con, Integer id, String nome, Object consultas[][], Object exames[][] )