|
|
|
@ -9,6 +9,7 @@ package siprp.pagina;
|
|
|
|
import java.io.*;
|
|
|
|
import java.io.*;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
import java.sql.*;
|
|
|
|
import java.sql.*;
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
import java.lang.reflect.Array;
|
|
|
|
import java.lang.reflect.Array;
|
|
|
|
import javax.servlet.*;
|
|
|
|
import javax.servlet.*;
|
|
|
|
import javax.servlet.http.*;
|
|
|
|
import javax.servlet.http.*;
|
|
|
|
@ -16,241 +17,340 @@ import javax.servlet.http.*;
|
|
|
|
import org.apache.velocity.*;
|
|
|
|
import org.apache.velocity.*;
|
|
|
|
import org.apache.velocity.app.*;
|
|
|
|
import org.apache.velocity.app.*;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.evolute.utils.arrays.*;
|
|
|
|
import com.evolute.utils.arrays.*;
|
|
|
|
import com.evolute.utils.db.*;
|
|
|
|
import com.evolute.utils.db.*;
|
|
|
|
import com.evolute.utils.sql.*;
|
|
|
|
import com.evolute.utils.sql.*;
|
|
|
|
import com.evolute.utils.strings.*;
|
|
|
|
import com.evolute.utils.strings.*;
|
|
|
|
/**
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @author fpalma
|
|
|
|
|
|
|
|
*/
|
|
|
|
public class doGetListaTrabalhadoresTudo extends siprpServlet implements GlobalConstants
|
|
|
|
public class doGetListaTrabalhadoresTudo
|
|
|
|
|
|
|
|
extends siprpServlet
|
|
|
|
|
|
|
|
implements GlobalConstants
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
protected java.util.Date today;
|
|
|
|
|
|
|
|
protected long todayMillis;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Creates a new instance of doGetListaTrabalhadores */
|
|
|
|
public doGetListaTrabalhadoresTudo( HttpServletRequest req, HttpServletResponse res, boolean print )
|
|
|
|
public doGetListaTrabalhadoresTudo(HttpServletRequest req, HttpServletResponse res, boolean print) throws IOException
|
|
|
|
throws Exception
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ServletOutputStream out = res.getOutputStream();
|
|
|
|
ServletOutputStream out = res.getOutputStream();
|
|
|
|
Connection con = null ;
|
|
|
|
HttpSession session = req.getSession( false );
|
|
|
|
Statement stmt = null ;
|
|
|
|
String userRole = ( String ) session.getAttribute( sessionUserRole );
|
|
|
|
ResultSet2DArray rs;
|
|
|
|
String empresaID = ( String ) session.getAttribute( sessionEmpresaId );
|
|
|
|
StringBuffer dbQuery, sBuffer;
|
|
|
|
String userName = ( String ) session.getAttribute( sessionUser );
|
|
|
|
String userRole, empresaId, estabelecimentoId, temp;
|
|
|
|
|
|
|
|
HttpSession session = req.getSession(false);
|
|
|
|
|
|
|
|
Vector links = new Vector();
|
|
|
|
|
|
|
|
Vector desc = new Vector();
|
|
|
|
|
|
|
|
Vector descAdicional = new Vector();
|
|
|
|
|
|
|
|
today = new java.util.Date();
|
|
|
|
|
|
|
|
todayMillis = today.getTime();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
String estabelecimentoID = ( String ) session.getAttribute( sessionEstabelecimentoId );
|
|
|
|
{
|
|
|
|
|
|
|
|
userRole = (String)session.getAttribute(super.sessionUserRole);
|
|
|
|
|
|
|
|
empresaId = (String)session.getAttribute(super.sessionEmpresaId);
|
|
|
|
|
|
|
|
estabelecimentoId = (String)session.getAttribute(super.sessionEstabelecimentoId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( userRole.equals ( super.superUserRole ) || userRole.equals ( empresaId ) )
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Class.forName(super.bdDriver);
|
|
|
|
if ( superUserRole.equals( userRole ) || userRole.equals( empresaID ) )
|
|
|
|
con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
|
|
|
|
{
|
|
|
|
if ( super.verificaEstabelecimento(con, empresaId, estabelecimentoId) ) // estabelecimento pertence 'a empresa ??
|
|
|
|
Class.forName( bdDriver );
|
|
|
|
{
|
|
|
|
Connection con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
|
|
|
|
//Class.forName(super.bdDriver);
|
|
|
|
if ( verificaEstabelecimento( con, empresaID, estabelecimentoID ) )
|
|
|
|
//con = DriverManager.getConnection( super.bdUrl, super.bdUsername, super.bdPassword );
|
|
|
|
{
|
|
|
|
dbQuery = new StringBuffer();
|
|
|
|
List< Map< String, Object > > data = new LinkedList< Map< String, Object > >();
|
|
|
|
// dbQuery.append( "SELECT id, nome, data_ficha FROM trabalhadores "
|
|
|
|
|
|
|
|
// + "WHERE estabelecimento_id = '"+estabelecimentoId+"'"
|
|
|
|
|
|
|
|
// + " AND ultima_consulta IS NOT NULL AND realizada = 'y' AND"
|
|
|
|
|
|
|
|
// + " ( proxima_consulta IS NULL OR proxima_consulta - current_date > 14 )"
|
|
|
|
|
|
|
|
// + " AND ( proximo_exame IS NULL OR proximo_exame - current_date > 14 )"
|
|
|
|
|
|
|
|
// + " ORDER BY nome" );
|
|
|
|
|
|
|
|
dbQuery.append( "SELECT trabalhadores.id, trabalhadores.nome, "
|
|
|
|
|
|
|
|
+ "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, "
|
|
|
|
|
|
|
|
// + "marcacoes_trabalhador.estado, "
|
|
|
|
|
|
|
|
+ " trabalhadores.nome_plain "
|
|
|
|
|
|
|
|
+ "FROM trabalhadores, marcacoes_trabalhador "
|
|
|
|
|
|
|
|
+ "WHERE estabelecimento_id = " + estabelecimentoId
|
|
|
|
|
|
|
|
+ " AND marcacoes_trabalhador.trabalhador_id = trabalhadores.id "
|
|
|
|
|
|
|
|
+ " AND trabalhadores.inactivo <> 'y' AND data_demissao IS NULL "
|
|
|
|
|
|
|
|
+ "ORDER BY 5, 3, 4 DESC " );
|
|
|
|
|
|
|
|
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
|
|
|
|
|
|
|
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int index=0;
|
|
|
|
String query = "select e.trabalhador_id, t.nome, max( e.data ) " +
|
|
|
|
int max = rs.columnLength();
|
|
|
|
"from exames e " +
|
|
|
|
|
|
|
|
"inner join trabalhadores t on ( t.id = e.trabalhador_id ) " +
|
|
|
|
|
|
|
|
"where " +
|
|
|
|
|
|
|
|
" e.inactivo != 'y' " +
|
|
|
|
|
|
|
|
" and t.inactivo != 'y' " +
|
|
|
|
|
|
|
|
" and t.data_demissao is null " +
|
|
|
|
|
|
|
|
" and t.estabelecimento_id = " + estabelecimentoID + " " +
|
|
|
|
|
|
|
|
"group by e.trabalhador_id, t.nome";
|
|
|
|
|
|
|
|
|
|
|
|
Integer trabalhadorID = new Integer( -1 );
|
|
|
|
Statement stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
|
|
|
|
String nomeTrabalhador = "";
|
|
|
|
Virtual2DArray array = new ResultSet2DArray( stmt.executeQuery( query ) );
|
|
|
|
Vector consultas = new Vector();
|
|
|
|
for ( int i = 0; i < array.columnLength(); i++ )
|
|
|
|
Vector exames = new Vector();
|
|
|
|
{
|
|
|
|
|
|
|
|
Integer trabalhadorID = ( Integer ) array.get( i, 0 );
|
|
|
|
|
|
|
|
String trabalhadorNome = ( String ) array.get( i, 1 );
|
|
|
|
|
|
|
|
Date dataFicha = ( Date ) array.get( i, 2 );
|
|
|
|
|
|
|
|
String trabalhadorLink = "/" + servletName + "/?" + empresaID + "/" + estabelecimentoID + "/" + trabalhadorID;
|
|
|
|
|
|
|
|
|
|
|
|
for ( index = 0; index <= max; index++ )
|
|
|
|
Map< String, Object > worker = new HashMap< String, Object >();
|
|
|
|
{
|
|
|
|
worker.put( "trabalhador_id", trabalhadorID );
|
|
|
|
Integer id = index < max ? ( Integer ) rs.get( index, 0 ) : new Integer( -1 );
|
|
|
|
worker.put( "trabalhador_nome", trabalhadorNome );
|
|
|
|
if( !id.equals( trabalhadorID ) )
|
|
|
|
worker.put( "trabalhador_link", trabalhadorLink );
|
|
|
|
{
|
|
|
|
worker.put( "ficha_aptidao_data", dataFicha );
|
|
|
|
Object listaConsultas[][] = ( Object[][] ) consultas.toArray( new Object[consultas.size()][2] );
|
|
|
|
data.add( worker );
|
|
|
|
Object listaExames[][] = ( Object[][] ) exames.toArray( new Object[exames.size()][2] );
|
|
|
|
}
|
|
|
|
if( trabalhadorID.intValue() > -1 &&
|
|
|
|
|
|
|
|
verificarTrabalhador( listaConsultas, listaExames ) )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
temp=""+rs.get(index - 1,0); // converter de int para String
|
|
|
|
|
|
|
|
java.util.Date dataUltimaConsulta = null;
|
|
|
|
|
|
|
|
for( int c = 0; c < listaConsultas.length; c++ )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if( new Integer( 2 ).equals( listaConsultas[ c ][ 1 ] ) )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dataUltimaConsulta = ( java.util.Date ) listaConsultas[ c ][ 0 ];
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
HashMap dadosTrabalhador = criarDadosTrabalhador( trabalhadorID, nomeTrabalhador, dataUltimaConsulta );
|
|
|
|
|
|
|
|
if( dadosTrabalhador != null )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
dbQuery = new StringBuffer();
|
|
|
|
|
|
|
|
dbQuery.append("/"+super.servletName+"/?"+empresaId+"/"+estabelecimentoId+"/"+temp); // construir url
|
|
|
|
|
|
|
|
links.add(dbQuery.toString());
|
|
|
|
|
|
|
|
desc.add( dadosTrabalhador );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
exames.clear();
|
|
|
|
|
|
|
|
consultas.clear();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if( index == max )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Integer tipo = ( Integer ) rs.get( index, 2 );
|
|
|
|
|
|
|
|
String nome = ( String ) rs.get( index, 1 );
|
|
|
|
|
|
|
|
java.util.Date data = ( java.util.Date ) rs.get( index, 3 );
|
|
|
|
|
|
|
|
// Integer estado = ( Integer ) rs.get( index, 4 );
|
|
|
|
|
|
|
|
trabalhadorID = id;
|
|
|
|
|
|
|
|
nomeTrabalhador = nome;
|
|
|
|
|
|
|
|
// Object marcacao[] = new Object[]{ data, estado };
|
|
|
|
|
|
|
|
// switch( tipo.intValue() )
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// case TIPO_MARCACAO_EXAMES:
|
|
|
|
|
|
|
|
// exames.add( marcacao );
|
|
|
|
|
|
|
|
// break;
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// case TIPO_MARCACAO_CONSULTA:
|
|
|
|
|
|
|
|
// consultas.add( marcacao );
|
|
|
|
|
|
|
|
// break;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
stmt.close();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sBuffer = new StringBuffer();
|
|
|
|
String empresaNome = nomeEmpresa( con, empresaID );
|
|
|
|
sBuffer.append("<b>"+super.nomeEmpresa(con,empresaId)+"</b><br><br><i>"
|
|
|
|
String estabelecimentoNome = nomeEstabelecimento( con, estabelecimentoID );
|
|
|
|
+super.nomeEstabelecimento(con, estabelecimentoId)+"</i>" );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HashMap hmValues = new HashMap();
|
|
|
|
Map< String, Object > hmValues = new HashMap< String, Object >();
|
|
|
|
hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
|
|
|
|
hmValues.put( "empresa_nome", empresaNome /*session.getAttribute( sessionCompanyName )*/ );
|
|
|
|
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
|
|
|
|
hmValues.put( "empresa_id", empresaID );
|
|
|
|
hmValues.put( "estabelecimento_nome", super.nomeEstabelecimento( con, estabelecimentoId ) );
|
|
|
|
hmValues.put( "estabelecimento_nome", estabelecimentoNome );
|
|
|
|
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", userName );
|
|
|
|
hmValues.put( msgTemplate , sBuffer.toString() ) ;
|
|
|
|
hmValues.put( msgTemplate, "<b>" + empresaNome + "</b><br><br><i>" + estabelecimentoNome + "</i>" );
|
|
|
|
hmValues.put( templateUserRole, userRole);
|
|
|
|
hmValues.put( templateUserRole, userRole );
|
|
|
|
hmValues.put( templateQuery, "trabalhadores_tudo" );
|
|
|
|
hmValues.put( templateQuery, "trabalhadores_tudo" );
|
|
|
|
hmValues.put( templateVector1,links);
|
|
|
|
hmValues.put( templateVector1, data );
|
|
|
|
hmValues.put( templateVector2,desc);
|
|
|
|
hmValues.put( templateVector2, null );
|
|
|
|
hmValues.put( templateVector3,null);
|
|
|
|
hmValues.put( templateVector3, null );
|
|
|
|
if( !print )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
out.println( mergeTemplate( super.msgLinkFormatError , userRole, super.errorTemplate) );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
con.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else // Role nao permite ver esta informacao
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
out.println( mergeTemplate( super.msgAcessoNegado , userRole, super.errorTemplate) );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch ( SQLException e )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
out.println( mergeTemplate( super.msgErroBd , super.errorTemplate) );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch ( Exception e )
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
out.println( mergeTemplate( super.msgGenericError , super.errorTemplate) );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected boolean verificarTrabalhador( Object consultas[][], Object exames[][] )
|
|
|
|
out.println( mergeTemplate( hmValues, ! print ? super.authenticatedUserTemplate : super.authenticatedUserPrintTemplate ) );
|
|
|
|
{
|
|
|
|
|
|
|
|
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
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
anterior = -1;
|
|
|
|
out.println( mergeTemplate( super.msgLinkFormatError, userRole, super.errorTemplate ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
con.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
proxima = -1;
|
|
|
|
out.println( mergeTemplate( super.msgAcessoNegado, userRole, super.errorTemplate ) );
|
|
|
|
anterior = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
estadoConsultas = anterior >= 0 && new Integer( 2 ).equals( consultas[ anterior ][ 1 ] ) &&
|
|
|
|
|
|
|
|
( proxima == -1 || ( ( ( java.util.Date )consultas[ proxima ][ 0 ] ).getTime() - todayMillis ) / 86400000 > 14 );
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return estadoConsultas && estadoExames;
|
|
|
|
catch ( SQLException e )
|
|
|
|
}
|
|
|
|
{
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
protected HashMap criarDadosTrabalhador( Integer id, String nome, java.util.Date ultimaConsulta )
|
|
|
|
out.println( mergeTemplate( super.msgErroBd, super.errorTemplate ) );
|
|
|
|
throws Exception
|
|
|
|
}
|
|
|
|
{
|
|
|
|
catch ( Exception e )
|
|
|
|
Executer executer = getExecuter();
|
|
|
|
|
|
|
|
HashMap trabalhador = new HashMap();
|
|
|
|
|
|
|
|
trabalhador.put( "Nome", nome );
|
|
|
|
|
|
|
|
Select select =
|
|
|
|
|
|
|
|
new Select( new String[]{ "exames" }, new String[]{ "data" },
|
|
|
|
|
|
|
|
new Field( "trabalhador_id" ).isEqual( id ).and(
|
|
|
|
|
|
|
|
new Field( "data" ).isGreaterOrEqual( ultimaConsulta ) ),
|
|
|
|
|
|
|
|
new String[]{ "data" }, null );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
|
|
|
|
|
|
|
// ResultSet2DArray rs = new ResultSet2DArray( stmt.executeQuery( select.toString() ) );
|
|
|
|
|
|
|
|
Virtual2DArray rs = executer.executeQuery( select );
|
|
|
|
|
|
|
|
Object data_ficha = rs.columnLength() > 0 ? rs.get( 0, 0 ) : null;
|
|
|
|
|
|
|
|
// stmt.close();
|
|
|
|
|
|
|
|
if( data_ficha == null )
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
e.printStackTrace();
|
|
|
|
// data_ficha = "";
|
|
|
|
out.println( mergeTemplate( super.msgGenericError, super.errorTemplate ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
trabalhador.put( "Data", data_ficha );
|
|
|
|
|
|
|
|
return trabalhador;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// public doGetListaTrabalhadoresTudo( HttpServletRequest req, HttpServletResponse res, boolean print )
|
|
|
|
|
|
|
|
// throws IOException
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// ServletOutputStream out = res.getOutputStream();
|
|
|
|
|
|
|
|
// Connection con = null;
|
|
|
|
|
|
|
|
// Statement stmt = null;
|
|
|
|
|
|
|
|
// ResultSet2DArray rs;
|
|
|
|
|
|
|
|
// StringBuffer dbQuery, sBuffer;
|
|
|
|
|
|
|
|
// String userRole, empresaId, estabelecimentoId, temp;
|
|
|
|
|
|
|
|
// HttpSession session = req.getSession( false );
|
|
|
|
|
|
|
|
// Vector links = new Vector();
|
|
|
|
|
|
|
|
// Vector desc = new Vector();
|
|
|
|
|
|
|
|
// Vector descAdicional = new Vector();
|
|
|
|
|
|
|
|
// Date today = new Date();
|
|
|
|
|
|
|
|
// long todayMillis = today.getTime();
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// try
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// userRole = ( String ) session.getAttribute( super.sessionUserRole );
|
|
|
|
|
|
|
|
// empresaId = ( String ) session.getAttribute( super.sessionEmpresaId );
|
|
|
|
|
|
|
|
// estabelecimentoId = ( String ) session.getAttribute( super.sessionEstabelecimentoId );
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// if ( userRole.equals( super.superUserRole ) || userRole.equals( empresaId ) )
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// Class.forName( super.bdDriver );
|
|
|
|
|
|
|
|
// con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
|
|
|
|
|
|
|
|
// if ( verificaEstabelecimento( con, empresaId, estabelecimentoId ) )
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// // Class.forName(super.bdDriver);
|
|
|
|
|
|
|
|
// // con = DriverManager.getConnection( super.bdUrl,
|
|
|
|
|
|
|
|
// // super.bdUsername, super.bdPassword );
|
|
|
|
|
|
|
|
// dbQuery = new StringBuffer();
|
|
|
|
|
|
|
|
// // dbQuery.append(
|
|
|
|
|
|
|
|
// // "SELECT id, nome, data_ficha FROM trabalhadores "
|
|
|
|
|
|
|
|
// // + "WHERE estabelecimento_id = '"+estabelecimentoId+"'"
|
|
|
|
|
|
|
|
// // +
|
|
|
|
|
|
|
|
// // " AND ultima_consulta IS NOT NULL AND realizada = 'y' AND"
|
|
|
|
|
|
|
|
// // +
|
|
|
|
|
|
|
|
// // " ( proxima_consulta IS NULL OR proxima_consulta - current_date > 14 )"
|
|
|
|
|
|
|
|
// // +
|
|
|
|
|
|
|
|
// // " AND ( proximo_exame IS NULL OR proximo_exame - current_date > 14 )"
|
|
|
|
|
|
|
|
// // + " ORDER BY nome" );
|
|
|
|
|
|
|
|
// dbQuery.append( "SELECT trabalhadores.id, trabalhadores.nome, "
|
|
|
|
|
|
|
|
// + "marcacoes_trabalhador.tipo, marcacoes_trabalhador.data, "
|
|
|
|
|
|
|
|
// // + "marcacoes_trabalhador.estado, "
|
|
|
|
|
|
|
|
// + " trabalhadores.nome_plain " + "FROM trabalhadores, marcacoes_trabalhador " + "WHERE estabelecimento_id = " + estabelecimentoId
|
|
|
|
|
|
|
|
// + " AND marcacoes_trabalhador.trabalhador_id = trabalhadores.id " + " AND trabalhadores.inactivo <> 'y' AND data_demissao IS NULL "
|
|
|
|
|
|
|
|
// + "ORDER BY 5, 3, 4 DESC " );
|
|
|
|
|
|
|
|
// stmt = con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY );
|
|
|
|
|
|
|
|
// rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString() ) );
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// int index = 0;
|
|
|
|
|
|
|
|
// int max = rs.columnLength();
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// Integer trabalhadorID = new Integer( -1 );
|
|
|
|
|
|
|
|
// String nomeTrabalhador = "";
|
|
|
|
|
|
|
|
// Vector consultas = new Vector();
|
|
|
|
|
|
|
|
// Vector exames = new Vector();
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// for ( index = 0; index <= max; index++ )
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// 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 ] );
|
|
|
|
|
|
|
|
// if ( trabalhadorID.intValue() > -1 && verificarTrabalhador( listaConsultas, listaExames ) )
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// temp = "" + rs.get( index - 1, 0 ); // converter
|
|
|
|
|
|
|
|
// // de int
|
|
|
|
|
|
|
|
// // para
|
|
|
|
|
|
|
|
// // String
|
|
|
|
|
|
|
|
// java.util.Date dataUltimaConsulta = null;
|
|
|
|
|
|
|
|
// for ( int c = 0; c < listaConsultas.length; c++ )
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// if ( new Integer( 2 ).equals( listaConsultas[ c ][ 1 ] ) )
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// dataUltimaConsulta = ( java.util.Date ) listaConsultas[ c ][ 0 ];
|
|
|
|
|
|
|
|
// break;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// HashMap dadosTrabalhador = criarDadosTrabalhador( trabalhadorID, nomeTrabalhador, dataUltimaConsulta );
|
|
|
|
|
|
|
|
// if ( dadosTrabalhador != null )
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// dbQuery = new StringBuffer();
|
|
|
|
|
|
|
|
// dbQuery.append( "/" + super.servletName + "/?" + empresaId + "/" + estabelecimentoId + "/" + temp ); // construir
|
|
|
|
|
|
|
|
// // url
|
|
|
|
|
|
|
|
// links.add( dbQuery.toString() );
|
|
|
|
|
|
|
|
// desc.add( dadosTrabalhador );
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// exames.clear();
|
|
|
|
|
|
|
|
// consultas.clear();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// if ( index == max )
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// break;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// Integer tipo = ( Integer ) rs.get( index, 2 );
|
|
|
|
|
|
|
|
// String nome = ( String ) rs.get( index, 1 );
|
|
|
|
|
|
|
|
// java.util.Date data = ( java.util.Date ) rs.get( index, 3 );
|
|
|
|
|
|
|
|
// // Integer estado = ( Integer ) rs.get( index, 4 );
|
|
|
|
|
|
|
|
// trabalhadorID = id;
|
|
|
|
|
|
|
|
// nomeTrabalhador = nome;
|
|
|
|
|
|
|
|
// // Object marcacao[] = new Object[]{ data, estado };
|
|
|
|
|
|
|
|
// // switch( tipo.intValue() )
|
|
|
|
|
|
|
|
// // {
|
|
|
|
|
|
|
|
// // case TIPO_MARCACAO_EXAMES:
|
|
|
|
|
|
|
|
// // exames.add( marcacao );
|
|
|
|
|
|
|
|
// // break;
|
|
|
|
|
|
|
|
// //
|
|
|
|
|
|
|
|
// // case TIPO_MARCACAO_CONSULTA:
|
|
|
|
|
|
|
|
// // consultas.add( marcacao );
|
|
|
|
|
|
|
|
// // break;
|
|
|
|
|
|
|
|
// // }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// stmt.close();
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// sBuffer = new StringBuffer();
|
|
|
|
|
|
|
|
// sBuffer.append( "<b>" + super.nomeEmpresa( con, empresaId ) + "</b><br><br><i>" + super.nomeEstabelecimento( con, estabelecimentoId )
|
|
|
|
|
|
|
|
// + "</i>" );
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// HashMap hmValues = new HashMap();
|
|
|
|
|
|
|
|
// hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
|
|
|
|
|
|
|
|
// hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
|
|
|
|
|
|
|
|
// hmValues.put( "estabelecimento_nome", super.nomeEstabelecimento( con, estabelecimentoId ) );
|
|
|
|
|
|
|
|
// hmValues.put( "estabelecimento_id", estabelecimentoId );
|
|
|
|
|
|
|
|
// hmValues.put( "userRole", userRole );
|
|
|
|
|
|
|
|
// hmValues.put( "userName", session.getAttribute( sessionUser ) );
|
|
|
|
|
|
|
|
// hmValues.put( msgTemplate, sBuffer.toString() );
|
|
|
|
|
|
|
|
// hmValues.put( templateUserRole, userRole );
|
|
|
|
|
|
|
|
// hmValues.put( templateQuery, "trabalhadores_tudo" );
|
|
|
|
|
|
|
|
// hmValues.put( templateVector1, links );
|
|
|
|
|
|
|
|
// hmValues.put( templateVector2, desc );
|
|
|
|
|
|
|
|
// hmValues.put( templateVector3, null );
|
|
|
|
|
|
|
|
// if ( !print )
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate ) );
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// else
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// out.println( mergeTemplate( super.msgLinkFormatError, userRole, super.errorTemplate ) );
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// con.close();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// else
|
|
|
|
|
|
|
|
// // Role nao permite ver esta informacao
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// out.println( mergeTemplate( super.msgAcessoNegado, userRole, super.errorTemplate ) );
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// catch ( SQLException e )
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
|
|
|
// out.println( mergeTemplate( super.msgErroBd, super.errorTemplate ) );
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// catch ( Exception e )
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// e.printStackTrace();
|
|
|
|
|
|
|
|
// out.println( mergeTemplate( super.msgGenericError, super.errorTemplate ) );
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// 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 && new Integer( 2 ).equals( consultas[ anterior ][ 1 ] )
|
|
|
|
|
|
|
|
// && ( proxima == -1 || ( ( ( java.util.Date ) consultas[ proxima ][ 0 ] ).getTime() - todayMillis ) / 86400000 > 14 );
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return estadoConsultas && estadoExames;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// protected HashMap criarDadosTrabalhador( Integer id, String nome, java.util.Date ultimaConsulta ) throws Exception
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// Executer executer = getExecuter();
|
|
|
|
|
|
|
|
// HashMap trabalhador = new HashMap();
|
|
|
|
|
|
|
|
// trabalhador.put( "Nome", nome );
|
|
|
|
|
|
|
|
// Select select = new Select( new String[] {
|
|
|
|
|
|
|
|
// "exames"
|
|
|
|
|
|
|
|
// }, new String[] {
|
|
|
|
|
|
|
|
// "data"
|
|
|
|
|
|
|
|
// }, new Field( "trabalhador_id" ).isEqual( id ).and( new Field( "data" ).isGreaterOrEqual( ultimaConsulta ) ), new String[] {
|
|
|
|
|
|
|
|
// "data"
|
|
|
|
|
|
|
|
// }, null );
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// // Statement stmt =
|
|
|
|
|
|
|
|
// // con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
|
|
|
|
|
|
|
|
// // ResultSet.CONCUR_READ_ONLY);
|
|
|
|
|
|
|
|
// // ResultSet2DArray rs = new ResultSet2DArray( stmt.executeQuery(
|
|
|
|
|
|
|
|
// // select.toString() ) );
|
|
|
|
|
|
|
|
// Virtual2DArray rs = executer.executeQuery( select );
|
|
|
|
|
|
|
|
// Object data_ficha = rs.columnLength() > 0 ? rs.get( 0, 0 ) : null;
|
|
|
|
|
|
|
|
// // stmt.close();
|
|
|
|
|
|
|
|
// if ( data_ficha == null )
|
|
|
|
|
|
|
|
// {
|
|
|
|
|
|
|
|
// return null;
|
|
|
|
|
|
|
|
// // data_ficha = "";
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// trabalhador.put( "Data", data_ficha );
|
|
|
|
|
|
|
|
// return trabalhador;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
|