forked from Coded/SIPRP
git-svn-id: https://svn.coded.pt/svn/SIPRP@1830 bb69d46d-e84e-40c8-a05a-06db0d633741
parent
32b28d3f0c
commit
32f589a678
@ -0,0 +1,160 @@
|
|||||||
|
/*
|
||||||
|
* To change this template, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package updates.updates;
|
||||||
|
|
||||||
|
import com.evolute.entity.ProviderInterface;
|
||||||
|
import com.evolute.entity.evo.EvoDataException;
|
||||||
|
import com.evolute.entity.evo.EvoDataObject;
|
||||||
|
import com.evolute.module.updater.AbstractUpdate;
|
||||||
|
import com.evolute.utils.Singleton;
|
||||||
|
import db.DBConstants.DB;
|
||||||
|
import db.data.siprp.outer.PlanoAreasData;
|
||||||
|
import db.data.siprp.outer.PlanoMedidasData;
|
||||||
|
import db.data.siprp.outer.PlanoPostosTrabalhoData;
|
||||||
|
import db.data.siprp.outer.PlanoRiscosData;
|
||||||
|
import db.data.siprp.outer.PlanosActuacaoData;
|
||||||
|
import db.data.siprp_local.outer.HsRelatorioAreaData;
|
||||||
|
import db.data.siprp_local.outer.HsRelatorioMedidaData;
|
||||||
|
import db.data.siprp_local.outer.HsRelatorioPostoData;
|
||||||
|
import db.data.siprp_local.outer.HsRelatorioRiscoData;
|
||||||
|
import db.providers.EvoBaseProvider;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
|
import utils.Utils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author dneves
|
||||||
|
*/
|
||||||
|
public class FixPlanoImportedUnicode extends AbstractUpdate
|
||||||
|
{
|
||||||
|
|
||||||
|
private ProviderInterface< EvoDataObject< ? >, EvoDataException > SIPRP = null;
|
||||||
|
|
||||||
|
private ProviderInterface< EvoDataObject< ? >, EvoDataException > LOCAL = null;
|
||||||
|
|
||||||
|
private final Integer planoID;
|
||||||
|
|
||||||
|
|
||||||
|
public FixPlanoImportedUnicode( double start, double end, Integer planoID )
|
||||||
|
{
|
||||||
|
super( start, end, "Corrigir encoding de planos importados" );
|
||||||
|
this.planoID = planoID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doUpdate() throws Exception
|
||||||
|
{
|
||||||
|
SIPRP = EvoBaseProvider.getInstance().getProvider( DB.SIPRP );
|
||||||
|
LOCAL = EvoBaseProvider.getInstance().getProvider( DB.SIPRP_LOCAL );
|
||||||
|
|
||||||
|
PlanosActuacaoData planoActuacao = SIPRP.load( PlanosActuacaoData.class, planoID, PlanosActuacaoData.ID );
|
||||||
|
System.out.println( "\nFixing planoActuacao ID : " + planoID + " = " + ( planoActuacao == null ? "null" : planoActuacao.getNome_estabelecimento() ) );
|
||||||
|
fixAreas( planoActuacao );
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fixAreas( PlanosActuacaoData planoActuacao ) throws Exception
|
||||||
|
{
|
||||||
|
if ( planoActuacao != null )
|
||||||
|
{
|
||||||
|
List<PlanoAreasData> areas = planoActuacao.fromPlanoAreas_plano_id();
|
||||||
|
for ( PlanoAreasData area : areas )
|
||||||
|
{
|
||||||
|
Integer hsRelatorioAreaID = area.getArea_id();
|
||||||
|
HsRelatorioAreaData relatorioArea = LOCAL.load( HsRelatorioAreaData.class, hsRelatorioAreaID );
|
||||||
|
if ( relatorioArea != null )
|
||||||
|
{
|
||||||
|
System.out.println( "\n\tAreaID : " + area.getId() + " = " + area.getDescricao() );
|
||||||
|
System.out.println( "\tLocalAreaID : " + relatorioArea.getId() + " = " + relatorioArea.getDescription() );
|
||||||
|
|
||||||
|
area.setDescricao( Utils.parseToInsert( relatorioArea.getDescription() ) );
|
||||||
|
area.save();
|
||||||
|
}
|
||||||
|
fixRiscos(area);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fixRiscos(PlanoAreasData area) throws Exception
|
||||||
|
{
|
||||||
|
List<PlanoRiscosData> riscos = area.fromPlanoRiscos_area_id();
|
||||||
|
for (PlanoRiscosData risco : riscos)
|
||||||
|
{
|
||||||
|
Integer hsRelatorioRiscoID = risco.getRisco_id();
|
||||||
|
HsRelatorioRiscoData relatorioRisco = LOCAL.load( HsRelatorioRiscoData.class, hsRelatorioRiscoID );
|
||||||
|
if ( relatorioRisco != null )
|
||||||
|
{
|
||||||
|
System.out.println( "\n\t\tRiscoID : " + risco.getId() + " = " + risco.getDescricao() );
|
||||||
|
System.out.println( "\t\tLocalRiscoID : " + relatorioRisco.getId() + " = " + relatorioRisco.getDescription() );
|
||||||
|
|
||||||
|
risco.setDescricao( Utils.parseToInsert( relatorioRisco.getDescription() ) );
|
||||||
|
risco.save();
|
||||||
|
}
|
||||||
|
fixMedidas(risco);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fixMedidas(PlanoRiscosData risco) throws Exception
|
||||||
|
{
|
||||||
|
List<PlanoMedidasData> medidas = risco.fromPlanoMedidas_risco_id();
|
||||||
|
for (PlanoMedidasData medida : medidas)
|
||||||
|
{
|
||||||
|
Integer hsRelatorioMedidaID = medida.getMedida_id();
|
||||||
|
HsRelatorioMedidaData relatorioMedida = LOCAL.load( HsRelatorioMedidaData.class, hsRelatorioMedidaID );
|
||||||
|
if ( relatorioMedida != null )
|
||||||
|
{
|
||||||
|
System.out.println( "\n\t\t\tMedidaID : " + medida.getId() + " = " + medida.getDescricao() );
|
||||||
|
System.out.println( "\t\t\tLocalMedidaID : " + relatorioMedida.getId() + " = " + relatorioMedida.getDescription() );
|
||||||
|
|
||||||
|
medida.setDescricao( Utils.parseToInsert( relatorioMedida.getDescription() ) );
|
||||||
|
medida.save();
|
||||||
|
}
|
||||||
|
fixPostosTrabalho(medida);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fixPostosTrabalho(PlanoMedidasData medida) throws Exception
|
||||||
|
{
|
||||||
|
List<PlanoPostosTrabalhoData> postosTrabalho = medida.fromPlanoPostosTrabalho_medida_id();
|
||||||
|
for (PlanoPostosTrabalhoData posto : postosTrabalho)
|
||||||
|
{
|
||||||
|
Integer hsRelatorioPostoID = posto.getPosto_id();
|
||||||
|
HsRelatorioPostoData relatorioPosto = LOCAL.load( HsRelatorioPostoData.class, hsRelatorioPostoID );
|
||||||
|
if ( relatorioPosto != null )
|
||||||
|
{
|
||||||
|
System.out.println( "\n\t\t\t\tPostoID : " + posto.getId() + " = " + posto.getDescricao() );
|
||||||
|
System.out.println( "\t\t\t\tLocalPostoID : " + relatorioPosto.getId() + " = " + relatorioPosto.getDescription() );
|
||||||
|
|
||||||
|
posto.setDescricao( Utils.parseToInsert( relatorioPosto.getDescription() ) );
|
||||||
|
posto.save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main( String ... args ) throws Exception
|
||||||
|
{
|
||||||
|
FixPlanoImportedUnicode update = new FixPlanoImportedUnicode( 0, 1, new Integer( 81 ) );
|
||||||
|
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.load( update.getClass().getClassLoader().getResourceAsStream( "app.properties" ) );
|
||||||
|
|
||||||
|
Set< Object > keySet = props.keySet();
|
||||||
|
Iterator< Object > it = keySet.iterator();
|
||||||
|
while ( it.hasNext() )
|
||||||
|
{
|
||||||
|
Object key = it.next();
|
||||||
|
Object value = props.getProperty( ( String ) key );
|
||||||
|
|
||||||
|
Singleton.setInstance( ( String ) key, value );
|
||||||
|
}
|
||||||
|
|
||||||
|
EvoBaseProvider.getInstance();
|
||||||
|
|
||||||
|
update.doUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
package updates.updates;
|
||||||
|
|
||||||
|
import com.evolute.module.updater.AbstractUpdate;
|
||||||
|
import com.evolute.utils.sql.*;
|
||||||
|
|
||||||
|
import java.beans.Expression;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: dneves
|
||||||
|
* Date: 8/29/11 12:32 PM
|
||||||
|
*/
|
||||||
|
public class Update1 extends AbstractUpdate
|
||||||
|
{
|
||||||
|
|
||||||
|
public Update1( double startVersion, double endVersion )
|
||||||
|
{
|
||||||
|
super( startVersion, endVersion, "Adicionar suporte para valor qualitativo nos riscos" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doUpdate() throws Exception
|
||||||
|
{
|
||||||
|
executeQuery(new Update("ALTER TABLE plano_riscos ADD COLUMN valor_qualitativo_id INTEGER;"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,90 @@
|
|||||||
|
package updates.updates;
|
||||||
|
|
||||||
|
import com.evolute.module.updater.AbstractUpdate;
|
||||||
|
import com.evolute.utils.arrays.Virtual2DArray;
|
||||||
|
import com.evolute.utils.db.Executer;
|
||||||
|
import com.evolute.utils.sql.Assignment;
|
||||||
|
import com.evolute.utils.sql.Field;
|
||||||
|
import com.evolute.utils.sql.Select;
|
||||||
|
import com.evolute.utils.sql.Update;
|
||||||
|
import com.evolute.utils.sql.backend.BackendProvider;
|
||||||
|
import db.providers.EvoBaseProvider;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User: dneves
|
||||||
|
* Date: 8/29/11 2:23 PM
|
||||||
|
*/
|
||||||
|
public class Update2 extends AbstractUpdate
|
||||||
|
{
|
||||||
|
|
||||||
|
public Update2( double startVersion, double endVersion )
|
||||||
|
{
|
||||||
|
super( startVersion, endVersion, "Actualizar valor qualitativo de riscos antigos" );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doUpdate() throws Exception
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
int countValue = 0;
|
||||||
|
|
||||||
|
Select query = new Select(
|
||||||
|
"select "
|
||||||
|
+ " distinct r.risco_id, t.posto_id, r.id "
|
||||||
|
+ "from plano_riscos r "
|
||||||
|
+ "inner join plano_medidas m on ( m.risco_id = r.id ) "
|
||||||
|
+ "inner join plano_postos_trabalho t on ( t.medida_id = m.id ) "
|
||||||
|
// + "where r.valor_qualitativo_id is null"
|
||||||
|
);
|
||||||
|
Virtual2DArray array = executeQuery( query );
|
||||||
|
for ( int i = 0; i < array.columnLength(); i++ )
|
||||||
|
{
|
||||||
|
Integer riscoID = array.get( i, 0 );
|
||||||
|
Integer postoID = array.get( i, 1 );
|
||||||
|
Integer planoRiscoID = array.get( i, 2 );
|
||||||
|
|
||||||
|
Integer valorID = getValorIDByRiscoIDPostoID( riscoID, postoID );
|
||||||
|
if ( valorID != null )
|
||||||
|
{
|
||||||
|
countValue++;
|
||||||
|
}
|
||||||
|
|
||||||
|
Update upd = new Update( "plano_riscos", new Assignment[] {
|
||||||
|
new Assignment( new Field( "valor_qualitativo_id" ), valorID )
|
||||||
|
},
|
||||||
|
new Field( "id" ).isEqual( planoRiscoID ) );
|
||||||
|
upd.setBackend( BackendProvider.getBackend( EvoBaseProvider.getInstance().getUrl() ) );
|
||||||
|
System.out.println( "UPDATE : " + upd );
|
||||||
|
executeQuery( upd );
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println( "\n-------------------------------------------------------" );
|
||||||
|
System.out.println( "---- TOTAL RISCOS UPDATED : " + count );
|
||||||
|
System.out.println( "---- TOTAL RISCOS UPDATED WITH VALUE : " + countValue );
|
||||||
|
System.out.println( "-------------------------------------------------------" );
|
||||||
|
}
|
||||||
|
|
||||||
|
private Integer getValorIDByRiscoIDPostoID( Integer riscoID, Integer postoID ) throws Exception
|
||||||
|
{
|
||||||
|
Integer result = null;
|
||||||
|
|
||||||
|
Executer LOCAL_EXECUTER = EvoBaseProvider.getInstance().getLocalExecuter();
|
||||||
|
|
||||||
|
Select query = new Select( "SELECT valor_qualitativo_id " +
|
||||||
|
"FROM hs_relatorio_posto_risco " +
|
||||||
|
"WHERE risco_id = " + riscoID + " AND posto_id = " + postoID );
|
||||||
|
query.setBackend( BackendProvider.getBackend( EvoBaseProvider.getInstance().getUrl() ) );
|
||||||
|
Virtual2DArray array = LOCAL_EXECUTER.executeQuery( query );
|
||||||
|
if ( array != null && array.columnLength() > 0 )
|
||||||
|
{
|
||||||
|
Number num = array.get( 0, 0 );
|
||||||
|
result = num == null ? null : num.intValue();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in new issue