- corretto scheda prodotto, record salvato

This commit is contained in:
Surya Paolo
2025-05-01 00:20:16 +02:00
parent 97abe8b46d
commit fcc3755c19
13 changed files with 89 additions and 49 deletions

View File

@@ -26,6 +26,8 @@ class Macro {
async updateLocalDbFromGM_T_Web_Articoli(params) {
console.log('INIZIO updateLocalDbFromGM_T_Web_Articoli...', params);
let mylog = ''
let numrec = 0;
const options = {
@@ -69,11 +71,12 @@ class Macro {
{ DescrizioneStatoProdotto: 'Prossima uscita/pubblicazione' },
{ DescrizioneStatoProdotto: 'In prevendita' },
{ DescrizioneStatoProdotto: 'Vendita sito' },
{ DescrizioneStatoProdotto: '2023 in commercio' },
]
{ DescrizioneStatoProdotto: '2023 in commercio' }
],
Ean13: { $not: /^USATO/ }
};
/*
1 In commercio
3 Ristampa
@@ -97,30 +100,18 @@ class Macro {
} else {
options.where = `
(DescrizioneStatoProdotto = 'In commercio' OR
DescrizioneStatoProdotto = 'Ristampa' OR
DescrizioneStatoProdotto = 'Prossima uscita/pubblicazione' OR
DescrizioneStatoProdotto = 'In promozione' OR
DescrizioneStatoProdotto = 'In fase di valutazione' OR
DescrizioneStatoProdotto = 'Titolo in esaurimento (in attesa Nuova Edizione)' OR
DescrizioneStatoProdotto = 'Titolo in esaurimento' OR
DescrizioneStatoProdotto = 'Titolo in esaurimento (in att N.E Ricopertinata)' OR
DescrizioneStatoProdotto = 'Titolo in Esaurimento (disponibile N.E.)' OR
DescrizioneStatoProdotto = 'In commercio (digitale)' OR
DescrizioneStatoProdotto = 'In prevendita' OR
DescrizioneStatoProdotto = 'Vendita sito' OR
DescrizioneStatoProdotto = '2023 in commercio' OR
DescrizioneStatoProdotto = 'Assoluto NO Reso' OR
DescrizioneStatoProdotto = 'Titolo esaurito'
DescrizioneStatoProdotto = '2023 in commercio' OR
DescrizioneStatoProdotto = 'Vendita sito' OR
DescrizioneStatoProdotto = 'In prevendita' OR
DescrizioneStatoProdotto = 'Prossima uscita') AND
DescrizioneStatoProdotto = 'Prossima uscita')
AND
(DescrizioneTipologia = 'Libri' OR
DescrizioneTipologia = 'Cartolibro' OR
DescrizioneTipologia = 'Carte')
AND
(Ean13 NOT LIKE 'USATO%')
`;
}
} else {
miolimit = 1;
miomatch = {
@@ -432,6 +423,7 @@ class Macro {
// if (!options.caricatutti) {
await this.elaboraProdotto(recproduct, opt);
const sku = recproduct.IdArticolo;
if (sku) {
@@ -775,7 +767,6 @@ class Macro {
if (productGM.DescrizioneTipologia === 'Usato')
vers = shared_consts.PRODUCTTYPE.USATO;
if (productGM.DescrizioneTipologia === 'Download')
vers = shared_consts.PRODUCTTYPE.DOWNLOAD;
else if (productGM.DescrizioneTipologia === 'DVD')

View File

@@ -28,11 +28,16 @@ class MssqlMigrator {
async migrateTables(tableNames) {
try {
const numtables = tableNames.length;
let indtab = 0;
let indtabok = 0;
const logs = [];
for (const tableName of tableNames) {
try {
logs.push(`\n>> Recupero dati da MSSQL per la tabella: ${tableName}`);
const percentuale = ((indtab / numtables) * 100).toFixed(2);
logs.push(`\n>> Recupero dati da MSSQL per la tabella: ${tableName} - (Completamento: ${percentuale}%)`);
console.log(logs[logs.length - 1]);
const dataQuery = `SELECT * FROM [${tableName}]`;
@@ -44,7 +49,7 @@ class MssqlMigrator {
{ query: dataQuery },
{ headers: { 'x-api-key': this.apiKey } },
null,
{ timeout: 300000 });
{ timeout: 900000 });
} catch (error) {
console.error('Error: ', error);
if (error.message === 'socket hang up') {
@@ -56,10 +61,11 @@ class MssqlMigrator {
{ query: dataQuery },
{ headers: { 'x-api-key': this.apiKey } },
null,
{ timeout: 300000 });
{ timeout: 900000 });
} else {
throw error;
console.error('Unexpected error while fetching data from MSSQL:', error.message);
// throw error;
}
}
@@ -101,14 +107,19 @@ class MssqlMigrator {
logs.push(`✅ Inserimento di ${records.length} record nella collezione MongoDB: ${modelName}`);
console.log(logs[logs.length - 1]);
await DynamicModel.insertMany(records);
indtabok++;
} catch (error) {
logs.push(`❌ Errore con la tabella ${tableName}:`, error.message);
console.log(logs[logs.length - 1]);
}
indtab++;
}
logs.push('\n🎉 Tutte le tabelle sono state migrate.');
logs.push(`\n🎉 ${indtabok} tabelle su ${numtables} sono state migrate.`);
console.log(logs[logs.length - 1]);
return logs.join('\n');
} catch (error) {