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.
257 lines
8.1 KiB
257 lines
8.1 KiB
/*
|
|
* To change this template, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
|
|
package db.providers;
|
|
|
|
import db.entidades.Medida;
|
|
import db.entidades.PlanoActuacao;
|
|
import db.entidades.PostoTrabalho;
|
|
import db.entidades.Risco;
|
|
import db.entidades.User;
|
|
import global.Global;
|
|
import java.sql.ResultSet;
|
|
import java.sql.Statement;
|
|
import java.util.ArrayList;
|
|
|
|
/**
|
|
*
|
|
* @author lluis
|
|
*/
|
|
public class PlanosDataProvider extends GenericDataProvider{
|
|
|
|
// PLANOS
|
|
public Integer createPlano(PlanoActuacao p) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
Integer newId = getMaxTableId("planos_actuacao");
|
|
String sql = "";
|
|
|
|
//To Do sql string here :
|
|
|
|
System.out.println("SQL CREATE PLANO : " + sql);
|
|
st.execute(sql);
|
|
|
|
return newId;
|
|
}
|
|
|
|
public void updatePlano(PlanoActuacao p) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = "";
|
|
|
|
//To Do sql string here :
|
|
|
|
sql += "WHERE id = " + p.getId();
|
|
System.out.println("SQL UPDATE PLANO : " + sql);
|
|
st.execute(sql);
|
|
}
|
|
|
|
public ArrayList getPlanosActivos(User u) throws Exception
|
|
{
|
|
int userType = u.getTipo().intValue();
|
|
Statement st = createStatement();
|
|
String sql = "select * from planos_actuacao ";
|
|
|
|
switch(userType)
|
|
{
|
|
case Global.TECNICO_HS:
|
|
sql += "WHERE estado = 1 OR estado = 5";
|
|
break;
|
|
|
|
case Global.RESPONSAVEL_SEGURANCA:
|
|
sql += "WHERE estado = 2";
|
|
break;
|
|
|
|
case Global.DIRECTOR_LOJA:
|
|
sql += "WHERE estado = 3";
|
|
break;
|
|
|
|
case Global.DIRECTOR_NACIONAL_SEGURANCA:
|
|
sql += "WHERE estado = 4";
|
|
break;
|
|
}
|
|
|
|
ResultSet rs = st.executeQuery(sql);
|
|
ArrayList list = fillPlanoFields(rs);
|
|
|
|
return list;
|
|
}
|
|
|
|
public ArrayList getPlanosConcluidos(User u) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
String sql = "select * from planos_actuacao where estado = 6";
|
|
ResultSet rs = st.executeQuery(sql);
|
|
ArrayList list = fillPlanoFields(rs);
|
|
return list;
|
|
}
|
|
|
|
private ArrayList fillPlanoFields(ResultSet rs) throws Exception
|
|
{
|
|
ArrayList list = new ArrayList();
|
|
if(rs.isBeforeFirst())
|
|
{
|
|
rs.first();
|
|
do
|
|
{
|
|
PlanoActuacao pa = new PlanoActuacao();
|
|
pa.setId( new Integer( rs.getInt("id") ) );
|
|
pa.setEstabelecimento_id(new Integer(rs.getInt("estabelecimento_id")));
|
|
pa.setEstado( new Integer( rs.getInt("estado") ) );
|
|
list.add(pa);
|
|
|
|
}while(rs.next());
|
|
}
|
|
return list;
|
|
}
|
|
|
|
// POSTOS TRABALHO
|
|
public void createPostoTrabalhoByRisco(Integer postoTrabalhoId, Integer riscoId, Integer planoId) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
Integer newId = getMaxTableId("postos_trabalho_risco");
|
|
|
|
String sql = "INSERT INTO postos_trabalho_risco (id, posto_trabalho_id, risco_id, plano_id) VALUES (";
|
|
sql += newId + ", ";
|
|
sql += postoTrabalhoId + ", ";
|
|
sql += riscoId + ", ";
|
|
sql += planoId + ")";
|
|
|
|
System.out.println("SQL CREATE POSTO TRABALHO BY RISCO : " + sql);
|
|
st.execute(sql);
|
|
}
|
|
|
|
public PostoTrabalho getPostoTrabalho(Integer postoTrabalhoId) throws Exception
|
|
{
|
|
PostoTrabalho pt = null;
|
|
Statement st = createStatement();
|
|
String sql = "SELECT * FROM postos_trabalho WHERE id = " + postoTrabalhoId + " AND activo = 'y'";
|
|
ResultSet rs = st.executeQuery(sql);
|
|
|
|
if(rs.isBeforeFirst())
|
|
{
|
|
rs.first();
|
|
pt = new PostoTrabalho();
|
|
pt.setId( new Integer( rs.getInt("id") ) );
|
|
pt.setDescricao( rs.getString("descricao") );
|
|
pt.setActivo( rs.getString("activo") );
|
|
}
|
|
return pt;
|
|
}
|
|
|
|
public ArrayList getPostosTrabalhoByRisco(Integer planoId, Integer riscoId) throws Exception
|
|
{
|
|
ArrayList list = new ArrayList();
|
|
Statement st = createStatement();
|
|
String sql = "SELECT * FROM postos_trabalho_risco WHERE plano_id = " + planoId + " AND risco_id = " + riscoId;
|
|
|
|
ResultSet rs = st.executeQuery(sql);
|
|
|
|
if(rs.isBeforeFirst())
|
|
{
|
|
rs.first();
|
|
do
|
|
{
|
|
Integer postoTrabalhoId = new Integer( rs.getInt("posto_trabalho_id") );
|
|
PostoTrabalho pt = getPostoTrabalho(postoTrabalhoId);
|
|
pt.setRisco_id(riscoId);
|
|
list.add(pt);
|
|
}while(rs.next());
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
// RISCOS
|
|
public void createRiscoByPlano(Integer riscoId, Integer planoId) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
Integer newId = getMaxTableId("riscos_plano_actuacao");
|
|
|
|
String sql = "INSERT INTO riscos_plano_actuacao (id, risco_id, plano_id) VALUES (";
|
|
sql += newId + ", ";
|
|
sql += riscoId + ", ";
|
|
sql += planoId + ")";
|
|
|
|
System.out.println("SQL CREATE RISCO BY PLANO : " + sql);
|
|
st.execute(sql);
|
|
}
|
|
|
|
public Risco getRisco(Integer riscoId) throws Exception
|
|
{
|
|
Risco r = null;
|
|
Statement st = createStatement();
|
|
String sql = "SELECT * FROM riscos WHERE id = " + riscoId + " AND activo = 'y'";
|
|
ResultSet rs = st.executeQuery(sql);
|
|
|
|
if(rs.isBeforeFirst())
|
|
{
|
|
rs.first();
|
|
r = new Risco();
|
|
r.setId( new Integer( rs.getInt("id") ) );
|
|
r.setDescricao( rs.getString("descricao") );
|
|
r.setActivo( rs.getString("activo") );
|
|
}
|
|
return r;
|
|
}
|
|
|
|
public ArrayList getRiscosByPlano(Integer planoId) throws Exception
|
|
{
|
|
ArrayList list = new ArrayList();
|
|
Statement st = createStatement();
|
|
String sql = "SELECT * FROM riscos_plano_actuacao WHERE plano_id = " + planoId;
|
|
|
|
ResultSet rs = st.executeQuery(sql);
|
|
|
|
if(rs.isBeforeFirst())
|
|
{
|
|
rs.first();
|
|
do
|
|
{
|
|
Integer riscoId = new Integer( rs.getInt("risco_id") );
|
|
Risco r = getRisco(riscoId);
|
|
r.setPlano_id(planoId);
|
|
list.add(r);
|
|
}while(rs.next());
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
// MEDIDAS
|
|
public void createMedidaByRisco(Integer medidaId, Integer riscoId, Integer planoId) throws Exception
|
|
{
|
|
Statement st = createStatement();
|
|
Integer newId = getMaxTableId("medidas_plano_actuacao_risco");
|
|
|
|
String sql = "INSERT INTO postos_trabalho_risco (id, medida_id, risco_id, plano_id) VALUES (";
|
|
sql += newId + ", ";
|
|
sql += medidaId + ", ";
|
|
sql += riscoId + ", ";
|
|
sql += planoId + ")";
|
|
|
|
System.out.println("SQL CREATE MEDIDA BY RISCO : " + sql);
|
|
st.execute(sql);
|
|
}
|
|
|
|
public Medida getMedida(Integer medidaId) throws Exception
|
|
{
|
|
Medida m= null;
|
|
Statement st = createStatement();
|
|
String sql = "SELECT * FROM madidas_plano_actuacao WHERE id = " + medidaId + " AND activo = 'y'";
|
|
ResultSet rs = st.executeQuery(sql);
|
|
|
|
if(rs.isBeforeFirst())
|
|
{
|
|
rs.first();
|
|
m = new Medida();
|
|
m.setId( new Integer( rs.getInt("id") ) );
|
|
m.setDescricao( rs.getString("descricao") );
|
|
m.setActiva( rs.getString("activo") );
|
|
}
|
|
return m;
|
|
}
|
|
}
|