327915 - Modifica flussi Cubo Saldi Netti (Consumer e Business) - Gestione parallelismo processo CO e BU -

This commit is contained in:
manuelstefanile
2025-01-28 15:20:20 +01:00
parent 8dd4bd7116
commit 8005b1b7d9
2 changed files with 64 additions and 11 deletions

View File

@@ -4,6 +4,8 @@ package it.valueteam.gnp.dao.db.hb;
import java.util.List;
import it.valueteam.gnp.utility.UserTransactionUtility;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.*;
@@ -17,6 +19,7 @@ import static org.hibernate.criterion.Example.create;
*/
import org.hibernate.criterion.Criterion;
import javax.transaction.UserTransaction;
import java.util.*;
@@ -188,7 +191,14 @@ public class GnpDwhe2eSaldinettiOutDAO extends BaseHibernateDAO{
}
}
public boolean updateFlagElaborato(String nomeFile, String flagElaborato) {
public boolean updateFlagElaborato(String nomeFile, String flagElaborato) throws Exception {
UserTransaction utx;
try {
utx = UserTransactionUtility.beginUserTransaction();
} catch (Exception e) {
throw e;
}
try {
String sqlQuery = this.QUERY_UPDATE_FLAG_LAVORATO;
Query hqlQuery = getSession().createSQLQuery(sqlQuery).addEntity("D", GnpDwhe2eSaldinettiOut.class)
@@ -198,10 +208,19 @@ public class GnpDwhe2eSaldinettiOutDAO extends BaseHibernateDAO{
// Esegui l'update
int rowsUpdated = hqlQuery.executeUpdate();
UserTransactionUtility.endUserTransaction(utx, true);
//almeno 1 update l'ha fatto
return rowsUpdated>0;
} catch (RuntimeException re) {
try {
UserTransactionUtility.endUserTransaction(utx, false);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
log.error("getNativiOloOpenAccess query failed", re);
throw re;
}finally {

View File

@@ -250,6 +250,7 @@ public class Dwhe2eRepoSaldiNettiIn extends InternalSenderProcess implements Log
log.write("9999", "Start readFileAndGetList");
List<GnpDwhe2eSaldinettiIn> listForFile = new ArrayList<GnpDwhe2eSaldinettiIn>();
Scanner reader = null;
try {
String pathLetturaFile = (piattaforma == this.CONSUMER) ? Resources.getPATH_FILE_DWHE2E_REPOSALDINETTI_CON_IN()
@@ -260,7 +261,7 @@ public class Dwhe2eRepoSaldiNettiIn extends InternalSenderProcess implements Log
log.write("9999", "file da elaborare "+ pathLetturaFile + fileName);
File wlFile = new File(pathLetturaFile+fileName);
Scanner reader = new Scanner(wlFile);
reader = new Scanner(wlFile);
int row=0;
int firstRowHeader= 0;
@@ -309,6 +310,17 @@ public class Dwhe2eRepoSaldiNettiIn extends InternalSenderProcess implements Log
} catch (Exception e) {
log.write("9999", "exception in readFileAndGetList "+e.getMessage());
throw e;
}finally {
if(null != reader) {
try {
// Closing when previously closed will have no effect;
reader.close();
} catch (Exception e) {
// no logging possible here, do nothing
} finally {
reader = null;
}
}
}
log.write("9999", "End readFileAndGetList");
return listForFile;
@@ -428,7 +440,9 @@ public class Dwhe2eRepoSaldiNettiIn extends InternalSenderProcess implements Log
throw e;
}
int counter = 0;
try{
//effettua la ricerca nelle tabelle sfruttando ID_RICHIESTA, aggiorna i campi dbcfx e SE trova allora salva
for(GnpDwhe2eSaldinettiIn dwhe2eItem : gnpDwhe2eSaldinettiIn ){
// del. 82
@@ -459,6 +473,16 @@ public class Dwhe2eRepoSaldiNettiIn extends InternalSenderProcess implements Log
continue;
}
counter++;
// Flush e clear ogni 100 record
if (counter % 100 == 0) {
UserTransactionUtility.endUserTransaction(utx, true);
utx = UserTransactionUtility.beginUserTransaction();
log.write("9999", "Processed " + counter + " records, flushed and cleared session.");
}
//se soon arrivato qui, allora non c'è corrispondenza nel DB dell'ID_RICHIESTA
log.write("9999", "ID_RICHIESTA non trovato a DB: " + dwhe2eItem.getIdRichiesta());
//aggiungo errori legati alla mancata presenza dell'ID_RICHIESTA tra le varie delibere
@@ -493,14 +517,6 @@ public class Dwhe2eRepoSaldiNettiIn extends InternalSenderProcess implements Log
private List<GnpDwhe2eSaldinettiOut> generaRecordAndStoreOut(String fileNameIn, String fileNameOut) throws Exception {
log.write("9999", "Start generaRecordAndStoreOut");
UserTransaction utx;
try {
utx = UserTransactionUtility.beginUserTransaction();
} catch (Exception e) {
log.error(e, "generaRecordAndStoreOut: beginUserTransaction");
throw e;
}
GnpDwhe2eSaldinettiOutDAO saldinettiOutDAO =new GnpDwhe2eSaldinettiOutDAO();
GnpDwhe2eSaldinettiInDAO saldinettiInDAO =new GnpDwhe2eSaldinettiInDAO();
@@ -509,12 +525,30 @@ public class Dwhe2eRepoSaldiNettiIn extends InternalSenderProcess implements Log
//Il flag Lavorato ad N è settato nel costruttore quando fa il mapping HB
List<GnpDwhe2eSaldinettiOut> listSaldinettiOut = saldinettiInDAO.groupBy(fileNameIn);
UserTransaction utx;
try {
utx = UserTransactionUtility.beginUserTransaction();
} catch (Exception e) {
log.error(e, "generaRecordAndStoreOut: beginUserTransaction");
throw e;
}
int counter = 0;
try{
log.write("9999", "Inizio salvataggio in GNP_DWHE2E_SALDINETTI_OUT per i record che POPOLERANNO il file " + fileNameOut);
//salva i record nella tabella di out
for(GnpDwhe2eSaldinettiOut itemOut : listSaldinettiOut){
itemOut.setNomeFile(fileNameOut);
saldinettiOutDAO.save(itemOut);
counter++;
if (counter % 100 == 0) {
UserTransactionUtility.endUserTransaction(utx, true);
utx = UserTransactionUtility.beginUserTransaction();
log.write("9999", "GnpDwhe2eSaldinettiOut Processed " + counter + " records, flushed and cleared session.");
}
}
UserTransactionUtility.endUserTransaction(utx, true);
log.write("9999", "Fine salvataggio");
@@ -587,7 +621,7 @@ public class Dwhe2eRepoSaldiNettiIn extends InternalSenderProcess implements Log
closeFile(true);
//aggiorno flag_elaborato a "Y"
saldinettiOutDAO.updateFlagElaborato(nomeFileOut, "Y");
saldinettiOutDAO.updateFlagElaborato(nomeFileOut, "Y");
} catch (Exception ex) {
log.write("0003", "ERRORE NEL RECUPERO DEI DATI PER DWHE2E_REPOSALDINETTI E2E " + ex.toString());