aggiunta tabelle equivalenti
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:
@@ -0,0 +1,15 @@
|
||||
package it.integry.ems.migration.model;import it.integry.ems.migration._base.BaseMigration;
|
||||
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||
|
||||
public class Migration_20251204131327 extends BaseMigration implements MigrationModelInterface{
|
||||
|
||||
@Override
|
||||
public void up()throws Exception {
|
||||
if(isHistoryDB())
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void down()throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -6,15 +6,18 @@ import it.integry.ems_model.annotation.PK;
|
||||
import it.integry.ems_model.annotation.SqlField;
|
||||
import it.integry.ems_model.annotation.Table;
|
||||
import it.integry.ems_model.base.EntityBase;
|
||||
import it.integry.ems_model.base.EquatableEntityInterface;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.kie.api.definition.type.PropertyReactive;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Master
|
||||
@PropertyReactive
|
||||
@Table(MtbAartEqui.ENTITY)
|
||||
@JsonTypeName(MtbAartEqui.ENTITY)
|
||||
public class MtbAartEqui extends EntityBase {
|
||||
public class MtbAartEqui extends EntityBase implements EquatableEntityInterface<MtbAartEqui> {
|
||||
|
||||
private final static Logger logger = LogManager.getLogger();
|
||||
|
||||
@@ -85,4 +88,29 @@ public class MtbAartEqui extends EntityBase {
|
||||
public void setDescrizioneEstera(String descrizioneEstera) {
|
||||
this.descrizioneEstera = descrizioneEstera;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof MtbAartEqui)) return false;
|
||||
MtbAartEqui that = (MtbAartEqui) o;
|
||||
return Objects.equals(getIdArtEqui(), that.getIdArtEqui()) && Objects.equals(getDescrizione(), that.getDescrizione()) && Objects.equals(getFlagEquiPrezzo(), that.getFlagEquiPrezzo()) && Objects.equals(getFlagEquiCosto(), that.getFlagEquiCosto()) && Objects.equals(getDescrizioneEstera(), that.getDescrizioneEstera());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getIdArtEqui(), getDescrizione(), getFlagEquiPrezzo(), getFlagEquiCosto(), getDescrizioneEstera());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCodeKey() {
|
||||
return Objects.hash(getIdArtEqui());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equalsKey(MtbAartEqui other) {
|
||||
if (this == other) return true;
|
||||
if (!(other instanceof MtbAartEqui)) return false;
|
||||
MtbAartEqui mtbAartEqui = (MtbAartEqui) other;
|
||||
return Objects.equals(getIdArtEqui(), mtbAartEqui.getIdArtEqui());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,8 @@ public class ExchangeArticoliImportService {
|
||||
|
||||
importTipi(internalMultiDb, exchangeMultiDb, useTempTable, requestDataDTO, OperationType.INSERT, OperationType.INSERT_OR_UPDATE, OperationType.UPDATE);
|
||||
|
||||
importArticoliEquivalenti(internalMultiDb, exchangeMultiDb, useTempTable, requestDataDTO, OperationType.INSERT, OperationType.INSERT_OR_UPDATE, OperationType.UPDATE);
|
||||
|
||||
importMarchi(internalMultiDb, exchangeMultiDb, useTempTable, requestDataDTO, OperationType.INSERT, OperationType.INSERT_OR_UPDATE, OperationType.UPDATE);
|
||||
|
||||
importColori(internalMultiDb, exchangeMultiDb, useTempTable, requestDataDTO, OperationType.INSERT, OperationType.INSERT_OR_UPDATE, OperationType.UPDATE);
|
||||
@@ -58,6 +60,8 @@ public class ExchangeArticoliImportService {
|
||||
|
||||
importAnagrafiche(internalMultiDb, exchangeMultiDb, useTempTable, requestDataDTO);
|
||||
|
||||
importArticoliEquivalenti(internalMultiDb, exchangeMultiDb, useTempTable, requestDataDTO, OperationType.DELETE);
|
||||
|
||||
importMarchi(internalMultiDb, exchangeMultiDb, useTempTable, requestDataDTO, OperationType.DELETE);
|
||||
|
||||
importColori(internalMultiDb, exchangeMultiDb, useTempTable, requestDataDTO, OperationType.DELETE);
|
||||
@@ -513,6 +517,66 @@ public class ExchangeArticoliImportService {
|
||||
mtbGrupTableName, null, retrieveAlreadyImported);
|
||||
}
|
||||
|
||||
private void importArticoliEquivalenti(MultiDBTransactionManager internalMultiDb, MultiDBTransactionManager exchangeDb, boolean useTempTable, RequestDataDTO requestDataDTO, OperationType... operationsToProcess) throws Exception {
|
||||
if (!UtilityDB.existDatabaseObject(exchangeDb.getPrimaryConnection(), "mtb_aart_equi", TypeDbObject.VIEW)) return;
|
||||
final List<MtbAartEqui> exchangeImportedDataMtbAartEqui = retrieveMtbAartEqui(
|
||||
exchangeDb.getPrimaryConnection(),
|
||||
true, false);
|
||||
|
||||
final List<MtbAartEqui> exchangeUpdatedDataMtbAartEqui = retrieveMtbAartEqui(
|
||||
exchangeDb.getPrimaryConnection(),
|
||||
false, useTempTable);
|
||||
|
||||
List<EquatableEntityInterface> allData = exchangeImportDataManagerService
|
||||
.runSync(MtbAartMarchio.class, exchangeImportedDataMtbAartEqui, exchangeUpdatedDataMtbAartEqui);
|
||||
|
||||
allData.forEach(x -> x.setOperation(x.getOperation() == OperationType.INSERT ? OperationType.INSERT_OR_UPDATE : x.getOperation()));
|
||||
|
||||
allData = allData.stream()
|
||||
.filter(x -> Arrays.stream(operationsToProcess).anyMatch(y -> x.getOperation() == y))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
final Exception[] firstExceptionToThrow = {null};
|
||||
|
||||
AtomicInteger importedCounter = new AtomicInteger();
|
||||
|
||||
for (EquatableEntityInterface dataToSave : allData) {
|
||||
|
||||
logger.debug("Importati {} articoli equivalenti di {}", importedCounter.incrementAndGet(), allData.size());
|
||||
try {
|
||||
entityProcessor.processEntity(dataToSave, true, true, EXCHANGE_USER, internalMultiDb, requestDataDTO);
|
||||
|
||||
singleUpdateImported(exchangeDb.getPrimaryConnection(), (MtbAartMarchio) dataToSave, useTempTable);
|
||||
internalMultiDb.commitAll();
|
||||
} catch (Exception ex) {
|
||||
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
|
||||
|
||||
logger.error("Errore durante l'importazione degli articoli equivalenti", ex);
|
||||
internalMultiDb.rollbackAll();
|
||||
}
|
||||
}
|
||||
|
||||
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
|
||||
}
|
||||
|
||||
private List<MtbAartEqui> retrieveMtbAartEqui(Connection connection, boolean retrieveAlreadyImported, boolean useTempTable) throws Exception {
|
||||
String originalTableName = "mtb_aart_equi";
|
||||
String tableName = originalTableName + (useTempTable ? "_tmp" : "");
|
||||
|
||||
|
||||
if (useTempTable) {
|
||||
UtilityDB.executeStatement(connection,
|
||||
"INSERT INTO " + tableName +
|
||||
" SELECT * FROM " + originalTableName
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
return exchangeImportDataManagerService.retrieveDataFromExchange(connection, MtbAartEqui.class,
|
||||
tableName, null, retrieveAlreadyImported);
|
||||
}
|
||||
|
||||
|
||||
private void importColori(MultiDBTransactionManager internalMultiDb, MultiDBTransactionManager exchangeDb, boolean useTempTable, RequestDataDTO requestDataDTO, OperationType... operationsToProcess) throws Exception {
|
||||
if (!UtilityDB.existDatabaseObject(exchangeDb.getPrimaryConnection(), "mtb_colori", TypeDbObject.VIEW)) return;
|
||||
|
||||
|
||||
@@ -107,6 +107,7 @@ public class ExchangeImportSchemaManagerService {
|
||||
put("mtb_aart_colori", MtbAartColori.class);
|
||||
put("mtb_aart_bar_code", MtbAartBarCode.class);
|
||||
put("mtb_aart_carat", MtbAartCarat.class);
|
||||
put("mtb_aart_equi", MtbAartEqui.class);
|
||||
}});
|
||||
put(SchemaType.PartiteMagazzinoLavorazione, new HashMap<String, Class<? extends EntityInterface>>() {{
|
||||
put("mtb_partita_mag_lav", MtbPartitaMag.class);
|
||||
|
||||
Reference in New Issue
Block a user