forked from Coded/SIPRP
				
			no message
	
		
	
				
					
				
			git-svn-id: https://svn.coded.pt/svn/SIPRP@465 bb69d46d-e84e-40c8-a05a-06db0d633741lxbfYeaa
							parent
							
								
									02417d98d9
								
							
						
					
					
						commit
						635590e7a5
					
				| @ -0,0 +1,167 @@ | ||||
| /* | ||||
|  * doGetListaTrabalhadoresPendentes.java | ||||
|  * | ||||
|  * Created on 22 de Abril de 2005, 15:56 | ||||
|  */ | ||||
| 
 | ||||
| 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 org.apache.velocity.*; | ||||
| import org.apache.velocity.app.*; | ||||
| /** | ||||
|  * | ||||
|  * @author  fpalma | ||||
|  */ | ||||
| public class doGetListaTrabalhadoresPendentes | ||||
| 	extends siprpServlet | ||||
| { | ||||
|      | ||||
|     /** Creates a new instance of doGetListaTrabalhadores */ | ||||
|     public doGetListaTrabalhadoresPendentes(HttpServletRequest req, HttpServletResponse res) 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(); | ||||
|         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( super.bdUrl, super.bdUsername, super.bdPassword );    | ||||
|                     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 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 current_date - proxima_consulta <= 14 ), " | ||||
| 										+ " ( proximo_exame IS NOT NULL AND current_date - proximo_exame <= 14 )" | ||||
| 										+ " FROM trabalhadores " | ||||
| 										+ " WHERE estabelecimento_id = '"+estabelecimentoId+"'" | ||||
| 										+ " AND ( ultima_consulta IS NULL OR realizada = 'n' OR" | ||||
| 										+ " ( proxima_consulta IS NOT NULL AND current_date - proxima_consulta <= 14 )" | ||||
| 										+ " OR ( proximo_exame IS NOT NULL AND ( realizado = 'n' OR current_date - proximo_exame <= 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(); | ||||
|                      | ||||
|                         while ( index < max ) | ||||
|                         { | ||||
|                             temp=""+rs.get(index,0); // converter de int para String
 | ||||
|                             dbQuery = new StringBuffer(); | ||||
|                             dbQuery.append("/"+super.servletName+"/?"+empresaId+"/"+estabelecimentoId+"/"+temp); // contruir url
 | ||||
|                             links.add(dbQuery.toString()); | ||||
| 							HashMap trabalhador = new HashMap(); | ||||
| 							trabalhador.put( "Nome", (String)rs.get(index,1) ); | ||||
| 							boolean  uc = ( (Boolean)rs.get(index,2) ).booleanValue(); | ||||
| 							boolean  ue = ( (Boolean)rs.get(index,3) ).booleanValue(); | ||||
| 							boolean  pc = ( (Boolean)rs.get(index,4) ).booleanValue(); | ||||
| 							boolean  pe = ( (Boolean)rs.get(index,5) ).booleanValue(); | ||||
| 							boolean quase_c = ( (Boolean)rs.get(index,6) ).booleanValue(); | ||||
| 							boolean quase_e = ( (Boolean)rs.get(index,7) ).booleanValue(); | ||||
| 							if( quase_c ) | ||||
| 							{ | ||||
| 								trabalhador.put( "Consulta", "yellow" ); | ||||
| 							} | ||||
| 							else if( uc ) | ||||
| 							{ | ||||
| 								trabalhador.put( "Consulta", "green" ); | ||||
| 							} | ||||
| 							else if( pc ) | ||||
| 							{ | ||||
| 								trabalhador.put( "Consulta", "yellow" ); | ||||
| 							} | ||||
| 							else | ||||
| 							{ | ||||
| 								trabalhador.put( "Consulta", "red" ); | ||||
| 							} | ||||
| 							 | ||||
| 							if( quase_e ) | ||||
| 							{ | ||||
| 								trabalhador.put( "Exame", "yellow" ); | ||||
| 							} | ||||
| 							else if( ue ) | ||||
| 							{ | ||||
| 								trabalhador.put( "Exame", "green" ); | ||||
| 							} | ||||
| 							else if( pe ) | ||||
| 							{ | ||||
| 								trabalhador.put( "Exame", "yellow" ); | ||||
| 							} | ||||
| 							else | ||||
| 							{ | ||||
| 								trabalhador.put( "Exame", "red" ); | ||||
| 							} | ||||
|                             desc.add( trabalhador ); | ||||
|                             ++index; | ||||
|                         } | ||||
|                         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); | ||||
| 						out.println( mergeTemplate( hmValues, super.authenticatedUserTemplate));   | ||||
| //                        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) ); | ||||
|         } | ||||
|     } | ||||
|      | ||||
| } | ||||
					Loading…
					
					
				
		Reference in new issue