package importer; import db.providers.*; 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 db.DBConstants.DB; import db.data.siprp.outer.PlanoAreasData; import db.data.siprp.outer.PlanoMedidasData; import db.data.siprp.outer.PlanoPostosTrabalhoData; import db.data.siprp.outer.PlanoRiscosData; import db.data.siprp.outer.PlanosActuacaoData; import db.data.siprp.outer.PlanoValoresQualitativosData; import db.data.siprp_local.outer.EmpresasData; import db.entidades.Area; import db.entidades.Medida; import db.entidades.PlanoActuacao; import db.entidades.PostoTrabalho; import db.entidades.Risco; import db.entidades.Valor; import db.entidades.ValorQualitativo; import java.sql.ResultSet; import java.sql.Statement; import java.util.Date; import java.util.LinkedList; import java.util.List; import utils.Utils; public class PlanosActuacaoImporterProvider extends GenericDataProvider { private static PlanosActuacaoImporterProvider INSTANCE = null; private PlanosActuacaoImporterProvider() throws Exception { super(); } protected static synchronized PlanosActuacaoImporterProvider getInstance() throws Exception { if ( INSTANCE == null ) { INSTANCE = new PlanosActuacaoImporterProvider(); } return INSTANCE; } public List< Date > getPlanosOnline( Integer estabelecimentoID ) throws Exception { System.out.println( "\n\t\tPlanosActuacaoImporterProvider . getPlanosOnline( " + estabelecimentoID + " ) : " ); List< Date > list = new LinkedList< Date >(); Expression where = new Field( PlanosActuacaoData.DELETED_DATE_FULL ).isEqual( null ); if ( estabelecimentoID != null ) { where = where.and( new Field( PlanosActuacaoData.ESTABELECIMENTO_ID_FULL ).isEqual( estabelecimentoID ) ); } Select2 query = new Select2( PlanosActuacaoData.TABLENAME, where, new String[] { PlanosActuacaoData.DATA_VISITA_FULL }, new String[] {} ); Virtual2DArray array = getExecuter().executeQuery( query ); for ( int i = 0; i < array.columnLength(); i++ ) { Date date = array.get( i, 0 ); System.out.println( "\n\t\t\tData-Visita Plano : " + date ); list.add( date ); } return list; } public List< Integer > getEstabelecimentosWithPlanos() throws Exception { List< Integer > result = new LinkedList< Integer >(); Select2 query = new Select2( PlanosActuacaoData.TABLENAME, new Field( PlanosActuacaoData.DELETED_DATE_FULL ).isEqual( null ), new String[] { "DISTINCT " + PlanosActuacaoData.ESTABELECIMENTO_ID_FULL }, new String[] {} ); Virtual2DArray array = getExecuter().executeQuery( query ); for ( int i = 0; i < array.columnLength(); i++ ) { Integer estabelecimentoID = array.get( i, 0 ); result.add( estabelecimentoID ); } return result; } public PlanoActuacao getFullPlano( PlanoActuacao plano, Integer relatorioId ) { try { plano = getAreasByPlano( plano, relatorioId ); } catch ( Exception ex ) { ErrorLogger.logException( ex ); } return plano; } private PlanoActuacao getAreasByPlano( PlanoActuacao plano, Integer relatorioID ) throws Exception { String sql = "select hs_relatorio_posto.area_id as area, hs_relatorio_area.description as descricao, hs_relatorio_area.ordem as ordem, bool_or( coalesce( hs_relatorio_posto.is_principal, false ) ) as is_principal " + " from hs_relatorio_posto " + " inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id " + " inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id " + " inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id " + " inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id " + " inner join hs_relatorio_area on hs_relatorio_area.id = hs_relatorio_posto.area_id " + " where hs_relatorio.id = " + relatorioID + " and hs_relatorio_posto_medida.is_plano_actuacao " + " and hs_relatorio_posto.deleted_date is null and hs_relatorio_area.deleted_date is null " + " group by area, descricao, ordem" + " order by area "; System.out.println( "\n\t\t\t\t\t\tprovider . getAreasByPlano( " + plano.getId() + ", " + relatorioID + " ) : " ); System.out.println( "\n\t\t\t\t\t\t\t\tSQL : " + sql ); Statement st = createLocalStatement(); ResultSet rs = st.executeQuery( sql ); List< Area > areas = new LinkedList< Area >(); if ( rs.isBeforeFirst() ) { rs.first(); do { Area a = new Area(); a.setId( new Integer( rs.getInt( "area" ) ) ); a.setArea_id( a.getId() ); a.setIs_principal( new Boolean( rs.getBoolean( "is_principal" ) ) ); Integer ordem = ( Integer ) rs.getObject( "ordem" ); if( ordem != null ) { a.setOrdem( ordem ); } if ( existemMedidasByArea( a.getId() ) ) { a.setDescricao( Utils.unicodeToHTML( rs.getString( "descricao") ) ); try { a.setRiscos( getRiscosByArea( a ) ); } catch ( Exception ex ) { System.out.println( "\nERRO RISCOS BY AREA !!!!" ); ErrorLogger.logException( ex ); a.setRiscos( null ); } if( a.getRiscos().size() > 0 ) { areas.add( a ); } } } while ( rs.next() ); plano.setAreas( areas ); } return plano; } private List< Risco > getRiscosByArea( Area a ) throws Exception { String sql = "select distinct hs_relatorio_risco.id, hs_relatorio_risco.description as descricao, hs_relatorio_risco.is_patrimonial as is_patrimonial " + " from hs_relatorio_posto " + " inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id " + " inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id " + " inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id " + " inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id " + " inner join hs_relatorio_area on hs_relatorio_area.id = area_id " + " where area_id = " + a.getId() + " and hs_relatorio_posto_medida.is_plano_actuacao and hs_relatorio_posto.deleted_date is null " + " order by hs_relatorio_risco.id "; System.out.println( "\t\t\t\t\t\t\tprovider . getRiscosByArea( " + a.getId() + " ) : " ); System.out.println( "\t\t\t\t\t\t\t\t\tSQL : " + sql ); Statement st = createLocalStatement(); ResultSet rs = st.executeQuery( sql ); List< Risco > riscos = new LinkedList< Risco >(); if ( rs.isBeforeFirst() ) { rs.first(); do { Risco r = new Risco(); r.setId( new Integer( rs.getInt( "id" ) ) ); if ( existemMedidasByRisco( r.getId() ) ) { r.setDescricao( Utils.unicodeToHTML( rs.getString( "descricao" ) ) ); r.setIsPatrimonial( rs.getBoolean( "is_patrimonial" ) ); r.setValores( getValoresByRisco( r, a ) ); r.setRisco_id( new Integer( rs.getInt( "id" ) ) ); r.setMedidas( getMedidasByRisco( r, a ) ); if( r.getMedidas().size() > 0 ) { riscos.add( r ); } } } while ( rs.next() ); } return riscos; } private List< Valor > getValoresByRisco( Risco r, Area a ) throws Exception { String sql = "select subquery.valor, subquery.valor_qualitativo_id from " + " (select distinct hs_relatorio_posto_risco.risco_id, hs_relatorio_posto_risco.valor_qualitativo_id, hs_relatorio_risco_valor_qualitativo.description, " + " case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null " + " when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade " + " else null " + " end as valor " + " from hs_relatorio_posto " + " inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id " + " inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id " + " inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id " + " inner join hs_relatorio_posto_risco on (hs_relatorio_posto_risco.posto_id = hs_relatorio_posto.id and hs_relatorio_posto_risco.risco_id = hs_relatorio_risco.id) " + " inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id " + " inner join hs_relatorio_area on hs_relatorio_area.id = area_id " + " left outer join hs_relatorio_risco_valor_qualitativo on ( hs_relatorio_risco_valor_qualitativo.id = hs_relatorio_posto_risco.valor_qualitativo_id ) " + " where hs_relatorio_posto_risco.risco_id = " + r.getId() + " and area_id = " + a.getId() + " and hs_relatorio_posto.deleted_date is null) subquery " + " order by subquery.valor"; System.out.println( "\t\t\t\t\t\t\t\tprovider . getValoresByRisco( " + r.getId() + ", " + a.getId() + " ) : " ); System.out.println( "\t\t\t\t\t\t\t\t\t\tSQL : " + sql ); Statement st = createLocalStatement(); ResultSet rs = st.executeQuery( sql ); List< Valor > valores = new LinkedList< Valor >(); if ( rs.isBeforeFirst() ) { rs.first(); do { Object oValor = rs.getObject( "valor" ); Object valorQualitativoID = rs.getObject( "valor_qualitativo_id" ); Valor v = new Valor(); v.setValorQuantitativo( oValor == null ? null : ( Integer ) oValor ); v.setValorQualitativoID( valorQualitativoID == null ? null : ( Integer ) valorQualitativoID ); valores.add( v ); } while ( rs.next() ); } return valores; } // private List getMedidasByValor(Valor v, Risco r, Area a) throws Exception // { // Statement st = dblocal.createStatement(); // String sql = "select distinct medida_id, valor, descricao from "; // sql += "( select distinct hs_relatorio_posto_medida.medida_id, hs_relatorio_posto_risco.risco_id, hs_relatorio_medida.description as descricao, "; // sql += "case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null "; // sql += "when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade "; // sql += "else hs_relatorio_posto_risco.valor_qualitativo_id "; // sql += "end as valor "; // sql += "from hs_relatorio_posto "; // sql += "inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id "; // sql += "inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id "; // sql += "inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id "; // sql += "inner join hs_relatorio_posto_risco on (hs_relatorio_posto_risco.posto_id = hs_relatorio_posto.id and hs_relatorio_posto_risco.risco_id = hs_relatorio_risco.id) "; // sql += "inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id "; // sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id "; // sql += "where hs_relatorio_posto_risco.risco_id = " + r.getId() + " and area_id = " + a.getId() + " and hs_relatorio_posto_medida.is_plano_actuacao = true" + ") subquery "; // //sql += "where hs_relatorio_posto_risco.risco_id = " + r.getId() + " and area_id = " + a.getId() + ") subquery "; // //sql += "where valor = " + v.getValorQuantitativo() + " "; // sql += "order by subquery.medida_id, valor"; // System.out.println("MEDIDAS BY VALOR SQL : " + sql); // ResultSet rs = st.executeQuery(sql); // List medidas = new ArrayList(); // if(rs.isBeforeFirst()) // { // rs.first(); // do // { // Medida m = new Medida(); // //int valor = rs.getInt("valor"); // //m.setValorQuantitativo(new Integer(valor)); // m.setId(new Integer( rs.getInt("medida_id") )); // m.setDescricao(Utils.unicodeToHTML(rs.getString("descricao"))); // m.setPostos(getPostosByMedidaAndValor(m, v, a)); // medidas.add(m); // }while(rs.next()); // } // return medidas; // } private List getMedidasByRisco( Risco r, Area a ) throws Exception { String sql = "select distinct medida_id, valor, descricao from " + " ( select distinct hs_relatorio_posto_medida.medida_id, hs_relatorio_posto_risco.risco_id, hs_relatorio_medida.description as descricao, " + " case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null " + " when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade " + " else hs_relatorio_posto_risco.valor_qualitativo_id " + " end as valor " + " from hs_relatorio_posto " + " inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id " + " inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id " + " inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id " + " inner join hs_relatorio_posto_risco on (hs_relatorio_posto_risco.posto_id = hs_relatorio_posto.id and hs_relatorio_posto_risco.risco_id = hs_relatorio_risco.id) " + " inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id " + " inner join hs_relatorio_area on hs_relatorio_area.id = area_id " + " where hs_relatorio_medida.description is not null and length( hs_relatorio_medida.description ) > 0 " + " and hs_relatorio_posto_risco.risco_id = " + r.getId() + " and area_id = " + a.getId() + " and hs_relatorio_posto_medida.is_plano_actuacao " + " and hs_relatorio_posto.deleted_date is null and hs_relatorio_medida.deleted_date is null ) subquery " //+ " where hs_relatorio_posto_risco.risco_id = " + r.getId() + " and area_id = " + a.getId() + ") subquery " //+ " where valor = " + v.getValorQuantitativo() + " " + " order by subquery.medida_id, valor"; System.out.println( "\t\t\t\t\t\t\t\t\tprovider . getMedidasByRisco( " + r.getId() + ", " + a.getId() + " ) : " ); System.out.println( "\t\t\t\t\t\t\t\t\t\t\tSQL : " + sql ); Statement st = createLocalStatement(); ResultSet rs = st.executeQuery( sql ); List< Medida > medidas = new LinkedList< Medida >(); if ( rs.isBeforeFirst() ) { rs.first(); do { Medida m = new Medida(); m.setId( new Integer( rs.getInt("medida_id") ) ); m.setMedida_id( m.getId() ); String descricao = rs.getString( "descricao" ); if( descricao != null && descricao.trim().length() > 8) { m.setDescricao( Utils.unicodeToHTML( descricao ) ); //m.setPostos(getPostosByMedidaAndValor(m, v, a)); m.setPostos( getPostosByMedida( r, m, a ) ); medidas.add( m ); } } while ( rs.next() ); } return medidas; } // private List getPostosByMedidaAndValor(Medida m, Valor v, Area a) throws Exception // { // Statement st = dblocal.createStatement(); // String sql = "select subquery.posto_id, valor, descricao from "; // sql += "(select hs_relatorio_posto_medida.posto_id, hs_relatorio_posto.description as descricao, "; // sql += "case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null "; // sql += "when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade "; // sql += "else hs_relatorio_posto_risco.valor_qualitativo_id "; // sql += "end as valor "; // sql += "from hs_relatorio_posto_medida "; // sql += "inner join hs_relatorio_posto_risco on hs_relatorio_posto_risco.posto_id = hs_relatorio_posto_medida.posto_id "; // sql += "inner join hs_relatorio_posto on hs_relatorio_posto.id = hs_relatorio_posto_medida.posto_id "; // sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id "; // sql += "where medida_id = " + m.getId() + " and area_id = " + a.getId() + ") subquery "; // //sql += "where valor = " + v.getValorQuantitativo(); // System.out.println("POSTOS BY MEDIDA SQL : " + sql); // ResultSet rs = st.executeQuery(sql); // List postos = new ArrayList(); // if(rs.isBeforeFirst()) // { // rs.first(); // do // { // PostoTrabalho p = new PostoTrabalho(); // p.setId(new Integer( rs.getInt("posto_id") )); // p.setDescricao(Utils.unicodeToHTML(rs.getString("descricao"))); // postos.add(p); // }while(rs.next()); // } // return postos; // } private List getPostosByMedida(Risco r, Medida m, Area a) throws Exception { String sql = "select subquery.posto_id, valor, descricao, is_principal from "; sql += "(select hs_relatorio_posto_medida.posto_id, hs_relatorio_posto.description as descricao, "; sql += "case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null "; sql += "when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade "; sql += "else hs_relatorio_posto_risco.valor_qualitativo_id "; sql += "end as valor, coalesce( hs_relatorio_posto.is_principal, false ) as is_principal "; sql += "from hs_relatorio_posto_medida "; sql += "inner join hs_relatorio_posto_risco on hs_relatorio_posto_risco.posto_id = hs_relatorio_posto_medida.posto_id "; sql += "inner join hs_relatorio_posto on hs_relatorio_posto.id = hs_relatorio_posto_medida.posto_id "; sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id "; sql += "where medida_id = " + m.getId() + " and area_id = " + a.getId() + " and risco_id = " + r.getId() + ") subquery "; //sql += "where valor = " + v.getValorQuantitativo(); System.out.println("POSTOS BY MEDIDA SQL : " + sql); Statement st = createLocalStatement(); ResultSet rs = st.executeQuery( sql ); List< PostoTrabalho > postos = new LinkedList< PostoTrabalho >(); if ( rs.isBeforeFirst() ) { rs.first(); do { PostoTrabalho p = new PostoTrabalho(); p.setId( new Integer( rs.getInt("posto_id") ) ); p.setPosto_id( p.getId() ); p.setDescricao( Utils.unicodeToHTML( rs.getString( "descricao" ) ) ); p.setIs_principal( new Boolean( rs.getBoolean( "is_principal" ) ) ); postos.add( p ); } while ( rs.next() ); } return postos; } public List getValoresQualitativos() throws Exception { String sql = "select id, description from hs_relatorio_risco_valor_qualitativo;"; System.out.println("VALORES QUALITATIVOS SQL : " + sql); Statement st = createLocalStatement(); ResultSet rs = st.executeQuery( sql ); List< ValorQualitativo > valores = new LinkedList< ValorQualitativo >(); if ( rs.isBeforeFirst() ) { rs.first(); do { ValorQualitativo v = new ValorQualitativo(); v.setId( new Integer( rs.getInt("id") ) ); v.setDescricao( Utils.unicodeToHTML( rs.getString( "description" ) ) ); valores.add( v ); } while ( rs.next() ); } return valores; } public List getValoresQualitativosOnline() throws Exception { return getProvider().listLoad( PlanoValoresQualitativosData.class, PlanoValoresQualitativosData.ID_FULL ); } private boolean existemMedidasByArea( Integer areaID ) throws Exception { String sql = "select distinct medida_id, valor, descricao " + " from ( select distinct hs_relatorio_posto_medida.medida_id, hs_relatorio_posto_risco.risco_id, hs_relatorio_medida.description as descricao, " + " case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null " + " when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade else hs_relatorio_posto_risco.valor_qualitativo_id end as valor from hs_relatorio_posto " + " inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id " + " inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id " + " inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id " + " inner join hs_relatorio_posto_risco on (hs_relatorio_posto_risco.posto_id = hs_relatorio_posto.id and hs_relatorio_posto_risco.risco_id = hs_relatorio_risco.id) " + " inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id " + " inner join hs_relatorio_area on hs_relatorio_area.id = area_id " + " where area_id = " + areaID + " and hs_relatorio_posto_medida.is_plano_actuacao = true) subquery " + " order by subquery.medida_id, valor"; System.out.println( "\t\t\t\t\t\t\t\t\tprovider . existemMedidasByArea( " + areaID + " ) : " ); System.out.println( "\t\t\t\t\t\t\t\t\t\t\tSQL : " + sql ); Statement st = createLocalStatement(); ResultSet rs = st.executeQuery( sql ); return rs.isBeforeFirst(); } private boolean existemMedidasByRisco(Integer risco_id) throws Exception { String sql = "select distinct medida_id " + " from ( select distinct hs_relatorio_posto_medida.medida_id, hs_relatorio_posto_risco.risco_id, hs_relatorio_medida.description as descricao, " + " case when hs_relatorio_posto_risco.valor_qualitativo_id isnull and hs_relatorio_posto_risco.probabilidade isnull and hs_relatorio_posto_risco.severidade isnull then null " + " when hs_relatorio_posto_risco.valor_qualitativo_id isnull then hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade else hs_relatorio_posto_risco.valor_qualitativo_id end as valor from hs_relatorio_posto " + " inner join hs_relatorio_posto_medida on hs_relatorio_posto_medida.posto_id = hs_relatorio_posto.id " + " inner join hs_relatorio_medida on hs_relatorio_medida.id = hs_relatorio_posto_medida.medida_id " + " inner join hs_relatorio_risco on hs_relatorio_risco.id = hs_relatorio_medida.risco_id " + " inner join hs_relatorio_posto_risco on (hs_relatorio_posto_risco.posto_id = hs_relatorio_posto.id and hs_relatorio_posto_risco.risco_id = hs_relatorio_risco.id) " + " inner join hs_relatorio on hs_relatorio.id = hs_relatorio_risco.relatorio_id " + " inner join hs_relatorio_area on hs_relatorio_area.id = area_id " + " where hs_relatorio_posto_risco.risco_id = " + risco_id + " and hs_relatorio_posto_medida.is_plano_actuacao = true) subquery " + " order by medida_id"; System.out.println("EXISTEM MEDIDAS BY RISCO SQL : " + sql); Statement st = createLocalStatement(); ResultSet rs = st.executeQuery( sql ); return rs.isBeforeFirst(); } public Integer createPlano( PlanoActuacao p ) throws Exception { Integer newPlanoID = null; Date todayDate = new Date(); boolean concluidoPorDesactivacao = p.getConcluidoPorDesactivacao() == null ? Boolean.FALSE : p.getConcluidoPorDesactivacao(); Date dataDesactivacao = p.getDataDesactivacao(); if ( dataDesactivacao == null && concluidoPorDesactivacao ) { dataDesactivacao = todayDate; } PlanosActuacaoData planoData = new PlanosActuacaoData(); planoData.setEstabelecimento_id( p.getEstabelecimento_id() ); planoData.setFase( p.getFase() ); planoData.setData_visita( p.getData_visita() ); planoData.setNome_estabelecimento( p.getNome_estabelecimento() ); planoData.setValidacao_director_loja( false ); planoData.setValidacao_dns( false ); planoData.setValidacao_hs( false ); planoData.setParecer_dns( null ); planoData.setObs_correcao( null ); planoData.setData_validacao_dir_loja( null ); planoData.setUser_dir_loja( null ); planoData.setData_validacao_dns( null ); planoData.setUser_dns( null ); planoData.setData_validacao_hs( null ); planoData.setUser_hs( null ); planoData.setFase_antes_correcao( null ); planoData.setCorrecao( "n" ); planoData.setObservacoes_dl( null ); planoData.setObservacoes_dns( null ); planoData.setVerificacao_siprp( null ); planoData.setData_controlo( todayDate ); planoData.setData_email_controlo( null ); planoData.setEmpresa_id( p.getEmpresa_id() ); planoData.setNome_empresa( p.getNome_empresa() ); planoData.setTecnico_hs_id( p.getTecnico_hs_id() ); planoData.setTecnico_hs_nome( p.getTecnico_hs_nome() ); planoData.setData_relatorio( p.getData_relatorio() ); planoData.setDeleted_date( null ); planoData.setConcluido_por_desactivacao( concluidoPorDesactivacao ); planoData.setTecnico_superior_hs_id( p.getTecnico_superior_hs_id() ); planoData.setTecnico_superior_hs_nome( p.getTecnico_superior_hs_nome() ); planoData.setData_desactivacao( dataDesactivacao ); // planoData.setData_disponibilizacao( p.getData_disponibilizacao() ); planoData.setData_validacao_seg( null ); planoData.setUser_seg( null ); planoData.setHs_relatorio_id( p.getHs_relatorio_id() ); System.out.println( "\nCREATE PLANO : " ); planoData.setProvider( EvoBaseProvider.getInstance().getProvider() ); planoData.save(); newPlanoID = planoData.getId(); System.out.println( "\n\tplanoID : " + newPlanoID ); return newPlanoID; } public Integer createArea( Area a ) throws Exception { Integer newAreaID = null; PlanoAreasData areaData = new PlanoAreasData(); areaData.setArea_id( a.getArea_id() ); areaData.setPlano_id( a.getPlano_id() ); areaData.setDescricao( Utils.parseToInsert( a.getDescricao() ) ); areaData.setIs_principal( a.getIs_principal() ); areaData.setOrdem( a.getOrdem() ); System.out.println( "\nCREATE AREA : " ); areaData.setProvider( EvoBaseProvider.getInstance().getProvider( DB.SIPRP ) ); areaData.save(); newAreaID = areaData.getId(); System.out.println( "\n\tareaID : " + newAreaID ); return newAreaID; } public Integer createRisco( Risco r ) throws Exception { Integer newRiscoID = null; PlanoRiscosData riscoData = new PlanoRiscosData(); riscoData.setDescricao( Utils.parseToInsert( r.getDescricao() ) ); riscoData.setActivo( r.getActivo() == null ? "y" : r.getActivo() ); riscoData.setArea_id( r.getArea_id() ); riscoData.setValor( r.getValorQuantitativo() ); riscoData.setRisco_id( r.getId() ); riscoData.setIs_patrimonial( r.getIsPatrimonial() ); riscoData.setValor_qualitativo_id( r.getValorQualitativoID() ); System.out.println( "\nCREATE RISCO : " ); riscoData.setProvider( EvoBaseProvider.getInstance().getProvider( DB.SIPRP ) ); riscoData.save(); newRiscoID = riscoData.getId(); System.out.println( "\n\triscoID : " + newRiscoID ); return newRiscoID; } public Integer createMedida( Medida m ) throws Exception { Integer newMedidaID = null; PlanoMedidasData medidaData = new PlanoMedidasData(); medidaData.setMedida_id( m.getMedida_id() ); medidaData.setRisco_id( m.getRisco_id() ); medidaData.setDescricao( Utils.parseToInsert( m.getDescricao() ) ); System.out.println( "\nCREATE MEDIDA : " ); medidaData.setProvider( EvoBaseProvider.getInstance().getProvider( DB.SIPRP ) ); medidaData.save(); newMedidaID = medidaData.getId(); System.out.println( "\n\tmedidaID : " + newMedidaID ); return newMedidaID; } public void createPostoTrabalho( PostoTrabalho p ) throws Exception { PlanoPostosTrabalhoData postoData = new PlanoPostosTrabalhoData(); postoData.setPosto_id( p.getPosto_id() ); postoData.setMedida_id( p.getMedida_id() ); postoData.setDescricao( Utils.parseToInsert( p.getDescricao() ) ); postoData.setIs_principal( p.getIs_principal() ); System.out.println( "\nCREATE POSTO TRABALHO : " ); postoData.setProvider( EvoBaseProvider.getInstance().getProvider( DB.SIPRP ) ); postoData.save(); } public void createValorQualitativo( ValorQualitativo v ) throws Exception { PlanoValoresQualitativosData valor = new PlanoValoresQualitativosData(); valor.setId( v.getId() ); valor.setDescricao( Utils.parseToInsert( v.getDescricao() ) ); System.out.println( "\nCREATE VALOR QUALITATIVO : " ); valor.setProvider( EvoBaseProvider.getInstance().getProvider( DB.SIPRP ) ); valor.save(); } public void updateValorQualitativo( ValorQualitativo v ) throws Exception { PlanoValoresQualitativosData valor = getProvider().load( PlanoValoresQualitativosData.class, v.getId() ); valor.setDescricao( Utils.parseToInsert( v.getDescricao() ) ); System.out.println( "\nUPDATE VALOR QUALITATIVO : " ); valor.setProvider( EvoBaseProvider.getInstance().getProvider( DB.SIPRP ) ); valor.save(); } public void deleteValorQualitativo( Integer vId ) throws Exception { PlanoValoresQualitativosData valor = getProvider().load( PlanoValoresQualitativosData.class, vId ); System.out.println( "\nDELETE VALOR QUALITATIVO : " ); valor.setDeleted_stamp( new java.sql.Timestamp( System.currentTimeMillis() ) ); valor.save(); } //==================== public String getEmpresaNome( Integer empresaID ) throws Exception { String nome = null; EmpresasData empresaData = getLocalProvider().load( EmpresasData.class, empresaID, EmpresasData.ID ); if ( empresaData != null ) { nome = Utils.unicodeToHTML( empresaData.getDesignacao_social() ); } else { ErrorLogger.logException( new Exception( "CreatePlanosDataProvider . getEmpresaNome( " + empresaID + " ) : is Null !" + "\n\tempresaData = " + (empresaData == null ? "null" : "not null") + ", nome = " + nome ) ); } return nome; } }