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,141 +45,147 @@ 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));
|
||||||
|
|
||||||
final List<DtbDoct> exchangeImportedTestateData = importTestateDocumentiLavorazione(
|
AtomicInteger dataCount = new AtomicInteger(0);
|
||||||
exchangeMultiDb.getPrimaryConnection(),
|
AtomicInteger importedCounter = new AtomicInteger(0);
|
||||||
UtilityLocalDate.getNow().minusMonths(1),
|
|
||||||
UtilityLocalDate.getNow(),
|
|
||||||
true, false);
|
|
||||||
|
|
||||||
final List<DtbDoct> exchangeUpdatedTestateData = importTestateDocumentiLavorazione(
|
LocalDate startDate = LocalDate.of(2024, 7, 1);
|
||||||
exchangeMultiDb.getPrimaryConnection(),
|
Result<DtbDoct> firstErrorObjectIfPresent = null;
|
||||||
UtilityLocalDate.getNow().minusMonths(1),
|
|
||||||
UtilityLocalDate.getNow(),
|
while (startDate.isBefore(UtilityLocalDate.getNow())) {
|
||||||
false, useTempTable);
|
|
||||||
|
final LocalDate tempStartDate = startDate;
|
||||||
|
final LocalDate tempEndDate = startDate;
|
||||||
|
|
||||||
|
startDate = startDate.plusDays(1);
|
||||||
|
|
||||||
|
final List<DtbDoct> exchangeImportedTestateData = importTestateDocumentiLavorazione(
|
||||||
|
exchangeMultiDb.getPrimaryConnection(),
|
||||||
|
tempStartDate,
|
||||||
|
tempEndDate,
|
||||||
|
true, false);
|
||||||
|
|
||||||
|
final List<DtbDoct> exchangeUpdatedTestateData = importTestateDocumentiLavorazione(
|
||||||
|
exchangeMultiDb.getPrimaryConnection(),
|
||||||
|
tempStartDate,
|
||||||
|
tempEndDate,
|
||||||
|
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
|
||||||
.runSync(DtbDoct.class, exchangeImportedTestateData, exchangeUpdatedTestateData);
|
.runSync(DtbDoct.class, exchangeImportedTestateData, exchangeUpdatedTestateData);
|
||||||
|
|
||||||
List<EquatableEntityInterface> allRigheData = exchangeImportDataManagerService
|
List<EquatableEntityInterface> allRigheData = exchangeImportDataManagerService
|
||||||
.runSync(DtbDocr.class, exchangeImportedRigheData, exchangeUpdatedRigheData);
|
.runSync(DtbDocr.class, exchangeImportedRigheData, exchangeUpdatedRigheData);
|
||||||
|
|
||||||
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()
|
||||||
|
.map(x -> (DtbDocr) x)
|
||||||
|
.filter(x -> allTestateData.stream()
|
||||||
|
.map(y -> (DtbDoct) y)
|
||||||
|
.noneMatch(y -> Objects.hash(x.getDataDoc(), x.getNumDoc(), x.getSerDoc(), x.getCodAnag(), x.getCodDtip()) ==
|
||||||
|
Objects.hash(y.getDataDoc(), y.getNumDoc(), y.getSerDoc(), y.getCodAnag(), y.getCodDtip()) &&
|
||||||
|
|
||||||
allRigheData.stream()
|
(Objects.equals(x.getCodAnag(), y.getCodAnag()) &&
|
||||||
.map(x -> (DtbDocr) x)
|
Objects.equals(x.getCodDtip(), y.getCodDtip()) &&
|
||||||
.filter(x -> allTestateData.stream()
|
Objects.equals(x.getDataDoc(), y.getDataDoc()) &&
|
||||||
.map(y -> (DtbDoct) y)
|
Objects.equals(x.getNumDoc(), y.getNumDoc()) &&
|
||||||
.noneMatch(y -> Objects.hash(x.getDataDoc(), x.getNumDoc(), x.getSerDoc(), x.getCodAnag(), x.getCodDtip()) ==
|
Objects.equals(x.getSerDoc(), y.getSerDoc()))))
|
||||||
Objects.hash(y.getDataDoc(), y.getNumDoc(), y.getSerDoc(), y.getCodAnag(), y.getCodDtip()) &&
|
.forEach(x -> {
|
||||||
|
DtbDoct testata = new DtbDoct()
|
||||||
|
.setSerDoc(x.getSerDoc())
|
||||||
|
.setDataDoc(x.getDataDoc())
|
||||||
|
.setNumDoc(x.getNumDoc())
|
||||||
|
.setCodDtip(x.getCodDtip())
|
||||||
|
.setCodAnag(x.getCodAnag())
|
||||||
|
.setUpdProgMaga(false);
|
||||||
|
|
||||||
(Objects.equals(x.getCodAnag(), y.getCodAnag()) &&
|
testata.setOperation(OperationType.UPDATE);
|
||||||
Objects.equals(x.getCodDtip(), y.getCodDtip()) &&
|
allTestateData.add(testata);
|
||||||
Objects.equals(x.getDataDoc(), y.getDataDoc()) &&
|
});
|
||||||
Objects.equals(x.getNumDoc(), y.getNumDoc()) &&
|
|
||||||
Objects.equals(x.getSerDoc(), y.getSerDoc()))))
|
|
||||||
.forEach(x -> {
|
|
||||||
DtbDoct testata = new DtbDoct()
|
|
||||||
.setSerDoc(x.getSerDoc())
|
|
||||||
.setDataDoc(x.getDataDoc())
|
|
||||||
.setNumDoc(x.getNumDoc())
|
|
||||||
.setCodDtip(x.getCodDtip())
|
|
||||||
.setCodAnag(x.getCodAnag())
|
|
||||||
.setUpdProgMaga(false);
|
|
||||||
|
|
||||||
testata.setOperation(OperationType.UPDATE);
|
allTestateData.parallelStream()
|
||||||
allTestateData.add(testata);
|
.map(x -> (DtbDoct) x)
|
||||||
});
|
.forEach(x ->
|
||||||
|
x.setDtbDocr(allRigheData.stream()
|
||||||
|
.map(y -> (DtbDocr) y)
|
||||||
|
.filter(y ->
|
||||||
|
Objects.hash(x.getDataDoc(), x.getNumDoc(), x.getSerDoc(), x.getCodAnag(), x.getCodDtip()) ==
|
||||||
|
Objects.hash(y.getDataDoc(), y.getNumDoc(), y.getSerDoc(), y.getCodAnag(), y.getCodDtip()) &&
|
||||||
|
|
||||||
allTestateData.parallelStream()
|
(Objects.equals(x.getCodAnag(), y.getCodAnag()) &&
|
||||||
.map(x -> (DtbDoct) x)
|
Objects.equals(x.getCodDtip(), y.getCodDtip()) &&
|
||||||
.forEach(x ->
|
Objects.equals(x.getDataDoc(), y.getDataDoc()) &&
|
||||||
x.setDtbDocr(allRigheData.stream()
|
Objects.equals(x.getNumDoc(), y.getNumDoc()) &&
|
||||||
.map(y -> (DtbDocr) y)
|
Objects.equals(x.getSerDoc(), y.getSerDoc())))
|
||||||
.filter(y ->
|
.collect(Collectors.toList())));
|
||||||
Objects.hash(x.getDataDoc(), x.getNumDoc(), x.getSerDoc(), x.getCodAnag(), x.getCodDtip()) ==
|
|
||||||
Objects.hash(y.getDataDoc(), y.getNumDoc(), y.getSerDoc(), y.getCodAnag(), y.getCodDtip()) &&
|
|
||||||
|
|
||||||
(Objects.equals(x.getCodAnag(), y.getCodAnag()) &&
|
dataCount.addAndGet(allTestateData.size());
|
||||||
Objects.equals(x.getCodDtip(), y.getCodDtip()) &&
|
|
||||||
Objects.equals(x.getDataDoc(), y.getDataDoc()) &&
|
|
||||||
Objects.equals(x.getNumDoc(), y.getNumDoc()) &&
|
|
||||||
Objects.equals(x.getSerDoc(), y.getSerDoc())))
|
|
||||||
.collect(Collectors.toList())));
|
|
||||||
|
|
||||||
List<EquatableEntityInterface> allData = allTestateData;
|
|
||||||
|
|
||||||
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;
|
logger.debug("Importati {} documenti di {}", importedCounter.incrementAndGet(), dataCount.get());
|
||||||
// calls.add(() -> {
|
try {
|
||||||
logger.debug("Importati {} documenti di {}", importedCounter.incrementAndGet(), allData.size());
|
//Inserisco prima la testata perché se inserisco testata+righe e la testata ha INSERT,
|
||||||
try {
|
// le righe vengono salvate con ID riga calcolato e non con ID riga passato
|
||||||
//Inserisco prima la testata perché se inserisco testata+righe e la testata ha INSERT,
|
DtbDoct cloneDocument = (DtbDoct) document.clone();
|
||||||
// le righe vengono salvate con ID riga calcolato e non con ID riga passato
|
cloneDocument.setDtbDocr(new ArrayList<>());
|
||||||
DtbDoct cloneDocument = (DtbDoct) document.clone();
|
entityProcessor.processEntity(cloneDocument, true, true, ROSSOGARGANO_EXCHANGE_USER, internalMultiDb, requestDataDTO);
|
||||||
cloneDocument.setDtbDocr(new ArrayList<>());
|
singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), (DtbDoct) dataToSave, useTempTable);
|
||||||
entityProcessor.processEntity(cloneDocument, true, true, ROSSOGARGANO_EXCHANGE_USER, internalMultiDb, requestDataDTO);
|
|
||||||
singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), (DtbDoct) dataToSave, useTempTable);
|
|
||||||
|
|
||||||
if (!document.getDtbDocr().isEmpty()) {
|
if (!document.getDtbDocr().isEmpty()) {
|
||||||
document.setOperation(OperationType.NO_OP);
|
document.setOperation(OperationType.NO_OP);
|
||||||
entityProcessor.processEntity(document, true, true, ROSSOGARGANO_EXCHANGE_USER, internalMultiDb, requestDataDTO);
|
entityProcessor.processEntity(document, true, true, ROSSOGARGANO_EXCHANGE_USER, internalMultiDb, requestDataDTO);
|
||||||
singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), document.getDtbDocr(), useTempTable);
|
singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), document.getDtbDocr(), useTempTable);
|
||||||
|
}
|
||||||
|
|
||||||
|
internalMultiDb.commitAll();
|
||||||
|
exchangeMultiDb.commitAll();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (firstErrorObjectIfPresent == null) firstErrorObjectIfPresent = new Result.Error<>(ex);
|
||||||
|
|
||||||
|
logger.error("Errore durante l'importazione del documento [" +
|
||||||
|
"num: " + document.getNumDoc() + ", " +
|
||||||
|
"serie: " + document.getSerDoc() + ", " +
|
||||||
|
"data: " + document.getDataDoc() + ", " +
|
||||||
|
"cod anag: " + document.getCodAnag() + ", " +
|
||||||
|
"cod dtip: " + document.getCodDtip() + "]", ex);
|
||||||
|
|
||||||
|
internalMultiDb.rollbackAll();
|
||||||
|
exchangeMultiDb.rollbackAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
internalMultiDb.commitAll();
|
|
||||||
exchangeMultiDb.commitAll();
|
|
||||||
} catch (Exception ex) {
|
|
||||||
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
|
|
||||||
|
|
||||||
logger.error("Errore durante l'importazione del documento [" +
|
|
||||||
"num: " + document.getNumDoc() + ", " +
|
|
||||||
"serie: " + document.getSerDoc() + ", " +
|
|
||||||
"data: " + document.getDataDoc() + ", " +
|
|
||||||
"cod anag: " + document.getCodAnag() + ", " +
|
|
||||||
"cod dtip: " + document.getCodDtip() + "]", ex);
|
|
||||||
//multiDBTransactionManager.rollbackAll();
|
|
||||||
//throw ex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
// 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,73 +63,87 @@ public class ExchangeOrdiniImportService {
|
|||||||
exchangeImportDataManagerService.prepareData(exchangeMultiDb.getPrimaryConnection(), useTempTable,
|
exchangeImportDataManagerService.prepareData(exchangeMultiDb.getPrimaryConnection(), useTempTable,
|
||||||
exchangeImportSchemaManagerService.getTablesBySchemaType(schemaType));
|
exchangeImportSchemaManagerService.getTablesBySchemaType(schemaType));
|
||||||
|
|
||||||
final List<DtbOrdt> exchangeImportedMtbColts = importOrdiniLavorazione(
|
AtomicInteger dataCount = new AtomicInteger(0);
|
||||||
exchangeMultiDb.getPrimaryConnection(),
|
AtomicInteger importedCounter = new AtomicInteger(0);
|
||||||
UtilityLocalDate.getNow().minusMonths(1),
|
|
||||||
UtilityLocalDate.getNow(),
|
|
||||||
true, false);
|
|
||||||
|
|
||||||
final List<DtbOrdt> exchangeUpdatedMtbColts = importOrdiniLavorazione(
|
LocalDate startDate = LocalDate.of(2024, 7, 1);
|
||||||
exchangeMultiDb.getPrimaryConnection(),
|
|
||||||
UtilityLocalDate.getNow().minusMonths(1),
|
|
||||||
UtilityLocalDate.getNow(),
|
|
||||||
false, useTempTable);
|
|
||||||
|
|
||||||
List<EquatableEntityInterface> allData = exchangeImportDataManagerService
|
Result<DtbOrdt> firstErrorObjectIfPresent = null;
|
||||||
.runSync(DtbOrdt.class, exchangeImportedMtbColts, exchangeUpdatedMtbColts);
|
|
||||||
|
|
||||||
allData.stream()
|
|
||||||
.map(x -> (DtbOrdt) x)
|
|
||||||
.filter(x -> x.getGestione().equalsIgnoreCase("L") &&
|
|
||||||
(x.getOperation() == OperationType.INSERT_OR_UPDATE || x.getOperation() == OperationType.INSERT))
|
|
||||||
.forEach(x -> {
|
|
||||||
DtbOrdSteps ordStep =
|
|
||||||
new DtbOrdSteps()
|
|
||||||
.setIdRiga(0)
|
|
||||||
.setCodJfas(x.getCodJfas())
|
|
||||||
.setQtaProd(x.getQtaProd());
|
|
||||||
|
|
||||||
ordStep.setOperation(OperationType.INSERT_OR_UPDATE);
|
while (startDate.isBefore(UtilityLocalDate.getNow())) {
|
||||||
x.getDtbOrdSteps().add(ordStep);
|
|
||||||
});
|
|
||||||
|
|
||||||
List<List<EquatableEntityInterface>> splittedOrders =
|
final LocalDate tempStartDate = startDate;
|
||||||
Arrays.asList(
|
final LocalDate tempEndDate = startDate;
|
||||||
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};
|
startDate = startDate.plusDays(1);
|
||||||
final AtomicInteger importedCounter = new AtomicInteger();
|
|
||||||
|
|
||||||
for (List<EquatableEntityInterface> listToProcess : splittedOrders) {
|
final List<DtbOrdt> exchangeImportedMtbColts = importOrdiniLavorazione(
|
||||||
|
exchangeMultiDb.getPrimaryConnection(),
|
||||||
|
tempStartDate,
|
||||||
|
tempEndDate,
|
||||||
|
true, false);
|
||||||
|
|
||||||
for (EquatableEntityInterface dataToSave : listToProcess) {
|
final List<DtbOrdt> exchangeUpdatedMtbColts = importOrdiniLavorazione(
|
||||||
|
exchangeMultiDb.getPrimaryConnection(),
|
||||||
|
tempStartDate,
|
||||||
|
tempEndDate,
|
||||||
|
false, useTempTable);
|
||||||
|
|
||||||
logger.debug("Importati {} ordini di {}", importedCounter.incrementAndGet(), allData.size());
|
List<EquatableEntityInterface> allData = exchangeImportDataManagerService
|
||||||
try {
|
.runSync(DtbOrdt.class, exchangeImportedMtbColts, exchangeUpdatedMtbColts);
|
||||||
entityProcessor.processEntity(dataToSave, true, true, ROSSOGARGANO_EXCHANGE_USER, internalMultiDb, requestDataDTO);
|
dataCount.addAndGet(allData.size());
|
||||||
|
|
||||||
singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), (DtbOrdt) dataToSave, useTempTable);
|
allData.stream()
|
||||||
internalMultiDb.commitAll();
|
.map(x -> (DtbOrdt) x)
|
||||||
exchangeMultiDb.commitAll();
|
.filter(x -> x.getGestione().equalsIgnoreCase("L") &&
|
||||||
} catch (Exception ex) {
|
(x.getOperation() == OperationType.INSERT_OR_UPDATE || x.getOperation() == OperationType.INSERT))
|
||||||
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
|
.forEach(x -> {
|
||||||
|
DtbOrdSteps ordStep =
|
||||||
|
new DtbOrdSteps()
|
||||||
|
.setIdRiga(0)
|
||||||
|
.setCodJfas(x.getCodJfas())
|
||||||
|
.setQtaProd(x.getQtaProd());
|
||||||
|
|
||||||
DtbOrdt order = (DtbOrdt) dataToSave;
|
ordStep.setOperation(OperationType.INSERT_OR_UPDATE);
|
||||||
|
x.getDtbOrdSteps().add(ordStep);
|
||||||
|
});
|
||||||
|
|
||||||
logger.error("Errore durante l'importazione dell'ordine [num: " + order.getNumOrd() + "," +
|
List<List<EquatableEntityInterface>> splittedOrders =
|
||||||
"data: " + order.getDataOrd() + "," +
|
Arrays.asList(
|
||||||
"gestione: " + order.getGestione() + "]", ex);
|
allData.stream().filter(x -> ((DtbOrdt) x).getGestione().equalsIgnoreCase("A")).collect(Collectors.toList()),
|
||||||
|
allData.stream().filter(x -> !((DtbOrdt) x).getGestione().equalsIgnoreCase("A")).collect(Collectors.toList())
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
for (List<EquatableEntityInterface> listToProcess : splittedOrders) {
|
||||||
|
|
||||||
|
for (EquatableEntityInterface dataToSave : listToProcess) {
|
||||||
|
|
||||||
|
logger.debug("Importati {} ordini di {}", importedCounter.incrementAndGet(), dataCount.get());
|
||||||
|
try {
|
||||||
|
entityProcessor.processEntity(dataToSave, true, true, ROSSOGARGANO_EXCHANGE_USER, internalMultiDb, requestDataDTO);
|
||||||
|
|
||||||
|
singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), (DtbOrdt) dataToSave, useTempTable);
|
||||||
|
internalMultiDb.commitAll();
|
||||||
|
exchangeMultiDb.commitAll();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
if (firstErrorObjectIfPresent == null) firstErrorObjectIfPresent = new Result.Error<>(ex);
|
||||||
|
|
||||||
|
DtbOrdt order = (DtbOrdt) dataToSave;
|
||||||
|
|
||||||
|
logger.error("Errore durante l'importazione dell'ordine [num: " + order.getNumOrd() + "," +
|
||||||
|
"data: " + order.getDataOrd() + "," +
|
||||||
|
"gestione: " + order.getGestione() + "]", ex);
|
||||||
|
|
||||||
|
internalMultiDb.rollbackAll();
|
||||||
|
exchangeMultiDb.rollbackAll();
|
||||||
|
}
|
||||||
|
|
||||||
internalMultiDb.rollbackAll();
|
|
||||||
exchangeMultiDb.rollbackAll();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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.OrdiniLavorazione);
|
exchangeImportSchemaManagerService.deleteTempTables(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.OrdiniLavorazione);
|
||||||
|
|||||||
Reference in New Issue
Block a user