- creato editor di Pagine (iniziato)

- fix: mancano i "t," su alcuni componenti...
This commit is contained in:
Surya Paolo
2025-09-02 16:22:31 +02:00
parent fcbc64cea8
commit 7ba408c053
25 changed files with 321 additions and 260 deletions

View File

@@ -1316,193 +1316,6 @@ router.post('/import', authenticate, async (req, res) => {
);
return res.status(200).send({ updated, imported, errors });
} else if (cmd === shared_consts.Cmd.MACRO_RANKING) {
/*
let updated = 0;
let imported = 0;
let errors = 0;
const ripopola = true; // SETTARE su TRUE
if (ripopola) {
dataObjects = null;
try {
dataObjects = JSON.parse(`[${data.arrdata}]`);
} catch (e) {
dataObjects = null;
}
if (dataObjects && dataObjects[0]) {
// Cancella la collection ImportaIsbn
await ImportaIsbn.deleteMany({ idapp });
const numtot = dataObjects[0].length
console.log('Numero di RECORD da Importare = ', numtot);
// Aggiungi i record su ImportaIsbn
for (const recinv of dataObjects[0]) {
let recmacro = recinv;
recmacro.idapp = idapp;
//recmacro._id = recmacro.id;
recmacro.sku = recmacro.IdArticolo;
if (recmacro.DataPubblicazione) {
// delete recmacro.id;
let queryprod = { idapp, sku: recmacro.sku };
// 13872
try {
let risrec = await ImportaIsbn.findOneAndUpdate(queryprod, { $set: recmacro }, { new: true, upsert: true, strict: false });
if (risrec) {
imported++;
if ((imported % 100) === 0)
console.log('Importati dir TEMPORANEA ... ', imported + '/' + numtot);
}
} catch (e) {
console.error(e);
errors++;
}
}
}
}
}
// Rileggi tutti i record di ImportaIsbn
dataObjects = await ImportaIsbn.find({ idapp }).lean();
let numprod = dataObjects.length;
console.log('*** INIZIO IMPORT RANKING ... NUMRECORD = ', numprod);
let indprod = 0;
let newprod = 0;
if (numprod) {
// Rimuove prima tutti i valori precedenti
let risupdate = await ProductInfo.updateMany({ idapp }, {
$set: {
totVen: 0,
totFat: 0,
vLast3M: 0,
vLast6M: 0,
vLast1Y: 0,
vLast2Y: 0,
rank3M: 0,
rank6M: 0,
rank1Y: 0,
}
});
}
imported = 0;
for (const product of dataObjects) {
let isnuovo = false
let setta = false
let importa = true;
//if (!product.title || !product.isbn)
if (!product.sku || !product.DataPubblicazione)
importa = false;
if (importa) {
let versGM = product.Versione ? product.Versione : '';
// split versioneGM in array with separated ","
let arrversGM = versGM.split(",").map(x => x.trim());
const recproductInfoAttuale = await ProductInfo.findOne({ idapp, code: product.isbn });
let productInfo = {
idapp: product.idapp,
code: product.isbn ? product.isbn : product.code,
sku: product.sku,
idCatProds: recproductInfoAttuale?.idCatProds,
// id_wp: product._id,
// name: product.title,
totVen: product.totVen || 0,
totFat: product.totFat || 0,
vLast3M: product.vLast3M || 0,
fatLast3M: product.fatLast3M || 0,
fatLast6M: product.fatLast6M || 0,
vLast6M: product.vLast6M || 0,
vLast1Y: product.vLast1Y || 0,
vLast2Y: product.vLast2Y || 0,
rank3M: product.rank3M || 0,
rank6M: product.rank6M || 0,
rank1Y: product.rank1Y || 0,
}
if (!productInfo.idCatProds) {
productInfo.idCatProds = [];
}
// Aggiorna la collana solo se non è stata già impostata nel record attuale
//if (recproductInfoAttuale && !recproductInfoAttuale.idCollana && product.DescrizioneCollana) {
if (recproductInfoAttuale && product.DescrizioneCollana) {
const idCollanaNum = parseInt(product.IdCollana)
reccollana = await Collana.findOne({ idapp, idCollana: idCollanaNum }).lean();
if (!reccollana) {
try {
// Non esiste questa collana, quindi la creo !
reccollana = new Collana({ idapp, idCollana: idCollanaNum, title: product.DescrizioneCollana });
ris = await reccoll.save();
} catch (e) {
console.error('Err', e);
}
}
if (reccollana)
productInfo.idCollana = reccollana._id;
}
if (recproductInfoAttuale && product.DescrArgomento) {
productInfo = await updateProductInfo(productInfo, product, idapp, product.DescrArgomento);
}
if (product.DataPubblicazione) {
productInfo.date_pub = new Date(product.DataPubblicazione);
// convert data to timestamp
productInfo.date_pub_ts = productInfo.date_pub.getTime();
}
if (product.dataUltimoOrdine) {
productInfo.dataUltimoOrdine = new Date(product.dataUltimoOrdine);
}
// Update ProductInfo
let risrecInfo = await ProductInfo.findOneAndUpdate({ idapp, code: productInfo.code }, { $set: productInfo }, { new: true, upsert: false });
if (risrecInfo) {
imported++;
if (imported % 100 === 0)
console.log('Importati... ', imported + '/' + numprod);
}
}
}
console.log('*** IMPORTATI: ', imported, ' [Prodotti = ' + indprod + '] *** NUOVI: ', newprod, 'AGGIORNATI = ' + updated + ' (su ' + dataObjects.length + ' RECORD)');
return res.status(200).send({ updated, imported, errors });
*/
} else if (cmd === shared_consts.Cmd.MACRO_CATALOGO_JSON) {
try {
const macro = new Macro(idapp, { importadaFDV: true }); // Crea un'istanza della classe Macro
@@ -1598,6 +1411,7 @@ router.post('/import', authenticate, async (req, res) => {
);
// .... ANDARE AVANTI DA QUI... .productInfo.... SISTEMARE!
if (risrecInfo) {
productImported.productInfo = risrecInfo._id;