forked from Coded/SIPRP
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							256 lines
						
					
					
						
							8.3 KiB
						
					
					
				
			
		
		
	
	
							256 lines
						
					
					
						
							8.3 KiB
						
					
					
				| /*
 | |
|  * HigieneDataProvider.java
 | |
|  *
 | |
|  * Created on February 1, 2006, 10:49 PM
 | |
|  *
 | |
|  * To change this template, choose Tools | Template Manager
 | |
|  * and open the template in the editor.
 | |
|  */
 | |
| 
 | |
| package siprp.higiene;
 | |
| 
 | |
| import java.awt.*;
 | |
| import java.util.*;
 | |
| 
 | |
| import com.evolute.utils.*;
 | |
| import com.evolute.utils.arrays.*;
 | |
| import com.evolute.utils.data.*;
 | |
| import com.evolute.utils.db.*;
 | |
| import com.evolute.utils.metadb.*;
 | |
| import com.evolute.utils.sql.*;
 | |
| import com.evolute.utils.strings.*;
 | |
| import com.evolute.utils.tables.*;
 | |
| 
 | |
| import siprp.*;
 | |
| import siprp.data.*;
 | |
| 
 | |
| /**
 | |
|  *
 | |
|  * @author fpalma
 | |
|  */
 | |
| public class HigieneDataProvider extends MetaProvider
 | |
