no message

git-svn-id: https://svn.coded.pt/svn/SIPRP@530 bb69d46d-e84e-40c8-a05a-06db0d633741
lxbfYeaa
Frederico Palma 20 years ago
parent ec69036cf7
commit efa6345302

@ -26,7 +26,17 @@ import com.evolute.utils.strings.*;
public class doGetListaTrabalhadoresPendentes public class doGetListaTrabalhadoresPendentes
extends siprpServlet 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; protected long todayMillis;
/** Creates a new instance of doGetListaTrabalhadores */ /** Creates a new instance of doGetListaTrabalhadores */
@ -42,11 +52,17 @@ public class doGetListaTrabalhadoresPendentes
Vector links = new Vector(); Vector links = new Vector();
Vector desc = new Vector(); Vector desc = new Vector();
Vector descAdicional = new Vector(); Vector descAdicional = new Vector();
today = new java.util.Date(); // today = new java.util.Date();
todayMillis = today.getTime(); // todayMillis = today.getTime();
try 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); userRole = (String)session.getAttribute(super.sessionUserRole);
empresaId = (String)session.getAttribute(super.sessionEmpresaId); empresaId = (String)session.getAttribute(super.sessionEmpresaId);
estabelecimentoId = (String)session.getAttribute(super.sessionEstabelecimentoId); estabelecimentoId = (String)session.getAttribute(super.sessionEstabelecimentoId);
@ -61,11 +77,12 @@ public class doGetListaTrabalhadoresPendentes
//con = DriverManager.getConnection( super.bdUrl, super.bdUsername, super.bdPassword ); //con = DriverManager.getConnection( super.bdUrl, super.bdUsername, super.bdPassword );
dbQuery = new StringBuffer(); dbQuery = new StringBuffer();
dbQuery.append( "SELECT trabalhadores.id, trabalhadores.nome, " dbQuery.append( "SELECT trabalhadores.id, trabalhadores.nome, "
+ "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.realizada, " + "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.estado, "
+ " trabalhadores.nome_plain " + " trabalhadores.nome_plain, marcacoes_trabalhador.motivo "
+ "FROM trabalhadores LEFT JOIN marcacoes_trabalhador ON ( marcacoes_trabalhador.trabalhador_id = trabalhadores.id )" + "FROM trabalhadores LEFT JOIN marcacoes_trabalhador ON ( marcacoes_trabalhador.trabalhador_id = trabalhadores.id )"
+ "WHERE estabelecimento_id = " + estabelecimentoId + "WHERE estabelecimento_id = " + estabelecimentoId
+ " AND trabalhadores.inactivo <> 'y' AND data_demissao IS NULL " + " AND trabalhadores.inactivo <> 'y' AND data_demissao IS NULL "
+ " AND marcacoes_trabalhador.estado NOT IN ( 3, 4, 5) "
+ "ORDER BY 6, 3, 4 DESC " ); + "ORDER BY 6, 3, 4 DESC " );
// dbQuery.append( "SELECT id, nome, ( ultima_consulta IS NOT NULL AND realizada = 'y' )," // dbQuery.append( "SELECT id, nome, ( ultima_consulta IS NOT NULL AND realizada = 'y' ),"
// + " ( ultimo_exame IS NOT NULL AND realizado = '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 ); Integer id = index < max ? ( Integer ) rs.get( index, 0 ) : new Integer( -1 );
if( !id.equals( trabalhadorID ) ) if( !id.equals( trabalhadorID ) )
{ {
Object listaConsultas[][] = ( Object[][] ) consultas.toArray( new Object[consultas.size()][2] ); Object listaConsultas[][] = ( Object[][] ) consultas.toArray( new Object[consultas.size()][3] );
Object listaExames[][] = ( Object[][] ) exames.toArray( new Object[exames.size()][2] ); Object listaExames[][] = ( Object[][] ) exames.toArray( new Object[exames.size()][3] );
if( trabalhadorID.intValue() > -1 && if( trabalhadorID.intValue() > -1 &&
verificarTrabalhador( listaConsultas, listaExames ) ) verificarTrabalhador( listaConsultas, listaExames ) )
{ {
@ -116,10 +133,11 @@ public class doGetListaTrabalhadoresPendentes
String nome = ( String ) rs.get( index, 1 ); String nome = ( String ) rs.get( index, 1 );
java.util.Date data = ( java.util.Date ) rs.get( index, 3 ); 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; trabalhadorID = id;
nomeTrabalhador = nome; nomeTrabalhador = nome;
Object marcacao[] = new Object[]{ data, realizada }; Object marcacao[] = new Object[]{ data, estado, motivo };
if( tipo == null ) if( tipo == null )
{ {
continue; continue;
@ -187,37 +205,111 @@ public class doGetListaTrabalhadoresPendentes
} }
} }
protected boolean verificarTrabalhador( Object consultas[][], Object exames[][] ) protected int[] classificarTrabalhador( 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 estado[] = new int[ 2 ];
int proxima; int indiceProximaConsulta = -1;
if( ( (java.util.Date) consultas[ 0 ][ 0 ] ).after( today ) ) 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( !today.after( (java.util.Date) consultas[ 0 ][ 0 ] ) )
if( consultas.length >= 2 )
{ {
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; estado[ 1 ] = ESTADO_NAO_SE_APLICA;
anterior = 0;
} }
estadoConsultas = anterior >= 0 && "y".equals( consultas[ anterior ][ 1 ] ) && else if( exames.length > 0 )
( proxima == -1 || ( ( ( java.util.Date )consultas[ proxima ][ 0 ] ).getTime() - todayMillis ) / 86400000 > 14 ); {
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, protected HashMap criarDadosTrabalhador( Connection con, Integer id, String nome,
Object consultas[][], Object exames[][] ) Object consultas[][], Object exames[][] )

Loading…
Cancel
Save