Migliorie su EXCHANGE
This commit is contained in:
@@ -96,7 +96,6 @@ public class ExchangeColliImportService {
|
|||||||
AtomicInteger importedCounter = new AtomicInteger(0);
|
AtomicInteger importedCounter = new AtomicInteger(0);
|
||||||
|
|
||||||
LocalDate startDate = LocalDate.of(2024, 7, 1);
|
LocalDate startDate = LocalDate.of(2024, 7, 1);
|
||||||
|
|
||||||
Result<Object> firstErrorObjectIfPresent = null;
|
Result<Object> firstErrorObjectIfPresent = null;
|
||||||
|
|
||||||
while (startDate.isBefore(UtilityLocalDate.getNow())) {
|
while (startDate.isBefore(UtilityLocalDate.getNow())) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package it.integry.ems.system.exchange.service;
|
package it.integry.ems.system.exchange.service;
|
||||||
|
|
||||||
import it.integry.ems.expansion.RunnableThrowable;
|
import it.integry.ems.dto.Result;
|
||||||
import it.integry.ems.javabeans.RequestDataDTO;
|
import it.integry.ems.javabeans.RequestDataDTO;
|
||||||
import it.integry.ems.service.EntityProcessor;
|
import it.integry.ems.service.EntityProcessor;
|
||||||
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
|
||||||
@@ -9,7 +9,6 @@ import it.integry.ems_model.entity.DtbDocr;
|
|||||||
import it.integry.ems_model.entity.DtbDoct;
|
import it.integry.ems_model.entity.DtbDoct;
|
||||||
import it.integry.ems_model.types.OperationType;
|
import it.integry.ems_model.types.OperationType;
|
||||||
import it.integry.ems_model.utility.Query;
|
import it.integry.ems_model.utility.Query;
|
||||||
import it.integry.ems_model.utility.UtilityDB;
|
|
||||||
import it.integry.ems_model.utility.UtilityLocalDate;
|
import it.integry.ems_model.utility.UtilityLocalDate;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -46,34 +45,49 @@ public class ExchangeDocumentImportService {
|
|||||||
public void importTestateDocumentiLavorazione(MultiDBTransactionManager internalMultiDb, MultiDBTransactionManager exchangeMultiDb, RequestDataDTO requestDataDTO) throws Exception {
|
public void importTestateDocumentiLavorazione(MultiDBTransactionManager internalMultiDb, MultiDBTransactionManager exchangeMultiDb, RequestDataDTO requestDataDTO) throws Exception {
|
||||||
|
|
||||||
boolean useTempTable = true;
|
boolean useTempTable = true;
|
||||||
|
ExchangeImportSchemaManagerService.SchemaType schemaType = ExchangeImportSchemaManagerService.SchemaType.DocumentiLavorazione;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exchangeImportSchemaManagerService.syncSchema(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.DocumentiLavorazione, useTempTable);
|
exchangeImportSchemaManagerService.syncSchema(exchangeMultiDb.getPrimaryConnection(), schemaType, useTempTable);
|
||||||
|
exchangeImportDataManagerService.prepareData(exchangeMultiDb.getPrimaryConnection(), useTempTable,
|
||||||
|
exchangeImportSchemaManagerService.getTablesBySchemaType(schemaType));
|
||||||
|
|
||||||
|
AtomicInteger dataCount = new AtomicInteger(0);
|
||||||
|
AtomicInteger importedCounter = new AtomicInteger(0);
|
||||||
|
|
||||||
|
LocalDate startDate = LocalDate.of(2024, 7, 1);
|
||||||
|
Result<DtbDoct> firstErrorObjectIfPresent = null;
|
||||||
|
|
||||||
|
while (startDate.isBefore(UtilityLocalDate.getNow())) {
|
||||||
|
|
||||||
|
final LocalDate tempStartDate = startDate;
|
||||||
|
final LocalDate tempEndDate = startDate;
|
||||||
|
|
||||||
|
startDate = startDate.plusDays(1);
|
||||||
|
|
||||||
final List<DtbDoct> exchangeImportedTestateData = importTestateDocumentiLavorazione(
|
final List<DtbDoct> exchangeImportedTestateData = importTestateDocumentiLavorazione(
|
||||||
exchangeMultiDb.getPrimaryConnection(),
|
exchangeMultiDb.getPrimaryConnection(),
|
||||||
UtilityLocalDate.getNow().minusMonths(1),
|
tempStartDate,
|
||||||
UtilityLocalDate.getNow(),
|
tempEndDate,
|
||||||
true, false);
|
true, false);
|
||||||
|
|
||||||
final List<DtbDoct> exchangeUpdatedTestateData = importTestateDocumentiLavorazione(
|
final List<DtbDoct> exchangeUpdatedTestateData = importTestateDocumentiLavorazione(
|
||||||
exchangeMultiDb.getPrimaryConnection(),
|
exchangeMultiDb.getPrimaryConnection(),
|
||||||
UtilityLocalDate.getNow().minusMonths(1),
|
tempStartDate,
|
||||||
UtilityLocalDate.getNow(),
|
tempEndDate,
|
||||||
false, useTempTable);
|
false, useTempTable);
|
||||||
|
|
||||||
|
|
||||||
final List<DtbDocr> exchangeImportedRigheData = importRigheDocumentiLavorazione(
|
final List<DtbDocr> exchangeImportedRigheData = importRigheDocumentiLavorazione(
|
||||||
exchangeMultiDb.getPrimaryConnection(),
|
exchangeMultiDb.getPrimaryConnection(),
|
||||||
UtilityLocalDate.getNow().minusMonths(1),
|
tempStartDate,
|
||||||
UtilityLocalDate.getNow(),
|
tempEndDate,
|
||||||
true, false);
|
true, false);
|
||||||
|
|
||||||
final List<DtbDocr> exchangeUpdatedRigheData = importRigheDocumentiLavorazione(
|
final List<DtbDocr> exchangeUpdatedRigheData = importRigheDocumentiLavorazione(
|
||||||
exchangeMultiDb.getPrimaryConnection(),
|
exchangeMultiDb.getPrimaryConnection(),
|
||||||
UtilityLocalDate.getNow().minusMonths(1),
|
tempStartDate,
|
||||||
UtilityLocalDate.getNow(),
|
tempEndDate,
|
||||||
false, useTempTable);
|
false, useTempTable);
|
||||||
|
|
||||||
List<EquatableEntityInterface> allTestateData = exchangeImportDataManagerService
|
List<EquatableEntityInterface> allTestateData = exchangeImportDataManagerService
|
||||||
@@ -84,9 +98,6 @@ public class ExchangeDocumentImportService {
|
|||||||
|
|
||||||
allTestateData.parallelStream().forEach(x -> {
|
allTestateData.parallelStream().forEach(x -> {
|
||||||
((DtbDoct) x).setUpdProgMaga(false);
|
((DtbDoct) x).setUpdProgMaga(false);
|
||||||
// .setOperation(x.getOperation() == OperationType.INSERT ? OperationType.INSERT_OR_UPDATE : x.getOperation());
|
|
||||||
// ((DtbDoct) x).getDtbDocr().parallelStream().forEach(y -> y.setOperation(y.getOperation() == OperationType.INSERT ? OperationType.INSERT_OR_UPDATE : y.getOperation()));
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
allRigheData.stream()
|
allRigheData.stream()
|
||||||
@@ -130,19 +141,13 @@ public class ExchangeDocumentImportService {
|
|||||||
Objects.equals(x.getSerDoc(), y.getSerDoc())))
|
Objects.equals(x.getSerDoc(), y.getSerDoc())))
|
||||||
.collect(Collectors.toList())));
|
.collect(Collectors.toList())));
|
||||||
|
|
||||||
List<EquatableEntityInterface> allData = allTestateData;
|
dataCount.addAndGet(allTestateData.size());
|
||||||
|
|
||||||
final Exception[] firstExceptionToThrow = {null};
|
|
||||||
|
|
||||||
AtomicInteger importedCounter = new AtomicInteger();
|
|
||||||
List<RunnableThrowable> calls = new ArrayList<>();
|
|
||||||
|
|
||||||
|
|
||||||
for (EquatableEntityInterface dataToSave : allData) {
|
for (EquatableEntityInterface dataToSave : allTestateData) {
|
||||||
|
|
||||||
DtbDoct document = (DtbDoct) dataToSave;
|
DtbDoct document = (DtbDoct) dataToSave;
|
||||||
// calls.add(() -> {
|
|
||||||
logger.debug("Importati {} documenti di {}", importedCounter.incrementAndGet(), allData.size());
|
logger.debug("Importati {} documenti di {}", importedCounter.incrementAndGet(), dataCount.get());
|
||||||
try {
|
try {
|
||||||
//Inserisco prima la testata perché se inserisco testata+righe e la testata ha INSERT,
|
//Inserisco prima la testata perché se inserisco testata+righe e la testata ha INSERT,
|
||||||
// le righe vengono salvate con ID riga calcolato e non con ID riga passato
|
// le righe vengono salvate con ID riga calcolato e non con ID riga passato
|
||||||
@@ -160,7 +165,7 @@ public class ExchangeDocumentImportService {
|
|||||||
internalMultiDb.commitAll();
|
internalMultiDb.commitAll();
|
||||||
exchangeMultiDb.commitAll();
|
exchangeMultiDb.commitAll();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
|
if (firstErrorObjectIfPresent == null) firstErrorObjectIfPresent = new Result.Error<>(ex);
|
||||||
|
|
||||||
logger.error("Errore durante l'importazione del documento [" +
|
logger.error("Errore durante l'importazione del documento [" +
|
||||||
"num: " + document.getNumDoc() + ", " +
|
"num: " + document.getNumDoc() + ", " +
|
||||||
@@ -168,19 +173,19 @@ public class ExchangeDocumentImportService {
|
|||||||
"data: " + document.getDataDoc() + ", " +
|
"data: " + document.getDataDoc() + ", " +
|
||||||
"cod anag: " + document.getCodAnag() + ", " +
|
"cod anag: " + document.getCodAnag() + ", " +
|
||||||
"cod dtip: " + document.getCodDtip() + "]", ex);
|
"cod dtip: " + document.getCodDtip() + "]", ex);
|
||||||
//multiDBTransactionManager.rollbackAll();
|
|
||||||
//throw ex;
|
internalMultiDb.rollbackAll();
|
||||||
|
exchangeMultiDb.rollbackAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
// });
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// UtilityThread.executeParallel(calls);
|
|
||||||
|
|
||||||
|
if (firstErrorObjectIfPresent != null) throw ((Result.Error) firstErrorObjectIfPresent).getError();
|
||||||
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
|
|
||||||
} finally {
|
} finally {
|
||||||
if (useTempTable)
|
if (useTempTable)
|
||||||
exchangeImportSchemaManagerService.deleteTempTables(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.DocumentiLavorazione);
|
exchangeImportSchemaManagerService.deleteTempTables(exchangeMultiDb.getPrimaryConnection(), schemaType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,13 +196,6 @@ public class ExchangeDocumentImportService {
|
|||||||
String dtbDoctLavOriginalName = "dtb_doct_lav";
|
String dtbDoctLavOriginalName = "dtb_doct_lav";
|
||||||
String dtbDoctLavTableName = dtbDoctLavOriginalName + (useTempTable ? "_tmp" : "");
|
String dtbDoctLavTableName = dtbDoctLavOriginalName + (useTempTable ? "_tmp" : "");
|
||||||
|
|
||||||
if (useTempTable) {
|
|
||||||
UtilityDB.executeStatement(connection,
|
|
||||||
"INSERT INTO " + dtbDoctLavTableName +
|
|
||||||
" SELECT * FROM " + dtbDoctLavOriginalName
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
final List<DtbDoct> dtbDoctLav = exchangeImportDataManagerService.retrieveDataFromExchange(connection, DtbDoct.class,
|
final List<DtbDoct> dtbDoctLav = exchangeImportDataManagerService.retrieveDataFromExchange(connection, DtbDoct.class,
|
||||||
dtbDoctLavTableName, Query.format("data_doc BETWEEN {} AND {}", minDate, maxDate), retrieveAlreadyImported);
|
dtbDoctLavTableName, Query.format("data_doc BETWEEN {} AND {}", minDate, maxDate), retrieveAlreadyImported);
|
||||||
|
|
||||||
@@ -216,16 +214,8 @@ public class ExchangeDocumentImportService {
|
|||||||
LocalDate minDate, LocalDate maxDate, boolean retrieveAlreadyImported, boolean useTempTable) throws Exception {
|
LocalDate minDate, LocalDate maxDate, boolean retrieveAlreadyImported, boolean useTempTable) throws Exception {
|
||||||
|
|
||||||
String dtbDocrLavOriginalName = "dtb_docr_lav";
|
String dtbDocrLavOriginalName = "dtb_docr_lav";
|
||||||
|
|
||||||
String dtbDocrLavTableName = dtbDocrLavOriginalName + (useTempTable ? "_tmp" : "");
|
String dtbDocrLavTableName = dtbDocrLavOriginalName + (useTempTable ? "_tmp" : "");
|
||||||
|
|
||||||
if (useTempTable) {
|
|
||||||
UtilityDB.executeStatement(connection,
|
|
||||||
"INSERT INTO " + dtbDocrLavTableName +
|
|
||||||
" SELECT * FROM " + dtbDocrLavOriginalName
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return exchangeImportDataManagerService.retrieveDataFromExchange(connection, DtbDocr.class,
|
return exchangeImportDataManagerService.retrieveDataFromExchange(connection, DtbDocr.class,
|
||||||
dtbDocrLavTableName, Query.format("data_doc BETWEEN {} AND {}", minDate, maxDate), retrieveAlreadyImported);
|
dtbDocrLavTableName, Query.format("data_doc BETWEEN {} AND {}", minDate, maxDate), retrieveAlreadyImported);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package it.integry.ems.system.exchange.service;
|
package it.integry.ems.system.exchange.service;
|
||||||
|
|
||||||
|
import it.integry.ems.dto.Result;
|
||||||
import it.integry.ems.javabeans.RequestDataDTO;
|
import it.integry.ems.javabeans.RequestDataDTO;
|
||||||
import it.integry.ems.production.agribook.AgribookFieldService;
|
import it.integry.ems.production.agribook.AgribookFieldService;
|
||||||
import it.integry.ems.production.agribook.model.AgribookNewFieldRequestDTO;
|
import it.integry.ems.production.agribook.model.AgribookNewFieldRequestDTO;
|
||||||
@@ -62,20 +63,36 @@ public class ExchangeOrdiniImportService {
|
|||||||
exchangeImportDataManagerService.prepareData(exchangeMultiDb.getPrimaryConnection(), useTempTable,
|
exchangeImportDataManagerService.prepareData(exchangeMultiDb.getPrimaryConnection(), useTempTable,
|
||||||
exchangeImportSchemaManagerService.getTablesBySchemaType(schemaType));
|
exchangeImportSchemaManagerService.getTablesBySchemaType(schemaType));
|
||||||
|
|
||||||
|
AtomicInteger dataCount = new AtomicInteger(0);
|
||||||
|
AtomicInteger importedCounter = new AtomicInteger(0);
|
||||||
|
|
||||||
|
LocalDate startDate = LocalDate.of(2024, 7, 1);
|
||||||
|
|
||||||
|
Result<DtbOrdt> firstErrorObjectIfPresent = null;
|
||||||
|
|
||||||
|
|
||||||
|
while (startDate.isBefore(UtilityLocalDate.getNow())) {
|
||||||
|
|
||||||
|
final LocalDate tempStartDate = startDate;
|
||||||
|
final LocalDate tempEndDate = startDate;
|
||||||
|
|
||||||
|
startDate = startDate.plusDays(1);
|
||||||
|
|
||||||
final List<DtbOrdt> exchangeImportedMtbColts = importOrdiniLavorazione(
|
final List<DtbOrdt> exchangeImportedMtbColts = importOrdiniLavorazione(
|
||||||
exchangeMultiDb.getPrimaryConnection(),
|
exchangeMultiDb.getPrimaryConnection(),
|
||||||
UtilityLocalDate.getNow().minusMonths(1),
|
tempStartDate,
|
||||||
UtilityLocalDate.getNow(),
|
tempEndDate,
|
||||||
true, false);
|
true, false);
|
||||||
|
|
||||||
final List<DtbOrdt> exchangeUpdatedMtbColts = importOrdiniLavorazione(
|
final List<DtbOrdt> exchangeUpdatedMtbColts = importOrdiniLavorazione(
|
||||||
exchangeMultiDb.getPrimaryConnection(),
|
exchangeMultiDb.getPrimaryConnection(),
|
||||||
UtilityLocalDate.getNow().minusMonths(1),
|
tempStartDate,
|
||||||
UtilityLocalDate.getNow(),
|
tempEndDate,
|
||||||
false, useTempTable);
|
false, useTempTable);
|
||||||
|
|
||||||
List<EquatableEntityInterface> allData = exchangeImportDataManagerService
|
List<EquatableEntityInterface> allData = exchangeImportDataManagerService
|
||||||
.runSync(DtbOrdt.class, exchangeImportedMtbColts, exchangeUpdatedMtbColts);
|
.runSync(DtbOrdt.class, exchangeImportedMtbColts, exchangeUpdatedMtbColts);
|
||||||
|
dataCount.addAndGet(allData.size());
|
||||||
|
|
||||||
allData.stream()
|
allData.stream()
|
||||||
.map(x -> (DtbOrdt) x)
|
.map(x -> (DtbOrdt) x)
|
||||||
@@ -98,14 +115,12 @@ public class ExchangeOrdiniImportService {
|
|||||||
allData.stream().filter(x -> !((DtbOrdt) x).getGestione().equalsIgnoreCase("A")).collect(Collectors.toList())
|
allData.stream().filter(x -> !((DtbOrdt) x).getGestione().equalsIgnoreCase("A")).collect(Collectors.toList())
|
||||||
);
|
);
|
||||||
|
|
||||||
final Exception[] firstExceptionToThrow = {null};
|
|
||||||
final AtomicInteger importedCounter = new AtomicInteger();
|
|
||||||
|
|
||||||
for (List<EquatableEntityInterface> listToProcess : splittedOrders) {
|
for (List<EquatableEntityInterface> listToProcess : splittedOrders) {
|
||||||
|
|
||||||
for (EquatableEntityInterface dataToSave : listToProcess) {
|
for (EquatableEntityInterface dataToSave : listToProcess) {
|
||||||
|
|
||||||
logger.debug("Importati {} ordini di {}", importedCounter.incrementAndGet(), allData.size());
|
logger.debug("Importati {} ordini di {}", importedCounter.incrementAndGet(), dataCount.get());
|
||||||
try {
|
try {
|
||||||
entityProcessor.processEntity(dataToSave, true, true, ROSSOGARGANO_EXCHANGE_USER, internalMultiDb, requestDataDTO);
|
entityProcessor.processEntity(dataToSave, true, true, ROSSOGARGANO_EXCHANGE_USER, internalMultiDb, requestDataDTO);
|
||||||
|
|
||||||
@@ -113,7 +128,7 @@ public class ExchangeOrdiniImportService {
|
|||||||
internalMultiDb.commitAll();
|
internalMultiDb.commitAll();
|
||||||
exchangeMultiDb.commitAll();
|
exchangeMultiDb.commitAll();
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
|
if (firstErrorObjectIfPresent == null) firstErrorObjectIfPresent = new Result.Error<>(ex);
|
||||||
|
|
||||||
DtbOrdt order = (DtbOrdt) dataToSave;
|
DtbOrdt order = (DtbOrdt) dataToSave;
|
||||||
|
|
||||||
@@ -127,8 +142,8 @@ public class ExchangeOrdiniImportService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
|
if (firstErrorObjectIfPresent != null) throw ((Result.Error) firstErrorObjectIfPresent).getError();
|
||||||
} finally {
|
} finally {
|
||||||
if (useTempTable)
|
if (useTempTable)
|
||||||
exchangeImportSchemaManagerService.deleteTempTables(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.OrdiniLavorazione);
|
exchangeImportSchemaManagerService.deleteTempTables(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.OrdiniLavorazione);
|
||||||
|
|||||||
Reference in New Issue
Block a user