no message

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

@ -6,16 +6,19 @@
package siprp.pagina;
import com.evolute.utils.arrays.*;
import com.evolute.utils.strings.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import java.lang.reflect.Array;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;
import org.apache.velocity.*;
import org.apache.velocity.app.*;
import com.evolute.utils.arrays.*;
import com.evolute.utils.strings.*;
/**
*
* @author fpalma
@ -23,214 +26,214 @@ import org.apache.velocity.app.*;
public class doGetListaTrabalhadoresPendentes
extends siprpServlet
{
protected java.util.Date today;
protected java.util.Date today;
protected long todayMillis;
/** Creates a new instance of doGetListaTrabalhadores */
public doGetListaTrabalhadoresPendentes(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();
/** Creates a new instance of doGetListaTrabalhadores */
public doGetListaTrabalhadoresPendentes(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();
today = new java.util.Date();
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 ( 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;
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
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 );
java.util.Date data = ( java.util.Date ) rs.get( index, 3 );
String realizada = ( String ) rs.get( index, 4 );
trabalhadorID = id;
nomeTrabalhador = nome;
Object marcacao[] = new Object[]{ data, realizada };
if( tipo == null )
{
continue;
}
switch( tipo.intValue() )
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 ( 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;
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 ) )
{
case TIPO_MARCACAO_EXAMES:
exames.add( marcacao );
break;
case TIPO_MARCACAO_CONSULTA:
consultas.add( marcacao );
break;
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 ) );
}
}
stmt.close();
sBuffer = new StringBuffer();
sBuffer.append("<b>"+super.nomeEmpresa(con,empresaId)+"</b><br><br><i>"
+super.nomeEstabelecimento(con, estabelecimentoId)+"</i>" );
exames.clear();
consultas.clear();
}
if( index == max )
{
break;
}
Integer tipo = ( Integer ) rs.get( index, 2 );
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_pendentes" );
hmValues.put( templateVector1,links);
hmValues.put( templateVector2,desc);
hmValues.put( templateVector3,null);
if( !print )
String nome = ( String ) rs.get( index, 1 );
java.util.Date data = ( java.util.Date ) rs.get( index, 3 );
String realizada = ( String ) rs.get( index, 4 );
trabalhadorID = id;
nomeTrabalhador = nome;
Object marcacao[] = new Object[]{ data, realizada };
if( tipo == null )
{
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) );
}
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[][] )
{
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;
}
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_pendentes" );
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
{
proxima = -1;
anterior = 0;
anterior = -1;
}
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,
Object consultas[][], Object exames[][] )
throws Exception
{
// 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" );
// 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" );
HashMap trabalhador = new HashMap();
trabalhador.put( "Nome", nome );
boolean uc = false;
@ -271,7 +274,7 @@ public class doGetListaTrabalhadoresPendentes
pc = proxima > -1;
quase_c = pc && diff <= 14;
}
if( exames.length > 0 )
{
int anterior;
@ -302,7 +305,7 @@ public class doGetListaTrabalhadoresPendentes
pe = proximo > -1;
quase_e = pe && diff <= 14;
}
if( quase_c )
{
trabalhador.put( "Consulta", "yellow" );

Loading…
Cancel
Save