forked from Coded/SIPRP
git-svn-id: https://svn.coded.pt/svn/SIPRP@971 bb69d46d-e84e-40c8-a05a-06db0d633741
parent
c2142eb47c
commit
8b3820cee6
@ -0,0 +1,59 @@
|
||||
package siprp.higiene.relatorio.print;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
public class AreaToPrint
|
||||
implements PrintableInterface
|
||||
{
|
||||
protected String designacao;
|
||||
protected Vector<RiscoToPrint> riscos;
|
||||
|
||||
public AreaToPrint( String designacao, Vector<RiscoToPrint> riscos )
|
||||
{
|
||||
super();
|
||||
this.designacao = designacao;
|
||||
this.riscos = riscos;
|
||||
}
|
||||
|
||||
public String getDesignacao()
|
||||
{
|
||||
return designacao;
|
||||
}
|
||||
|
||||
public void setDesignacao( String designacao )
|
||||
{
|
||||
this.designacao = designacao;
|
||||
}
|
||||
|
||||
public Vector<RiscoToPrint> getRiscos()
|
||||
{
|
||||
return riscos;
|
||||
}
|
||||
|
||||
public void setRiscos( Vector<RiscoToPrint> riscos )
|
||||
{
|
||||
this.riscos = riscos;
|
||||
}
|
||||
|
||||
public void addRisco( RiscoToPrint risco )
|
||||
{
|
||||
riscos.add( risco );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element toJdomElement() throws Exception
|
||||
{
|
||||
Element areaElement = new Element( "area" );
|
||||
Element designacaoElement = new Element( "designacao" );
|
||||
designacaoElement.setText( designacao );
|
||||
areaElement.addContent( designacaoElement );
|
||||
for( RiscoToPrint risco : riscos )
|
||||
{
|
||||
areaElement.addContent( risco.toJdomElement() );
|
||||
}
|
||||
return areaElement;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
package siprp.higiene.relatorio.print;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
import com.evolute.utils.date.DateUtils;
|
||||
|
||||
public class DataToPrint
|
||||
implements PrintableInterface
|
||||
{
|
||||
protected String tag;
|
||||
protected Date data;
|
||||
|
||||
public DataToPrint( String tag, Date data )
|
||||
{
|
||||
super();
|
||||
this.tag = tag;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element toJdomElement() throws Exception
|
||||
{
|
||||
Element dataElement = new Element( tag );
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime( data );
|
||||
int ano = cal.get( Calendar.YEAR );
|
||||
int mes = cal.get( Calendar.MONTH );
|
||||
int dia = cal.get( Calendar.DAY_OF_MONTH );
|
||||
Element anoElement = new Element( "ano" );
|
||||
anoElement.setText( "" + ano );
|
||||
dataElement.addContent( anoElement );
|
||||
Element mesElement = new Element( "mes" );
|
||||
mesElement.setText( "" + ( mes + 1 ) );
|
||||
dataElement.addContent( mesElement );
|
||||
Element mesExtensoElement = new Element( "mes-extenso" );
|
||||
mesExtensoElement.setText( DateUtils.MONTHS_FULL_PT[ mes ] );
|
||||
dataElement.addContent( mesExtensoElement );
|
||||
Element diaElement = new Element( "dia" );
|
||||
diaElement.setText( "" + dia );
|
||||
dataElement.addContent( diaElement );
|
||||
return dataElement;
|
||||
}
|
||||
|
||||
public String getTag()
|
||||
{
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void setTag( String tag )
|
||||
{
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public Date getData()
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData( Date data )
|
||||
{
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,82 @@
|
||||
package siprp.higiene.relatorio.print;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
public class EmpresaToPrint
|
||||
implements PrintableInterface
|
||||
{
|
||||
protected String designacaoSocial;
|
||||
protected String logotipo;
|
||||
protected String estabelecimento;
|
||||
protected String actividade;
|
||||
|
||||
public EmpresaToPrint( String designacaoSocial, String logotipo,
|
||||
String estabelecimento, String actividade )
|
||||
{
|
||||
super();
|
||||
this.designacaoSocial = designacaoSocial;
|
||||
this.logotipo = logotipo;
|
||||
this.estabelecimento = estabelecimento;
|
||||
this.actividade = actividade;
|
||||
}
|
||||
|
||||
public String getDesignacaoSocial()
|
||||
{
|
||||
return designacaoSocial;
|
||||
}
|
||||
|
||||
public void setDesignacaoSocial( String designacaoSocial )
|
||||
{
|
||||
this.designacaoSocial = designacaoSocial;
|
||||
}
|
||||
|
||||
public String getLogotipo()
|
||||
{
|
||||
return logotipo;
|
||||
}
|
||||
|
||||
public void setLogotipo( String logotipo )
|
||||
{
|
||||
this.logotipo = logotipo;
|
||||
}
|
||||
|
||||
public String getEstabelecimento()
|
||||
{
|
||||
return estabelecimento;
|
||||
}
|
||||
|
||||
public void setEstabelecimento( String estabelecimento )
|
||||
{
|
||||
this.estabelecimento = estabelecimento;
|
||||
}
|
||||
|
||||
public String getActividade()
|
||||
{
|
||||
return actividade;
|
||||
}
|
||||
|
||||
public void setActividade( String actividade )
|
||||
{
|
||||
this.actividade = actividade;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element toJdomElement() throws Exception
|
||||
{
|
||||
Element empresaElement = new Element( "empresa" );
|
||||
Element designacaoSocialElement = new Element( "designacao-social" );
|
||||
designacaoSocialElement.setText( designacaoSocial );
|
||||
empresaElement.addContent( designacaoSocialElement );
|
||||
Element logotipoElement = new Element( "logotipo" );
|
||||
logotipoElement.setText( logotipo );
|
||||
empresaElement.addContent( logotipoElement );
|
||||
Element estabelecimentoElement = new Element( "estabelecimento" );
|
||||
estabelecimentoElement.setText( estabelecimento );
|
||||
empresaElement.addContent( estabelecimentoElement );
|
||||
Element actividadeElement = new Element( "actividade" );
|
||||
actividadeElement.setText( actividade );
|
||||
empresaElement.addContent( actividadeElement );
|
||||
return empresaElement;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
package siprp.higiene.relatorio.print;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
public class LegislacaoAplicavelToPrint
|
||||
implements PrintableInterface
|
||||
{
|
||||
protected Vector<String> diplomas;
|
||||
|
||||
public LegislacaoAplicavelToPrint( Vector<String> diplomas )
|
||||
{
|
||||
super();
|
||||
this.diplomas = diplomas;
|
||||
}
|
||||
|
||||
public Vector<String> getDiplomas()
|
||||
{
|
||||
return diplomas;
|
||||
}
|
||||
|
||||
public void setDiplomas( Vector<String> diplomas )
|
||||
{
|
||||
this.diplomas = diplomas;
|
||||
}
|
||||
|
||||
protected void addDiploma( String diploma )
|
||||
{
|
||||
diplomas.add( diploma );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element toJdomElement() throws Exception
|
||||
{
|
||||
Element legislacaoAplicavelElement = new Element( "legislacao-aplicavel" );
|
||||
for( String diploma : diplomas )
|
||||
{
|
||||
Element diplomaElement = new Element( "diploma" );
|
||||
diplomaElement.setText( diploma );
|
||||
legislacaoAplicavelElement.addContent( diploma );
|
||||
}
|
||||
return legislacaoAplicavelElement;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package siprp.higiene.relatorio.print;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.Date;
|
||||
|
||||
import com.evolute.utils.data.Mappable;
|
||||
|
||||
public class LogotiposDumper
|
||||
{
|
||||
public static void main( String args[] )
|
||||
throws Exception
|
||||
{
|
||||
System.out.println( "Dumper: " + new Date() );
|
||||
dump( args[ 0 ] );
|
||||
}
|
||||
|
||||
public static void dump( String path )
|
||||
throws Exception
|
||||
{
|
||||
Mappable[] logotipos = RelatorioPrintDataProvider.getProvider( true ).getLogotipos();
|
||||
for( Mappable logotipo : logotipos )
|
||||
{
|
||||
File file = new File( path, "" + logotipo.getID() + ".png" );
|
||||
file.createNewFile();
|
||||
FileOutputStream fos = new FileOutputStream( file );
|
||||
fos.write( ( byte[] ) logotipo.getValue() );
|
||||
fos.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
package siprp.higiene.relatorio.print;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.Date;
|
||||
import java.util.Vector;
|
||||
|
||||
public class LogotiposImporter
|
||||
{
|
||||
public static void main( String args[] )
|
||||
throws Exception
|
||||
{
|
||||
System.out.println( "Importer: " + new Date() );
|
||||
load( args[ 0 ] );
|
||||
}
|
||||
|
||||
public static void load( String path )
|
||||
throws Exception
|
||||
{
|
||||
File dir = new File( path );
|
||||
File files[] = dir.listFiles( new FilenameFilter(){
|
||||
|
||||
@Override
|
||||
public boolean accept( File dir, String name )
|
||||
{
|
||||
return name.length() >= 4 && ".jpg".equals( name.substring( name.length() - 4, name.length() ) );
|
||||
}
|
||||
} );
|
||||
for( File file : files )
|
||||
{
|
||||
FileInputStream fis = new FileInputStream( file );
|
||||
int ret = 0;
|
||||
Vector<byte[]> buffers = new Vector<byte[]>();
|
||||
Vector<Integer> sizes = new Vector<Integer>();
|
||||
byte data[];
|
||||
int size = 0;
|
||||
do
|
||||
{
|
||||
byte buff[] = new byte[ 1024 ];
|
||||
ret = fis.read( buff, 0, buff.length );
|
||||
if( ret > 0 )
|
||||
{
|
||||
size += ret;
|
||||
buffers.add( buff );
|
||||
sizes.add( ret );
|
||||
}
|
||||
} while( ret >= 0 );
|
||||
fis.close();
|
||||
data = new byte[ size ];
|
||||
int off = 0;
|
||||
for( int n = 0; n < buffers.size(); n++ )
|
||||
{
|
||||
byte buff[] = buffers.get( n );
|
||||
int s = sizes.get( n );
|
||||
System.arraycopy( buff, 0, data, off, s );
|
||||
off += s;
|
||||
}
|
||||
Integer id = new Integer( file.getName().split( "[.]" )[ 0 ] );
|
||||
|
||||
RelatorioPrintDataProvider.getProvider( true ).updateLogotipo( id, data );
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,58 @@
|
||||
package siprp.higiene.relatorio.print;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
public class MedidaToPrint
|
||||
implements PrintableInterface
|
||||
{
|
||||
protected String descricao;
|
||||
protected Vector<PostoToPrint> postos;
|
||||
|
||||
public MedidaToPrint( String descricao, Vector<PostoToPrint> postos )
|
||||
{
|
||||
super();
|
||||
this.descricao = descricao;
|
||||
this.postos = postos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element toJdomElement() throws Exception
|
||||
{
|
||||
Element medidaElement = new Element( "medida" );
|
||||
Element descricaoElement = new Element( "descricao" );
|
||||
descricaoElement.setText( descricao );
|
||||
medidaElement.addContent( descricaoElement );
|
||||
for( PostoToPrint posto : postos )
|
||||
{
|
||||
medidaElement.addContent( posto.toJdomElement() );
|
||||
}
|
||||
return medidaElement;
|
||||
}
|
||||
|
||||
public String getDescricao()
|
||||
{
|
||||
return descricao;
|
||||
}
|
||||
|
||||
public void setDescricao( String descricao )
|
||||
{
|
||||
this.descricao = descricao;
|
||||
}
|
||||
|
||||
public Vector<PostoToPrint> getPostos()
|
||||
{
|
||||
return postos;
|
||||
}
|
||||
|
||||
public void setPostos( Vector<PostoToPrint> postos )
|
||||
{
|
||||
this.postos = postos;
|
||||
}
|
||||
|
||||
public void addPosto( PostoToPrint posto )
|
||||
{
|
||||
postos.add( posto );
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
package siprp.higiene.relatorio.print;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.jdom.Document;
|
||||
import org.jdom.output.XMLOutputter;
|
||||
|
||||
import com.evolute.utils.fop.PDFCreator;
|
||||
import com.evolute.utils.xml.XSLTransformer;
|
||||
|
||||
public class PlanoActuacaoPDFCreator
|
||||
{
|
||||
|
||||
public byte[] createPDF( Integer planoId, boolean web ) throws Exception
|
||||
{
|
||||
RelatorioToPrint plano = RelatorioPrintDataProvider.getProvider( web ).getPlanoToPrint( planoId );
|
||||
Document foDoc = new Document( plano.toJdomElement() );
|
||||
XMLOutputter outputter = new XMLOutputter();
|
||||
ByteArrayOutputStream foBaos = new ByteArrayOutputStream();
|
||||
outputter.output( foDoc, foBaos );
|
||||
byte fo[] =
|
||||
applyTemplate(
|
||||
getClass().getClassLoader().getResourceAsStream(
|
||||
RelatorioPrintDataProvider.getProvider( web ).empresaUsaPlanoAlargadoPorPlanoId( planoId ) ?
|
||||
"siprp/planoactuacao/print/plano_actuacao_alargado.xsl"
|
||||
: "siprp/planoactuacao/print/plano_actuacao.xsl" ),
|
||||
new ByteArrayInputStream( foBaos.toByteArray() ) );
|
||||
byte pdf[] = PDFCreator.getPDFCreator().createPdfFromFo( fo );
|
||||
return pdf;
|
||||
}
|
||||
|
||||
public byte[] applyTemplate( InputStream xsl, InputStream dataStream ) throws Exception
|
||||
{
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
XSLTransformer.getXSLTransformer().transform( dataStream, xsl, baos );
|
||||
return baos.toByteArray();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package siprp.higiene.relatorio.print;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
|
||||
public class PostoToPrint
|
||||
implements PrintableInterface
|
||||
{
|
||||
protected String designacao;
|
||||
|
||||
public PostoToPrint( String designacao )
|
||||
{
|
||||
this.designacao = designacao;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element toJdomElement()
|
||||
throws Exception
|
||||
{
|
||||
Element postoElement = new Element( "posto" );
|
||||
Element designacaoElement = new Element( "designacao" );
|
||||
designacaoElement.setText( designacao );
|
||||
postoElement.addContent( designacaoElement );
|
||||
return postoElement;
|
||||
}
|
||||
|
||||
public String getDesignacao()
|
||||
{
|
||||
return designacao;
|
||||
}
|
||||
|
||||
public void setDesignacao( String designacao )
|
||||
{
|
||||
this.designacao = designacao;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
package siprp.higiene.relatorio.print;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
public interface PrintableInterface
|
||||
{
|
||||
public Element toJdomElement() throws Exception;
|
||||
}
|
||||
@ -0,0 +1,365 @@
|
||||
package siprp.higiene.relatorio.print;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Vector;
|
||||
|
||||
import siprp.SingletonConstants;
|
||||
import siprp.planoactuacao.db.DBConstants;
|
||||
import siprp.planoactuacao.db.PlanoActuacaoDBInit;
|
||||
|
||||
import com.evolute.utils.Singleton;
|
||||
import com.evolute.utils.arrays.Virtual2DArray;
|
||||
import com.evolute.utils.data.Mappable;
|
||||
import com.evolute.utils.data.MappableObject;
|
||||
import com.evolute.utils.db.DBManager;
|
||||
import com.evolute.utils.db.Executer;
|
||||
import com.evolute.utils.sql.BlobUpdate;
|
||||
import com.evolute.utils.sql.Expression;
|
||||
import com.evolute.utils.sql.Field;
|
||||
import com.evolute.utils.sql.Select;
|
||||
import com.evolute.utils.sql.Select2;
|
||||
|
||||
|
||||
public class RelatorioPrintDataProvider
|
||||
{
|
||||
private static final Object LOCK = new Object();
|
||||
private static RelatorioPrintDataProvider instance = null;
|
||||
|
||||
protected final Executer EXECUTER;
|
||||
|
||||
public RelatorioPrintDataProvider( boolean web )
|
||||
throws Exception
|
||||
{
|
||||
if( Singleton.getInstance( DBConstants.WEB_DBMANAGER ) == null )
|
||||
{
|
||||
PlanoActuacaoDBInit.initDB( web );
|
||||
}
|
||||
DBManager LOCAL_DBMANAGER = ( DBManager ) Singleton.getInstance( DBConstants.LOCAL_DBMANAGER );
|
||||
EXECUTER = LOCAL_DBMANAGER.getSharedExecuter( this );
|
||||
}
|
||||
|
||||
public static RelatorioPrintDataProvider getProvider( boolean web )
|
||||
throws Exception
|
||||
{
|
||||
synchronized( LOCK )
|
||||
{
|
||||
if( instance == null )
|
||||
{
|
||||
instance = new RelatorioPrintDataProvider( web );
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public boolean empresaUsaPlanoAlargadoPorPlanoId( Integer planoId )
|
||||
throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
Select select =
|
||||
new Select2(
|
||||
new String[]{ "hs_relatorio", "marcacoes_estabelecimento", "estabelecimentos", "empresas" },
|
||||
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER },
|
||||
new Expression[]{
|
||||
new Field( "hs_relatorio.marcacao_id" ).isEqual( new Field( "marcacoes_estabelecimento.id" ) ),
|
||||
new Field( "marcacoes_estabelecimento.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ),
|
||||
new Field( "estabelecimentos.empresa_id" ).isEqual( new Field( "empresas.id" ) )
|
||||
},
|
||||
new String[]{ "imprimir_tabela_alargada" },
|
||||
new Field( "hs_relatorio.id" ).isEqual( planoId ),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null );
|
||||
Virtual2DArray array = EXECUTER.executeQuery( select );
|
||||
|
||||
return ( ( Boolean ) array.get( 0, 0 ) ).booleanValue();
|
||||
}
|
||||
catch( Exception ex )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public RelatorioToPrint getPlanoToPrint( Integer id )
|
||||
throws Exception
|
||||
{
|
||||
Virtual2DArray array;
|
||||
|
||||
Select select =
|
||||
new Select2(
|
||||
new String[]{ "hs_relatorio", "marcacoes_estabelecimento", "estabelecimentos", "empresas" },
|
||||
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER, Select2.JOIN_INNER },
|
||||
new Expression[]{
|
||||
new Field( "hs_relatorio.marcacao_id" ).isEqual( new Field( "marcacoes_estabelecimento.id" ) ),
|
||||
new Field( "marcacoes_estabelecimento.estabelecimento_id" ).isEqual( new Field( "estabelecimentos.id" ) ),
|
||||
new Field( "estabelecimentos.empresa_id" ).isEqual( new Field( "empresas.id" ) )
|
||||
},
|
||||
new String[]{ "empresas.id", "empresas.designacao_social", "empresas.actividade",
|
||||
"estabelecimentos.id", "estabelecimentos.nome",
|
||||
"hs_relatorio.data", "marcacoes_estabelecimento.data", "''",
|
||||
"''", "false",
|
||||
"false" },
|
||||
new Field( "hs_relatorio.id" ).isEqual( id ),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null );
|
||||
array = EXECUTER.executeQuery( select );
|
||||
Integer empresaId = ( Integer ) array.get( 0, 0 );
|
||||
String nomeEmpresa = ( String ) array.get( 0, 1 );
|
||||
String actividadeEmpresa = ( String ) array.get( 0, 2 );
|
||||
Integer estabelecimentoId = ( Integer ) array.get( 0, 3 );
|
||||
String nomeEstabelecimento = ( String ) array.get( 0, 4 );
|
||||
Integer logoId = getLogotipoIdForEmpresaId( empresaId );
|
||||
Date dataRelatorio = ( Date ) array.get( 0, 5 );
|
||||
Date dataVisita = ( Date ) array.get( 0, 6 );
|
||||
String observacoesDl = ( String ) array.get( 0, 7 );
|
||||
String observacoesDns = ( String ) array.get( 0, 8 );
|
||||
Boolean validacaoDl = ( Boolean ) array.get( 0, 9 );
|
||||
Boolean validacaoDns = ( Boolean ) array.get( 0, 10 );
|
||||
EmpresaToPrint empresa = new EmpresaToPrint( nomeEmpresa,
|
||||
"http://www.evolute.pt:13080/SIPRPImages/image?id=" + logoId,
|
||||
nomeEstabelecimento, actividadeEmpresa );
|
||||
//TODO:
|
||||
RelatorioToPrint plano = null;
|
||||
// new RelatorioToPrint(
|
||||
// empresa,
|
||||
// dataRelatorio != null ? new DataToPrint( "data-relatorio", dataRelatorio ) : null,
|
||||
// dataVisita != null ? new DataToPrint( "data-hs", dataVisita ) : null,
|
||||
// getLegislacaoAplicavel( empresaId, estabelecimentoId ),
|
||||
// getAreasToPrintByPlanoId( id, validacaoDl, validacaoDns ),
|
||||
// observacoesDl,
|
||||
// observacoesDns );
|
||||
return plano;
|
||||
}
|
||||
|
||||
public Integer getLogotipoIdForEmpresaId( Integer empresaId )
|
||||
throws Exception
|
||||
{
|
||||
Select select =
|
||||
new Select2(
|
||||
new String[]{ "empresas" },
|
||||
new Integer[]{},
|
||||
new Expression[]{},
|
||||
new String[]{ "empresa_logo_id" },
|
||||
new Field( "id" ).isEqual( empresaId ),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null );
|
||||
Virtual2DArray array = EXECUTER.executeQuery( select );
|
||||
return array.columnLength() > 0 ? ( Integer ) array.get( 0, 0 ) : null;
|
||||
}
|
||||
|
||||
public LegislacaoAplicavelToPrint getLegislacaoAplicavel( Integer empresaId, Integer estabelecimentoId )
|
||||
throws Exception
|
||||
{
|
||||
//TODO:
|
||||
LegislacaoAplicavelToPrint legislacao = new LegislacaoAplicavelToPrint( new Vector<String>() );
|
||||
return legislacao;
|
||||
}
|
||||
|
||||
public Vector<AreaToPrint> getAreasToPrintByPlanoId( Integer planoId, boolean validacaoDl, boolean validacaoDns )
|
||||
throws Exception
|
||||
{
|
||||
Virtual2DArray array;
|
||||
Vector<AreaToPrint> areas = new Vector<AreaToPrint>();
|
||||
|
||||
Select select =
|
||||
new Select2(
|
||||
new String[]{ "hs_relatorio_area" },
|
||||
new Integer[]{},
|
||||
new Expression[]{},
|
||||
new String[]{ "id", "description" },
|
||||
new Field( "relatorio_id" ).isEqual( planoId ).and(
|
||||
new Field( "deleted_date" ).isEqual( null ) ),
|
||||
new String[]{ "id" },
|
||||
null,
|
||||
null,
|
||||
null );
|
||||
array = EXECUTER.executeQuery( select );
|
||||
|
||||
for( int n = 0; n < array.columnLength(); n++ )
|
||||
{
|
||||
Integer areaId = ( Integer ) array.get( n, 0 );
|
||||
String areaDescricao = ( String ) array.get( n, 1 );
|
||||
Vector<RiscoToPrint> riscos = getRiscosToPrintByAreaId( areaId, validacaoDl, validacaoDns );
|
||||
if( riscos.size() > 0 )
|
||||
{
|
||||
areas.add( new AreaToPrint( areaDescricao, riscos ) );
|
||||
}
|
||||
}
|
||||
return areas;
|
||||
}
|
||||
|
||||
public Vector<RiscoToPrint> getRiscosToPrintByAreaId( Integer areaId, boolean validacaoDl, boolean validacaoDns )
|
||||
throws Exception
|
||||
{
|
||||
Virtual2DArray array;
|
||||
Vector<RiscoToPrint> riscos = new Vector<RiscoToPrint>();
|
||||
Select select =
|
||||
new Select2(
|
||||
new String[]{ "hs_relatorio_risco", "hs_relatorio_posto_risco", "hs_relatorio_posto" },
|
||||
new Integer[]{ Select2.JOIN_INNER, Select2.JOIN_INNER },
|
||||
new Expression[]{
|
||||
new Field( "hs_relatorio_risco.id" ).isEqual( new Field( "hs_relatorio_posto_risco.risco_id" ) ),
|
||||
new Field( "hs_relatorio_posto_risco.posto_id" ).isEqual( new Field( "hs_relatorio_posto.id" ) )
|
||||
},
|
||||
new String[]{ "hs_relatorio_risco.id",
|
||||
"hs_relatorio_risco.description",
|
||||
"hs_relatorio_posto_risco.probabilidade * hs_relatorio_posto_risco.severidade",
|
||||
"null",
|
||||
"null",
|
||||
"null",
|
||||
"null",
|
||||
"null",
|
||||
"null",
|
||||
"null" },
|
||||
new Field( "hs_relatorio_posto.area_id" ).isEqual( areaId ).and(
|
||||
new Field( "hs_relatorio_risco.deleted_date" ).isEqual( null ) ).and(
|
||||
new Field( "hs_relatorio_posto.deleted_date" ).isEqual( null ) ),
|
||||
new String[]{ "hs_relatorio_risco.id" },
|
||||
null,
|
||||
null,
|
||||
null );
|
||||
array = EXECUTER.executeQuery( select );
|
||||
Vector<String> riscosVector = new Vector<String>();
|
||||
HashMap<String,Vector<Integer>> riscosIdMap = new HashMap<String,Vector<Integer>>();
|
||||
for( int n = 0; n < array.columnLength(); n++ )
|
||||
{
|
||||
Integer id = ( Integer ) array.get( n, 0 );
|
||||
String descricao = ( String ) array.get( n, 1 );
|
||||
Integer risco = ( Integer ) array.get( n, 2 );
|
||||
if( risco == null )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
String key = descricao + "_" + risco;
|
||||
if( !riscosIdMap.containsKey( key ) )
|
||||
{
|
||||
riscosIdMap.put( key, new Vector<Integer>() );
|
||||
riscosVector.add( key );
|
||||
}
|
||||
riscosIdMap.get( key ).add( id );
|
||||
}
|
||||
for( String risco : riscosVector )
|
||||
{
|
||||
int index = risco.lastIndexOf( "_" );
|
||||
String descricao = risco.substring( 0, index );
|
||||
Integer valor = new Integer( risco.substring( index + 1, risco.length() ) );
|
||||
Vector<MedidaToPrint> medidas = new Vector<MedidaToPrint>();
|
||||
for( Integer id : riscosIdMap.get( risco ) )
|
||||
{
|
||||
medidas.addAll( getMedidasToPrintByRiscoId( id ) );
|
||||
}
|
||||
if( medidas.size() > 0 )
|
||||
{
|
||||
riscos.add(
|
||||
new RiscoToPrint(
|
||||
descricao,
|
||||
valor,
|
||||
medidas,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null ) );
|
||||
}
|
||||
}
|
||||
|
||||
return riscos;
|
||||
}
|
||||
|
||||
public Vector<MedidaToPrint> getMedidasToPrintByRiscoId( Integer riscoId )
|
||||
throws Exception
|
||||
{
|
||||
Vector<MedidaToPrint> medidas = new Vector<MedidaToPrint>();
|
||||
Virtual2DArray array;
|
||||
Select select =
|
||||
new Select2(
|
||||
new String[]{ "hs_relatorio_medida" },
|
||||
new Integer[]{},
|
||||
new Expression[]{},
|
||||
new String[]{ "hs_relatorio_medida.id", "hs_relatorio_medida.description" },
|
||||
new Field( "hs_relatorio_medida.risco_id" ).isEqual( riscoId ).and(
|
||||
new Field( "hs_relatorio_medida.deleted_date" ).isEqual( null ) ),
|
||||
new String[]{ "hs_relatorio_medida.id" },
|
||||
null,
|
||||
null,
|
||||
null );
|
||||
array = EXECUTER.executeQuery( select );
|
||||
return medidas;
|
||||
}
|
||||
|
||||
public Vector<PostoToPrint> getPostosToPrintByMedidaId( Integer medidaId )
|
||||
throws Exception
|
||||
{
|
||||
Vector<PostoToPrint> postos = new Vector<PostoToPrint>();
|
||||
Virtual2DArray array;
|
||||
Select select =
|
||||
new Select2(
|
||||
new String[]{ "hs_relatorio_posto", "hs_relatorio_posto_medida" },
|
||||
new Integer[]{ Select2.JOIN_INNER },
|
||||
new Expression[]{
|
||||
new Field( "hs_relatorio_posto.id" ).isEqual( new Field( "hs_relatorio_posto_medida.posto_id" ) )
|
||||
},
|
||||
new String[]{ "hs_relatorio_posto.id", "hs_relatorio_posto.description" },
|
||||
new Field( "hs_relatorio_posto_medida.medida_id" ).isEqual( medidaId ),
|
||||
new String[]{ "hs_relatorio_posto.id" },
|
||||
null,
|
||||
null,
|
||||
null );
|
||||
array = EXECUTER.executeQuery( select );
|
||||
for( int n = 0; n < array.columnLength(); n++ )
|
||||
{
|
||||
String descricao = ( String ) array.get( n, 1 );
|
||||
postos.add( new PostoToPrint( descricao ) );
|
||||
}
|
||||
return postos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Para fazer dump dos logotipos para converter para jpeg
|
||||
*/
|
||||
public Mappable[] getLogotipos()
|
||||
throws Exception
|
||||
{
|
||||
Select select =
|
||||
new Select2(
|
||||
new String[]{ "image" },
|
||||
new Integer[]{},
|
||||
new Expression[]{},
|
||||
new String[]{ "id", "image_data" },
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null );
|
||||
Virtual2DArray array = EXECUTER.executeQuery( select );
|
||||
Mappable logotipos[] = new Mappable[ array.columnLength() ];
|
||||
for( int n = 0; n < logotipos.length; n++ )
|
||||
{
|
||||
Integer id = ( Integer ) array.get( n, 0 );
|
||||
byte data[] = ( byte[] ) array.get( n, 1 );
|
||||
logotipos[ n ] =
|
||||
new MappableObject( id, data );
|
||||
}
|
||||
return logotipos;
|
||||
}
|
||||
|
||||
/**
|
||||
* Para fazer import dos logotipos convertidos para jpeg
|
||||
*/
|
||||
public void updateLogotipo( Integer id, byte[] data )
|
||||
throws Exception
|
||||
{
|
||||
BlobUpdate update =
|
||||
new BlobUpdate( "image", "image_data", data, new Field( "id" ).isEqual( id ) );
|
||||
EXECUTER.executeQuery( update );
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,118 @@
|
||||
package siprp.higiene.relatorio.print;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
public class RelatorioToPrint
|
||||
implements PrintableInterface
|
||||
{
|
||||
protected EmpresaToPrint empresa;
|
||||
protected DataToPrint dataRelatorio;
|
||||
protected DataToPrint dataHs;
|
||||
protected DataToPrint dataProximaHs;
|
||||
protected LegislacaoAplicavelToPrint legislacaoAplicavel;
|
||||
protected Vector<AreaToPrint> areas;
|
||||
|
||||
public RelatorioToPrint( EmpresaToPrint empresa, DataToPrint dataRelatorio,
|
||||
DataToPrint dataHs, DataToPrint dataProximaHs, LegislacaoAplicavelToPrint legislacaoAplicavel,
|
||||
Vector<AreaToPrint> areas )
|
||||
{
|
||||
super();
|
||||
this.empresa = empresa;
|
||||
this.dataRelatorio = dataRelatorio;
|
||||
this.dataHs = dataHs;
|
||||
this.dataProximaHs = dataProximaHs;
|
||||
this.legislacaoAplicavel = legislacaoAplicavel;
|
||||
this.areas = areas;
|
||||
}
|
||||
|
||||
public EmpresaToPrint getEmpresa()
|
||||
{
|
||||
return empresa;
|
||||
}
|
||||
|
||||
public void setEmpresa( EmpresaToPrint empresa )
|
||||
{
|
||||
this.empresa = empresa;
|
||||
}
|
||||
|
||||
public DataToPrint getDataRelatorio()
|
||||
{
|
||||
return dataRelatorio;
|
||||
}
|
||||
|
||||
public void setDataRelatorio( DataToPrint dataRelatorio )
|
||||
{
|
||||
this.dataRelatorio = dataRelatorio;
|
||||
}
|
||||
|
||||
public DataToPrint getDataHs()
|
||||
{
|
||||
return dataHs;
|
||||
}
|
||||
|
||||
public void setDataHs( DataToPrint dataHs )
|
||||
{
|
||||
this.dataHs = dataHs;
|
||||
}
|
||||
|
||||
public DataToPrint getDataProximaHs()
|
||||
{
|
||||
return dataProximaHs;
|
||||
}
|
||||
|
||||
public void setDataProximaHs( DataToPrint dataProximaHs )
|
||||
{
|
||||
this.dataProximaHs = dataProximaHs;
|
||||
}
|
||||
|
||||
public LegislacaoAplicavelToPrint getLegislacaoAplicavel()
|
||||
{
|
||||
return legislacaoAplicavel;
|
||||
}
|
||||
|
||||
public void setLegislacaoAplicavel(
|
||||
LegislacaoAplicavelToPrint legislacaoAplicavel )
|
||||
{
|
||||
this.legislacaoAplicavel = legislacaoAplicavel;
|
||||
}
|
||||
|
||||
public Vector<AreaToPrint> getAreas()
|
||||
{
|
||||
return areas;
|
||||
}
|
||||
|
||||
public void setAreas( Vector<AreaToPrint> areas )
|
||||
{
|
||||
this.areas = areas;
|
||||
}
|
||||
|
||||
public void addArea( AreaToPrint area )
|
||||
{
|
||||
areas.add( area );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element toJdomElement() throws Exception
|
||||
{
|
||||
Element planoElement = new Element( "plano" );
|
||||
planoElement.addContent( empresa.toJdomElement() );
|
||||
planoElement.addContent( dataRelatorio.toJdomElement() );
|
||||
planoElement.addContent( dataHs.toJdomElement() );
|
||||
planoElement.addContent( dataProximaHs.toJdomElement() );
|
||||
planoElement.addContent( legislacaoAplicavel.toJdomElement() );
|
||||
if( areas.size() > 0 )
|
||||
{
|
||||
Element conclusoesElement = new Element( "conclusoes" );
|
||||
for( AreaToPrint area : areas )
|
||||
{
|
||||
conclusoesElement.addContent( area.toJdomElement() );
|
||||
}
|
||||
planoElement.addContent( conclusoesElement );
|
||||
}
|
||||
return planoElement;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,184 @@
|
||||
package siprp.higiene.relatorio.print;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import org.jdom.Element;
|
||||
|
||||
public class RiscoToPrint
|
||||
implements PrintableInterface
|
||||
{
|
||||
protected String descricao;
|
||||
protected Integer valor;
|
||||
protected Vector<MedidaToPrint> medidas;
|
||||
protected String responsavel;
|
||||
protected String recursos;
|
||||
protected DataToPrint dataPrevistaInicio;
|
||||
protected DataToPrint dataPrevistaConclusao;
|
||||
protected String parecerDl;
|
||||
protected String parecerDns;
|
||||
protected String verificacaoSiprp;
|
||||
|
||||
public RiscoToPrint( String descricao, Integer valor,
|
||||
Vector<MedidaToPrint> medidas, String responsavel, String recursos,
|
||||
DataToPrint dataPrevistaInicio, DataToPrint dataPrevistaConclusao,
|
||||
String parecerDl, String parecerDns, String verificacaoSiprp )
|
||||
{
|
||||
super();
|
||||
this.descricao = descricao;
|
||||
this.valor = valor;
|
||||
this.medidas = medidas;
|
||||
this.responsavel = responsavel;
|
||||
this.recursos = recursos;
|
||||
this.dataPrevistaInicio = dataPrevistaInicio;
|
||||
this.dataPrevistaConclusao = dataPrevistaConclusao;
|
||||
this.parecerDl = parecerDl;
|
||||
this.parecerDns = parecerDns;
|
||||
this.verificacaoSiprp = verificacaoSiprp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Element toJdomElement() throws Exception
|
||||
{
|
||||
Element riscoElement = new Element( "risco" );
|
||||
Element descricaoElement = new Element( "descricao" );
|
||||
descricaoElement.setText( descricao );
|
||||
riscoElement.addContent( descricaoElement );
|
||||
Element valorElement = new Element( "valor" );
|
||||
valorElement.setText( valor != null ? valor.toString() : " " );
|
||||
riscoElement.addContent( valorElement );
|
||||
for( MedidaToPrint medida : medidas )
|
||||
{
|
||||
riscoElement.addContent( medida.toJdomElement() );
|
||||
}
|
||||
Element responsavelElement = new Element( "responsavel" );
|
||||
responsavelElement.setText( responsavel );
|
||||
riscoElement.addContent( responsavelElement );
|
||||
Element recursosElement = new Element( "recursos" );
|
||||
recursosElement.setText( recursos );
|
||||
riscoElement.addContent( recursosElement );
|
||||
if( dataPrevistaInicio != null )
|
||||
{
|
||||
riscoElement.addContent( dataPrevistaInicio.toJdomElement() );
|
||||
}
|
||||
if( dataPrevistaConclusao != null )
|
||||
{
|
||||
riscoElement.addContent( dataPrevistaConclusao.toJdomElement() );
|
||||
}
|
||||
Element parecerDlElement = new Element( "parecer-dl" );
|
||||
parecerDlElement.setText( parecerDl );
|
||||
riscoElement.addContent( parecerDlElement );
|
||||
Element parecerDnsElement = new Element( "parecer-dns" );
|
||||
parecerDnsElement.setText( parecerDns );
|
||||
riscoElement.addContent( parecerDnsElement );
|
||||
Element verificacaoSiprpElement = new Element( "verificacao-siprp" );
|
||||
verificacaoSiprpElement.setText( verificacaoSiprp );
|
||||
riscoElement.addContent( verificacaoSiprpElement );
|
||||
return riscoElement;
|
||||
}
|
||||
|
||||
public String getDescricao()
|
||||
{
|
||||
return descricao;
|
||||
}
|
||||
|
||||
public void setDescricao( String descricao )
|
||||
{
|
||||
this.descricao = descricao;
|
||||
}
|
||||
|
||||
public Integer getValor()
|
||||
{
|
||||
return valor;
|
||||
}
|
||||
|
||||
public void setValor( Integer valor )
|
||||
{
|
||||
this.valor = valor;
|
||||
}
|
||||
|
||||
public Vector<MedidaToPrint> getMedidas()
|
||||
{
|
||||
return medidas;
|
||||
}
|
||||
|
||||
public void setMedidas( Vector<MedidaToPrint> medidas )
|
||||
{
|
||||
this.medidas = medidas;
|
||||
}
|
||||
|
||||
public void addMedida( MedidaToPrint medida )
|
||||
{
|
||||
medidas.add( medida );
|
||||
}
|
||||
|
||||
public String getResponsavel()
|
||||
{
|
||||
return responsavel;
|
||||
}
|
||||
|
||||
public void setResponsavel( String responsavel )
|
||||
{
|
||||
this.responsavel = responsavel;
|
||||
}
|
||||
|
||||
public String getRecursos()
|
||||
{
|
||||
return recursos;
|
||||
}
|
||||
|
||||
public void setRecursos( String recursos )
|
||||
{
|
||||
this.recursos = recursos;
|
||||
}
|
||||
|
||||
public DataToPrint getDataPrevistaInicio()
|
||||
{
|
||||
return dataPrevistaInicio;
|
||||
}
|
||||
|
||||
public void setDataPrevistaInicio( DataToPrint dataPrevistaInicio )
|
||||
{
|
||||
this.dataPrevistaInicio = dataPrevistaInicio;
|
||||
}
|
||||
|
||||
public DataToPrint getDataPrevistaConclusao()
|
||||
{
|
||||
return dataPrevistaConclusao;
|
||||
}
|
||||
|
||||
public void setDataPrevistaConclusao( DataToPrint dataPrevistaConclusao )
|
||||
{
|
||||
this.dataPrevistaConclusao = dataPrevistaConclusao;
|
||||
}
|
||||
|
||||
public String getParecerDl()
|
||||
{
|
||||
return parecerDl;
|
||||
}
|
||||
|
||||
public void setParecerDl( String parecerDl )
|
||||
{
|
||||
this.parecerDl = parecerDl;
|
||||
}
|
||||
|
||||
public String getParecerDns()
|
||||
{
|
||||
return parecerDns;
|
||||
}
|
||||
|
||||
public void setParecerDns( String parecerDns )
|
||||
{
|
||||
this.parecerDns = parecerDns;
|
||||
}
|
||||
|
||||
public String getVerificacaoSiprp()
|
||||
{
|
||||
return verificacaoSiprp;
|
||||
}
|
||||
|
||||
public void setVerificacaoSiprp( String verificacaoSiprp )
|
||||
{
|
||||
this.verificacaoSiprp = verificacaoSiprp;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in new issue