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.
488 lines
24 KiB
488 lines
24 KiB
/*
|
|
* To change this template, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
|
|
package db.providers;
|
|
|
|
import com.evolute.utils.error.ErrorLogger;
|
|
import db.data.siprp_local.outer.EmpresasData;
|
|
import db.data.siprp_local.outer.ImageData;
|
|
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 java.sql.ResultSet;
|
|
import java.sql.Statement;
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
import utils.Utils;
|
|
|
|
/**
|
|
*
|
|
* @author lluis
|
|
*/
|
|
public class RelatoriosDataProvider extends GenericDataProvider
|
|
{
|
|
// private DbLocal dblocal = DbLocal.getInstance();
|
|
|
|
private static RelatoriosDataProvider INSTANCE = null;
|
|
|
|
private RelatoriosDataProvider() throws Exception
|
|
{
|
|
super();
|
|
// dblocal.connect();
|
|
}
|
|
|
|
public static synchronized RelatoriosDataProvider getInstance() throws Exception
|
|
{
|
|
if ( INSTANCE == null )
|
|
{
|
|
INSTANCE = new RelatoriosDataProvider();
|
|
}
|
|
return INSTANCE;
|
|
}
|
|
|
|
|
|
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
|
|
{
|
|
Statement st = createLocalStatement();
|
|
|
|
String sql = "select distinct area_id, hs_relatorio_area.description as descricao 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 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.id = " + relatorioID + " ";
|
|
sql += "order by area_id ";
|
|
System.out.println("AREAS BY PLANO SQL : " + sql);
|
|
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_id") ));
|
|
a.setArea_id(a.getId());
|
|
if(existemMedidasByArea(a.getId()))
|
|
{
|
|
a.setDescricao(Utils.unicodeToHTML(rs.getString("descricao")));
|
|
try
|
|
{
|
|
a.setRiscos(getRiscosByArea(a));
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
System.out.println("ERRO RISCOS BY AREA !!!!");
|
|
ErrorLogger.logException( ex );
|
|
a.setRiscos(null);
|
|
}
|
|
|
|
areas.add(a);
|
|
}
|
|
|
|
}while(rs.next());
|
|
plano.setAreas(areas);
|
|
}
|
|
return plano;
|
|
}
|
|
|
|
private List<Risco> getRiscosByArea(Area a) throws Exception
|
|
{
|
|
// Statement st = dblocal.createStatement();
|
|
Statement st = createLocalStatement();
|
|
|
|
String sql = "select distinct hs_relatorio_risco.id, hs_relatorio_risco.description as descricao 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 on hs_relatorio.id = hs_relatorio_risco.relatorio_id ";
|
|
sql += "inner join hs_relatorio_area on hs_relatorio_area.id = area_id ";
|
|
sql += "where area_id = " + a.getId() + " ";
|
|
sql += "order by hs_relatorio_risco.id ";
|
|
System.out.println("RISCOS BY AREA SQL : " + sql);
|
|
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.setValores(getValoresByRisco(r, a));
|
|
//Integer valor = getValorByRisco(r, a);
|
|
//r.setValorQuantitativo(valor);
|
|
r.setRisco_id(new Integer( rs.getInt("id") ));
|
|
r.setMedidas(getMedidasByRisco( r, a));
|
|
riscos.add(r);
|
|
}
|
|
|
|
}while(rs.next());
|
|
}
|
|
return riscos;
|
|
|
|
}
|
|
|
|
private List<Valor> getValoresByRisco(Risco r, Area a) throws Exception
|
|
//private Integer getValorByRisco(Risco r, Area a) throws Exception
|
|
{
|
|
// Statement st = dblocal.createStatement();
|
|
Statement st = createLocalStatement();
|
|
|
|
String sql = "select valor from ";
|
|
sql += "(select distinct hs_relatorio_posto_risco.risco_id, ";
|
|
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() + ") subquery ";
|
|
sql += "order by subquery.valor";
|
|
System.out.println("VALORES BY RISCO : " + sql);
|
|
ResultSet rs = st.executeQuery(sql);
|
|
List< Valor > valores = new LinkedList< Valor >();
|
|
Integer valor = null;
|
|
if(rs.isBeforeFirst())
|
|
{
|
|
rs.first();
|
|
do
|
|
{
|
|
Valor v = new Valor();
|
|
Object oValor = rs.getObject("valor");
|
|
|
|
if(oValor == null)
|
|
{
|
|
v.setValorQuantitativo(null);
|
|
//r.setValorQuantitativo(null);
|
|
valor = null;
|
|
}
|
|
else
|
|
{
|
|
v.setValorQuantitativo((Integer) oValor);
|
|
//r.setValorQuantitativo((Integer) oValor);
|
|
valor = (Integer) oValor;
|
|
}
|
|
// System.out.println("RISCO : " + r.getId().toString() + "VALOR : " + oValor.toString());
|
|
//int valor = rs.getInt("valor");
|
|
//v.setValorQuantitativo(new Integer(valor));
|
|
//v.setMedidas(getMedidasByValor(v, r, a));
|
|
valores.add(v);
|
|
}while(rs.next());
|
|
}
|
|
return valores;
|
|
//return valor;
|
|
}
|
|
|
|
// private List<Medida> 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<Medida> 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<Medida> getMedidasByRisco(Risco r, Area a) throws Exception
|
|
{
|
|
// Statement st = dblocal.createStatement();
|
|
Statement st = createLocalStatement();
|
|
|
|
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 RISCO SQL : " + sql);
|
|
ResultSet rs = st.executeQuery(sql);
|
|
List< Medida > medidas = new LinkedList< Medida >();
|
|
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.setMedida_id(m.getId());
|
|
m.setDescricao(Utils.unicodeToHTML(rs.getString("descricao")));
|
|
//m.setPostos(getPostosByMedidaAndValor(m, v, a));
|
|
m.setPostos(getPostosByMedida(r, m, a));
|
|
medidas.add(m);
|
|
}while(rs.next());
|
|
}
|
|
return medidas;
|
|
}
|
|
|
|
// private List<PostoTrabalho> 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<PostoTrabalho> 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<PostoTrabalho> getPostosByMedida(Risco r, Medida m, Area a) throws Exception
|
|
{
|
|
// Statement st = dblocal.createStatement();
|
|
Statement st = createLocalStatement();
|
|
|
|
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() + " and risco_id = " + r.getId() + ") subquery ";
|
|
//sql += "where valor = " + v.getValorQuantitativo();
|
|
System.out.println("POSTOS BY MEDIDA SQL : " + sql);
|
|
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")));
|
|
postos.add(p);
|
|
}while(rs.next());
|
|
}
|
|
return postos;
|
|
}
|
|
|
|
|
|
|
|
private boolean existemMedidasByArea(Integer area_id) throws Exception
|
|
{
|
|
// Statement st = dblocal.createStatement();
|
|
Statement st = createLocalStatement();
|
|
|
|
String sql = "select distinct medida_id, valor, descricao ";
|
|
sql += "from ( 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 else hs_relatorio_posto_risco.valor_qualitativo_id end as valor 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 area_id = " + area_id + " and hs_relatorio_posto_medida.is_plano_actuacao = true) subquery order by subquery.medida_id, valor";
|
|
System.out.println("EXISTEM MEDIDAS BY AREA SQL : " + sql);
|
|
ResultSet rs = st.executeQuery(sql);
|
|
if(rs.isBeforeFirst())
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
private boolean existemMedidasByRisco(Integer risco_id) throws Exception
|
|
{
|
|
// Statement st = dblocal.createStatement();
|
|
Statement st = createLocalStatement();
|
|
|
|
String sql = "select distinct medida_id ";
|
|
sql += "from ( 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 else hs_relatorio_posto_risco.valor_qualitativo_id end as valor 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 = " + 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);
|
|
ResultSet rs = st.executeQuery(sql);
|
|
if(rs.isBeforeFirst())
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public String getEmpresaNome(Integer empresa_id) throws Exception
|
|
{
|
|
String nome = "";
|
|
EmpresasData empresaData = getLocalProvider().load( EmpresasData.class, empresa_id, EmpresasData.ID );
|
|
if ( empresaData != null )
|
|
{
|
|
nome = Utils.unicodeToHTML( empresaData.getDesignacao_social() );
|
|
}
|
|
return nome;
|
|
|
|
// Statement st = createLocalStatement();
|
|
//
|
|
// String sql ="SELECT designacao_social FROM empresas WHERE id = " + empresa_id;
|
|
// ResultSet rslocal = st.executeQuery(sql);
|
|
// rslocal.first();
|
|
// String nome = Utils.unicodeToHTML(rslocal.getString("designacao_social"));
|
|
// return nome;
|
|
}
|
|
|
|
public byte[] getLogoByEmpresa( Integer empresaId )
|
|
throws Exception
|
|
{
|
|
byte[] logo = null;
|
|
EmpresasData empresaData = getLocalProvider().load( EmpresasData.class, empresaId, EmpresasData.ID );
|
|
if ( empresaData != null )
|
|
{
|
|
Integer logoID = empresaData.getEmpresa_logo_id();
|
|
logo = getLogo( logoID );
|
|
}
|
|
return logo;
|
|
|
|
// Statement st = createLocalStatement();
|
|
//
|
|
// String sql = "select empresa_logo_id from empresas where id = " + empresaId;
|
|
// ResultSet rslocal = st.executeQuery(sql);
|
|
// if ( rslocal.isBeforeFirst() )
|
|
// {
|
|
// rslocal.first();
|
|
// Integer logoId = new Integer( rslocal.getInt("empresa_logo_id") );
|
|
// byte[] logo = getLogo( logoId );
|
|
// return logo;
|
|
// }
|
|
//
|
|
// return null;
|
|
}
|
|
|
|
|
|
public byte[] getLogo( Integer logoID ) throws Exception
|
|
{
|
|
byte[] logo = null;
|
|
ImageData imageData = getLocalProvider().load( ImageData.class, logoID, ImageData.ID );
|
|
if ( imageData != null )
|
|
{
|
|
logo = imageData.getImage_data();
|
|
}
|
|
System.out.println( "\nRelatoriosDataProvider . getLogo( " + logoID + " ) : " + ( logo == null ? "null" : "size = " + logo.length ) );
|
|
return logo;
|
|
}
|
|
|
|
// public byte[] getLogo(Integer logoId) throws Exception
|
|
// {
|
|
// Statement st = createLocalStatement();
|
|
//
|
|
// String sql = "select image_data from image where id = " + logoId;
|
|
// ResultSet rslocal = st.executeQuery(sql);
|
|
// rslocal.first();
|
|
// byte[] logo = rslocal.getBytes("image_data");
|
|
// System.out.println("LOGO SIZE : " + logo.length);
|
|
// return logo;
|
|
// }
|
|
} |