- ordinamento tabella titoli
- migliorata la lista degli argomenti
This commit is contained in:
@@ -885,7 +885,7 @@ exports.mssqlmigrateTables = async (req) => {
|
||||
if (options?.tutte) {
|
||||
// const listaTabelle = ['T_WEB_StatiProdotto'];
|
||||
listaTabelle = ['T_WEB_TitoliOriginali', 'T_WEB_TestateOrdini', 'T_WEB_Ordini', 'T_WEB_Disponibile', 'T_WOO_TestateOrdini', 'T_WOO_Ordini', 'T_WEB_Articoli',
|
||||
'T_WEB_Argomenti', 'T_WEB_Autori', 'T_WEB_Collane', 'T_WEB_MarchiEditoriali', 'T_WEB_StatiProdotto', 'T_WEB_TipiFormato', 'T_WEB_Tipologie', 'T_WEB_ArticoliFatturati', 'T_WEB_IdInternetFatturati',
|
||||
'T_WEB_Argomenti', 'T_WEB_ClientiInternet', 'T_WOO_Clienti', 'T_WEB_Autori', 'T_WEB_Collane', 'T_WEB_MarchiEditoriali', 'T_WEB_StatiProdotto', 'T_WEB_TipiFormato', 'T_WEB_Tipologie', 'T_WEB_ArticoliFatturati', 'T_WEB_IdInternetFatturati',
|
||||
'T_WEB_Edizioni', 'T_WEB_Contratti'];
|
||||
} else {
|
||||
listaTabelle = ['T_WEB_Articoli', 'T_WEB_ArticoliFatturati'];
|
||||
|
||||
@@ -69,6 +69,7 @@ const catalogo = new Schema(
|
||||
printable: { type: Boolean },
|
||||
indebug: { type: Boolean },
|
||||
maxnumlibri: { type: Number },
|
||||
showListaArgomenti: { type: Boolean},
|
||||
|
||||
first_page: IDimensioni,
|
||||
last_page: IDimensioni,
|
||||
|
||||
@@ -241,9 +241,11 @@ module.exports.executeQueryTable = function (idapp, params) {
|
||||
|
||||
module.exports.executeQueryPickup = async function (idapp, params) {
|
||||
|
||||
let strfind = params.search;
|
||||
let strfind = tools.removeAccents(params.search.trim().toLowerCase());
|
||||
|
||||
strfind = strfind.replace(/[-@]/g, '');
|
||||
// Rimuove le parole "il" e "la" e gli spazi, le @ e i tabulazioni
|
||||
// per non farli influire sulla ricerca
|
||||
strfind = strfind.replace(/\b(il|la|gli|le|lo|un|una)\b/g, '').replace(/[-@\t]/g, '').trim();
|
||||
|
||||
if (strfind === '' && !params.filter) {
|
||||
return [];
|
||||
@@ -262,7 +264,7 @@ module.exports.executeQueryPickup = async function (idapp, params) {
|
||||
$or: [
|
||||
{
|
||||
'productInfo.name': {
|
||||
$regex: `(?i).*${tools.removeAccents(strfind)}.*`, // Cerca una o più parole che sono contenute
|
||||
$regex: `(?i).*${strfind}.*`, // Cerca una o più parole che sono contenute
|
||||
$options: 'i' // Rende la ricerca case-insensitive
|
||||
}
|
||||
},
|
||||
@@ -275,15 +277,31 @@ module.exports.executeQueryPickup = async function (idapp, params) {
|
||||
{
|
||||
'productInfo.sku': strfind
|
||||
},
|
||||
{
|
||||
$and: [
|
||||
{
|
||||
'productInfo.authors.name': {
|
||||
$regex: `(?i).*${strfind.split(' ').shift()}.*`, // Cerca la prima parola
|
||||
$options: 'i' // Rende la ricerca case-insensitive
|
||||
}
|
||||
},
|
||||
{
|
||||
'productInfo.authors.surname': {
|
||||
$regex: `(?i).*${strfind.split(' ').pop()}.*`, // Cerca la seconda parola
|
||||
$options: 'i' // Rende la ricerca case-insensitive
|
||||
}
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
'productInfo.authors.name': {
|
||||
$regex: `(?i).*${tools.removeAccents(strfind)}.*`, // Cerca una o più parole che sono contenute
|
||||
$regex: `(?i).*${strfind}.*`, // Cerca una o più parole che sono contenute
|
||||
$options: 'i' // Rende la ricerca case-insensitive
|
||||
}
|
||||
},
|
||||
{
|
||||
'productInfo.authors.surname': {
|
||||
$regex: `(?i)\\b${tools.removeAccents(strfind)}\\b`, // Cerca parole che iniziano con strfind, e ignora gli accenti
|
||||
$regex: `(?i).*${strfind}.*`, // Cerca una o più parole che sono contenute
|
||||
$options: 'i' // Rende la ricerca case-insensitive
|
||||
}
|
||||
},
|
||||
@@ -337,6 +355,7 @@ module.exports.executeQueryPickup = async function (idapp, params) {
|
||||
authors: '$productInfo.authors',
|
||||
idStatoProdotto: "$productInfo.idStatoProdotto",
|
||||
},
|
||||
arrvariazioni: "$arrvariazioni",
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
@@ -31,27 +31,19 @@ module.exports.findAllIdApp = async function () {
|
||||
|
||||
const myquery = [
|
||||
{
|
||||
$sort: { DataOra: -1 } // Prima ordina per DataOra in modo decrescente
|
||||
$sort: { IdStatoProdotto: 1, DataOra: -1 } // ordina per ID e DataOra decrescente
|
||||
},
|
||||
{
|
||||
$group: {
|
||||
_id: "$IdStatoProdotto", // Raggruppa per IdStatoProdotto
|
||||
latestRecord: { $first: "$$ROOT" } // Prendi il primo record per ogni gruppo (cioè il più recente)
|
||||
_id: "$IdStatoProdotto",
|
||||
IdStatoProdotto: { $first: "$IdStatoProdotto" },
|
||||
Descrizione: { $first: "$Descrizione" },
|
||||
DataOra: { $first: "$DataOra" },
|
||||
// aggiungi altri campi se servono
|
||||
}
|
||||
},
|
||||
{
|
||||
$lookup: {
|
||||
from: 't_web_statiprodottos',
|
||||
localField: '_id', // Usa _id che è l'IdStatoProdotto
|
||||
foreignField: 'IdStatoProdotto',
|
||||
as: 'record'
|
||||
}
|
||||
},
|
||||
{
|
||||
$replaceRoot: { newRoot: { $arrayElemAt: ["$record", 0] } } // Estrai il primo (e unico) record dal risultato di $lookup
|
||||
},
|
||||
{
|
||||
$sort: { IdStatoProdotto: 1 } // Ordina per IdStatoProdotto, se necessario
|
||||
$sort: { IdStatoProdotto: 1 } // opzionale, per ordinare il risultato
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -6158,7 +6158,7 @@ module.exports = {
|
||||
|
||||
const aggiornatoimg = await downloader.downloadImage(productInfo.image_link, savePath,
|
||||
{
|
||||
maxRetries: 3,
|
||||
maxRetries: 1,
|
||||
initialDelay: 300,
|
||||
timeout: 15000,
|
||||
}).then(result => {
|
||||
@@ -6209,7 +6209,7 @@ module.exports = {
|
||||
|
||||
const aggiornatoimg = await downloader.downloadImage(link, savePath,
|
||||
{
|
||||
maxRetries: 3,
|
||||
maxRetries: 1,
|
||||
initialDelay: 300,
|
||||
timeout: 15000,
|
||||
nomefileoriginale: true,
|
||||
|
||||
Reference in New Issue
Block a user