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.
477 lines
16 KiB
477 lines
16 KiB
/*
|
|
* To change this template, choose Tools | Templates
|
|
* and open the template in the editor.
|
|
*/
|
|
|
|
package planosactuacao;
|
|
|
|
import com.evolute.utils.error.ErrorLogger;
|
|
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.CreatePlanosDataProvider;
|
|
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 shst.data.outer.HsRelatorioData;
|
|
import shst.data.provider.PlanoActuacaoDataProvider;
|
|
import static com.evolute.utils.strings.UnicodeLatin1Map.*;
|
|
|
|
/**
|
|
*
|
|
* @author lluis
|
|
*/
|
|
public class PlanosActuacao
|
|
{
|
|
//PlanosDataProvider pdp = new PlanosDataProvider();
|
|
// CreatePlanosDataProvider cpdp = new CreatePlanosDataProvider();
|
|
//RelatoriosDataProvider rdp;
|
|
private List< PlanoActuacao > planosList;
|
|
private List< Date > planosOnlineList;
|
|
|
|
// PlanoActuacaoDAO pa = new PlanoActuacaoDAO();
|
|
|
|
//DB
|
|
|
|
|
|
public PlanosActuacao()
|
|
{
|
|
try
|
|
{
|
|
System.out.println( "Importar planos de actua" + ccedil + atilde + "o" );
|
|
//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(null);
|
|
// System.out.println("PLANOS ONLINE LIST : " + planosOnlineList.size());
|
|
initRelatorios( null, null );
|
|
// System.out.println("LIST RELATORIOS : " + listRelatorios.size());
|
|
// putPlanosOnline(listRelatorios);
|
|
}
|
|
catch ( Exception ex )
|
|
{
|
|
ErrorLogger.logException( ex );
|
|
}
|
|
}
|
|
|
|
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( estabelecimentoId );
|
|
System.out.println("PLANOS ONLINE LIST : " + planosOnlineList.size());
|
|
initRelatorios( planosOnlineList, estabelecimentoId );
|
|
}
|
|
catch ( Exception ex )
|
|
{
|
|
ErrorLogger.logException( ex );
|
|
}
|
|
}
|
|
|
|
private List<Date> getPlanosOnline(Integer estabelecimentoId)
|
|
{
|
|
List<Date> list = new ArrayList<Date>();
|
|
try
|
|
{
|
|
if( estabelecimentoId != null )
|
|
{
|
|
CreatePlanosDataProvider cpdp = CreatePlanosDataProvider.getInstance();
|
|
list = cpdp.getPlanosOnline( estabelecimentoId );
|
|
}
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
ErrorLogger.logException( ex );
|
|
}
|
|
return list;
|
|
}
|
|
|
|
private void initRelatorios( List< Date > list, Integer estabelecimentoId )
|
|
{
|
|
System.out.println("initRelatorios for estabelecimento id: " + estabelecimentoId );
|
|
try
|
|
{
|
|
CreatePlanosDataProvider cpdp = CreatePlanosDataProvider.getInstance();
|
|
PlanoActuacaoDataProvider pa = PlanoActuacaoDataProvider.getProvider();
|
|
|
|
if( estabelecimentoId == null )
|
|
{
|
|
System.out.println("A adicionar planos de estabelecimentos novos");
|
|
List< Integer > estabelecimentos = cpdp.getEstabelecimentosWithPlanos();
|
|
putPlanosOnline( pa.getRelatoriosNotIn( estabelecimentos ) );
|
|
estabelecimentos = cpdp.getEstabelecimentosWithPlanos();
|
|
System.out.println("A adicionar planos a estabelecimentos anteriores");
|
|
for( Integer estabelecimentoID : estabelecimentos )
|
|
{
|
|
try
|
|
{
|
|
System.out.println("A importar relatorio para o estabelecimento: " + estabelecimentoID );
|
|
List<Date> datas = cpdp.getPlanosOnline(estabelecimentoID);
|
|
if( datas.isEmpty() )
|
|
{
|
|
System.out.println("Nenhuma data de relatorio para o estabelecimento: " + estabelecimentoID );
|
|
}
|
|
else
|
|
{
|
|
List< HsRelatorioData > relatorios = pa.getRelatoriosNotIn(datas, estabelecimentoID);
|
|
if( relatorios.isEmpty() )
|
|
{
|
|
System.out.println("Nenhum relatorio novo para o estabelecimento: " + estabelecimentoID );
|
|
}
|
|
else
|
|
{
|
|
putPlanosOnline( relatorios );
|
|
}
|
|
}
|
|
}
|
|
catch(Exception e )
|
|
{
|
|
ErrorLogger.logException( e );
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
putPlanosOnline( pa.getRelatoriosNotIn( list, estabelecimentoId ) );
|
|
}
|
|
}
|
|
catch ( Exception e )
|
|
{
|
|
ErrorLogger.logException( e );
|
|
}
|
|
}
|
|
|
|
private void putPlanosOnline( List< HsRelatorioData > listRelatorios )
|
|
{
|
|
System.out.println("putPlanosOnline (" + listRelatorios == null ? "null" : listRelatorios.size() );
|
|
Iterator< HsRelatorioData > iter = listRelatorios.iterator();
|
|
while ( iter.hasNext() )
|
|
{
|
|
HsRelatorioData relatorio = iter.next();
|
|
System.out.println("\tRELATORIO ID : " + relatorio.getId().toString() );
|
|
try
|
|
{
|
|
PlanoActuacao p = createPlano( relatorio );
|
|
if ( p != null )
|
|
{
|
|
enviarMail( p );
|
|
}
|
|
//showPlano(p);
|
|
}
|
|
catch ( Exception ex )
|
|
{
|
|
ErrorLogger.logException( ex );
|
|
System.out.println( "ERRO NA CRIACAO DOS PLANOS : " + ex.getMessage() );
|
|
}
|
|
}
|
|
}
|
|
|
|
private PlanoActuacao createPlano(HsRelatorioData relatorio) throws Exception
|
|
{
|
|
System.out.println("CREATE PLANO - RELATORIO ID : " + relatorio.getId().toString());
|
|
|
|
CreatePlanosDataProvider cpdp = CreatePlanosDataProvider.getInstance();
|
|
|
|
PlanoActuacao p = new PlanoActuacao();
|
|
p.setData_visita( relatorio.toMarcacao_id().getData() );
|
|
// p.setData_visita(relatorio.getToHsMarcacoesEstabelecimento().getData());
|
|
|
|
|
|
// if(relatorio.getToHsMarcacoesEstabelecimento().getToMarcacoesTecnicosHst() != null)
|
|
if ( relatorio.toMarcacao_id().toTecnico_hst() != null )
|
|
{
|
|
// p.setTecnico_hs_id(relatorio.getToHsMarcacoesEstabelecimento().getToMarcacoesTecnicosHst().getId());
|
|
// p.setTecnico_hs_nome(relatorio.getToHsMarcacoesEstabelecimento().getToMarcacoesTecnicosHst().getNome());
|
|
p.setTecnico_hs_id( relatorio.toMarcacao_id().toTecnico_hst().getId() );
|
|
p.setTecnico_hs_nome( relatorio.toMarcacao_id().toTecnico_hst().getNome() );
|
|
}
|
|
|
|
// if ( relatorio.getToHsMarcacoesEstabelecimento().getToMarcacoesTecnicosSuperioresHst() != null )
|
|
if ( relatorio.toMarcacao_id().toTecnico_superior_hst() != null )
|
|
{
|
|
// p.setTecnico_superior_hs_id( relatorio.getToHsMarcacoesEstabelecimento().getToMarcacoesTecnicosSuperioresHst().getId() );
|
|
// p.setTecnico_superior_hs_nome( relatorio.getToHsMarcacoesEstabelecimento().getToMarcacoesTecnicosSuperioresHst().getNome() );
|
|
p.setTecnico_superior_hs_id( relatorio.toMarcacao_id().toTecnico_superior_hst().getId() );
|
|
p.setTecnico_superior_hs_nome( relatorio.toMarcacao_id().toTecnico_superior_hst().getNome() );
|
|
}
|
|
|
|
/////////
|
|
p.setFase(new Integer(Global.FASE_SEGURANCA_PREENCHIMENTO));
|
|
|
|
// p.setEstabelecimento_id(relatorio.getToHsMarcacoesEstabelecimento().getToEstabelecimentos().getId());
|
|
// p.setEmpresa_id(relatorio.getToHsMarcacoesEstabelecimento().getToEstabelecimentos().getToEmpresas().getId());
|
|
p.setEstabelecimento_id( relatorio.toMarcacao_id().toEstabelecimento_id().getId() );
|
|
p.setEmpresa_id( relatorio.toMarcacao_id().toEstabelecimento_id().toEmpresa_id().getId() );
|
|
try
|
|
{
|
|
//p.setNome_empresa(utils.Utils.unicodeToHTML(rdp.getEmpresaNome(p.getEmpresa_id())));
|
|
p.setNome_empresa(utils.Utils.unicodeToHTML(cpdp.getEmpresaNome(p.getEmpresa_id())));
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
ErrorLogger.logException( ex );
|
|
}
|
|
// p.setNome_estabelecimento(relatorio.getToHsMarcacoesEstabelecimento().getToEstabelecimentos().getNome());
|
|
p.setNome_estabelecimento( relatorio.toMarcacao_id().toEstabelecimento_id().getNome() );
|
|
p.setData_relatorio(relatorio.getData());
|
|
p.setData_disponibilizacao( relatorio.getIs_submetido() );
|
|
p.setHs_relatorio_id( relatorio.getId() );
|
|
|
|
//p = rdp.getFullPlano(p, relatorio.getId());
|
|
p = cpdp.getFullPlano( p, relatorio.getId() );
|
|
|
|
if ( p.getAreas() != null )
|
|
{
|
|
if ( p.getAreas().size() > 0 )
|
|
{
|
|
p.setId( cpdp.createPlano( p ) );
|
|
System.out.println("CREATE PLANO - PLANO ID : " + p.getId().toString());
|
|
if ( p.getAreas() != null )
|
|
{
|
|
createAreas( p.getId(), p.getAreas() );
|
|
}
|
|
}
|
|
else
|
|
{
|
|
p = null;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
p = null;
|
|
}
|
|
|
|
|
|
|
|
return p;
|
|
}
|
|
|
|
private void createAreas(Integer plano_id, List<Area> areas) throws Exception
|
|
{
|
|
CreatePlanosDataProvider cpdp = CreatePlanosDataProvider.getInstance();
|
|
|
|
for(Area a : areas)
|
|
{
|
|
a.setPlano_id( plano_id );
|
|
a.setId( cpdp.createArea( a ) );
|
|
System.out.println("AREA =: " + a.getId().toString());
|
|
if(a.getRiscos() != null)
|
|
{
|
|
System.out.println("AREA RISCOS: " + a.getRiscos().size());
|
|
createRiscos(a.getId(), a.getRiscos());
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
/**
|
|
* FIXME : importacao -> r.setPatrimonial( ... )
|
|
*
|
|
* @param area_id
|
|
* @param riscos
|
|
* @throws Exception
|
|
*/
|
|
private void createRiscos( Integer area_id, List< Risco > riscos ) throws Exception
|
|
{
|
|
CreatePlanosDataProvider cpdp = CreatePlanosDataProvider.getInstance();
|
|
|
|
for ( Risco r : riscos )
|
|
{
|
|
r.setArea_id( area_id );
|
|
//r.setId(pdp.createRisco(r));
|
|
System.out.println( "CREATE RISCO: " );
|
|
if ( r.getValores() != null )
|
|
{
|
|
for ( Valor v : r.getValores() )
|
|
{
|
|
//System.out.println("RISCO -> " + r.getRisco_id().toString() + "VALOR -> " + v.getValor().toString());
|
|
r.setValor( v.getValor() );
|
|
r.setId( cpdp.createRisco( r ) );
|
|
}
|
|
}
|
|
if ( r.getMedidas() != null )
|
|
{
|
|
createMedidas( r.getId(), r.getMedidas() );
|
|
}
|
|
// 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 risco_id, List<Medida> medidas) throws Exception
|
|
{
|
|
CreatePlanosDataProvider cpdp = CreatePlanosDataProvider.getInstance();
|
|
|
|
for(Medida m : medidas)
|
|
{
|
|
m.setRisco_id( risco_id );
|
|
m.setId( cpdp.createMedida( m ) );
|
|
if(m.getPostos() != null)
|
|
{
|
|
createPostos(m.getId(), m.getPostos());
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
private void createPostos(Integer medida_id, List<PostoTrabalho> postos) throws Exception
|
|
{
|
|
CreatePlanosDataProvider cpdp = CreatePlanosDataProvider.getInstance();
|
|
|
|
for(PostoTrabalho p : postos)
|
|
{
|
|
p.setMedida_id( medida_id );
|
|
cpdp.createPostoTrabalho( p );
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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ção da Avaliaçã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();
|
|
|
|
String responsavel_loja = "n";
|
|
if(tipo_utilizador == Global.RESPONSAVEL_SEGURANCA)
|
|
{
|
|
responsavel_loja = "y";
|
|
}
|
|
try
|
|
{
|
|
UtilizadoresDataProvider udp = UtilizadoresDataProvider.getInstance();
|
|
List< Utilizador > 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( "\t\tUSER MAIL NEXT FASE : " + u.getLogin() + " ; " + u.getEmail() );
|
|
try
|
|
{
|
|
mail.send( u.getEmail(), Mail.ENDERECO_ENVIO, assunto, mail_text );
|
|
System.out.println( "\t\t\tEMAIL ENVIADO !!" );
|
|
}
|
|
catch(Exception ex1)
|
|
{
|
|
ErrorLogger.logException( ex1 );
|
|
System.out.println("\t\t\tMAIL ERROR : " + ex1.getMessage());
|
|
}
|
|
|
|
}
|
|
}
|
|
catch ( Exception ex )
|
|
{
|
|
ErrorLogger.logException( ex );
|
|
}
|
|
}
|
|
}
|