git-svn-id: https://svn.coded.pt/svn/SIPRP@1608 bb69d46d-e84e-40c8-a05a-06db0d633741

lxbfYeaa
Diogo Neves 15 years ago
parent a9b50a35d1
commit c81c9b5d85

@ -23,7 +23,7 @@ public class doGetListaTrabalhadores extends siprpServlet
return rs; return rs;
} }
/** Creates a new instance of doGetListaTrabalhadores */
public doGetListaTrabalhadores(HttpServletRequest req, HttpServletResponse res, String query) throws IOException public doGetListaTrabalhadores(HttpServletRequest req, HttpServletResponse res, String query) throws IOException
{ {
boolean print = false; boolean print = false;
@ -90,101 +90,130 @@ public class doGetListaTrabalhadores extends siprpServlet
/** dados de consultas **/ /** dados de consultas **/
dbQuery = "SELECT id, data, estado FROM marcacoes_trabalhador " // dbQuery = "SELECT id, data, estado FROM marcacoes_trabalhador "
+ "WHERE tipo = 1 and trabalhador_id = " + id // + "WHERE tipo = 1 and trabalhador_id = " + id
+ " ORDER BY data DESC"; // + " ORDER BY data DESC";
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); // stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery ) ); // rs = new ResultSet2DArray( stmt.executeQuery( dbQuery ) );
rs.getObjects(); // rs.getObjects();
stmt.close(); // stmt.close();
if( rs.columnLength() > 0 ) // if( rs.columnLength() > 0 )
{ // {
java.util.Date dataConsulta2 = ( java.util.Date ) rs.get( 0, 1 ); // java.util.Date dataConsulta2 = ( java.util.Date ) rs.get( 0, 1 );
Integer estado2 = ( Integer ) rs.get( 0, 2 ); // Integer estado2 = ( Integer ) rs.get( 0, 2 );
java.util.Date dataConsulta1; // java.util.Date dataConsulta1;
// java.util.Date dataRelatorio1; // Integer estado1;
// java.util.Date dataRelatorio2 = (java.util.Date) rs.get( 0, 3 ); // String realizada1 = "";
Integer estado1; // String realizada2 = "";
String realizada1 = ""; // if( rs.columnLength() >= 2 )
String realizada2 = ""; // {
if( rs.columnLength() >= 2 ) // dataConsulta1 = ( java.util.Date ) rs.get( 1, 1 );
{ // estado1 = ( Integer ) rs.get( 1, 2 );
dataConsulta1 = ( java.util.Date ) rs.get( 1, 1 ); // }
estado1 = ( Integer ) rs.get( 1, 2 ); // else
// dataRelatorio1 = (java.util.Date) rs.get( 1, 3 ); // {
} // dataConsulta1 = dataConsulta2;
else // estado1 = estado2;
{ // }
dataConsulta1 = dataConsulta2; // if( ESTADO_REALIZADO.equals( estado2 ) || ( dataConsulta2 != null && today.after( dataConsulta2 ) ) )
estado1 = estado2; // {
// dataRelatorio1 = dataRelatorio2; // trabalhador.put( "ultima_consulta", dataConsulta2 );
} // if( estado2.equals( ESTADO_POR_REALIZAR ) )
if( ESTADO_REALIZADO.equals( estado2 ) || ( dataConsulta2 != null && today.after( dataConsulta2 ) ) ) // {
{ // realizada2 = "não";
trabalhador.put( "ultima_consulta", dataConsulta2 ); // }
if( estado2.equals( ESTADO_POR_REALIZAR ) ) // else if( estado2.equals( ESTADO_REALIZADO ) )
{ // {
realizada2 = "não"; // realizada2 = "sim";
} // }
else if( estado2.equals( ESTADO_REALIZADO ) ) // trabalhador.put( "realizada", realizada2 );
{ // trabalhador.put( "proxima_consulta", "" );
realizada2 = "sim"; // }
} // else
trabalhador.put( "realizada", realizada2 ); // {
trabalhador.put( "proxima_consulta", "" ); // try
} // {
else // for( int c = 1; c < rs.columnLength(); c++ )
{ // {
try // java.util.Date dataTemp = ( java.util.Date ) rs.get( c, 1 );
{ // dataConsulta1 = dataTemp;
for( int c = 1; c < rs.columnLength(); c++ ) // estado1 = ( Integer ) rs.get( c, 2 );
{ // if( dataTemp.after( today ) )
java.util.Date dataTemp = ( java.util.Date ) rs.get( c, 1 ); // {
dataConsulta1 = dataTemp; // dataConsulta2 = dataTemp;
estado1 = ( Integer ) rs.get( c, 2 ); // }
if( dataTemp.after( today ) ) // else
{ // {
dataConsulta2 = dataTemp; // break;
} // }
else // }
{ // }
break; // catch( Exception ex )
} // {
} // ex.printStackTrace();
} // }
catch( Exception ex ) // trabalhador.put( "proxima_consulta", dataConsulta2 );
{ //
ex.printStackTrace(); // if( !dataConsulta2.equals( dataConsulta1 ) )
} // {
trabalhador.put( "proxima_consulta", dataConsulta2 ); // if( estado1.equals( ESTADO_POR_REALIZAR ) )
// {
// realizada1 = "n&atilde;o";
// }
// else if( estado1.equals( ESTADO_REALIZADO ) )
// {
// realizada1 = "sim";
// }
// trabalhador.put( "realizada", realizada1 );
// trabalhador.put( "ultima_consulta", dataConsulta1 );
// }
// else
// {
// trabalhador.put( "ultima_consulta", "" );
// trabalhador.put( "realizada", null );
// }
// }
// }
// else
// {
// trabalhador.put( "ultima_consulta", "" );
// trabalhador.put( "realizada", null );
// trabalhador.put( "proxima_consulta", "" );
// }
dbQuery = "select id, data, estado " +
"from marcacoes_trabalhador " +
"where deleted_stamp is null and tipo = 1 and estado = 2 and trabalhador_id = " + id + " " +
"order by data desc " +
"limit 1";
rs = executeQuery( con, dbQuery );
if( !dataConsulta2.equals( dataConsulta1 ) ) java.util.Date dataUltimaConsultaRealizada = null;
{ String consultaRealizada = "";
if( estado1.equals( ESTADO_POR_REALIZAR ) ) if ( rs.columnLength() > 0 )
{ {
realizada1 = "n&atilde;o"; dataUltimaConsultaRealizada = ( java.util.Date ) rs.get( 0, 1 );
} consultaRealizada = "Sim";
else if( estado1.equals( ESTADO_REALIZADO ) )
{
realizada1 = "sim";
}
trabalhador.put( "realizada", realizada1 );
trabalhador.put( "ultima_consulta", dataConsulta1 );
}
else
{
trabalhador.put( "ultima_consulta", "" );
trabalhador.put( "realizada", null );
}
}
} }
else
dbQuery = "select id, data, estado " +
"from marcacoes_trabalhador " +
"where deleted_stamp is null and tipo = 1 and estado != 2 and data >= now() and trabalhador_id = " + id + " " +
"order by data desc " +
"limit 1";
rs = executeQuery( con, dbQuery );
java.util.Date dataProximaConsulta = null;
if ( rs.columnLength() > 0 )
{ {
trabalhador.put( "ultima_consulta", "" ); dataProximaConsulta = ( java.util.Date ) rs.get( 0, 1 );
trabalhador.put( "realizada", null );
trabalhador.put( "proxima_consulta", "" );
} }
trabalhador.put( "ultima_consulta", dataUltimaConsultaRealizada == null ? "" : dataUltimaConsultaRealizada );
trabalhador.put( "realizada", consultaRealizada );
trabalhador.put( "proxima_consulta", dataProximaConsulta == null ? "" : dataProximaConsulta );
/** eof dados consulta **/
/** dados de exames **/ /** dados de exames **/
dbQuery = "select id, data, estado " + dbQuery = "select id, data, estado " +

@ -10,8 +10,8 @@ import java.io.*;
import java.lang.reflect.Array; import java.lang.reflect.Array;
import javax.servlet.*; import javax.servlet.*;
import javax.servlet.http.*; import javax.servlet.http.*;
import java.sql.*;
import java.util.*; import java.util.*;
import java.sql.SQLException;
import org.apache.velocity.*; import org.apache.velocity.*;
import org.apache.velocity.app.*; import org.apache.velocity.app.*;
@ -57,7 +57,7 @@ public class doGetListaTrabalhadoresPendentes
// TEXTOS_ESTADOS.put( new Integer( ESTADO_TRATADO ), "green" ); // TEXTOS_ESTADOS.put( new Integer( ESTADO_TRATADO ), "green" );
} }
protected java.sql.Date today; protected Date today;
protected long todayMillis; protected long todayMillis;
/** Creates a new instance of doGetListaTrabalhadores */ /** Creates a new instance of doGetListaTrabalhadores */
@ -227,43 +227,46 @@ public class doGetListaTrabalhadoresPendentes
// } // }
// } // }
public doGetListaTrabalhadoresPendentes(HttpServletRequest req, HttpServletResponse res, boolean print ) public doGetListaTrabalhadoresPendentes( HttpServletRequest req, HttpServletResponse res, boolean print )
throws IOException throws IOException
{ {
System.out.println( "\ndoGetListaTrabalhadoresPendentes() : " );
ServletOutputStream out = res.getOutputStream(); ServletOutputStream out = res.getOutputStream();
String userRole, empresaId, estabelecimentoId; String userRole, empresaId, estabelecimentoId;
HttpSession session = req.getSession(false); HttpSession session = req.getSession( false );
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();
// todayMillis = today.getTime();
try try
{ {
Executer executer = getExecuter(); Executer executer = getExecuter();
Virtual2DArray array = executer.executeQuery( new Select( "SELECT CURRENT_DATE" ) ); today = new Date();
today = ( java.sql.Date ) array.get( 0, 0 );
todayMillis = today.getTime(); todayMillis = today.getTime();
userRole = (String)session.getAttribute(sessionUserRole); userRole = ( String ) session.getAttribute( sessionUserRole );
empresaId = (String)session.getAttribute(sessionEmpresaId); empresaId = ( String ) session.getAttribute( sessionEmpresaId );
estabelecimentoId = (String)session.getAttribute(sessionEstabelecimentoId); estabelecimentoId = ( String ) session.getAttribute( sessionEstabelecimentoId );
System.out.println( "\tuserRole : " + userRole );
System.out.println( "\tempresaID : " + empresaId );
System.out.println( "\testabelecimentoID : " + estabelecimentoId );
if ( userRole.equals ( superUserRole ) || userRole.equals ( empresaId ) ) if ( userRole.equals ( superUserRole ) || userRole.equals ( empresaId ) )
{ {
if ( verificaEstabelecimento(null, empresaId, estabelecimentoId) ) // estabelecimento pertence 'a empresa ?? if ( verificaEstabelecimento( null, empresaId, estabelecimentoId ) ) // estabelecimento pertence 'a empresa ??
{ {
//Class.forName(super.bdDriver);
//con = DriverManager.getConnection( super.bdUrl, super.bdUsername, super.bdPassword );
String query = "( SELECT trabalhadores.id, trabalhadores.nome, " String query = "( SELECT trabalhadores.id, trabalhadores.nome, "
+ "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.estado, " + "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.estado, "
+ " trabalhadores.nome_plain, marcacoes_trabalhador.motivo, marcacoes_trabalhador.data " + " trabalhadores.nome_plain, marcacoes_trabalhador.motivo, marcacoes_trabalhador.data "
+ "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) " + " AND marcacoes_trabalhador.estado NOT IN ( 2, 3, 4, 5 ) "
+ " AND marcacoes_trabalhador.tipo = " + TIPO_MARCACAO_CONSULTA + " AND marcacoes_trabalhador.tipo = " + TIPO_MARCACAO_CONSULTA
+ " AND marcacoes_trabalhador.deleted_stamp is null"
+ " AND marcacoes_trabalhador.data < now()"
+ " AND marcacoes_trabalhador.motivo <> " + MOTIVO_OCASIONAL + " )" + " AND marcacoes_trabalhador.motivo <> " + MOTIVO_OCASIONAL + " )"
+ " UNION " + " UNION "
+ "( SELECT trabalhadores.id, trabalhadores.nome, " + "( SELECT trabalhadores.id, trabalhadores.nome, "
@ -272,10 +275,12 @@ public class doGetListaTrabalhadoresPendentes
+ "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) " + " AND marcacoes_trabalhador.estado NOT IN ( 2, 3, 4, 5 ) "
+ " AND marcacoes_trabalhador.deleted_stamp is null"
+ " AND marcacoes_trabalhador.data < now()"
+ " AND marcacoes_trabalhador.tipo = " + TIPO_MARCACAO_EXAMES + " )" + " AND marcacoes_trabalhador.tipo = " + TIPO_MARCACAO_EXAMES + " )"
+ "ORDER BY 6, 8, 3 DESC "; + " ORDER BY 6, 8, 3 DESC ";
array = executer.executeQuery( new Select( query ) ); Virtual2DArray array = executer.executeQuery( new Select( query ) );
query = "SELECT trabalhadores.id, trabalhadores.nome, " query = "SELECT trabalhadores.id, trabalhadores.nome, "
+ "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.estado, " + "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, marcacoes_trabalhador.estado, "
@ -283,9 +288,11 @@ public class doGetListaTrabalhadoresPendentes
+ "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) " + " AND marcacoes_trabalhador.estado NOT IN ( 2, 3, 4, 5 ) "
+ " AND marcacoes_trabalhador.tipo = " + TIPO_MARCACAO_CONSULTA + " AND marcacoes_trabalhador.tipo = " + TIPO_MARCACAO_CONSULTA
+ " AND marcacoes_trabalhador.motivo = " + MOTIVO_OCASIONAL + " AND marcacoes_trabalhador.motivo = " + MOTIVO_OCASIONAL
+ " AND marcacoes_trabalhador.data < now()"
+ " AND marcacoes_trabalhador.deleted_stamp is null"
+ " ORDER BY 6, 8, 3 DESC"; + " ORDER BY 6, 8, 3 DESC";
Virtual2DArray ocasionaisArray = executer.executeQuery( new Select( query ) ); Virtual2DArray ocasionaisArray = executer.executeQuery( new Select( query ) );
@ -306,13 +313,13 @@ public class doGetListaTrabalhadoresPendentes
preencherMarcacoes( array, nomesPorID, marcacoesPorID ); preencherMarcacoes( array, nomesPorID, marcacoesPorID );
preencherMarcacoes( ocasionaisArray, nomesPorID, ocasionaisPorID ); preencherMarcacoes( ocasionaisArray, nomesPorID, ocasionaisPorID );
Integer ids[] = ( Integer[] ) nomesPorID.keySet().toArray( new Integer[0] ); Integer ids[] = ( Integer[] ) nomesPorID.keySet().toArray( new Integer[ 0 ] );
IDObject trabalhadores[] = new IDObject[ ids.length ]; IDObject trabalhadores[] = new IDObject[ ids.length ];
for( int n = 0; n < ids.length; n++ ) for( int n = 0; n < ids.length; n++ )
{ {
trabalhadores[ n ] = new MappableObject( ids[ n ], nomesPorID.get( ids[ n ] ) ); trabalhadores[ n ] = new MappableObject( ids[ n ], nomesPorID.get( ids[ n ] ) );
} }
Arrays.sort( trabalhadores, new Comparator(){ Arrays.sort( trabalhadores, new Comparator() {
public int compare( Object o1, Object o2 ) public int compare( Object o1, Object o2 )
{ {
String nome1 = StringPlainer.convertString( o1.toString() ); String nome1 = StringPlainer.convertString( o1.toString() );
@ -323,30 +330,25 @@ public class doGetListaTrabalhadoresPendentes
for( int n = 0; n < trabalhadores.length; n++ ) for( int n = 0; n < trabalhadores.length; n++ )
{ {
Object marcacoes[][]; Integer trabalhadorID = trabalhadores[ n ].getID();
if( marcacoesPorID.containsKey( trabalhadores[ n ].getID() ) )
{ Object marcacoes[][] = new Object[ 0 ][ ];
marcacoes = ( Object[][] ) ( ( Vector )marcacoesPorID.get( trabalhadores[ n ].getID() ) ).toArray( new Object[ 0 ][] ); if ( marcacoesPorID.containsKey( trabalhadorID ) )
}
else
{
marcacoes = new Object[0][];
}
Object ocasionais[][];
if( ocasionaisPorID.containsKey( trabalhadores[ n ].getID() ) )
{ {
ocasionais = ( Object[][] ) ( ( Vector )ocasionaisPorID.get( trabalhadores[ n ].getID() ) ).toArray( new Object[ 0 ][] ); marcacoes = ( Object[][] ) ( ( Vector ) marcacoesPorID.get( trabalhadorID ) ).toArray( new Object[ 0 ][] );
} }
else Object ocasionais[][] = new Object[ 0 ][ ];
if( ocasionaisPorID.containsKey( trabalhadorID ) )
{ {
ocasionais = new Object[ 0 ][]; ocasionais = ( Object[][] ) ( ( Vector ) ocasionaisPorID.get( trabalhadorID ) ).toArray( new Object[ 0 ][] );
} }
Object agrupadas[][] = agruparMarcacoes( marcacoes, ocasionais ); Object agrupadas[][] = agruparMarcacoes( marcacoes, ocasionais );
acrescentarTrabalhador( empresaId, estabelecimentoId, acrescentarTrabalhador( empresaId, estabelecimentoId,
trabalhadores[ n ], null, trabalhadores[ n ], null,
agrupadas, links, desc, agrupadas, links, desc,
perfilTemConsultas( trabalhadores[ n ].getID(), new Integer( empresaId ) ), perfilTemConsultas( trabalhadorID, new Integer( empresaId ) ),
perfilTemExames( trabalhadores[ n ].getID(), new Integer( empresaId ) ) ); perfilTemExames( trabalhadorID, new Integer( empresaId ) ) );
} }
HashMap hmValues = new HashMap(); HashMap hmValues = new HashMap();
@ -356,64 +358,64 @@ public class doGetListaTrabalhadoresPendentes
hmValues.put( "estabelecimento_id", estabelecimentoId ); hmValues.put( "estabelecimento_id", estabelecimentoId );
hmValues.put( "userRole", userRole ); hmValues.put( "userRole", userRole );
hmValues.put( "userName", session.getAttribute( sessionUser ) ); hmValues.put( "userName", session.getAttribute( sessionUser ) );
hmValues.put( msgTemplate , "<b>"+nomeEmpresa(null,empresaId)+"</b><br><br><i>" hmValues.put( msgTemplate , "<b>" + nomeEmpresa( null, empresaId ) + "</b><br><br><i>"
+nomeEstabelecimento(null, estabelecimentoId)+"</i>" ) ; + nomeEstabelecimento( null, estabelecimentoId ) + "</i>" ) ;
hmValues.put( templateUserRole, userRole); hmValues.put( templateUserRole, userRole );
hmValues.put( templateQuery, "trabalhadores_pendentes" ); hmValues.put( templateQuery, "trabalhadores_pendentes" );
hmValues.put( templateVector1,links); hmValues.put( templateVector1, links );
hmValues.put( templateVector2,desc); hmValues.put( templateVector2, desc );
hmValues.put( templateVector3,null); hmValues.put( templateVector3, null );
if( !print ) if ( ! print )
{ {
out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate)); out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate ) );
} }
else else
{ {
out.println( mergeTemplate( hmValues, super.authenticatedUserPrintTemplate)); out.println( mergeTemplate( hmValues, super.authenticatedUserPrintTemplate ) );
} }
// out.println( mergeTemplate( sBuffer.toString(), userRole, super.queryStringTrabalhadores, links, desc, null, super.authenticatedUserTemplate) );
} }
else // est nao pertence 'a empresa else // est nao pertence 'a empresa
{ {
out.println( mergeTemplate( super.msgLinkFormatError , userRole, super.errorTemplate) ); out.println( mergeTemplate( super.msgLinkFormatError, userRole, super.errorTemplate ) );
} }
} }
else // Role nao permite ver esta informacao else // Role nao permite ver esta informacao
{ {
out.println( mergeTemplate( super.msgAcessoNegado , userRole, super.errorTemplate) ); out.println( mergeTemplate( super.msgAcessoNegado, userRole, super.errorTemplate ) );
} }
} }
catch ( SQLException e ) catch ( SQLException e )
{ {
e.printStackTrace(); e.printStackTrace();
out.println( mergeTemplate( super.msgErroBd , super.errorTemplate) ); out.println( mergeTemplate( super.msgErroBd, super.errorTemplate ) );
} }
catch ( Exception e ) catch ( Exception e )
{ {
e.printStackTrace(); e.printStackTrace();
out.println( mergeTemplate( super.msgGenericError , super.errorTemplate) ); out.println( mergeTemplate( super.msgGenericError, super.errorTemplate ) );
} }
} }
protected void preencherMarcacoes( Virtual2DArray array, Hashtable nomesPorID, Hashtable marcacoesPorID ) protected void preencherMarcacoes( Virtual2DArray array, Hashtable nomesPorID, Hashtable marcacoesPorID )
{ {
int max = array.columnLength(); for ( int index = 0; index < array.columnLength(); index++ )
for( int index = 0; index < max; index++ )
{ {
Integer id = index < max ? ( Integer ) array.get( index, 0 ) : new Integer( -1 ); Integer id = ( Integer ) array.get( index, 0 );
Integer tipo = ( Integer ) array.get( index, 2 ); Integer tipo = ( Integer ) array.get( index, 2 );
String nome = ( String ) array.get( index, 1 ); String nome = ( String ) array.get( index, 1 );
java.util.Date data = ( java.util.Date ) array.get( index, 3 ); java.util.Date data = ( java.util.Date ) array.get( index, 3 );
Integer estado = ( Integer ) array.get( index, 4 ); Integer estado = ( Integer ) array.get( index, 4 );
Integer motivo = ( Integer ) array.get( index, 6 ); Integer motivo = ( Integer ) array.get( index, 6 );
if( !marcacoesPorID.containsKey( id ) )
if ( ! marcacoesPorID.containsKey( id ) )
{ {
nomesPorID.put( id, nome ); nomesPorID.put( id, nome );
marcacoesPorID.put( id, new Vector() ); marcacoesPorID.put( id, new Vector() );
} }
if( data != null ) if ( data != null )
{ {
Object marcacao[] = new Object[]{ data, estado, motivo, tipo }; Object marcacao[] = new Object[] { data, estado, motivo, tipo };
( ( Vector ) marcacoesPorID.get( id ) ).add( marcacao ); ( ( Vector ) marcacoesPorID.get( id ) ).add( marcacao );
} }
} }
@ -430,11 +432,11 @@ public class doGetListaTrabalhadoresPendentes
Object grupo[] = null; Object grupo[] = null;
Vector grupos = new Vector(); Vector grupos = new Vector();
if( marcacoes != null ) if ( marcacoes != null )
{ {
for( int n = 0; n < marcacoes.length; n++ ) for ( int n = 0; n < marcacoes.length; n++ )
{ {
if( grupo == null ) if ( grupo == null )
{ {
grupo = new Object[ 5 ]; grupo = new Object[ 5 ];
dataExame = null; dataExame = null;
@ -497,9 +499,9 @@ public class doGetListaTrabalhadoresPendentes
} }
} }
} }
if( ocasionais != null ) if ( ocasionais != null )
{ {
for( int n = 0; n < ocasionais.length; n++ ) for ( int n = 0; n < ocasionais.length; n++ )
{ {
grupo = new Object[ 5 ]; grupo = new Object[ 5 ];
for( int i = 0; i < 3; i++ ) for( int i = 0; i < 3; i++ )
@ -511,7 +513,8 @@ public class doGetListaTrabalhadoresPendentes
} }
Object agrupadas[][] = ( Object[][] ) grupos.toArray( new Object[ grupos.size() ][] ); Object agrupadas[][] = ( Object[][] ) grupos.toArray( new Object[ grupos.size() ][] );
Arrays.sort( agrupadas, new Comparator(){ Arrays.sort( agrupadas, new Comparator()
{
public int compare( Object o1, Object o2 ) public int compare( Object o1, Object o2 )
{ {
Object g1[] = ( Object[] ) o1; Object g1[] = ( Object[] ) o1;
@ -529,20 +532,32 @@ public class doGetListaTrabalhadoresPendentes
Object marcacoes[][], Vector links, Vector dados, Object marcacoes[][], Vector links, Vector dados,
boolean perfilConsultas, boolean perfilExames ) boolean perfilConsultas, boolean perfilExames )
{ {
// System.out.println( "\ndoGetListaTrabalhadoresPendentes . acrescentarTrabalhador( " + empresaID + ", " + estabelecimentoID + ", "
// + trabalhador + ", " + dataFicha + ", " + marcacoes + ", " + links + ", " + dados + ", " + perfilConsultas + ", " + perfilExames + " ) : " );
// System.out.println( "\tTrabalhador : " + trabalhador.getID() );
int estado[] = new int[ 2 ]; int estado[] = new int[ 2 ];
int index = 0; int index = 0;
boolean pendente = false; boolean pendente = false;
if( marcacoes.length == 0 ) if ( marcacoes.length == 0 )
{ {
// System.out.println( "\tmarcacoes.length == 0 : true" );
estado[ 0 ] = perfilConsultas ? ESTADO_PENDENTE : ESTADO_NAO_APLICAVEL; estado[ 0 ] = perfilConsultas ? ESTADO_PENDENTE : ESTADO_NAO_APLICAVEL;
estado[ 1 ] = perfilExames ? ESTADO_PENDENTE : ESTADO_NAO_APLICAVEL; estado[ 1 ] = perfilExames ? ESTADO_PENDENTE : ESTADO_NAO_APLICAVEL;
// System.out.println( "\t\testado[ 0 ] : " + estado[ 0 ] );
// System.out.println( "\t\testado[ 1 ] : " + estado[ 1 ] );
} }
else else
{ {
// System.out.println( "\tmarcacoes.length == 0 : false" );
java.util.Date dataConsulta; java.util.Date dataConsulta;
java.util.Date dataExame; java.util.Date dataExame;
index = -1; index = -1;
for( ; index + 1 < marcacoes.length; index++ ) for ( ; index + 1 < marcacoes.length; index++ )
{ {
int n = index + 1; int n = index + 1;
dataConsulta = ( java.util.Date ) marcacoes[ n ][ 0 ]; dataConsulta = ( java.util.Date ) marcacoes[ n ][ 0 ];
@ -553,21 +568,15 @@ public class doGetListaTrabalhadoresPendentes
boolean exameAntigo = temExame && dataExame.before( today ); boolean exameAntigo = temExame && dataExame.before( today );
if( ( temConsulta && consultaAntiga && temExame && exameAntigo ) || if( ( temConsulta && consultaAntiga && temExame && exameAntigo ) ||
( temConsulta && consultaAntiga && !temExame && !exameAntigo ) || ( temConsulta && consultaAntiga && ! temExame && ! exameAntigo ) ||
( !temConsulta && !consultaAntiga && temExame && exameAntigo ) ) ( ! temConsulta && ! consultaAntiga && temExame && exameAntigo ) )
{ {
break; break;
} }
} }
if( index == -1 )
{ index = index == -1 ? 0 : index;
index = 0; for ( ; index < marcacoes.length; index++ )
}
// else if( index < marcacoes.length - 1 )
// {
// index = 0;
// }
for( ; index < marcacoes.length; index++ )
{ {
dataConsulta = ( java.util.Date ) marcacoes[ index ][ 0 ]; dataConsulta = ( java.util.Date ) marcacoes[ index ][ 0 ];
dataExame = ( java.util.Date ) marcacoes[ index ][ 3 ]; dataExame = ( java.util.Date ) marcacoes[ index ][ 3 ];
@ -575,28 +584,29 @@ public class doGetListaTrabalhadoresPendentes
long diffConsulta = temConsulta ? dataConsulta.getTime() - today.getTime() : 0; long diffConsulta = temConsulta ? dataConsulta.getTime() - today.getTime() : 0;
boolean temExame = dataExame != null; boolean temExame = dataExame != null;
long diffExame = temExame ? dataExame.getTime() - today.getTime() : 0; long diffExame = temExame ? dataExame.getTime() - today.getTime() : 0;
if( ( temConsulta && diffConsulta < CATORZE_DIAS ) || ( temExame && diffExame < CATORZE_DIAS ) ) if ( ( temConsulta && diffConsulta < CATORZE_DIAS ) || ( temExame && diffExame < CATORZE_DIAS ) )
{ {
break; break;
} }
} }
if( index >= marcacoes.length )
if ( index >= marcacoes.length )
{ {
index = marcacoes.length - 1; index = marcacoes.length - 1;
} }
else else
{ {
if( marcacoes.length > 1 ) if ( marcacoes.length > 1 )
{ {
dataConsulta = ( java.util.Date ) marcacoes[ index ][ 0 ]; dataConsulta = ( java.util.Date ) marcacoes[ index ][ 0 ];
dataExame = ( java.util.Date ) marcacoes[ index ][ 3 ]; dataExame = ( java.util.Date ) marcacoes[ index ][ 3 ];
Calendar calToday = Calendar.getInstance(); Calendar calToday = Calendar.getInstance();
calToday.setTime( today ); calToday.setTime( today );
calToday.add( Calendar.YEAR, -2 ); calToday.add( Calendar.YEAR, -2 );
if( ( dataConsulta != null && dataConsulta.before( calToday.getTime() ) ) if ( ( dataConsulta != null && dataConsulta.before( calToday.getTime() ) )
|| ( dataConsulta == null && dataExame != null && dataExame.before( calToday.getTime() ) ) ) || ( dataConsulta == null && dataExame != null && dataExame.before( calToday.getTime() ) ) )
{ {
if( index > 0 ) if ( index > 0 )
{ {
index--; index--;
} }
@ -612,13 +622,13 @@ public class doGetListaTrabalhadoresPendentes
Integer motivoConsulta = ( Integer ) marcacoes[ index ][ 2 ]; Integer motivoConsulta = ( Integer ) marcacoes[ index ][ 2 ];
dataExame = ( java.util.Date ) marcacoes[ index ][ 3 ]; dataExame = ( java.util.Date ) marcacoes[ index ][ 3 ];
Integer estadoExame = ( Integer ) marcacoes[ index ][ 4 ]; Integer estadoExame = ( Integer ) marcacoes[ index ][ 4 ];
if( perfilConsultas ) if ( perfilConsultas )
{ {
if( dataConsulta == null || pendente ) if ( dataConsulta == null || pendente )
{ {
estado[ 0 ] = ESTADO_PENDENTE; estado[ 0 ] = ESTADO_PENDENTE;
} }
else if( estadoConsulta == null || estadoConsulta.intValue() != 2 ) else if ( estadoConsulta == null || estadoConsulta.intValue() != 2 )
{ {
estado[ 0 ] = ESTADO_MARCADO; estado[ 0 ] = ESTADO_MARCADO;
} }
@ -631,20 +641,15 @@ public class doGetListaTrabalhadoresPendentes
{ {
estado[ 0 ] = ESTADO_NAO_APLICAVEL; estado[ 0 ] = ESTADO_NAO_APLICAVEL;
} }
if( perfilExames )
if ( perfilExames )
{ {
if( dataExame == null || pendente ) if ( dataExame == null || pendente )
{ {
if( motivoConsulta != null && motivoConsulta.intValue() != MOTIVO_OCASIONAL ) estado[ 1 ] = motivoConsulta != null && motivoConsulta.intValue() != MOTIVO_OCASIONAL ?
{ ESTADO_PENDENTE : ESTADO_NAO_APLICAVEL ;
estado[ 1 ] = ESTADO_PENDENTE;
}
else
{
estado[ 1 ] = ESTADO_NAO_APLICAVEL;
}
} }
else if( estadoExame == null || estadoExame.intValue() != 2 ) else if ( estadoExame == null || estadoExame.intValue() != 2 )
{ {
estado[ 1 ] = ESTADO_MARCADO; estado[ 1 ] = ESTADO_MARCADO;
} }
@ -658,18 +663,29 @@ public class doGetListaTrabalhadoresPendentes
estado[ 1 ] = ESTADO_NAO_APLICAVEL; estado[ 1 ] = ESTADO_NAO_APLICAVEL;
} }
} }
if( estado[ 0 ] == 1 || estado[ 0 ] == 2 ||
estado[ 1 ] == 1 || estado[ 1 ] == 2 ) // System.out.println( "\testado[ 0 ] : " + estado[ 0 ] );
// System.out.println( "\testado[ 1 ] : " + estado[ 1 ] );
if ( estado[ 0 ] == 1 || estado[ 0 ] == 2 || estado[ 1 ] == 1 || estado[ 1 ] == 2 )
{ {
links.add( "/"+servletName+"/?"+empresaID+"/"+estabelecimentoID+"/"+trabalhador.getID() ); // System.out.println( "\t\testado[ 0 ] == 1 || estado[ 0 ] == 2 || estado[ 1 ] == 1 || estado[ 1 ] == 2 : true" );
links.add( "/" + servletName + "/?" + empresaID + "/" + estabelecimentoID + "/" + trabalhador.getID() );
HashMap dadosTrabalhador = new HashMap(); HashMap dadosTrabalhador = new HashMap();
dadosTrabalhador.put( "Nome", trabalhador.toString() ); dadosTrabalhador.put( "Nome", trabalhador.toString() );
dadosTrabalhador.put( "Consulta", CORES_ESTADOS.get( new Integer( estado[ 0 ] ) ) ); dadosTrabalhador.put( "Consulta", CORES_ESTADOS.get( new Integer( estado[ 0 ] ) ) );
Object text = TEXTOS_ESTADOS.get( new Integer( estado[ 0 ] ) ); Object text = TEXTOS_ESTADOS.get( new Integer( estado[ 0 ] ) );
// System.out.println( "\t\t\tCONSULTA_ESTADO : " + text );
dadosTrabalhador.put( "Consulta_estado", text != null ? text : marcacoes[ index ][ 0 ] ); dadosTrabalhador.put( "Consulta_estado", text != null ? text : marcacoes[ index ][ 0 ] );
// System.out.println( "\t\t\t\tFinal : " + dadosTrabalhador.get( "Consulta_estado" ) );
dadosTrabalhador.put( "Exame", CORES_ESTADOS.get( new Integer( estado[ 1 ] ) ) ); dadosTrabalhador.put( "Exame", CORES_ESTADOS.get( new Integer( estado[ 1 ] ) ) );
text = TEXTOS_ESTADOS.get( new Integer( estado[ 1 ] ) ); text = TEXTOS_ESTADOS.get( new Integer( estado[ 1 ] ) );
// System.out.println( "\t\t\tEXAME_ESTADO : " + text );
dadosTrabalhador.put( "Exame_estado", text != null ? text : marcacoes[ index ][ 3 ] ); dadosTrabalhador.put( "Exame_estado", text != null ? text : marcacoes[ index ][ 3 ] );
// System.out.println( "\t\t\t\tFinal : " + dadosTrabalhador.get( "Exame_estado" ) );
dados.add( dadosTrabalhador ); dados.add( dadosTrabalhador );
} }
} }
@ -677,43 +693,33 @@ public class doGetListaTrabalhadoresPendentes
protected boolean perfilTemConsultas( Integer trabalhadorID, Integer empresaID ) protected boolean perfilTemConsultas( Integer trabalhadorID, Integer empresaID )
throws Exception throws Exception
{ {
Executer executer = getExecuter();
String query = "SELECT a_consultas, b_consultas FROM empresas WHERE id = " + empresaID; String query = "SELECT a_consultas, b_consultas FROM empresas WHERE id = " + empresaID;
Virtual2DArray array = executer.executeQuery( new Select( query ) ); return perfilTem( query, trabalhadorID );
boolean consultas[] = new boolean[]{ "y".equals( array.get( 0, 0 ) ), "n".equals( array.get( 0, 0 ) ) };
query = "SELECT perfil FROM trabalhadores WHERE id = " + trabalhadorID;
array = executer.executeQuery( new Select( query ) );
Integer perfil = ( Integer )array.get( 0, 0 );
if( perfil != null )
{
return consultas[ perfil.intValue() - 1 ];
}
else
{
return false;
}
} }
protected boolean perfilTemExames( Integer trabalhadorID, Integer empresaID ) protected boolean perfilTemExames( Integer trabalhadorID, Integer empresaID )
throws Exception throws Exception
{ {
Executer executer = getExecuter();
String query = "SELECT a_exames, b_exames FROM empresas WHERE id = " + empresaID; String query = "SELECT a_exames, b_exames FROM empresas WHERE id = " + empresaID;
return perfilTem( query, trabalhadorID );
}
private boolean perfilTem( String query, Integer trabalhadorID ) throws Exception
{
Executer executer = getExecuter();
Virtual2DArray array = executer.executeQuery( new Select( query ) ); Virtual2DArray array = executer.executeQuery( new Select( query ) );
boolean consultas[] = new boolean[]{ "y".equals( array.get( 0, 0 ) ), "n".equals( array.get( 0, 0 ) ) }; boolean consultas[] = new boolean[]{ "y".equals( array.get( 0, 0 ) ), "n".equals( array.get( 0, 0 ) ) };
query = "SELECT perfil FROM trabalhadores WHERE id = " + trabalhadorID; query = "SELECT perfil FROM trabalhadores WHERE id = " + trabalhadorID;
array = executer.executeQuery( new Select( query ) ); array = executer.executeQuery( new Select( query ) );
Integer perfil = ( Integer )array.get( 0, 0 ); Integer perfil = ( Integer )array.get( 0, 0 );
if( perfil != null ) return perfil != null && consultas[ perfil.intValue() - 1 ];
{
return consultas[ perfil.intValue() - 1 ];
}
else
{
return false;
}
} }
// protected boolean verificarTrabalhador( Object consultas[][], Object exames[][] ) // protected boolean verificarTrabalhador( Object consultas[][], Object exames[][] )
// { // {
// boolean estadoConsultas = false; // boolean estadoConsultas = false;

@ -23,7 +23,7 @@ public class doGetTrabalhador extends siprpServlet
return rs; return rs;
} }
/** Creates a new instance of doGetTrabalhador */
public doGetTrabalhador(HttpServletRequest req, HttpServletResponse res) throws IOException public doGetTrabalhador(HttpServletRequest req, HttpServletResponse res) throws IOException
{ {
ServletOutputStream out = res.getOutputStream(); ServletOutputStream out = res.getOutputStream();
@ -222,98 +222,130 @@ public class doGetTrabalhador extends siprpServlet
hmFuncionario.put( "resultado", null ); hmFuncionario.put( "resultado", null );
} }
query = "SELECT id, data, estado FROM marcacoes_trabalhador "
+ "WHERE tipo = 1 and trabalhador_id = " + trabalhadorId /** consulta dados **/
+ " ORDER BY data DESC"; String queryUltima = "select id, data, estado " +
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); "from marcacoes_trabalhador " +
rs = new ResultSet2DArray( stmt.executeQuery( query ) ); "where deleted_stamp is null and tipo = 1 and estado = 2 and trabalhador_id = " + trabalhadorId + " " +
if( rs.columnLength() > 0 ) "order by data desc " +
"limit 1";
rs = executeQuery( con, queryUltima );
java.util.Date dataUltimaConsultaRealizada = null;
String consultaRealizada = "";
if ( rs.columnLength() > 0 )
{ {
java.util.Date dataConsulta2 = ( java.util.Date ) rs.get( 0, 1 ); dataUltimaConsultaRealizada = ( java.util.Date ) rs.get( 0, 1 );
Integer estado1; consultaRealizada = "Sim";
Integer estado2 = ( Integer ) rs.get( 0, 2 );
java.util.Date dataConsulta1;
// java.util.Date dataRelatorio1;
// java.util.Date dataRelatorio2 = (java.util.Date) rs.get( 0, 3 );
String realizada1 = "";
String realizada2 = "";
if( rs.columnLength() >= 2 )
{
dataConsulta1 = ( java.util.Date ) rs.get( 1, 1 );
estado1 = ( Integer ) rs.get( 1, 2 );
// dataRelatorio1 = (java.util.Date) rs.get( 1, 3 );
}
else
{
dataConsulta1 = dataConsulta2;
estado1 = estado2;
// dataRelatorio1 = dataRelatorio2;
}
if( ESTADO_REALIZADO.equals( estado2 ) || today.after( dataConsulta2 ) )
{
hmFuncionario.put( "ultima_consulta", dataConsulta2 );
if( estado2.equals( ESTADO_REALIZADO ) )
{
realizada2 = "sim";
}
else
{
realizada2 = "n&atilde;o";
}
hmFuncionario.put( "realizada", realizada2 );
hmFuncionario.put( "proxima_consulta", null );
}
else
{
try
{
for( int c = 1; c < rs.columnLength(); c++ )
{
java.util.Date dataTemp = ( java.util.Date ) rs.get( c, 1 );
dataConsulta1 = dataTemp;
estado1 = ( Integer ) rs.get( c, 2 );
if( dataTemp.after( today ) )
{
dataConsulta2 = dataTemp;
}
else
{
break;
}
}
}
catch( Exception ex )
{
ex.printStackTrace();
}
hmFuncionario.put( "proxima_consulta", dataConsulta2 );
if( !dataConsulta2.equals( dataConsulta1 ) )
{
if( estado1.equals( ESTADO_REALIZADO ) )
{
realizada1 = "sim";
}
else
{
realizada1 = "n&atilde;o";
}
hmFuncionario.put( "realizada", realizada1 );
hmFuncionario.put( "ultima_consulta", dataConsulta1 );
}
else
{
hmFuncionario.put( "ultima_consulta", null );
hmFuncionario.put( "realizada", null );
}
}
} }
else
String queryProxima = "select id, data, estado " +
"from marcacoes_trabalhador " +
"where deleted_stamp is null and tipo = 1 and estado != 2 and data >= now() and trabalhador_id = " + trabalhadorId + " " +
"order by data desc " +
"limit 1";
rs = executeQuery( con, queryProxima );
java.util.Date dataProximaConsulta = null;
if ( rs.columnLength() > 0 )
{ {
hmFuncionario.put( "ultima_consulta", null ); dataProximaConsulta = ( java.util.Date ) rs.get( 0, 1 );
hmFuncionario.put( "realizada", null );
hmFuncionario.put( "proxima_consulta", null );
} }
stmt.close();
hmFuncionario.put( "ultima_consulta", dataUltimaConsultaRealizada == null ? "" : dataUltimaConsultaRealizada );
hmFuncionario.put( "realizada", consultaRealizada );
hmFuncionario.put( "proxima_consulta", dataProximaConsulta == null ? "" : dataProximaConsulta );
// query = "SELECT id, data, estado FROM marcacoes_trabalhador "
// + "WHERE tipo = 1 and trabalhador_id = " + trabalhadorId
// + " ORDER BY data DESC";
// stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
// rs = new ResultSet2DArray( stmt.executeQuery( query ) );
// if( rs.columnLength() > 0 )
// {
// java.util.Date dataConsulta2 = ( java.util.Date ) rs.get( 0, 1 );
// Integer estado1;
// Integer estado2 = ( Integer ) rs.get( 0, 2 );
// java.util.Date dataConsulta1;
// String realizada1 = "";
// String realizada2 = "";
// if( rs.columnLength() >= 2 )
// {
// dataConsulta1 = ( java.util.Date ) rs.get( 1, 1 );
// estado1 = ( Integer ) rs.get( 1, 2 );
// }
// else
// {
// dataConsulta1 = dataConsulta2;
// estado1 = estado2;
// }
// if( ESTADO_REALIZADO.equals( estado2 ) || today.after( dataConsulta2 ) )
// {
// hmFuncionario.put( "ultima_consulta", dataConsulta2 );
// if( estado2.equals( ESTADO_REALIZADO ) )
// {
// realizada2 = "sim";
// }
// else
// {
// realizada2 = "n&atilde;o";
// }
// hmFuncionario.put( "realizada", realizada2 );
// hmFuncionario.put( "proxima_consulta", null );
// }
// else
// {
// try
// {
// for( int c = 1; c < rs.columnLength(); c++ )
// {
// java.util.Date dataTemp = ( java.util.Date ) rs.get( c, 1 );
// dataConsulta1 = dataTemp;
// estado1 = ( Integer ) rs.get( c, 2 );
// if( dataTemp.after( today ) )
// {
// dataConsulta2 = dataTemp;
// }
// else
// {
// break;
// }
// }
// }
// catch( Exception ex )
// {
// ex.printStackTrace();
// }
// hmFuncionario.put( "proxima_consulta", dataConsulta2 );
// if( !dataConsulta2.equals( dataConsulta1 ) )
// {
// if( estado1.equals( ESTADO_REALIZADO ) )
// {
// realizada1 = "sim";
// }
// else
// {
// realizada1 = "n&atilde;o";
// }
// hmFuncionario.put( "realizada", realizada1 );
// hmFuncionario.put( "ultima_consulta", dataConsulta1 );
// }
// else
// {
// hmFuncionario.put( "ultima_consulta", null );
// hmFuncionario.put( "realizada", null );
// }
// }
// }
// else
// {
// hmFuncionario.put( "ultima_consulta", null );
// hmFuncionario.put( "realizada", null );
// hmFuncionario.put( "proxima_consulta", null );
// }
// stmt.close();
/** eof consulta dados **/
} }
sBuffer = new StringBuffer(); sBuffer = new StringBuffer();

Loading…
Cancel
Save