aggiornamento cataloghi, search
This commit is contained in:
@@ -22,6 +22,7 @@ class Macro {
|
||||
|
||||
let mylog = ''
|
||||
let numrec = 0;
|
||||
|
||||
try {
|
||||
|
||||
const options = {
|
||||
@@ -54,6 +55,7 @@ class Macro {
|
||||
if (options.usaDBGMLocale) {
|
||||
mylog += '*** usaDBGMLocale ***\n';
|
||||
miomatch = { IdStatoProdotto: { $in: [1, 4, 34, 45, 46] } };
|
||||
|
||||
// options.where = { IdStatoProdotto: { $in: [1, 4, 34, 45, 46] } };
|
||||
} else {
|
||||
options.where = `
|
||||
@@ -74,6 +76,17 @@ class Macro {
|
||||
};
|
||||
}
|
||||
|
||||
let filtroTipologia = null;
|
||||
|
||||
// FILTRO PER LIBRI
|
||||
if (true) {
|
||||
filtroTipologia = {
|
||||
$match: {
|
||||
DescrizioneTipologia: 'Libri',
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (options.usaDBGMLocale) {
|
||||
mylog += '*** usaDBGMLocale ***\n';
|
||||
options.aggregation = [
|
||||
@@ -88,19 +101,26 @@ class Macro {
|
||||
{
|
||||
$group: {
|
||||
_id: "$IdArticolo",
|
||||
lastRecord: { $first: "$$ROOT" } // prendi il record più recente
|
||||
lastRecord: { $first: "$$ROOT" }
|
||||
}
|
||||
},
|
||||
{
|
||||
$replaceRoot: { newRoot: "$lastRecord" }
|
||||
},
|
||||
...(miolimit > 0 ? [{ $limit: miolimit }] : []),
|
||||
{
|
||||
$lookup: {
|
||||
from: 't_web_statiprodottos',
|
||||
localField: 'IdStatoProdotto',
|
||||
foreignField: 'IdStatoProdotto',
|
||||
as: 'StatoProdotto',
|
||||
pipeline: [
|
||||
{
|
||||
$sort: { DataOra: -1 },
|
||||
},
|
||||
{
|
||||
$limit: 1
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -111,9 +131,17 @@ class Macro {
|
||||
{
|
||||
$lookup: {
|
||||
from: 't_web_tipologies',
|
||||
localField: 'idTipologia',
|
||||
foreignField: 'idTipologia',
|
||||
localField: 'IdTipologia',
|
||||
foreignField: 'IdTipologia',
|
||||
as: 'DescrizioneTipologia',
|
||||
pipeline: [
|
||||
{
|
||||
$sort: { DataOra: -1 },
|
||||
},
|
||||
{
|
||||
$limit: 1
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -121,6 +149,13 @@ class Macro {
|
||||
DescrizioneTipologia: { $arrayElemAt: ['$DescrizioneTipologia.Descrizione', 0] },
|
||||
}
|
||||
},
|
||||
{
|
||||
$match: {
|
||||
$expr: {
|
||||
$eq: ["$DescrizioneTipologia", "Libri"]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 't_web_tipiformatos',
|
||||
@@ -134,6 +169,7 @@ class Macro {
|
||||
DescrizioneFormato: { $arrayElemAt: ['$DescrizioneFormato.Descrizione', 0] },
|
||||
}
|
||||
},
|
||||
...(filtroTipologia ? [filtroTipologia] : []),
|
||||
{
|
||||
$lookup: {
|
||||
from: 't_web_collanes',
|
||||
@@ -203,6 +239,12 @@ class Macro {
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
$project: {
|
||||
ListaAutoriArray: 0,
|
||||
AutoriDettagliati: 0,
|
||||
}
|
||||
},
|
||||
{
|
||||
$addFields: {
|
||||
ListaArgomentiArray: {
|
||||
@@ -230,7 +272,8 @@ class Macro {
|
||||
}
|
||||
},
|
||||
{ $sort: { DataOra: -1 } },
|
||||
{ $limit: 1 }
|
||||
{ $limit: 1 },
|
||||
{ $project: { Descrizione: 1 } }
|
||||
],
|
||||
as: 'ArgomentiDettagliati'
|
||||
}
|
||||
@@ -253,11 +296,34 @@ class Macro {
|
||||
}
|
||||
}
|
||||
},
|
||||
// Step: Pulisci i campi temporanei
|
||||
{
|
||||
$project: {
|
||||
ArgomentiDettagliati: 0,
|
||||
ListaArgomentiArray: 0,
|
||||
// ArgomentiDettagliati: 0
|
||||
}
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 't_web_disponibiles',
|
||||
let: { codice: { $toString: '$IdArticolo' } },
|
||||
pipeline: [
|
||||
{ $match: { $expr: { $eq: ['$Codice', '$$codice'] } } },
|
||||
{ $sort: { DataOra: -1 } },
|
||||
{ $limit: 1 },
|
||||
{ $project: { QtaDisponibile: 1 } }
|
||||
],
|
||||
as: 'DisponibileDettaglio'
|
||||
}
|
||||
},
|
||||
{
|
||||
$addFields: {
|
||||
QtaDisponibile: { $arrayElemAt: ['$DisponibileDettaglio.QtaDisponibile', 0] }
|
||||
}
|
||||
},
|
||||
// Step: Pulisci i campi temporanei
|
||||
{
|
||||
$project: {
|
||||
DisponibileDettaglio: 0,
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -275,31 +341,40 @@ class Macro {
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
} else {
|
||||
if (!options.caricatutti) {
|
||||
// Singolo
|
||||
options.where = 'T.IdArticolo =' + options.sku + ' AND T.Ean13 = ' + options.isbn;
|
||||
if (options.sku) {
|
||||
options.where = 'T.IdArticolo =' + options.sku + ' AND T.Ean13 = \'' + options.isbn + '\'';
|
||||
} else {
|
||||
options.where = 'T.Ean13 = \'' + options.isbn + '\'';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const recproducts = await getTableContent(options);
|
||||
|
||||
|
||||
if (!tools.isArray(recproducts)) {
|
||||
console.error('Error: ', recproducts);
|
||||
mylog += recproducts + '\n';
|
||||
} else {
|
||||
numrec = recproducts?.length || 0;
|
||||
|
||||
console.log('numrec', numrec);
|
||||
console.log('numrec', numrec);
|
||||
}
|
||||
|
||||
|
||||
let count = 0;
|
||||
if (Array.isArray(recproducts)) {
|
||||
for (const recproduct of recproducts) {
|
||||
if (!options.caricatutti) {
|
||||
await this.elaboraProdotto(recproduct, opt);
|
||||
}
|
||||
// if (!options.caricatutti) {
|
||||
await this.
|
||||
elaboraProdotto(recproduct, opt);
|
||||
count++;
|
||||
|
||||
if (count % 50 === 0)
|
||||
console.log(' *** IMPORTATI: ' + opt.imported + ' AGGIORNATI = ' + opt.updated + ' (su ' + numrec + ' RECORD)');
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -443,8 +518,8 @@ class Macro {
|
||||
const risrecInfo = await ProductInfo.findOneAndUpdate(
|
||||
{ code: productInfo.code },
|
||||
{ $set: productInfo },
|
||||
{ new: true, upsert: true }
|
||||
);
|
||||
{ new: true, upsert: true, returnOriginal: false }
|
||||
).lean();
|
||||
|
||||
if (risrecInfo) {
|
||||
await this.aggiornaImmagineSeNecessario(risrecInfo);
|
||||
@@ -757,12 +832,17 @@ class Macro {
|
||||
const publisher = productInfo.publisher.trim();
|
||||
const recpublisher = await Publisher.findOne({ idapp: this.idapp, name: publisher }).lean();
|
||||
|
||||
let nuovoEditore = null;
|
||||
if (!recpublisher) {
|
||||
const nuovoEditore = new Publisher({ idapp: this.idapp, name: publisher });
|
||||
nuovoEditore = new Publisher({ idapp: this.idapp, name: publisher });
|
||||
await nuovoEditore.save();
|
||||
if (!nuovoEditore._id) {
|
||||
console.error('Errore gestisciEditore: nuovoEditore non ha id');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
productInfo.idPublisher = recpublisher?._id || nuovoEditore._id;
|
||||
if (recpublisher?._id || nuovoEditore?._id)
|
||||
productInfo.idPublisher = recpublisher?._id || nuovoEditore._id;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user