diff --git a/trunk/AnaliseAcidentesTrabalho/nbproject/navigation.NavData b/trunk/AnaliseAcidentesTrabalho/nbproject/navigation.NavData index df9fdf13..e4acdba4 100644 --- a/trunk/AnaliseAcidentesTrabalho/nbproject/navigation.NavData +++ b/trunk/AnaliseAcidentesTrabalho/nbproject/navigation.NavData @@ -2,16 +2,16 @@ - + - + - + @@ -22,8 +22,8 @@ - + diff --git a/trunk/AnaliseAcidentesTrabalho/src/java/analiseacidentestrabalho/EstatisticasProcesso.java b/trunk/AnaliseAcidentesTrabalho/src/java/analiseacidentestrabalho/EstatisticasProcesso.java index 113c039f..21afdc5f 100644 --- a/trunk/AnaliseAcidentesTrabalho/src/java/analiseacidentestrabalho/EstatisticasProcesso.java +++ b/trunk/AnaliseAcidentesTrabalho/src/java/analiseacidentestrabalho/EstatisticasProcesso.java @@ -10,12 +10,14 @@ import beans.Utilizador; import com.evolute.utils.error.ErrorLogger; import com.sun.rave.web.ui.appbase.AbstractPageBean; import com.sun.rave.web.ui.component.Button; +import com.sun.rave.web.ui.component.DropDown; import com.sun.rave.web.ui.component.Hyperlink; import com.sun.rave.web.ui.component.RadioButton; import com.sun.rave.web.ui.component.RadioButtonGroup; import com.sun.rave.web.ui.component.StaticText; import com.sun.rave.web.ui.component.Table; import com.sun.rave.web.ui.component.TextField; +import com.sun.rave.web.ui.model.Option; import db.EstatisticasConstants; import db.providers.EstatisticasDataProvider; import global.Global; @@ -143,14 +145,26 @@ public class EstatisticasProcesso extends AbstractPageBean this.tableEstatisticas = t; } - private TextField textCausas = new TextField(); - public TextField getTextCausas() { - return textCausas; + private DropDown dropCausas = new DropDown(); + + public DropDown getDropCausas() { + return dropCausas; } - public void setTextCausas(TextField textCausas) { - this.textCausas = textCausas; + + public void setDropCausas(DropDown dropCausas) { + this.dropCausas = dropCausas; } + + +// private TextField textCausas = new TextField(); +// public TextField getTextCausas() { +// return textCausas; +// } +// public void setTextCausas(TextField textCausas) { +// this.textCausas = textCausas; +// } + private TextField textDepartamento = new TextField(); public TextField getTextDepartamento() { return textDepartamento; @@ -159,21 +173,42 @@ public class EstatisticasProcesso extends AbstractPageBean this.textDepartamento = textDepartamento; } - private TextField textSeccao = new TextField(); - public TextField getTextSeccao() { - return textSeccao; + private DropDown dropSeccoes = new DropDown(); + + public DropDown getDropSeccoes() { + return dropSeccoes; } - public void setTextSeccao(TextField textSeccao) { - this.textSeccao = textSeccao; + + public void setDropSeccoes(DropDown dropSeccoes) { + this.dropSeccoes = dropSeccoes; } - private TextField textTurno = new TextField(); - public TextField getTextTurno() { - return textTurno; + +// private TextField textSeccao = new TextField(); +// public TextField getTextSeccao() { +// return textSeccao; +// } +// public void setTextSeccao(TextField textSeccao) { +// this.textSeccao = textSeccao; +// } + + private DropDown dropTurno = new DropDown(); + + public DropDown getDropTurno() { + return dropTurno; } - public void setTextTurno(TextField textTurno) { - this.textTurno = textTurno; + + public void setDropTurno(DropDown dropTurno) { + this.dropTurno = dropTurno; } + +// private TextField textTurno = new TextField(); +// public TextField getTextTurno() { +// return textTurno; +// } +// public void setTextTurno(TextField textTurno) { +// this.textTurno = textTurno; +// } private RadioButtonGroup formacaoSHST = new RadioButtonGroup(); public RadioButtonGroup getFormacaoSHST() @@ -257,16 +292,7 @@ public class EstatisticasProcesso extends AbstractPageBean private boolean canAccess() { boolean canAccess = false; - - if ( getSessionBean1().isLoggedIn() ) - { - Utilizador u = getSessionBean1().getCurrentUser(); - if ( u != null && u.getTipo().intValue() == Global.TIPO_UTILIZADOR_DIRECTOR_SIPRP ) - { - canAccess = true; - } - } - + canAccess = getSessionBean1().getCanAccessEstatisticas(); return canAccess; } @@ -332,7 +358,32 @@ public class EstatisticasProcesso extends AbstractPageBean lblUser.setText( getSessionBean1().getCurrentUser().getLogin() ); - + Option[] turnosOptions = new Option[ 4 ]; + turnosOptions[ 0 ] = new Option( "", "" ); + turnosOptions[ 1 ] = new Option( "m", "Manhã" ); + turnosOptions[ 2 ] = new Option( "t", "Tarde" ); + turnosOptions[ 3 ] = new Option( "n", "Noite" ); + dropTurno.setItems( turnosOptions ); + + try + { + EstatisticasDataProvider statsProvider = EstatisticasDataProvider.getInstance(); + Option[] causas = statsProvider.getCausasAcidente(); + if ( causas != null ) + { + dropCausas.setItems( causas ); + } + + Option[] seccoes = statsProvider.getSeccoesList(); + if ( seccoes != null ) + { + dropSeccoes.setItems( seccoes ); + } + } + catch ( Exception e ) + { + ErrorLogger.logException( e ); + } } /** @@ -431,23 +482,42 @@ public class EstatisticasProcesso extends AbstractPageBean departamento = "".equals( departamento ) ? null : departamento; } String seccao = null; - if ( textSeccao.getText() != null ) + if ( dropSeccoes.getSelected() != null ) { - seccao = ( ( String ) textSeccao.getText() ).trim(); - seccao = "".equals( seccao ) ? null : seccao; + seccao = ( String ) dropSeccoes.getSelected(); } - String causas = null; - if ( textCausas.getText() != null ) +// if ( textSeccao.getText() != null ) +// { +// seccao = ( ( String ) textSeccao.getText() ).trim(); +// seccao = "".equals( seccao ) ? null : seccao; +// } + Integer causas = null; + if ( dropCausas.getSelected() != null ) { - causas = ( ( String ) textCausas.getText() ).trim(); - causas = "".equals( causas ) ? null : causas; + String causaID = ( String ) dropCausas.getSelected(); + if ( causaID != null ) + { + try { causas = Integer.parseInt( causaID ); } + catch ( Exception e ) { } + } } +// String causas = null; +// if ( textCausas.getText() != null ) +// { +// causas = ( ( String ) textCausas.getText() ).trim(); +// causas = "".equals( causas ) ? null : causas; +// } String turno = null; - if ( textTurno.getText() != null ) + if ( dropTurno.getSelected() != null ) { - turno = ( ( String ) textTurno.getText() ).trim(); - turno = "".equals( turno ) ? null : turno; + turno = ( String ) dropTurno.getSelected(); + turno = turno == null || "".equals( turno.trim() ) ? null : turno; } +// if ( textTurno.getText() != null ) +// { +// turno = ( ( String ) textTurno.getText() ).trim(); +// turno = "".equals( turno ) ? null : turno; +// } Boolean shst = null; if ( formacaoSHST_true.getSelected() != null || formacaoSHST_false.getSelected() != null ) { @@ -629,7 +699,7 @@ public class EstatisticasProcesso extends AbstractPageBean String horasTrabalhadas = ( String ) searchProperties.get( EstatisticasConstants.KEY_HORAS_TRABALHADAS ); String departamento = ( String ) searchProperties.get( EstatisticasConstants.KEY_DEPARTAMENTO ); String seccao = ( String ) searchProperties.get( EstatisticasConstants.KEY_SECCAO ); - String causas = ( String ) searchProperties.get( EstatisticasConstants.KEY_CAUSAS_ACIDENTE ); + Integer causas = ( Integer ) searchProperties.get( EstatisticasConstants.KEY_CAUSAS_ACIDENTE ); String turno = ( String ) searchProperties.get( EstatisticasConstants.KEY_TURNO_TRABALHO ); Boolean formacao_shst = ( Boolean ) searchProperties.get( EstatisticasConstants.KEY_FORMACAO_SHST ); Boolean postoAcidentado = ( Boolean ) searchProperties.get( EstatisticasConstants.KEY_POSTO_ACIDENTADO ); @@ -705,20 +775,50 @@ public class EstatisticasProcesso extends AbstractPageBean columnValue.setCellValue( seccao ); row++; + + String causa = ""; + if ( causas != null ) + { + try + { + EstatisticasDataProvider statsProvider = EstatisticasDataProvider.getInstance(); + causa = statsProvider.getCausaByID( causas ); + } + catch ( Exception e ) + { + ErrorLogger.logException( e ); + } + } keyName = EstatisticasConstants.KEY_NAMES[ row ]; currentRow = getRow( sheet, row ); columnLabel = getCell( currentRow, 0 ); columnLabel.setCellValue( keyName ); columnValue = getCell( currentRow, 1 ); - columnValue.setCellValue( causas ); + columnValue.setCellValue( causa ); row++; + String turnoDesc = ""; + if ( turno != null ) + { + if ( "m".equals( turno ) ) + { + turnoDesc = "Manhã"; + } + else if ( "t".equals( turno ) ) + { + turnoDesc = "Tarde"; + } + else if ( "n".equals( turno ) ) + { + turnoDesc = "Noite"; + } + } keyName = EstatisticasConstants.KEY_NAMES[ row ]; currentRow = getRow( sheet, row ); columnLabel = getCell( currentRow, 0 ); columnLabel.setCellValue( keyName ); columnValue = getCell( currentRow, 1 ); - columnValue.setCellValue( turno ); + columnValue.setCellValue( turnoDesc ); row++; keyName = EstatisticasConstants.KEY_NAMES[ row ]; diff --git a/trunk/AnaliseAcidentesTrabalho/src/java/analiseacidentestrabalho/SessionBean1.java b/trunk/AnaliseAcidentesTrabalho/src/java/analiseacidentestrabalho/SessionBean1.java index 5877dd35..0c653e57 100644 --- a/trunk/AnaliseAcidentesTrabalho/src/java/analiseacidentestrabalho/SessionBean1.java +++ b/trunk/AnaliseAcidentesTrabalho/src/java/analiseacidentestrabalho/SessionBean1.java @@ -42,7 +42,14 @@ public class SessionBean1 extends AbstractSessionBean private Boolean canAccessEstatisticas = false; - public Boolean getCanAccessEstatisticas() { + public Boolean getCanAccessEstatisticas() + { + if ( isLoggedIn() && getCurrentUser() != null && getCurrentUser().getTipo() != null ) + { + int tipo = getCurrentUser().getTipo().intValue(); + + canAccessEstatisticas = tipo == Global.TIPO_UTILIZADOR_DIRECTOR_SIPRP || tipo == Global.TIPO_UTILIZADOR_HS; + } return canAccessEstatisticas; } @@ -182,8 +189,7 @@ public class SessionBean1 extends AbstractSessionBean public void setCurrentUser(Utilizador currentUser) { this.currentUser = currentUser; - - setCanAccessEstatisticas( currentUser != null && currentUser.getTipo().intValue() == Global.TIPO_UTILIZADOR_DIRECTOR_SIPRP ); + setCanAccessEstatisticas( getCanAccessEstatisticas() ); } private db.providers.AnalisesActualDataProvider analisesActualDataProvider; diff --git a/trunk/AnaliseAcidentesTrabalho/src/java/app.properties b/trunk/AnaliseAcidentesTrabalho/src/java/app.properties index 980adc6d..eb561548 100644 --- a/trunk/AnaliseAcidentesTrabalho/src/java/app.properties +++ b/trunk/AnaliseAcidentesTrabalho/src/java/app.properties @@ -12,6 +12,19 @@ database.siprp_local = siprp_local_3 username.siprp_local = postgres #password.siprp_local = +# tests evoserver +#server.siprp = evoserver +#port.siprp = 5432 +#database.siprp = siprp_20100813 +#username.siprp = postgres +##password.siprp = +# +#server.siprp_local = evoserver +#port.siprp_local = 5432 +#database.siprp_local = siprp_local_3_20100813 +#username.siprp_local = postgres +##password.siprp_local = + # tests #server.siprp = www.evolute.pt #port.siprp = 5436 diff --git a/trunk/AnaliseAcidentesTrabalho/src/java/db/providers/EstatisticasDataProvider.java b/trunk/AnaliseAcidentesTrabalho/src/java/db/providers/EstatisticasDataProvider.java index 22588f47..c7828636 100644 --- a/trunk/AnaliseAcidentesTrabalho/src/java/db/providers/EstatisticasDataProvider.java +++ b/trunk/AnaliseAcidentesTrabalho/src/java/db/providers/EstatisticasDataProvider.java @@ -7,7 +7,14 @@ package db.providers; import db.*; import beans.EstatisticaProcessoBean; +import com.evolute.utils.arrays.Virtual2DArray; import com.evolute.utils.error.ErrorLogger; +import com.evolute.utils.sql.Expression; +import com.evolute.utils.sql.Field; +import com.evolute.utils.sql.Select2; +import com.sun.rave.web.ui.model.Option; +import db.data.siprp.outer.AnalisesAcidentesData; +import db.data.siprp.outer.CausasData; import java.sql.ResultSet; import java.sql.Statement; import java.text.ParseException; @@ -62,7 +69,7 @@ public class EstatisticasDataProvider extends GenericDataProvider String horasTrabalhadas = ( String ) searchProperties.get( EstatisticasConstants.KEY_HORAS_TRABALHADAS ); String departamento = ( String ) searchProperties.get( EstatisticasConstants.KEY_DEPARTAMENTO ); String seccao = ( String ) searchProperties.get( EstatisticasConstants.KEY_SECCAO ); - String causas = ( String ) searchProperties.get( EstatisticasConstants.KEY_CAUSAS_ACIDENTE ); + Integer causas = ( Integer ) searchProperties.get( EstatisticasConstants.KEY_CAUSAS_ACIDENTE ); String turno = ( String ) searchProperties.get( EstatisticasConstants.KEY_TURNO_TRABALHO ); Boolean formacao_shst = ( Boolean ) searchProperties.get( EstatisticasConstants.KEY_FORMACAO_SHST ); Boolean postoAcidentado = ( Boolean ) searchProperties.get( EstatisticasConstants.KEY_POSTO_ACIDENTADO ); @@ -146,8 +153,7 @@ public class EstatisticasDataProvider extends GenericDataProvider } if ( causas != null ) { - causas = causas.replaceAll( " ", "%" ); - whereConditions += " AND " + EstatisticasConstants.KEY_CAUSAS_ACIDENTE + " ILIKE '%" + causas + "%' "; + whereConditions += " AND " + EstatisticasConstants.KEY_CAUSAS_ACIDENTE + " = " + causas + " "; } if ( departamento != null ) { @@ -174,7 +180,7 @@ public class EstatisticasDataProvider extends GenericDataProvider List< EstatisticaProcessoBean > stats = new LinkedList< EstatisticaProcessoBean >(); try { - stats = getEstatisticasForSQL(sql); + stats = getEstatisticasForSQL( sql ); } catch ( Exception ex ) { @@ -220,5 +226,71 @@ public class EstatisticasDataProvider extends GenericDataProvider return stats; } + public com.sun.rave.web.ui.model.Option[] getSeccoesList( ) throws Exception + { + com.sun.rave.web.ui.model.Option[] options = null; + + Select2 query = new Select2( + new String[] { AnalisesAcidentesData.TABLENAME }, + new Integer[] { }, + new Expression[] { }, + new String[] { "DISTINCT( " + AnalisesAcidentesData.SECCAO_FULL + " )" }, + new Field( AnalisesAcidentesData.APAGADA_FULL ).isEqual( "n" ).and( new Field( AnalisesAcidentesData.SECCAO_FULL ).isDifferent( null ) ), + new String[] { AnalisesAcidentesData.SECCAO_FULL }, + null, null, null + ); + Virtual2DArray array = getExecuter().executeQuery( query ); + if ( array != null ) + { + options = new com.sun.rave.web.ui.model.Option[ array.columnLength() + 1 ]; + options[ 0 ] = new Option( "", "" ); + for ( int i = 0; i < array.columnLength(); i++ ) + { + String seccao = array.get( i, 0 ); + options[ (i+1) ] = new Option( seccao, seccao ); + } + } + return options; + } + + public com.sun.rave.web.ui.model.Option[] getCausasAcidente( ) throws Exception + { + com.sun.rave.web.ui.model.Option[] options = null; + + Select2 query = new Select2( + new String[] { CausasData.TABLENAME }, + new Integer[] { }, + new Expression[] { }, + new String[] { CausasData.ID_FULL, CausasData.CAUSA_FULL }, + new Field( CausasData.ACTIVA_FULL ).isEqual( "y" ), + new String[] { CausasData.CAUSA_FULL }, + null, null, null + ); + Virtual2DArray array = getExecuter().executeQuery( query ); + if ( array != null ) + { + options = new com.sun.rave.web.ui.model.Option[ array.columnLength() + 1 ]; + options[ 0 ] = new Option( "", "" ); + for ( int i = 0; i < array.columnLength(); i++ ) + { + Integer causaID = array.get( i, 0 ); + String causa = array.get( i, 1 ); + options[ (i+1) ] = new Option( causaID, causa ); + } + } + return options; + } + + public String getCausaByID( Integer causaID ) throws Exception + { + String causa = ""; + + CausasData causaData = getProvider().load( CausasData.class, causaID, CausasData.ID ); + if ( causaData != null ) + { + causa = causaData.getCausa(); + } + return causa; + } } diff --git a/trunk/AnaliseAcidentesTrabalho/web/EstatisticasProcesso.jsp b/trunk/AnaliseAcidentesTrabalho/web/EstatisticasProcesso.jsp index a15c588a..0f2a451a 100644 --- a/trunk/AnaliseAcidentesTrabalho/web/EstatisticasProcesso.jsp +++ b/trunk/AnaliseAcidentesTrabalho/web/EstatisticasProcesso.jsp @@ -98,13 +98,13 @@ - + - + - + diff --git a/trunk/AnaliseAcidentesTrabalho/web/FormHS.jsp b/trunk/AnaliseAcidentesTrabalho/web/FormHS.jsp index cbfdfaeb..c7624579 100644 --- a/trunk/AnaliseAcidentesTrabalho/web/FormHS.jsp +++ b/trunk/AnaliseAcidentesTrabalho/web/FormHS.jsp @@ -36,6 +36,10 @@ + + + + diff --git a/trunk/AnaliseAcidentesTrabalho/web/WEB-INF/navigation.xml b/trunk/AnaliseAcidentesTrabalho/web/WEB-INF/navigation.xml index b76ef483..e459ffaf 100644 --- a/trunk/AnaliseAcidentesTrabalho/web/WEB-INF/navigation.xml +++ b/trunk/AnaliseAcidentesTrabalho/web/WEB-INF/navigation.xml @@ -120,6 +120,10 @@ user /FichaUtilizador.jsp + + + estatisticasProcesso + /EstatisticasProcesso.jsp