- 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;
|
||||
@@ -33,13 +33,27 @@ class MssqlMigrator {
|
||||
let indtab = 0;
|
||||
let indtabok = 0;
|
||||
const logs = [];
|
||||
for (const tableName of tableNames) {
|
||||
for (const rectable of tableNames) {
|
||||
try {
|
||||
const tableName = rectable.table;
|
||||
const usaDataOra = rectable.usaDataOra;
|
||||
const fieldId = rectable.fieldId;
|
||||
|
||||
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}]`;
|
||||
let dataQuery = `SELECT * FROM ${tableName}`;
|
||||
|
||||
if (usaDataOra) {
|
||||
dataQuery = `SELECT T.* FROM ${tableName} T`;
|
||||
dataQuery += ` JOIN (
|
||||
SELECT ${fieldId}, MAX(DataOra) AS data
|
||||
FROM ${tableName}
|
||||
GROUP BY ${fieldId}
|
||||
) b ON T.${fieldId} = b.${fieldId} AND T.DataOra = b.data; `;
|
||||
}
|
||||
|
||||
console.log('query', dataQuery);
|
||||
|
||||
let dataResponse = null;
|
||||
|
||||
@@ -51,11 +65,12 @@ class MssqlMigrator {
|
||||
null,
|
||||
{ timeout: 900000 });
|
||||
} catch (error) {
|
||||
console.error('Error: ', error);
|
||||
console.error('Error: ', error.response?.data?.error || error.message || error);
|
||||
if (error.message === 'socket hang up') {
|
||||
console.log('Error: hangup, waiting 5 seconds and retrying...');
|
||||
await new Promise(resolve => setTimeout(resolve, 5000));
|
||||
|
||||
|
||||
dataResponse = await axios.post(
|
||||
`${this.serverUrl}/query`,
|
||||
{ query: dataQuery },
|
||||
@@ -69,6 +84,7 @@ class MssqlMigrator {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const records = dataResponse?.data;
|
||||
|
||||
if (!records || records.length === 0) {
|
||||
|
||||
Reference in New Issue
Block a user