- newsletter: prende la lista utenti (flag news_on)
- Abilita a Tutti la Newsletter news_on - isCommerciale - JobsInProgress - PCB: Corretto Totali che era a zero
This commit is contained in:
@@ -15,6 +15,7 @@ const { getTableContent } = require('../controllers/articleController');
|
||||
|
||||
const T_WEB_ArticoliFatturati = require('../models/t_web_articolifatturati');
|
||||
const T_WEB_Ordini = require('../models/t_web_ordini');
|
||||
const { JobsInProgress } = require('../models/JobsInProgress');
|
||||
|
||||
class Macro {
|
||||
constructor(idapp, options) {
|
||||
@@ -51,6 +52,18 @@ class Macro {
|
||||
idapp: options.idapp,
|
||||
}
|
||||
|
||||
let myjob = null;
|
||||
|
||||
const lavoromassivo = options.caricatutti;
|
||||
if (lavoromassivo) {
|
||||
myjob = await JobsInProgress.addNewJob({ idapp, descr: 'Riaggiorna Articoli', nomeFunzioneDbOp: 'updateAllBook', status: shared_consts.STATUS_JOB.START });
|
||||
if (!myjob) {
|
||||
mylog = 'ATTENZIONE! ❌ STAVO GIA ESEGUENDO QUESTO JOB, quindi ESCO !';
|
||||
console.error(mylog);
|
||||
return { updated: opt.updated, imported: opt.imported, errors: opt.errors, mylog, idRecUpdated: opt.idRecUpdated, table: opt.table };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
|
||||
@@ -417,13 +430,21 @@ class Macro {
|
||||
console.log('numrec', numrec);
|
||||
}
|
||||
|
||||
let rimuoviTabellePerIniziare = false;
|
||||
|
||||
|
||||
let count = 0;
|
||||
if (Array.isArray(recproducts)) {
|
||||
for (const recproduct of recproducts) {
|
||||
// if (!options.caricatutti) {
|
||||
await this.elaboraProdotto(recproduct, opt);
|
||||
if (recproducts.length > 10 && lavoromassivo) {
|
||||
// rimuovi dalla tabella productInfo tutti i campi date_updated_fromGM
|
||||
const result = await ProductInfo.updateMany({ idapp: options.idapp }, { $unset: { date_updated_fromGM: null } });
|
||||
let quanti_rimossi = result.modifiedCount;
|
||||
console.log(`Sbianca date_updated_fromGM da ProductInfo: (${quanti_rimossi} su ${result.matchedCount})`);
|
||||
rimuoviTabellePerIniziare = true;
|
||||
}
|
||||
|
||||
for (const recproduct of recproducts) {
|
||||
await this.elaboraProdotto(recproduct, opt);
|
||||
|
||||
const sku = recproduct.IdArticolo;
|
||||
|
||||
@@ -439,6 +460,12 @@ class Macro {
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
if (rimuoviTabellePerIniziare) {
|
||||
await ProductInfo.removeProductInfoWithoutDateUpdatedFromGM(options.idapp);
|
||||
}
|
||||
if (myjob)
|
||||
await myjob.terminateJob();
|
||||
}
|
||||
|
||||
if (numrec > 1) {
|
||||
@@ -455,6 +482,8 @@ class Macro {
|
||||
} catch (e) {
|
||||
mylog += 'ERRORE ! *** IMPORTATI: ' + opt?.imported + ' AGGIORNATI = ' + opt?.updated + ' (su ' + numrec + ' RECORD)';
|
||||
opt.logerror = e.message;
|
||||
if (myjob)
|
||||
await myjob.terminateJob(true);
|
||||
console.error(e.message);
|
||||
return { updated: opt.updated, imported: opt.imported, errors: opt.errors, mylog, logerror: opt.logerror };
|
||||
}
|
||||
@@ -1075,6 +1104,15 @@ class Macro {
|
||||
return listaCampi.some((campo) => recordOld[campo] !== recordNew[campo]);
|
||||
}
|
||||
|
||||
async getStat() {
|
||||
let mystr = '';
|
||||
|
||||
const ris = await ProductInfo.countDocuments({ $or: [{ date_updated_fromGM: { $exists: false } }, { date_updated_fromGM: null }] });
|
||||
mystr += `${ris} ProductInfo non aggiornati da GM, quindi da cancellare ! \n`;
|
||||
|
||||
return mystr;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = Macro;
|
||||
Reference in New Issue
Block a user