forked from Coded/SIPRP
no message
git-svn-id: https://svn.coded.pt/svn/SIPRP@305 bb69d46d-e84e-40c8-a05a-06db0d6337410'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z
parent
2a65376af1
commit
7cc27e8c08
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* RemarcacoesDataProvider.java
|
||||
*
|
||||
* Created on February 14, 2007, 10:56 AM
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package siprp.lembretes.remarcacoes;
|
||||
|
||||
import com.evolute.utils.Singleton;
|
||||
import com.evolute.utils.arrays.Virtual2DArray;
|
||||
import com.evolute.utils.data.IDObject;
|
||||
import com.evolute.utils.data.MappableObject;
|
||||
import com.evolute.utils.db.DBManager;
|
||||
import com.evolute.utils.db.Executer;
|
||||
import com.evolute.utils.sql.Expression;
|
||||
import com.evolute.utils.sql.Field;
|
||||
import com.evolute.utils.sql.Select;
|
||||
import com.evolute.utils.sql.Select2;
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import siprp.data.Marcacao;
|
||||
import siprp.lembretes.LembretesConstants;
|
||||
import siprp.lembretes.LembretesDataProvider;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author lflores
|
||||
*/
|
||||
public class RemarcacoesDataProvider
|
||||
{
|
||||
private static final DateFormat D_F = DateFormat.getDateInstance( DateFormat.SHORT, new Locale( "pt", "PT" ) );
|
||||
|
||||
private static final Object LOCK = new Object();
|
||||
private static RemarcacoesDataProvider instance = null;
|
||||
|
||||
private Executer EXECUTER;
|
||||
private LembretesDataProvider lembretesProvider;
|
||||
|
||||
/** Creates a new instance of RemarcacoesDataProvider */
|
||||
public RemarcacoesDataProvider()
|
||||
throws Exception
|
||||
{
|
||||
DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER );
|
||||
EXECUTER = dbm.getSharedExecuter( this );
|
||||
lembretesProvider = LembretesDataProvider.getProvider();
|
||||
}
|
||||
|
||||
public static RemarcacoesDataProvider getProvider()
|
||||
throws Exception
|
||||
{
|
||||
synchronized( LOCK )
|
||||
{
|
||||
if( instance == null )
|
||||
{
|
||||
instance = new RemarcacoesDataProvider();
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public IDObject[] getLembretesRemarcacaoTrabalhador()
|
||||
throws Exception
|
||||
{
|
||||
Select select =
|
||||
new Select2( new String[]{ "lembretes", "marcacoes_trabalhador", "trabalhadores",
|
||||
"estabelecimentos", "empresas" },
|
||||
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER },
|
||||
new Expression[]{
|
||||
new Field( "lembretes.marcacao_trabalhador_id" ).isEqual( new Field( "marcacoes_trabalhador.id" ) ),
|
||||
new Field( "marcacoes_trabalhador.trabalhador_id" ).isEqual( new Field( "trabalhadores.id" ) ),
|
||||
new Field( "trabalhadores.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ),
|
||||
new Field( "estabelecimentos.empresa_id" ).isEqual( new Field( "empresas.id" ) ),
|
||||
},
|
||||
new String[]{ "lembretes.id", "lembretes.descricao",
|
||||
"marcacoes_trabalhador.tipo", "marcacoes_trabalhador.data",
|
||||
"trabalhadores.nome", "estabelecimentos.nome", "empresas.designacao_social",
|
||||
"trabalhadores.nome_plain" },
|
||||
new Field( "lembretes.tipo_id" ).isEqual(
|
||||
lembretesProvider.getTipoLembreteByCodigo( LembretesConstants.CODE_REMARCACOES ).getID() ).and(
|
||||
new Field( "lembretes.data" ).isLessOrEqual( new Field( "current_date" ) ) ),
|
||||
new String[]{ "trabalhadores.nome_plain" },
|
||||
null,
|
||||
null,
|
||||
null );
|
||||
Virtual2DArray array = EXECUTER.executeQuery( select );
|
||||
IDObject lembretes[] = new IDObject[ array.columnLength() ];
|
||||
for( int n = 0; n < lembretes.length; n++ )
|
||||
{
|
||||
Integer id = ( Integer ) array.get( n, 0 );
|
||||
String descricao = ( String ) array.get( n, 1 );
|
||||
Integer tipoMarcacao = ( Integer ) array.get( n, 2 );
|
||||
String tipoMarcacaoStr = "";
|
||||
switch( tipoMarcacao.intValue() )
|
||||
{
|
||||
case Marcacao.TIPO_MARCACAO_TRABALHADOR_EXAMES:
|
||||
tipoMarcacaoStr = "ECDs";
|
||||
break;
|
||||
|
||||
case Marcacao.TIPO_MARCACAO_TRABALHADOR_CONSULTA:
|
||||
tipoMarcacaoStr = "Consulta";
|
||||
break;
|
||||
}
|
||||
Date data = ( Date ) array.get( n, 3 );
|
||||
String trabalhador = ( String ) array.get( n, 4 );
|
||||
String split[] = trabalhador.split( " " );
|
||||
trabalhador = split[ 0 ] + " " + ( split.length > 2 ? split[ 1 ].charAt( 0 ) + ". " : " " ) +
|
||||
( split.length > 1 ? split[ split.length - 1 ] : "" );
|
||||
String estabelecimento = ( String ) array.get( n, 5 );
|
||||
String empresa = ( String ) array.get( n, 6 );
|
||||
String str = "<html><body><font color=\"#00009f\">" + trabalhador + "</font>"
|
||||
+ "<br> " + tipoMarcacaoStr + " de " + D_F.format( data )
|
||||
+ "<br> <font color=\"#009f00\">" + descricao + "</font>"
|
||||
+ "<br> " + empresa.substring( 0, empresa.length() > 20 ? 20 : empresa.length() )
|
||||
+ " / " + estabelecimento.substring( 0, estabelecimento.length() > 10 ? 10 : estabelecimento.length() )
|
||||
+ "</body></html>";
|
||||
lembretes[ n ] = new MappableObject( id, str );
|
||||
}
|
||||
return lembretes;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue