varie modifiche per improtazione e esportazioni rosso gargano

This commit is contained in:
2024-10-04 11:00:33 +02:00
parent 07f20765cb
commit 41afab06d6
8 changed files with 191 additions and 36 deletions

View File

@@ -0,0 +1,56 @@
package it.integry.ems.migration.model;
import it.integry.ems.migration._base.BaseMigration;
import it.integry.ems.migration._base.IntegryCustomer;
import it.integry.ems.migration._base.MigrationModelInterface;
public class Migration_20241004105513 extends BaseMigration implements MigrationModelInterface {
@Override
public void up() throws Exception {
if (isHistoryDB())
return;
if (!isCustomer(IntegryCustomer.RossoGargano)) return;
executeStatement("insert into ctb_movr_intercode\n" +
"select num_cmov,\n" +
"id_riga,\n" +
"chiave,\n" +
"PN_NRO_DOCUMENTO\n" +
"from (\n" +
"select \n" +
"PNOTA.PN_DATA_COMPETENZA,\n" +
"PNOTA.PN_NRO_REG ,\n" +
"PNOTA.PN_NRO_RIGA_REG,\n" +
"PNOTA.PN_SEGNO_MOVIMENTO,\n" +
"PNOTA.PN_IMPORTO_MOV,\n" +
"gtb_anag.diacod,\n" +
"ctb_movr.num_cmov,\n" +
"ctb_movr.id_riga,\n" +
"PNOTA.PN_PARTITA + Space(8 - len(PNOTA.PN_PARTITA)) + format(PNOTA.PN_NRO_RIGA_REG, '000') as chiave,\n" +
"PNOTA.PN_NRO_DOCUMENTO,\n" +
"ctb_movr.cod_anag,\n" +
"sum(ctb_movr.imp_dare - ctb_movr.imp_avere) over (PARTITION by ctb_movr.cod_anag) as tot_scoperto \n" +
"from ctb_movr \n" +
"inner join ctb_movt on ctb_movr.num_cmov = ctb_movt.num_cmov\n" +
"inner join gtb_anag on ctb_movr.cod_anag = gtb_anag.cod_anag\n" +
"inner join ctb_caus on ctb_movt.cod_ccau = ctb_caus.cod_ccau and ctb_caus.flag_ap_ch = 'N'\n" +
"inner join rg_crl_movt on ctb_movt.num_cmov = rg_crl_movt.num_cmov\n" +
"inner join RossoGarganoExchange.dbo.PNOTA PNOTA on rg_crl_movt.PN_DATA_COMPETENZA = PNOTA.PN_DATA_COMPETENZA and rg_crl_movt.PN_NRO_REG = PNOTA.PN_NRO_REG \n" +
"and gtb_anag.diacod = PN_COD_ANAG\n" +
"and ( (PNOTA.PN_SEGNO_MOVIMENTO = 'D' and ctb_movr.imp_dare = PNOTA.PN_IMPORTO_MOV)\n" +
"or (PNOTA.PN_SEGNO_MOVIMENTO = 'A' and ctb_movr.imp_avere = PNOTA.PN_IMPORTO_MOV)) \n" +
"and PNOTA.PN_NRO_RIGA_REG = ctb_movr.riga\n" +
"where anno_part is null \n" +
"and not exists (select * from ctb_movr_intercode where ctb_movr.num_cmov = ctb_movr_intercode.num_cmov and ctb_movr.id_riga = ctb_movr_intercode.id_riga )\n" +
")t\n" +
"order by cod_anag, num_cmov");
}
@Override
public void down() throws Exception {
}
}

View File

@@ -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(GtbBanc.ENTITY)
@JsonTypeName(GtbBanc.ENTITY)
public class GtbBanc extends EntityBase {
public class GtbBanc extends EntityBase implements EquatableEntityInterface<GtbBanc> {
private final static Logger logger = LogManager.getLogger();
@@ -92,4 +95,21 @@ public class GtbBanc extends EntityBase {
public void setNote(String note) {
this.note = note;
}
@Override
public int hashCodeKey() {
return Objects.hash(getCodBanc());
}
@Override
public boolean equalsKey(GtbBanc other) {
if (this == other)
return true;
if(hashCodeKey() != other.hashCodeKey())
return false;
return Objects.equals(getCodBanc(), other.getCodBanc());
}
}

View File

@@ -1436,7 +1436,7 @@ public class RossoGarganoSyncService {
" ctb_part.anno_part = ctb_parr.anno_part AND ctb_part.ser_doc = ctb_parr.ser_doc AND\n" +
" ctb_part.num_doc = ctb_parr.num_doc\n" +
"WHERE " + (anno != null ? "ctb_part.anno_part = " + anno + " AND \n" : "") +
" ISNULL(ctb_part.num_doc_forn, cast(ctb_part.num_doc as varchar)) = %s\n" +
" ISNULL(ISNULL(cast(try_cast(ctb_part.num_doc_forn as int) as varchar), ctb_part.num_doc_forn), cast(ctb_part.num_doc as varchar)) = %s\n" +
" AND ctb_part.cod_anag = %s\n" +
" AND ctb_part.tipo_anag = %s\n",
numero, codAnag, tipoAnag);

View File

@@ -4,8 +4,7 @@ import it.integry.common.var.CommonConstants;
import it.integry.ems.javabeans.RequestDataDTO;
import it.integry.ems.response.ServiceRestResponse;
import it.integry.ems.sync.MultiDBTransaction.MultiDBTransactionManager;
import it.integry.ems.system.exchange.service.ExchangeBancheAziendaliImportService;
import it.integry.ems.system.exchange.service.ExchangePartiteMagazzinoImportService;
import it.integry.ems.system.exchange.service.ExchangeBancheImportService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
@@ -16,27 +15,27 @@ import javax.servlet.http.HttpServletRequest;
@RestController
@Scope("request")
@RequestMapping("exchange/banche-aziendali/")
public class ExchangeBancheAziendaliImportController {
@RequestMapping("exchange/banche/")
public class ExchangeBancheImportController {
private final Logger logger = LogManager.getLogger();
@Autowired
private ExchangeBancheAziendaliImportService exchangeBancheAziendaliImportService;
private ExchangeBancheImportService exchangeBancheAziendaliImportService;
@Autowired
private RequestDataDTO requestDataDTO;
@RequestMapping(value = "import", method = RequestMethod.GET)
public @ResponseBody
ServiceRestResponse importBancheAziendali(HttpServletRequest request,
ServiceRestResponse importBanche(HttpServletRequest request,
@RequestParam(CommonConstants.PROFILE_DB) String profileDb,
@RequestParam() String profileDbExchange) throws Exception {
try (MultiDBTransactionManager internalDb = new MultiDBTransactionManager(profileDb);
MultiDBTransactionManager exchangeDb = new MultiDBTransactionManager(profileDbExchange)) {
exchangeBancheAziendaliImportService.importBancheAziendali(internalDb, exchangeDb,requestDataDTO);
exchangeBancheAziendaliImportService.importBanche(internalDb, exchangeDb,requestDataDTO);
}
return ServiceRestResponse.createPositiveResponse();
}

View File

@@ -1,5 +1,6 @@
package it.integry.ems.system.exchange.service;
import it.integry.ems.exception.PrimaryDatabaseNotPresentException;
import it.integry.ems.expansion.RunnableThrowable;
import it.integry.ems.javabeans.RequestDataDTO;
import it.integry.ems.service.EntityProcessor;
@@ -13,7 +14,9 @@ import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -22,7 +25,7 @@ import java.util.stream.Collectors;
@SuppressWarnings("rawtypes")
@Service
public class ExchangeBancheAziendaliImportService {
public class ExchangeBancheImportService {
//TODO: To be remove, only for fast development
private final String ROSSOGARGANO_EXCHANGE_USER = "EXCHANGE";
@@ -39,45 +42,47 @@ public class ExchangeBancheAziendaliImportService {
private final Logger logger = LogManager.getLogger();
public void importBancheAziendali(MultiDBTransactionManager internalMultiDb, MultiDBTransactionManager exchangeMultiDb, RequestDataDTO requestDataDTO) throws Exception {
public void importBanche(MultiDBTransactionManager internalMultiDb, MultiDBTransactionManager exchangeMultiDb, RequestDataDTO requestDataDTO) throws Exception {
boolean useTempTable = true;
try {
exchangeImportSchemaManagerService.syncSchema(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.BancheAziendali, useTempTable);
exchangeImportSchemaManagerService.syncSchema(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.Banche, useTempTable);
final List<GtbBancAzi> exchangeImportedDataBanche = retrieveBanche(
importBanche(internalMultiDb, exchangeMultiDb, useTempTable, requestDataDTO);
final List<GtbBancAzi> exchangeImportedDataBancheAzi = retrieveBancheAzi(
exchangeMultiDb.getPrimaryConnection(),
true, false);
final List<GtbBancAzi> exchangeUpdatedDataBancheAzi = retrieveBancheAzi(
exchangeMultiDb.getPrimaryConnection(),
false, useTempTable);
final List<GtbBancAziIntercode> exchangeImportedDataBancheIntercode = retrieveBancheIntercode(
exchangeMultiDb.getPrimaryConnection(),
true, false);
final List<GtbBancAzi> exchangeUpdatedDataBanche = retrieveBanche(
exchangeMultiDb.getPrimaryConnection(),
false, useTempTable);
final List<GtbBancAziIntercode> exchangeUpdatedDataBancheIntercode = retrieveBancheIntercode(
exchangeMultiDb.getPrimaryConnection(),
false, useTempTable);
List<EquatableEntityInterface> allDataBanche = exchangeImportDataManagerService
.runSync(GtbBancAzi.class, exchangeImportedDataBanche, exchangeUpdatedDataBanche);
List<EquatableEntityInterface> allDataBancheAzie = exchangeImportDataManagerService
.runSync(GtbBancAzi.class, exchangeImportedDataBancheAzi, exchangeUpdatedDataBancheAzi);
List<EquatableEntityInterface> allDataBancheIntercode = exchangeImportDataManagerService
.runSync(GtbBancAziIntercode.class, exchangeImportedDataBancheIntercode, exchangeUpdatedDataBancheIntercode );
allDataBanche.forEach(x -> x.setOperation(x.getOperation() == OperationType.INSERT ? OperationType.INSERT_OR_UPDATE : x.getOperation()));
allDataBancheAzie.forEach(x -> x.setOperation(x.getOperation() == OperationType.INSERT ? OperationType.INSERT_OR_UPDATE : x.getOperation()));
allDataBancheIntercode.forEach(x -> x.setOperation(x.getOperation() == OperationType.INSERT ? OperationType.INSERT_OR_UPDATE : x.getOperation()));
allDataBanche = allDataBanche.stream().filter(x -> x.getOperation() != OperationType.DELETE)
allDataBancheAzie = allDataBancheAzie.stream().filter(x -> x.getOperation() != OperationType.DELETE)
.collect(Collectors.toList());
allDataBancheIntercode = allDataBancheIntercode.stream().filter(x -> x.getOperation() != OperationType.DELETE)
.collect(Collectors.toList());
List<EquatableEntityInterface> finalAllBancheData = allDataBanche;
List<EquatableEntityInterface> finalAllBancheData = allDataBancheAzie;
List<EquatableEntityInterface> finalAllBancheDataIntercode = allDataBancheIntercode;
allDataBancheIntercode.stream()
@@ -93,7 +98,7 @@ public class ExchangeBancheAziendaliImportService {
finalAllBancheData.add(testata);
});
allDataBanche.stream()
allDataBancheAzie.stream()
.map(x -> (GtbBancAzi) x)
.forEach(x -> x.setGtbBancAziIntercode(finalAllBancheDataIntercode.stream()
.map(y -> (GtbBancAziIntercode) y)
@@ -105,8 +110,8 @@ public class ExchangeBancheAziendaliImportService {
AtomicInteger importedCounter = new AtomicInteger();
List<RunnableThrowable> calls = new ArrayList<>();
for (EquatableEntityInterface dataToSave : allDataBanche) {
logger.debug("Importate {} banche aziendali di {}", importedCounter.incrementAndGet(), allDataBanche.size());
for (EquatableEntityInterface dataToSave : allDataBancheAzie) {
logger.debug("Importate {} banche aziendali di {}", importedCounter.incrementAndGet(), allDataBancheAzie.size());
try {
entityProcessor.processEntity(dataToSave, true, true, ROSSOGARGANO_EXCHANGE_USER, internalMultiDb, requestDataDTO);
singleUpdateImported(exchangeMultiDb.getPrimaryConnection(), (GtbBancAzi) dataToSave, useTempTable);
@@ -128,13 +133,60 @@ public class ExchangeBancheAziendaliImportService {
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
} finally {
if (useTempTable)
exchangeImportSchemaManagerService.deleteTempTables(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.BancheAziendali);
exchangeImportSchemaManagerService.deleteTempTables(exchangeMultiDb.getPrimaryConnection(), ExchangeImportSchemaManagerService.SchemaType.Banche);
}
}
private void importBanche(MultiDBTransactionManager internalMultiDb, MultiDBTransactionManager exchangeMultiDb, boolean useTempTable, RequestDataDTO requestDataDTO) throws Exception {
private List<GtbBancAzi> retrieveBanche(Connection connection,
boolean retrieveAlreadyImported, boolean useTempTable) throws Exception {
final List<GtbBanc> exchangeImportedDataBanche = retrieveBanche(
exchangeMultiDb.getPrimaryConnection(),
true, false);
final List<GtbBanc> exchangeUpdatedDataBanche = retrieveBanche(
exchangeMultiDb.getPrimaryConnection(),
false, useTempTable);
List<EquatableEntityInterface> allDataBanche = exchangeImportDataManagerService
.runSync(GtbBanc.class, exchangeImportedDataBanche, exchangeUpdatedDataBanche);
allDataBanche.forEach(x -> x.setOperation(x.getOperation() == OperationType.INSERT ? OperationType.INSERT_OR_UPDATE : x.getOperation()));
allDataBanche = allDataBanche.stream().filter(x -> x.getOperation() != OperationType.DELETE)
.collect(Collectors.toList());
AtomicInteger importedCounter = new AtomicInteger();
List<RunnableThrowable> calls = new ArrayList<>();
final Exception[] firstExceptionToThrow = {null};
for (EquatableEntityInterface dataToSave : allDataBanche) {
try {
entityProcessor.processEntity(dataToSave, true, true, ROSSOGARGANO_EXCHANGE_USER, internalMultiDb, requestDataDTO);
logger.debug("Importate {} banche di {}", importedCounter.incrementAndGet(), allDataBanche.size());
singleUpdateBancheImported(exchangeMultiDb.getPrimaryConnection(), (GtbBanc) dataToSave, useTempTable);
internalMultiDb.commitAll();
exchangeMultiDb.commitAll();
} catch (Exception ex) {
if (firstExceptionToThrow[0] == null) firstExceptionToThrow[0] = ex;
logger.error("Errore durante l'importazione della banca", ex);
internalMultiDb.rollbackAll();
exchangeMultiDb.rollbackAll();
}
if (firstExceptionToThrow[0] != null) throw firstExceptionToThrow[0];
}
}
private List<GtbBancAzi> retrieveBancheAzi(Connection connection,
boolean retrieveAlreadyImported, boolean useTempTable) throws Exception {
String gtbBancAziOriginalName = "gtb_banc_azi";
String gtbBancAziTableName = gtbBancAziOriginalName + (useTempTable ? "_tmp" : "");
@@ -150,6 +202,24 @@ public class ExchangeBancheAziendaliImportService {
gtbBancAziTableName, null, retrieveAlreadyImported);
}
private List<GtbBanc> retrieveBanche(Connection connection,
boolean retrieveAlreadyImported, boolean useTempTable) throws Exception {
String gtbBancOriginalName = "gtb_banc";
String gtbBancTableName = gtbBancOriginalName + (useTempTable ? "_tmp" : "");
if (useTempTable) {
UtilityDB.executeStatement(connection,
"INSERT INTO " + gtbBancTableName +
" SELECT * FROM " + gtbBancOriginalName
);
}
return exchangeImportDataManagerService.retrieveDataFromExchange(connection, GtbBanc.class,
gtbBancTableName, null, retrieveAlreadyImported);
}
private List<GtbBancAziIntercode> retrieveBancheIntercode(Connection connection,
boolean retrieveAlreadyImported, boolean useTempTable) throws Exception {
@@ -184,4 +254,13 @@ public class ExchangeBancheAziendaliImportService {
exchangeImportDataManagerService.updateImportedStatus(connection, "gtb_banc_azi_intercode", importedIntercodeKey, useTempTable);
}
private void singleUpdateBancheImported(Connection connection, GtbBanc importedData, boolean useTempTable) throws Exception {
final HashMap<String, Object> importedKey = new HashMap<String, Object>() {{
put("cod_banc", importedData.getCodBanc());
}};
exchangeImportDataManagerService.updateImportedStatus(connection, "gtb_banc", importedKey, useTempTable);
}
}

View File

@@ -25,9 +25,9 @@ public class ExchangeImportSchemaManagerService {
PartiteMagazzinoLavorazione(5),
VersamentoGrezzo(6),
CampiRaccolta(7),
BancheAziendali(8),
Banche(8),
ValorizzazioneCertificati(9),
DocumentiVendita(10),;
DocumentiVendita(10);
private final int value;
@@ -71,7 +71,7 @@ public class ExchangeImportSchemaManagerService {
put(SchemaType.PartiteMagazzinoLavorazione, Arrays.asList("mtb_partita_mag_lav"));
put(SchemaType.VersamentoGrezzo, Arrays.asList("mtb_colt_versamento_grezzo", "mtb_colr_versamento_grezzo"));
put(SchemaType.CampiRaccolta, Collections.singletonList("campi_raccolta"));
put(SchemaType.BancheAziendali, Arrays.asList("gtb_banc_azi","gtb_banc_azi_intercode" ));
put(SchemaType.Banche, Arrays.asList("gtb_banc", "gtb_banc_azi","gtb_banc_azi_intercode" ));
put(SchemaType.ValorizzazioneCertificati, Collections.singletonList("valorizzazione_certificati"));
}};

View File

@@ -139,9 +139,9 @@ public class ExchangeSystemManagerService {
final ExchangeOrdiniImportService beanCampiRaccolta = ContextLoader.getCurrentWebApplicationContext().getBean(ExchangeOrdiniImportService.class);
beanCampiRaccolta.importCampiDiRaccolta(internalDb, exchangeDb, requestDataDTO);
break;
case BancheAziendali:
final ExchangeBancheAziendaliImportService beanBancheAziendali = ContextLoader.getCurrentWebApplicationContext().getBean(ExchangeBancheAziendaliImportService.class);
beanBancheAziendali.importBancheAziendali(internalDb, exchangeDb, requestDataDTO);
case Banche:
final ExchangeBancheImportService beanBancheAziendali = ContextLoader.getCurrentWebApplicationContext().getBean(ExchangeBancheImportService.class);
beanBancheAziendali.importBanche(internalDb, exchangeDb, requestDataDTO);
break;
}

View File

@@ -90,6 +90,7 @@ public class RestLoggerBodyFilter extends AbstractRequestLoggingFilter {
!serviceName.startsWith("agribook/orders/attachment/") &&
!serviceName.contains("upload") &&
!serviceName.startsWith("users/") &&
!serviceName.startsWith("exportVariazioniPv") &&
!serviceName.startsWith("variazioni-negozi/") &&
!serviceName.startsWith("decodeUcs/") &&
(!serviceName.contains("processSql") || UtilityDebug.isDebugExecution());