no message

git-svn-id: https://svn.coded.pt/svn/SIPRP@529 bb69d46d-e84e-40c8-a05a-06db0d633741
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
Frederico Palma 20 years ago
parent de490bb93a
commit ec69036cf7

@ -6,16 +6,19 @@
package siprp.pagina; package siprp.pagina;
import com.evolute.utils.arrays.*;
import com.evolute.utils.strings.*;
import java.io.*; import java.io.*;
import java.util.*;
import java.sql.*;
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 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.strings.*;
/** /**
* *
* @author fpalma * @author fpalma
@ -23,214 +26,214 @@ import org.apache.velocity.app.*;
public class doGetListaTrabalhadoresPendentes public class doGetListaTrabalhadoresPendentes
extends siprpServlet extends siprpServlet
{ {
protected java.util.Date today; protected java.util.Date today;
protected long todayMillis; protected long todayMillis;
/** Creates a new instance of doGetListaTrabalhadores */ /** Creates a new instance of doGetListaTrabalhadores */
public doGetListaTrabalhadoresPendentes(HttpServletRequest req, HttpServletResponse res, boolean print) throws IOException public doGetListaTrabalhadoresPendentes(HttpServletRequest req, HttpServletResponse res, boolean print) throws IOException
{ {
ServletOutputStream out = res.getOutputStream(); ServletOutputStream out = res.getOutputStream();
Connection con = null ; Connection con = null ;
Statement stmt = null ; Statement stmt = null ;
ResultSet2DArray rs; ResultSet2DArray rs;
StringBuffer dbQuery, sBuffer; StringBuffer dbQuery, sBuffer;
String userRole, empresaId, estabelecimentoId, temp; String userRole, empresaId, estabelecimentoId, temp;
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(); today = new java.util.Date();
todayMillis = today.getTime(); todayMillis = today.getTime();
try try
{ {
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);
if ( userRole.equals ( super.superUserRole ) || userRole.equals ( empresaId ) )
{
Class.forName(super.bdDriver);
con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
if ( super.verificaEstabelecimento(con, empresaId, estabelecimentoId) ) // estabelecimento pertence à empresa ??
{
//Class.forName(super.bdDriver);
//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 "
+ "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 "
+ "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' ),"
// + " proxima_consulta IS NOT NULL, proximo_exame IS NOT NULL, "
// + " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 ), "
// + " ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 )"
// + " FROM trabalhadores "
// + " WHERE estabelecimento_id = '"+estabelecimentoId+"'"
// + " AND ( ultima_consulta IS NULL OR realizada = 'n' OR"
// + " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 )"
// + " OR ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 ) )"
// + " ORDER BY nome" );
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
int index=0; if ( userRole.equals ( super.superUserRole ) || userRole.equals ( empresaId ) )
int max = rs.columnLength(); {
Class.forName(super.bdDriver);
con = DriverManager.getConnection( bdLocalUrl, bdLocalUsername, bdLocalPassword );
if ( super.verificaEstabelecimento(con, empresaId, estabelecimentoId) ) // estabelecimento pertence à empresa ??
{
//Class.forName(super.bdDriver);
//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 "
+ "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 "
+ "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' ),"
// + " proxima_consulta IS NOT NULL, proximo_exame IS NOT NULL, "
// + " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 ), "
// + " ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 )"
// + " FROM trabalhadores "
// + " WHERE estabelecimento_id = '"+estabelecimentoId+"'"
// + " AND ( ultima_consulta IS NULL OR realizada = 'n' OR"
// + " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 )"
// + " OR ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 ) )"
// + " ORDER BY nome" );
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
rs = new ResultSet2DArray( stmt.executeQuery( dbQuery.toString()) );
Integer trabalhadorID = new Integer( -1 ); int index=0;
String nomeTrabalhador = ""; int max = rs.columnLength();
Vector consultas = new Vector();
Vector exames = new Vector();
for ( index = 0; index <= max; index++ ) Integer trabalhadorID = new Integer( -1 );
{ String nomeTrabalhador = "";
Integer id = index < max ? ( Integer ) rs.get( index, 0 ) : new Integer( -1 ); Vector consultas = new Vector();
if( !id.equals( trabalhadorID ) ) Vector exames = new Vector();
{
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
dbQuery = new StringBuffer();
dbQuery.append("/"+super.servletName+"/?"+empresaId+"/"+estabelecimentoId+"/"+temp); // contruir url
links.add(dbQuery.toString());
desc.add( criarDadosTrabalhador( con, trabalhadorID, nomeTrabalhador, listaConsultas, listaExames ) );
}
exames.clear();
consultas.clear();
}
if( index == max )
{
break;
}
Integer tipo = ( Integer ) rs.get( index, 2 );
String nome = ( String ) rs.get( index, 1 ); for ( index = 0; index <= max; index++ )
java.util.Date data = ( java.util.Date ) rs.get( index, 3 ); {
String realizada = ( String ) rs.get( index, 4 ); Integer id = index < max ? ( Integer ) rs.get( index, 0 ) : new Integer( -1 );
trabalhadorID = id; if( !id.equals( trabalhadorID ) )
nomeTrabalhador = nome; {
Object marcacao[] = new Object[]{ data, realizada }; Object listaConsultas[][] = ( Object[][] ) consultas.toArray( new Object[consultas.size()][2] );
if( tipo == null ) Object listaExames[][] = ( Object[][] ) exames.toArray( new Object[exames.size()][2] );
{ if( trabalhadorID.intValue() > -1 &&
continue; verificarTrabalhador( listaConsultas, listaExames ) )
}
switch( tipo.intValue() )
{ {
case TIPO_MARCACAO_EXAMES: temp=""+rs.get(index - 1,0); // converter de int para String
exames.add( marcacao ); dbQuery = new StringBuffer();
break; dbQuery.append("/"+super.servletName+"/?"+empresaId+"/"+estabelecimentoId+"/"+temp); // contruir url
links.add(dbQuery.toString());
case TIPO_MARCACAO_CONSULTA: desc.add( criarDadosTrabalhador( con, trabalhadorID, nomeTrabalhador, listaConsultas, listaExames ) );
consultas.add( marcacao );
break;
} }
} exames.clear();
stmt.close(); consultas.clear();
}
sBuffer = new StringBuffer(); if( index == max )
sBuffer.append("<b>"+super.nomeEmpresa(con,empresaId)+"</b><br><br><i>" {
+super.nomeEstabelecimento(con, estabelecimentoId)+"</i>" ); break;
}
Integer tipo = ( Integer ) rs.get( index, 2 );
HashMap hmValues = new HashMap(); String nome = ( String ) rs.get( index, 1 );
hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) ); java.util.Date data = ( java.util.Date ) rs.get( index, 3 );
hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) ); String realizada = ( String ) rs.get( index, 4 );
hmValues.put( "estabelecimento_nome", super.nomeEstabelecimento( con, estabelecimentoId ) ); trabalhadorID = id;
hmValues.put( "estabelecimento_id", estabelecimentoId ); nomeTrabalhador = nome;
hmValues.put( "userRole", userRole ); Object marcacao[] = new Object[]{ data, realizada };
hmValues.put( "userName", session.getAttribute( sessionUser ) ); if( tipo == null )
hmValues.put( msgTemplate , sBuffer.toString() ) ;
hmValues.put( templateUserRole, userRole);
hmValues.put( templateQuery, "trabalhadores_pendentes" );
hmValues.put( templateVector1,links);
hmValues.put( templateVector2,desc);
hmValues.put( templateVector3,null);
if( !print )
{ {
out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate)); continue;
} }
else switch( tipo.intValue() )
{ {
out.println( mergeTemplate( hmValues, super.authenticatedUserPrintTemplate)); case TIPO_MARCACAO_EXAMES:
exames.add( marcacao );
break;
case TIPO_MARCACAO_CONSULTA:
consultas.add( marcacao );
break;
} }
// out.println( mergeTemplate( sBuffer.toString(), userRole, super.queryStringTrabalhadores, links, desc, null, super.authenticatedUserTemplate) ); }
} stmt.close();
else // est não pertence à empresa
{
out.println( mergeTemplate( super.msgLinkFormatError , userRole, super.errorTemplate) );
}
con.close();
}
else // Role não permite ver esta informação
{
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[][] ) sBuffer = new StringBuffer();
{ sBuffer.append("<b>"+super.nomeEmpresa(con,empresaId)+"</b><br><br><i>"
boolean estadoConsultas = false; +super.nomeEstabelecimento(con, estabelecimentoId)+"</i>" );
boolean estadoExames = ( exames.length == 0 ) || ( ( java.util.Date )exames[ 0 ][ 0 ] ).before(today) ||
( ( ( ( java.util.Date )exames[ 0 ][ 0 ] ).getTime() - todayMillis ) / 86400000 > 14 ); HashMap hmValues = new HashMap();
if( consultas.length > 0 ) hmValues.put( "empresa_nome", session.getAttribute( sessionCompanyName ) );
{ hmValues.put( "empresa_id", session.getAttribute( sessionEmpresaId ) );
int anterior; hmValues.put( "estabelecimento_nome", super.nomeEstabelecimento( con, estabelecimentoId ) );
int proxima; hmValues.put( "estabelecimento_id", estabelecimentoId );
if( ( (java.util.Date) consultas[ 0 ][ 0 ] ).after( today ) ) hmValues.put( "userRole", userRole );
{ hmValues.put( "userName", session.getAttribute( sessionUser ) );
proxima = 0; hmValues.put( msgTemplate , sBuffer.toString() ) ;
if( consultas.length >= 2 ) hmValues.put( templateUserRole, userRole);
{ hmValues.put( templateQuery, "trabalhadores_pendentes" );
anterior = 1; 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 else // est não pertence à empresa
{ {
anterior = -1; out.println( mergeTemplate( super.msgLinkFormatError , userRole, super.errorTemplate) );
} }
con.close();
}
else // Role não permite ver esta informação
{
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 else
{ {
proxima = -1; anterior = -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); 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);
}
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[][] )
throws Exception throws Exception
{ {
// 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' ),"
// + " proxima_consulta IS NOT NULL, proximo_exame IS NOT NULL, " // + " proxima_consulta IS NOT NULL, proximo_exame IS NOT NULL, "
// + " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 ), " // + " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 ), "
// + " ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 )" // + " ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 )"
// + " FROM trabalhadores " // + " FROM trabalhadores "
// + " WHERE estabelecimento_id = '"+estabelecimentoId+"'" // + " WHERE estabelecimento_id = '"+estabelecimentoId+"'"
// + " AND ( ultima_consulta IS NULL OR realizada = 'n' OR" // + " AND ( ultima_consulta IS NULL OR realizada = 'n' OR"
// + " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 )" // + " ( proxima_consulta IS NOT NULL AND proxima_consulta - current_date <= 14 )"
// + " OR ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 ) )" // + " OR ( proximo_exame IS NOT NULL AND proximo_exame - current_date <= 14 ) )"
// + " ORDER BY nome" ); // + " ORDER BY nome" );
HashMap trabalhador = new HashMap(); HashMap trabalhador = new HashMap();
trabalhador.put( "Nome", nome ); trabalhador.put( "Nome", nome );
boolean uc = false; boolean uc = false;

Loading…
Cancel
Save