|
|
/*
|
|
|
* To change this template, choose Tools | Templates
|
|
|
* and open the template in the editor.
|
|
|
*/
|
|
|
|
|
|
package planosactuacao;
|
|
|
|
|
|
import db.entidades.Area;
|
|
|
import db.entidades.Medida;
|
|
|
import db.entidades.PlanoActuacao;
|
|
|
import db.entidades.PostoTrabalho;
|
|
|
import db.entidades.Risco;
|
|
|
import db.entidades.Utilizador;
|
|
|
import db.entidades.Valor;
|
|
|
import db.providers.PlanosDataProvider;
|
|
|
import db.providers.RelatoriosDataProvider;
|
|
|
import db.providers.UtilizadoresDataProvider;
|
|
|
import global.Global;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
import java.util.ListIterator;
|
|
|
import mail.Mail;
|
|
|
import siprp.database.cayenne.objects.HsRelatorio;
|
|
|
import siprp.database.cayenne.providers.PlanoActuacaoDAO;
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
* @author lluis
|
|
|
*/
|
|
|
public class PlanosActuacao {
|
|
|
PlanosDataProvider pdp = new PlanosDataProvider();
|
|
|
RelatoriosDataProvider rdp;
|
|
|
List<PlanoActuacao> planosList;
|
|
|
List<Date> planosOnlineList;
|
|
|
PlanoActuacaoDAO pa = new PlanoActuacaoDAO();
|
|
|
|
|
|
|
|
|
public PlanosActuacao(Utilizador u){
|
|
|
try
|
|
|
{
|
|
|
rdp = new RelatoriosDataProvider();
|
|
|
Integer estabelecimentoId = null;
|
|
|
if(u.getTipo().intValue() != Global.TECNICO_HS && u.getTipo().intValue() != Global.DIRECTOR_SIPRP)
|
|
|
{
|
|
|
estabelecimentoId = u.getEstabelecimento_id();
|
|
|
}
|
|
|
List<Date> planosOnlineList = getPlanosOnline();
|
|
|
System.out.println("PLANOS ONLINE LIST : " + planosOnlineList.size());
|
|
|
List<HsRelatorio> listRelatorios = getRelatorios(planosOnlineList, estabelecimentoId);
|
|
|
System.out.println("LIST RELATORIOS : " + listRelatorios.size());
|
|
|
putPlanosOnline(listRelatorios);
|
|
|
}
|
|
|
catch(Exception ex)
|
|
|
{
|
|
|
ex.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private List<Date> getPlanosOnline()
|
|
|
{
|
|
|
List<Date> list = null;
|
|
|
try
|
|
|
{
|
|
|
list = pdp.getPlanosOnline();
|
|
|
|
|
|
}
|
|
|
catch(Exception ex)
|
|
|
{
|
|
|
ex.printStackTrace();
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
private List<HsRelatorio> getRelatorios(List<Date> list, Integer estabelecimentoId)
|
|
|
{
|
|
|
List<HsRelatorio> listRelatorios = pa.getRelatoriosNotIn(list, estabelecimentoId);
|
|
|
return listRelatorios;
|
|
|
}
|
|
|
|
|
|
private void putPlanosOnline(List<HsRelatorio> listRelatorios)
|
|
|
{
|
|
|
|
|
|
Iterator<HsRelatorio> iter = listRelatorios.iterator();
|
|
|
|
|
|
while(iter.hasNext())
|
|
|
{
|
|
|
HsRelatorio relatorio = iter.next();
|
|
|
System.out.println("RELATORIO ID : " + relatorio.getId().toString());
|
|
|
try
|
|
|
{
|
|
|
PlanoActuacao p = createPlano(relatorio);
|
|
|
enviarMail(p);
|
|
|
//showPlano(p);
|
|
|
}
|
|
|
catch(Exception ex)
|
|
|
{
|
|
|
ex.printStackTrace();
|
|
|
System.out.println("ERRO NA CRIACAO DOS PLANOS : " + ex.getMessage());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private PlanoActuacao createPlano(HsRelatorio relatorio) throws Exception
|
|
|
{
|
|
|
System.out.println("CREATE PLANO - RELATORIO ID : " + relatorio.getId().toString());
|
|
|
PlanoActuacao p = new PlanoActuacao();
|
|
|
p.setData_visita(relatorio.getToHsMarcacoesEstabelecimento().getData());
|
|
|
|
|
|
//////////
|
|
|
if(relatorio.getToHsMarcacoesEstabelecimento().getToMarcacoesTecnicosHst() != null)
|
|
|
{
|
|
|
p.setTecnico_hs_id(relatorio.getToHsMarcacoesEstabelecimento().getToMarcacoesTecnicosHst().getId());
|
|
|
p.setTecnico_hs_nome(relatorio.getToHsMarcacoesEstabelecimento().getToMarcacoesTecnicosHst().getNome());
|
|
|
}
|
|
|
|
|
|
/////////
|
|
|
p.setFase(new Integer(Global.FASE_SEGURANCA_PREENCHIMENTO));
|
|
|
p.setEstabelecimento_id(relatorio.getToHsMarcacoesEstabelecimento().getToEstabelecimentos().getId());
|
|
|
p.setEmpresa_id(relatorio.getToHsMarcacoesEstabelecimento().getToEstabelecimentos().getToEmpresas().getId());
|
|
|
try
|
|
|
{
|
|
|
p.setNome_empresa(utils.Utils.unicodeToHTML(rdp.getEmpresaNome(p.getEmpresa_id())));
|
|
|
}
|
|
|
catch(Exception ex)
|
|
|
{
|
|
|
ex.printStackTrace();
|
|
|
}
|
|
|
p.setNome_estabelecimento(relatorio.getToHsMarcacoesEstabelecimento().getToEstabelecimentos().getNome());
|
|
|
p = rdp.getFullPlano(p, relatorio.getId());
|
|
|
|
|
|
p.setId(pdp.createPlano(p));
|
|
|
if(p.getAreas() != null)
|
|
|
{
|
|
|
createAreas(p.getId(), p.getAreas());
|
|
|
}
|
|
|
|
|
|
System.out.println("CREATE PLANO - PLANO ID : " + p.getId().toString());
|
|
|
return p;
|
|
|
}
|
|
|
|
|
|
private void createAreas(Integer plano_id, List<Area> areas) throws Exception
|
|
|
{
|
|
|
for(Area a : areas)
|
|
|
{
|
|
|
a.setPlano_id(plano_id);
|
|
|
a.setId(pdp.createArea(a));
|
|
|
if(a.getRiscos() != null)
|
|
|
{
|
|
|
createRiscos(a.getId(), a.getRiscos());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void createRiscos(Integer area_id, List<Risco> riscos) throws Exception
|
|
|
{
|
|
|
for(Risco r : riscos)
|
|
|
{
|
|
|
r.setArea_id(area_id);
|
|
|
r.setId(pdp.createRisco(r));
|
|
|
if(r.getValores() != null)
|
|
|
{
|
|
|
createValores(r.getId(), r.getValores());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void createValores(Integer risco_id, List<Valor> valores) throws Exception
|
|
|
{
|
|
|
for(Valor v : valores)
|
|
|
{
|
|
|
v.setRisco_id(risco_id);
|
|
|
v.setId(pdp.createValor(v));
|
|
|
if(v.getMedidas() != null)
|
|
|
{
|
|
|
createMedidas(v.getId(), v.getMedidas());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void createMedidas(Integer valor_id, List<Medida> medidas) throws Exception
|
|
|
{
|
|
|
for(Medida m : medidas)
|
|
|
{
|
|
|
m.setValor_id(valor_id);
|
|
|
m.setId(pdp.createMedida(m));
|
|
|
if(m.getPostos() != null)
|
|
|
{
|
|
|
createPostos(m.getId(), m.getPostos());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void createPostos(Integer medida_id, List<PostoTrabalho> postos) throws Exception
|
|
|
{
|
|
|
for(PostoTrabalho p : postos)
|
|
|
{
|
|
|
p.setMedida_id(medida_id);
|
|
|
pdp.createPostoTrabalho(p);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public List<PlanoActuacao> getPlanosActivos(Utilizador u)
|
|
|
{
|
|
|
ArrayList list = new ArrayList();
|
|
|
try
|
|
|
{
|
|
|
list = pdp.getPlanosActivos(u);
|
|
|
}
|
|
|
catch(Exception ex)
|
|
|
{
|
|
|
ex.printStackTrace();
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
public List<PlanoActuacao> getPlanosSeguimento(Utilizador u)
|
|
|
{
|
|
|
ArrayList list = new ArrayList();
|
|
|
try
|
|
|
{
|
|
|
list = pdp.getPlanosSeguimento(u);
|
|
|
}
|
|
|
catch(Exception ex)
|
|
|
{
|
|
|
ex.printStackTrace();
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
public List<PlanoActuacao> getPlanosConcluidos(Utilizador u)
|
|
|
{
|
|
|
ArrayList list = new ArrayList();
|
|
|
try
|
|
|
{
|
|
|
list = pdp.getPlanosConcluidos(u);
|
|
|
}
|
|
|
catch(Exception ex)
|
|
|
{
|
|
|
ex.printStackTrace();
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void showPlano(PlanoActuacao p)
|
|
|
{
|
|
|
System.out.println("================================================");
|
|
|
System.out.println("PLANO : " + p.getData_visita_str() + " | " + p.getDescricao() + " | " + p.getFase_nome() + " | " + p.getNome_estabelecimento());
|
|
|
showAreas(p.getAreas());
|
|
|
System.out.println("================================================");
|
|
|
}
|
|
|
|
|
|
private void showAreas(List<Area> areas)
|
|
|
{
|
|
|
for(Area a : areas)
|
|
|
{
|
|
|
System.out.println(" " + a.getDescricao());
|
|
|
showRiscos(a.getRiscos());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void showRiscos(List<Risco> riscos)
|
|
|
{
|
|
|
for(Risco r : riscos)
|
|
|
{
|
|
|
System.out.println(" " + r.getDescricao());
|
|
|
showValores(r.getValores());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void showValores(List<Valor> valores)
|
|
|
{
|
|
|
for(Valor v : valores)
|
|
|
{
|
|
|
System.out.println(" " + v.getValor());
|
|
|
showMedidas(v.getMedidas());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void showMedidas(List<Medida> medidas)
|
|
|
{
|
|
|
for(Medida m : medidas)
|
|
|
{
|
|
|
System.out.println(" " + m.getDescricao());
|
|
|
showPostos(m.getPostos());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void showPostos(List<PostoTrabalho> postos)
|
|
|
{
|
|
|
for(PostoTrabalho p : postos)
|
|
|
{
|
|
|
System.out.println(" " + p.getDescricao());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private void enviarMail(PlanoActuacao p)
|
|
|
{
|
|
|
String assunto = "";
|
|
|
String mail_text = "";
|
|
|
|
|
|
int fase = p.getFase().intValue();
|
|
|
int tipo_utilizador = 0;
|
|
|
switch(fase)
|
|
|
{
|
|
|
case Global.FASE_SEGURANCA_PREENCHIMENTO:
|
|
|
tipo_utilizador = Global.RESPONSAVEL_SEGURANCA;
|
|
|
assunto = "Plano de Actua<75><61>o da Avalia<69><61>o de Riscos de " + p.getData_visita_str() + " - " + p.getNome_estabelecimento();
|
|
|
mail_text = "<p>Exmo. (a) Senhor (a),</p>";
|
|
|
mail_text += "<p>Encontra-se disponível em www.siprp.com o Plano de Actuação referente à auditoria de Avaliação de Riscos Laborais realizada no passado dia " + p.getData_visita_str() + " para que possa efectuar o seu preenchimento.</p>";
|
|
|
mail_text += "<p>Recordamos que dispõe de duas semanas para efectuar o seu preenchimento e passar o respectivo processo para a fase seguinte, ou seja, para o responsável pelo seu estabelecimento.</p>";
|
|
|
mail_text += "<p>Caso tenha alguma dúvida ou necessite de qualquer esclarecimento, contacte, por favor, a área técnica da SIPRP através do telefone 213 504 540.</p>";
|
|
|
mail_text += "<p>Cumprimentos,</p>";
|
|
|
mail_text += "<p>A equipa da SIPRP</p>";
|
|
|
mail_text += "<p><center><b>Por favor não responda a esta mensagem, dado tratar-se de um e-mail automático</b></center></p>";
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
Mail mail = new Mail();
|
|
|
|
|
|
|
|
|
|
|
|
UtilizadoresDataProvider udp = new UtilizadoresDataProvider();
|
|
|
String responsavel_loja = "n";
|
|
|
if(tipo_utilizador == Global.RESPONSAVEL_SEGURANCA)
|
|
|
{
|
|
|
responsavel_loja = "y";
|
|
|
}
|
|
|
try
|
|
|
{
|
|
|
ArrayList list = udp.getUtilizadoresListByTipo(tipo_utilizador, responsavel_loja, p.getEstabelecimento_id());
|
|
|
ListIterator iter = list.listIterator();
|
|
|
while(iter.hasNext())
|
|
|
{
|
|
|
Utilizador u = (Utilizador) iter.next();
|
|
|
System.out.println("USER MAIL NEXT FASE : " + u.getLogin() + " ; " + u.getEmail());
|
|
|
try
|
|
|
{
|
|
|
mail.send(u.getEmail(), Mail.ENDERECO_ENVIO, assunto, mail_text);
|
|
|
System.out.println("EMAIL ENVIADO !!");
|
|
|
}
|
|
|
catch(Exception ex1)
|
|
|
{
|
|
|
ex1.printStackTrace();
|
|
|
System.out.println("MAIL ERROR : " + ex1.getMessage());
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
catch(Exception ex)
|
|
|
{
|
|
|
//ex.printStackTrace();
|
|
|
}
|
|
|
|
|
|
|
|
|
// try
|
|
|
// {
|
|
|
// mail.send("lluis@evolute.pt", Mail.ENDERECO_ENVIO, assunto, mail_text);
|
|
|
// System.out.println("EMAIL ENVIADO !!");
|
|
|
// }
|
|
|
// catch(Exception ex)
|
|
|
// {
|
|
|
// ex.printStackTrace();
|
|
|
// System.out.println("ERRO NO ENVIO DO EMAIL !!");
|
|
|
// }
|
|
|
}
|
|
|
}
|