Migliorato exchange clienti
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
This commit is contained in:
@@ -178,7 +178,6 @@ public class AnagRules extends QueryRules {
|
||||
precode = setupGest.getSetup(connection, "GTB_ANAG", "SETUP", keySection);
|
||||
}
|
||||
String sql = "SELECT dbo.f_suggestCodeCodAnag(" + UtilityDB.valueToString(precode) + ")";
|
||||
logger.info("SUGGEST_COD_ANAG " + sql);
|
||||
return UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(connection, sql);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,10 @@ import it.integry.ems_model.base.EquatableEntityInterface;
|
||||
import it.integry.ems_model.entity.GtbAnag;
|
||||
import it.integry.ems_model.entity.VtbClie;
|
||||
import it.integry.ems_model.exception.EntityException;
|
||||
import it.integry.ems_model.service.SetupGest;
|
||||
import it.integry.ems_model.types.OperationType;
|
||||
import it.integry.ems_model.utility.UtilityDB;
|
||||
import it.integry.ems_model.utility.UtilityQuery;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -20,6 +23,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class ExchangeClientiImportService {
|
||||
@@ -39,71 +43,85 @@ public class ExchangeClientiImportService {
|
||||
@Autowired
|
||||
private ExchangeImportDataManagerService exchangeImportDataManagerService;
|
||||
|
||||
@Autowired
|
||||
private SetupGest setupGest;
|
||||
|
||||
|
||||
public void importClienti(MultiDBTransactionManager internalMultiDb, MultiDBTransactionManager exchangeMultiDb, RequestDataDTO requestDataDTO) throws Exception {
|
||||
boolean useTempTable = true;
|
||||
ExchangeImportSchemaManagerService.SchemaType schemaType = ExchangeImportSchemaManagerService.SchemaType.Clienti;
|
||||
|
||||
try {
|
||||
final String precode = setupGest.getSetup(internalMultiDb.getPrimaryConnection(), "GTB_ANAG", "SETUP", "PRECODE_CLIENTI");
|
||||
|
||||
exchangeImportSchemaManagerService.syncSchema(exchangeMultiDb.getPrimaryConnection(), schemaType, useTempTable);
|
||||
exchangeImportDataManagerService.prepareData(exchangeMultiDb.getPrimaryConnection(), useTempTable, exchangeImportSchemaManagerService.getTablesBySchemaType(schemaType));
|
||||
|
||||
final List<GtbAnag> exchangeImportedData = retrieveClienti(
|
||||
exchangeMultiDb.getPrimaryConnection(),
|
||||
true, false);
|
||||
String sqlDistinctDiacods = "SELECT DISTINCT diacod FROM gtb_anag_clienti" + (useTempTable ? "_tmp" : "");
|
||||
List<String> diacodsToSync = UtilityDB.executeSimpleQueryOnlyFirstColumn(exchangeMultiDb.getPrimaryConnection(), sqlDistinctDiacods);
|
||||
|
||||
final List<GtbAnag> exchangeUpdatedData = retrieveClienti(
|
||||
exchangeMultiDb.getPrimaryConnection(),
|
||||
false, useTempTable);
|
||||
|
||||
List<EquatableEntityInterface> allData = exchangeImportDataManagerService
|
||||
.runSync(GtbAnag.class, exchangeImportedData, exchangeUpdatedData);
|
||||
|
||||
allData.parallelStream()
|
||||
.map(x -> (GtbAnag) x)
|
||||
.forEach(x -> {
|
||||
if (x.getOperation() == OperationType.DELETE)
|
||||
x.setOperation(OperationType.UPDATE);
|
||||
|
||||
if (x.getVtbClie() != null) {
|
||||
if (x.getVtbClie().getOperation() == OperationType.DELETE) {
|
||||
x.getVtbClie().setFlagStato("I")
|
||||
.setOperation(OperationType.UPDATE);
|
||||
x.setOperation(OperationType.UPDATE);
|
||||
} else {
|
||||
x.getVtbClie().setFlagStato("A");
|
||||
x.setOperation(x.getOperation() == OperationType.INSERT ? OperationType.INSERT_OR_UPDATE : x.getOperation());
|
||||
}
|
||||
}
|
||||
});
|
||||
AtomicInteger dataCount = new AtomicInteger(diacodsToSync.size());
|
||||
AtomicInteger importedCounter = new AtomicInteger(0);
|
||||
|
||||
final Exception[] firstExceptionToThrow = {null};
|
||||
|
||||
AtomicInteger importedCounter = new AtomicInteger();
|
||||
for (String diacod : diacodsToSync) {
|
||||
|
||||
for (EquatableEntityInterface dataToSave : allData) {
|
||||
final List<GtbAnag> exchangeImportedData = retrieveClienti(
|
||||
exchangeMultiDb.getPrimaryConnection(),
|
||||
true, false, diacod);
|
||||
|
||||
logger.debug("Importati {} clienti di {}", importedCounter.incrementAndGet(), allData.size());
|
||||
try {
|
||||
entityProcessor.processEntity(dataToSave, true, true, EXCHANGE_USER, internalMultiDb, requestDataDTO);
|
||||
final List<GtbAnag> exchangeUpdatedData = retrieveClienti(
|
||||
exchangeMultiDb.getPrimaryConnection(),
|
||||
false, useTempTable, diacod);
|
||||
|
||||
singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), (GtbAnag) dataToSave, useTempTable);
|
||||
internalMultiDb.commitAll();
|
||||
exchangeMultiDb.commitAll();
|
||||
} catch (Exception ex) {
|
||||
internalMultiDb.rollbackAll();
|
||||
exchangeMultiDb.commitAll();
|
||||
List<EquatableEntityInterface> allData = exchangeImportDataManagerService
|
||||
.runSync(GtbAnag.class, exchangeImportedData, exchangeUpdatedData);
|
||||
|
||||
GtbAnag gtbAnagError = (GtbAnag) dataToSave;
|
||||
Exception newException = new EntityException("Errore durante l'importazione del cliente [" +
|
||||
"cod_anag: " + gtbAnagError.getCodAnag() + "]", ex);
|
||||
allData.parallelStream()
|
||||
.map(x -> (GtbAnag) x)
|
||||
.forEach(x -> {
|
||||
if (x.getOperation() == OperationType.DELETE)
|
||||
x.setOperation(OperationType.UPDATE);
|
||||
|
||||
if (x.getVtbClie() != null) {
|
||||
if (x.getVtbClie().getOperation() == OperationType.DELETE) {
|
||||
x.getVtbClie().setFlagStato("I")
|
||||
.setOperation(OperationType.UPDATE);
|
||||
x.setOperation(OperationType.UPDATE);
|
||||
} else {
|
||||
x.getVtbClie().setFlagStato("A");
|
||||
x.setOperation(x.getOperation() == OperationType.INSERT ? OperationType.INSERT_OR_UPDATE : x.getOperation());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
for (EquatableEntityInterface dataToSave : allData) {
|
||||
|
||||
((GtbAnag) dataToSave).setPrecode(precode);
|
||||
|
||||
logger.debug("Importati {} clienti di {}", importedCounter.incrementAndGet(), dataCount.get());
|
||||
try {
|
||||
entityProcessor.processEntity(dataToSave, true, true, EXCHANGE_USER, internalMultiDb, requestDataDTO);
|
||||
|
||||
singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), (GtbAnag) dataToSave, useTempTable);
|
||||
internalMultiDb.commitAll();
|
||||
exchangeMultiDb.commitAll();
|
||||
} catch (Exception ex) {
|
||||
internalMultiDb.rollbackAll();
|
||||
exchangeMultiDb.commitAll();
|
||||
|
||||
GtbAnag gtbAnagError = (GtbAnag) dataToSave;
|
||||
Exception newException = new EntityException("Errore durante l'importazione del cliente [" +
|
||||
"cod_anag: " + gtbAnagError.getCodAnag() + "]", ex);
|
||||
|
||||
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = newException;
|
||||
logger.error(newException);
|
||||
}
|
||||
|
||||
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = newException;
|
||||
logger.error(newException);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
|
||||
|
||||
} finally {
|
||||
@@ -114,7 +132,7 @@ public class ExchangeClientiImportService {
|
||||
|
||||
|
||||
private List<GtbAnag> retrieveClienti(Connection connection,
|
||||
boolean retrieveAlreadyImported, boolean useTempTable) throws Exception {
|
||||
boolean retrieveAlreadyImported, boolean useTempTable, String diacod) throws Exception {
|
||||
|
||||
String testataOriginalName = "gtb_anag_clienti";
|
||||
String testataTableName = testataOriginalName + (useTempTable ? "_tmp" : "");
|
||||
@@ -124,10 +142,20 @@ public class ExchangeClientiImportService {
|
||||
|
||||
|
||||
final List<GtbAnag> gtbAnags = exchangeImportDataManagerService.retrieveDataFromExchange(connection, GtbAnag.class,
|
||||
testataTableName, null, retrieveAlreadyImported);
|
||||
testataTableName, diacod != null ? ("diacod = " + UtilityDB.valueToString(diacod)) : null, retrieveAlreadyImported);
|
||||
|
||||
List<String> codAnags = gtbAnags.stream()
|
||||
.map(GtbAnag::getCodAnag)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (codAnags.isEmpty())
|
||||
return gtbAnags;
|
||||
|
||||
final List<VtbClie> vtbClies = exchangeImportDataManagerService.retrieveDataFromExchange(connection, VtbClie.class,
|
||||
righeTableName, null, retrieveAlreadyImported);
|
||||
righeTableName,
|
||||
"cod_anag IN ( " + UtilityQuery.concatStringFieldsWithSeparator(codAnags, ",") + ")",
|
||||
retrieveAlreadyImported);
|
||||
|
||||
|
||||
gtbAnags
|
||||
|
||||
Reference in New Issue
Block a user