| {
 | |
| 	public static final int  ESTADO_POR_REALIZAR = 0;
 | |
| 	public static final int  ESTADO_REALIZADO = 2;
 | |
| 	public static final int  ESTADO_DESMARCADO_TRABALHADOR = 3;
 | |
| 	public static final int  ESTADO_DESMARCADO_EMPRESA = 4;
 | |
| 	public static final int  ESTADO_FALTOU = 5;
 | |
| 	
 | |
| 	public static final String  ESTADOS_STR[] = 
 | |
| 			new String[]{ "Por realizar", "", "Realizada",
 | |
| 							"Desmarcada empresa", 
 | |
| 							"Desmarcada " + Singleton.getInstance( SingletonConstants.COMPANY_ACRONYM ),
 | |
| 							"Faltou" };
 | |
| 	
 | |
| 	public static final Color CORES_TECNICOS[] = 
 | |
| 			new Color[]{ Color.white, Color.red.darker(), Color.blue, 
 | |
| 							Color.green.darker(), Color.yellow.darker(), 
 | |
| 							Color.gray, Color.pink.darker() };
 | |
| 	
 | |
| 	private static final Object LOCK = new Object();
 | |
| 	private static HigieneDataProvider instance = null;
 | |
| 	private final Executer executer;
 | |
| 	
 | |
| 	/** Creates a new instance of HigieneDataProvider */
 | |
| 	public HigieneDataProvider()
 | |
| 		throws Exception
 | |
| 	{
 | |
| 		DBManager dbm = ( DBManager ) Singleton.getInstance( Singleton.DEFAULT_DBMANAGER /*SingletonConstants.DBMANAGER*/ );
 | |
| 		executer = dbm.getSharedExecuter( this );
 | |
| 	}
 | |
| 	
 | |
| 	public static MetaProvider getProvider()
 | |
| 		throws Exception
 | |
| 	{
 | |
| 		synchronized( LOCK )
 | |
| 		{
 | |
| 			if( instance == null )
 | |
| 			{
 | |
| 				instance = new HigieneDataProvider();
 | |
| 			}
 | |
| 		}
 | |
| 		return instance;
 | |
| 	}
 | |
| 	
 | |
| 	public Object[][] getAllTecnicosHST()
 | |
| 		throws Exception
 | |
| 	{
 | |
| 		Select select = 
 | |
| 				new Select( new String[]{ "marcacoes_tecnicos_hst" },
 | |
| 							new String[]{ "id", "nome", "iniciais", "identificador", "nome_plain" },
 | |
| 							new Field( "inactivo" ).isDifferent( "y" ),
 | |
| 							new String[]{ "nome_plain" },
 | |
| 							null );
 | |
| 		Virtual2DArray array = executer.executeQuery( select );
 | |
| 		return array.getObjects();
 | |
| 	}
 | |
| 	
 | |
| 	public ColumnizedMappable[] getAllEmpresas()
 | |
| 		throws Exception
 | |
| 	{
 | |
| 		Select select =
 | |
| 				new Select( new String[]{ "empresas" },
 | |
| 							new String[]{ "id", "designacao_social", "designacao_social_plain" },
 | |
| 							new Field( "inactivo" ).isDifferent( "y" ),
 | |
| 							new String[]{ "designacao_social_plain" },
 | |
| 							null );
 | |
| 		Virtual2DArray array = executer.executeQuery( select );
 | |
| 		ColumnizedMappable empresas[] = new ColumnizedMappable[ array.columnLength() ];
 | |
| 		for( int n = 0; n < empresas.length; n++ )
 | |
| 		{
 | |
| 			Integer id = ( Integer ) array.get( n, 0 );
 | |
| 			String designacao = ( String ) array.get( n, 1 );
 | |
| 			empresas[ n ] = new ColumnizedMappable( id, designacao );
 | |
| 		}
 | |
| 		return empresas;
 | |
| 	}
 | |
| 	
 | |
| 	public ColumnizedMappable[] getAllEstabelecimentosForEmpresa( Integer empresaID )
 | |
| 		throws Exception
 | |
| 	{
 | |
| 		Select select =
 | |
| 				new Select( new String[]{ "estabelecimentos" },
 | |
| 							new String[]{ "id", "nome", "nome_plain" },
 | |
| 							new Field( "empresa_id" ).isEqual( empresaID ).and( 
 | |
| 							new Field( "inactivo" ).isDifferent( "y" ) ),
 | |
| 							new String[]{ "nome_plain" },
 | |
| 							null );
 | |
| 		Virtual2DArray array = executer.executeQuery( select );
 | |
| 		ColumnizedMappable estabelecimentos[] = new ColumnizedMappable[ array.columnLength() ];
 | |
| 		for( int n = 0; n < estabelecimentos.length; n++ )
 | |
| 		{
 | |
| 			Integer id = ( Integer ) array.get( n, 0 );
 | |
| 			String nome = ( String ) array.get( n, 1 );
 | |
| 			estabelecimentos[ n ] = new ColumnizedMappable( id, nome );
 | |
| 		}
 | |
| 		return estabelecimentos;
 | |
| 	}
 | |
| 	
 | |
| 	public String getEmpresa( Integer empresaID )
 | |
| 		throws Exception
 | |
| 	{
 | |
| 		String nomes[] = new String[ 2 ];
 | |
| 		Select select = new Select( new String[]{ "empresas" }, 
 | |
| 									new String[]{ "designacao_social" },
 | |
| 									new Field( "id" ).isEqual( empresaID ) );
 | |
| 		Virtual2DArray array = executer.executeQuery( select );
 | |
| 		return ( String ) array.get( 0, 0 );
 | |
| 	}
 | |
| 	
 | |
| 	public Object[][] getVisitasEstabelecimento( Integer estabelecimentoID )
 | |
| 		throws Exception
 | |
| 	{
 | |
| 		Select select = 
 | |
| 				new Select( new String[]{ "marcacoes_estabelecimento" },
 | |
| 							new String[]{ "id", "data", "estado" },
 | |
| 							new Field( "estabelecimento_id" ).isEqual( estabelecimentoID ),
 | |
| 							new String[]{ "data desc" },
 | |
| 							null );
 | |
| 		Virtual2DArray array = executer.executeQuery( select );
 | |
| 		Object data[][] = array.getObjects();
 | |
| 		for( int n = 0; n < data.length; n++ )
 | |
| 		{
 | |
| 			int estado = ( ( Integer ) data[ n ][ 2 ] ).intValue();
 | |
| 			data[ n ][ 2 ] = ESTADOS_STR[ estado ];
 | |
| 		}
 | |
| 		return data;
 | |
| 	}
 | |
| 	
 | |
| 	public Vector[][] getMapaAnual( Integer ano )
 | |
| 		throws Exception
 | |
| 	{
 | |
| 		String deleted = "__DELETED__";
 | |
| 		Select select = 
 | |
| 				new Select( new String[]{ "marcacoes_tecnicos_hst" },
 | |
| 							new String[]{ "id", "nome", "iniciais", "identificador", "nome_plain" },
 | |
| 							new Field( "inactivo" ).isDifferent( "y" ),
 | |
| 							new String[]{ "nome_plain" },
 | |
| 							null );
 | |
| 		Virtual2DArray array = executer.executeQuery( select );
 | |
| 		Object tecnicosArr[][] =  array.getObjects();
 | |
| 		Hashtable tecnicos = new Hashtable();
 | |
| 		for( int n = 0; n < tecnicosArr.length; n++ )
 | |
| 		{
 | |
| 			tecnicos.put( tecnicosArr[ n ][ 0 ], tecnicosArr[ n ] );
 | |
| 		}
 | |
| 		Hashtable empresas = new Hashtable();
 | |
| 		Hashtable estabelecimentos = new Hashtable();
 | |
| 		Hashtable empresasEstabelecimentos = new Hashtable();
 | |
| 		Vector data[][] = new Vector[ 31 ][ 12 ];
 | |
| 		select = new Select( new String[]{ "marcacoes_estabelecimento" },
 | |
| 								new String[]{ "data", "estabelecimento_id", "tecnico_hst" },
 | |
| 								new Field( "data" ).between( new Object[]{ ano + "-01-01", ano + "-12-31" } ).and(
 | |
| 								new Field( "estado" ).in( new Integer[]{ new Integer( 0 ), new Integer( 2 ) } ) ) );
 | |
| 		array = executer.executeQuery( select );
 | |
| 		for( int n = 0; n < array.columnLength(); n++ )
 | |
| 		{
 | |
| 			Date dataVisita = ( Date ) array.get( n, 0 );
 | |
| 			Integer estabelecimentoID = ( Integer ) array.get( n, 1 );
 | |
| 			Integer tecnicoID = ( Integer ) array.get( n, 2 );
 | |
| 			Integer empresaID = null;
 | |
| 			if( !estabelecimentos.containsKey( estabelecimentoID ) )
 | |
| 			{
 | |
| 				Select estabelecimentoSelect =
 | |
| 					new Select( new String[]{ "estabelecimentos" },
 | |
| 								new String[]{ "nome", "empresa_id", "inactivo" },
 | |
| 								new Field( "id" ).isEqual( estabelecimentoID ) );
 | |
| 				Virtual2DArray estabelecimentoArray = executer.executeQuery( estabelecimentoSelect );
 | |
| 				if( "y".equals( estabelecimentoArray.get( 0, 2 ) ) )
 | |
| 				{
 | |
| 					estabelecimentos.put( estabelecimentoID, deleted );
 | |
| 				}
 | |
| 				else
 | |
| 				{
 | |
| 					estabelecimentos.put( estabelecimentoID, estabelecimentoArray.get( 0, 0 ) );
 | |
| 				}
 | |
| 				empresaID = ( Integer ) estabelecimentoArray.get( 0, 1 );
 | |
| 				empresasEstabelecimentos.put( estabelecimentoID, empresaID );
 | |
| 				if( !empresas.containsKey( empresaID ) )
 | |
| 				{
 | |
| 					Select empresaSelect = 
 | |
| 						new Select( new String[]{ "empresas" },
 | |
| 									new String[]{ "designacao_social", "inactivo" },
 | |
| 									new Field( "id" ).isEqual( empresaID ) );
 | |
| 					Virtual2DArray empresaArray = executer.executeQuery( empresaSelect );
 | |
| 					if( "y".equals( empresaArray.get( 0, 1 ) ) )
 | |
| 					{
 | |
| 						empresas.put( empresaID, deleted );
 | |
| 					}
 | |
| 					else
 | |
| 					{
 | |
| 						empresas.put( empresaID, empresaArray.get( 0, 0 ) );
 | |
| 					}
 | |
| 				}
 | |
| 			}
 | |
| 			String nomeEstabelecimento = ( String ) estabelecimentos.get( estabelecimentoID );
 | |
| 			empresaID = ( Integer ) empresasEstabelecimentos.get( estabelecimentoID );
 | |
| 			String nomeEmpresa = ( String ) empresas.get( empresaID );
 | |
| 			String nomeTecnico = " ";
 | |
| 			Integer indiceCor = null;
 | |
| 			Color cor = null;
 | |
| 			if( tecnicoID != null )
 | |
| 			{
 | |
| 				Object tecnico[] = ( Object[] ) tecnicos.get( tecnicoID );
 | |
| 				nomeTecnico = ( String ) tecnico[ 1 ];
 | |
| 				indiceCor = ( Integer ) tecnico[ 3 ];
 | |
| 				cor = CORES_TECNICOS[ indiceCor.intValue() ];
 | |
| 			}
 | |
| 			Calendar cal = Calendar.getInstance();
 | |
| 			cal.setTime( dataVisita );
 | |
| 			int dia = cal.get( Calendar.DAY_OF_MONTH ) - 1;
 | |
| 			int mes = cal.get( Calendar.MONTH );
 | |
| 			if( data[ dia ][ mes ] == null )
 | |
| 			{
 | |
| 				data[ dia ][ mes ] = new Vector();
 | |
| 				data[ dia ][ mes ].add( new Object[]{ new Integer( dia + 1 ) } );
 | |
| 			}
 | |
| 			if( nomeEmpresa != deleted && nomeEstabelecimento != deleted )
 | |
| 			{
 | |
| 				data[ dia ][ mes ].add( new Object[]{ nomeEmpresa, nomeEstabelecimento, nomeTecnico, cor } );
 | |
| 			}
 | |
| 		}
 | |
| 		
 | |
| 		return data;
 | |
| 	}
 | |
| }
 |