- ordinamento tabella titoli

- migliorata la lista degli argomenti
This commit is contained in:
Surya Paolo
2025-04-23 01:59:45 +02:00
parent 58431c144c
commit 85e2df56e1
6 changed files with 78 additions and 47 deletions

View File

@@ -16,7 +16,9 @@ class Macro {
constructor(idapp, options) {
this.idapp = idapp;
this.localoptions = options;
}
this.recProductExist = false;
this.queryprod = null;
}
async updateLocalDbFromGM_T_Web_Articoli(params) {
@@ -372,8 +374,10 @@ class Macro {
elaboraProdotto(recproduct, opt);
count++;
if (count % 50 === 0)
console.log(' *** IMPORTATI: ' + opt.imported + ' AGGIORNATI = ' + opt.updated + ' (su ' + numrec + ' RECORD)');
if (count % 50 === 0) {
const percentuale = Math.round((count / numrec) * 100);
console.log(` *** RECORD ${count} - IMPORTATI: ${opt.imported} AGGIORNATI = ${opt.updated} (su ${numrec} RECORD) - Completato al ${percentuale}%`);
}
//}
}
}
@@ -397,7 +401,8 @@ class Macro {
async importaCatalogo(data) {
let updated = 0,
imported = 0,
errors = 0;
errors = 0,
indice = 0;
try {
const ripopola = true; //++MODIFICARE!
@@ -410,14 +415,12 @@ class Macro {
for (const product of dataObjects) {
await this.elaboraProdotto(product, { updated, imported, errors });
indice++;
}
console.log(
'*** IMPORTATI: ',
imported,
'AGGIORNATI = ' + updated + ' (su ' + dataObjects.length + ' RECORD)'
);
return { updated, imported, error };
const percentuale = (indice / dataObjects.length * 100).toFixed(2);
console.log(`*** RECORD: ${indice} - IMPORTATI: ${imported}, AGGIORNATI = ${updated} (su ${dataObjects.length} RECORD) - Completamento: ${percentuale}%`);
return { updated, imported, errors };
} catch (e) {
console.error(e.message);
throw e;
@@ -522,6 +525,9 @@ class Macro {
).lean();
if (risrecInfo) {
product.idProductInfo = risrecInfo._id;
this.queryprod = { idProductInfo: product.idProductInfo };
await this.aggiornaImmagineSeNecessario(risrecInfo);
await this.gestisciGasOrdine(product, risrecInfo);
await this.gestisciVariazioni(product, risrecInfo, options);
@@ -547,16 +553,13 @@ class Macro {
recGas = await Gasordine.findOne({ idapp, name: product.gas_name }).lean();
}
let recProductExist = null;
let queryprod = { idProductInfo: product.idProductInfo };
if (recGas) {
queryprod = { ...queryprod, idGasordine: recGas._id };
this.queryprod = { ...this.queryprod, idGasordine: recGas._id };
}
recProductExist = await Product.findOne(queryprod).lean();
this.recProductExist = await Product.findOne(this.queryprod).lean();
if (!recProductExist) {
if (!this.recProductExist) {
product.idGasordine = recGas ? recGas._id : null;
await Product.findOneAndUpdate({ _id: product._id }, { $set: { idGasordine: product.idGasordine } });
@@ -894,20 +897,36 @@ class Macro {
* Gestisce le variazioni del prodotto.
*/
async gestisciVariazioni(product, risrecInfo, options) {
const queryprod = { idProductInfo: risrecInfo._id };
const recold = await Product.findOne(queryprod).lean();
const recold = await Product.findOne(this.queryprod).lean();
const variazione = this.preparaVariazione(product);
const myproduct = {
...product,
...(!product.isbn ? [{ isbn: risrecInfo.code }]: []),
...(!product.maxbookableGASQty && risrecInfo.maxbookableGASQty ? [{ maxbookableGASQty: risrecInfo.maxbookableGASQty }]: []),
idapp: this.idapp,
arrvariazioni: [variazione],
};
let risultupdate = null;
if (recold) {
const arrvariazioni = this.aggiornaVariazioni(recold.arrvariazioni, variazione);
risultupdate = await Product.findOneAndUpdate(queryprod, { $set: { arrvariazioni } });
options.updated++;
} else {
const myproduct = { ...queryprod, arrvariazioni: [variazione] };
risultupdate = await Product.findOneAndUpdate(queryprod, { $set: myproduct }, { new: true, upsert: true });
options.imported++;
risultupdate = await Product.updateOne(this.queryprod, { $set: { arrvariazioni } }, { new: true });
if (risultupdate && risultupdate.modifiedCount > 0) {
options.updated++;
}
if (recold.isbn !== risrecInfo.code) {
product.isbn = risrecInfo.code;
}
}
if (!recold || recold.isbn !== myproduct.isbn || !recold.idapp || !this.recProductExist) {
risultupdate = await Product.updateOne(this.queryprod, { $set: myproduct }, { new: true, upsert: true });
if (risultupdate && risultupdate.modifiedCount > 0) {
options.imported++;
}
}
// console.log('risultupdate', risultupdate);