- ordinamento tabella titoli
- migliorata la lista degli argomenti
This commit is contained in:
@@ -885,7 +885,7 @@ exports.mssqlmigrateTables = async (req) => {
|
|||||||
if (options?.tutte) {
|
if (options?.tutte) {
|
||||||
// const listaTabelle = ['T_WEB_StatiProdotto'];
|
// 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',
|
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'];
|
'T_WEB_Edizioni', 'T_WEB_Contratti'];
|
||||||
} else {
|
} else {
|
||||||
listaTabelle = ['T_WEB_Articoli', 'T_WEB_ArticoliFatturati'];
|
listaTabelle = ['T_WEB_Articoli', 'T_WEB_ArticoliFatturati'];
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ const catalogo = new Schema(
|
|||||||
printable: { type: Boolean },
|
printable: { type: Boolean },
|
||||||
indebug: { type: Boolean },
|
indebug: { type: Boolean },
|
||||||
maxnumlibri: { type: Number },
|
maxnumlibri: { type: Number },
|
||||||
|
showListaArgomenti: { type: Boolean},
|
||||||
|
|
||||||
first_page: IDimensioni,
|
first_page: IDimensioni,
|
||||||
last_page: IDimensioni,
|
last_page: IDimensioni,
|
||||||
|
|||||||
@@ -241,9 +241,11 @@ module.exports.executeQueryTable = function (idapp, params) {
|
|||||||
|
|
||||||
module.exports.executeQueryPickup = async 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) {
|
if (strfind === '' && !params.filter) {
|
||||||
return [];
|
return [];
|
||||||
@@ -262,7 +264,7 @@ module.exports.executeQueryPickup = async function (idapp, params) {
|
|||||||
$or: [
|
$or: [
|
||||||
{
|
{
|
||||||
'productInfo.name': {
|
'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
|
$options: 'i' // Rende la ricerca case-insensitive
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -275,15 +277,31 @@ module.exports.executeQueryPickup = async function (idapp, params) {
|
|||||||
{
|
{
|
||||||
'productInfo.sku': strfind
|
'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': {
|
'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
|
$options: 'i' // Rende la ricerca case-insensitive
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'productInfo.authors.surname': {
|
'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
|
$options: 'i' // Rende la ricerca case-insensitive
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -337,6 +355,7 @@ module.exports.executeQueryPickup = async function (idapp, params) {
|
|||||||
authors: '$productInfo.authors',
|
authors: '$productInfo.authors',
|
||||||
idStatoProdotto: "$productInfo.idStatoProdotto",
|
idStatoProdotto: "$productInfo.idStatoProdotto",
|
||||||
},
|
},
|
||||||
|
arrvariazioni: "$arrvariazioni",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -31,27 +31,19 @@ module.exports.findAllIdApp = async function () {
|
|||||||
|
|
||||||
const myquery = [
|
const myquery = [
|
||||||
{
|
{
|
||||||
$sort: { DataOra: -1 } // Prima ordina per DataOra in modo decrescente
|
$sort: { IdStatoProdotto: 1, DataOra: -1 } // ordina per ID e DataOra decrescente
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$group: {
|
$group: {
|
||||||
_id: "$IdStatoProdotto", // Raggruppa per IdStatoProdotto
|
_id: "$IdStatoProdotto",
|
||||||
latestRecord: { $first: "$$ROOT" } // Prendi il primo record per ogni gruppo (cioè il più recente)
|
IdStatoProdotto: { $first: "$IdStatoProdotto" },
|
||||||
|
Descrizione: { $first: "$Descrizione" },
|
||||||
|
DataOra: { $first: "$DataOra" },
|
||||||
|
// aggiungi altri campi se servono
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
$lookup: {
|
$sort: { IdStatoProdotto: 1 } // opzionale, per ordinare il risultato
|
||||||
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
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ class Macro {
|
|||||||
constructor(idapp, options) {
|
constructor(idapp, options) {
|
||||||
this.idapp = idapp;
|
this.idapp = idapp;
|
||||||
this.localoptions = options;
|
this.localoptions = options;
|
||||||
}
|
this.recProductExist = false;
|
||||||
|
this.queryprod = null;
|
||||||
|
}
|
||||||
|
|
||||||
async updateLocalDbFromGM_T_Web_Articoli(params) {
|
async updateLocalDbFromGM_T_Web_Articoli(params) {
|
||||||
|
|
||||||
@@ -372,8 +374,10 @@ class Macro {
|
|||||||
elaboraProdotto(recproduct, opt);
|
elaboraProdotto(recproduct, opt);
|
||||||
count++;
|
count++;
|
||||||
|
|
||||||
if (count % 50 === 0)
|
if (count % 50 === 0) {
|
||||||
console.log(' *** IMPORTATI: ' + opt.imported + ' AGGIORNATI = ' + opt.updated + ' (su ' + numrec + ' RECORD)');
|
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) {
|
async importaCatalogo(data) {
|
||||||
let updated = 0,
|
let updated = 0,
|
||||||
imported = 0,
|
imported = 0,
|
||||||
errors = 0;
|
errors = 0,
|
||||||
|
indice = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const ripopola = true; //++MODIFICARE!
|
const ripopola = true; //++MODIFICARE!
|
||||||
@@ -410,14 +415,12 @@ class Macro {
|
|||||||
|
|
||||||
for (const product of dataObjects) {
|
for (const product of dataObjects) {
|
||||||
await this.elaboraProdotto(product, { updated, imported, errors });
|
await this.elaboraProdotto(product, { updated, imported, errors });
|
||||||
|
indice++;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(
|
const percentuale = (indice / dataObjects.length * 100).toFixed(2);
|
||||||
'*** IMPORTATI: ',
|
console.log(`*** RECORD: ${indice} - IMPORTATI: ${imported}, AGGIORNATI = ${updated} (su ${dataObjects.length} RECORD) - Completamento: ${percentuale}%`);
|
||||||
imported,
|
return { updated, imported, errors };
|
||||||
'AGGIORNATI = ' + updated + ' (su ' + dataObjects.length + ' RECORD)'
|
|
||||||
);
|
|
||||||
return { updated, imported, error };
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e.message);
|
console.error(e.message);
|
||||||
throw e;
|
throw e;
|
||||||
@@ -522,6 +525,9 @@ class Macro {
|
|||||||
).lean();
|
).lean();
|
||||||
|
|
||||||
if (risrecInfo) {
|
if (risrecInfo) {
|
||||||
|
product.idProductInfo = risrecInfo._id;
|
||||||
|
this.queryprod = { idProductInfo: product.idProductInfo };
|
||||||
|
|
||||||
await this.aggiornaImmagineSeNecessario(risrecInfo);
|
await this.aggiornaImmagineSeNecessario(risrecInfo);
|
||||||
await this.gestisciGasOrdine(product, risrecInfo);
|
await this.gestisciGasOrdine(product, risrecInfo);
|
||||||
await this.gestisciVariazioni(product, risrecInfo, options);
|
await this.gestisciVariazioni(product, risrecInfo, options);
|
||||||
@@ -547,16 +553,13 @@ class Macro {
|
|||||||
recGas = await Gasordine.findOne({ idapp, name: product.gas_name }).lean();
|
recGas = await Gasordine.findOne({ idapp, name: product.gas_name }).lean();
|
||||||
}
|
}
|
||||||
|
|
||||||
let recProductExist = null;
|
|
||||||
let queryprod = { idProductInfo: product.idProductInfo };
|
|
||||||
|
|
||||||
if (recGas) {
|
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;
|
product.idGasordine = recGas ? recGas._id : null;
|
||||||
|
|
||||||
await Product.findOneAndUpdate({ _id: product._id }, { $set: { idGasordine: product.idGasordine } });
|
await Product.findOneAndUpdate({ _id: product._id }, { $set: { idGasordine: product.idGasordine } });
|
||||||
@@ -894,20 +897,36 @@ class Macro {
|
|||||||
* Gestisce le variazioni del prodotto.
|
* Gestisce le variazioni del prodotto.
|
||||||
*/
|
*/
|
||||||
async gestisciVariazioni(product, risrecInfo, options) {
|
async gestisciVariazioni(product, risrecInfo, options) {
|
||||||
const queryprod = { idProductInfo: risrecInfo._id };
|
const recold = await Product.findOne(this.queryprod).lean();
|
||||||
const recold = await Product.findOne(queryprod).lean();
|
|
||||||
const variazione = this.preparaVariazione(product);
|
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;
|
let risultupdate = null;
|
||||||
|
|
||||||
if (recold) {
|
if (recold) {
|
||||||
const arrvariazioni = this.aggiornaVariazioni(recold.arrvariazioni, variazione);
|
const arrvariazioni = this.aggiornaVariazioni(recold.arrvariazioni, variazione);
|
||||||
risultupdate = await Product.findOneAndUpdate(queryprod, { $set: { arrvariazioni } });
|
risultupdate = await Product.updateOne(this.queryprod, { $set: { arrvariazioni } }, { new: true });
|
||||||
options.updated++;
|
if (risultupdate && risultupdate.modifiedCount > 0) {
|
||||||
} else {
|
options.updated++;
|
||||||
const myproduct = { ...queryprod, arrvariazioni: [variazione] };
|
}
|
||||||
risultupdate = await Product.findOneAndUpdate(queryprod, { $set: myproduct }, { new: true, upsert: true });
|
|
||||||
options.imported++;
|
|
||||||
|
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);
|
// console.log('risultupdate', risultupdate);
|
||||||
|
|||||||
@@ -6158,7 +6158,7 @@ module.exports = {
|
|||||||
|
|
||||||
const aggiornatoimg = await downloader.downloadImage(productInfo.image_link, savePath,
|
const aggiornatoimg = await downloader.downloadImage(productInfo.image_link, savePath,
|
||||||
{
|
{
|
||||||
maxRetries: 3,
|
maxRetries: 1,
|
||||||
initialDelay: 300,
|
initialDelay: 300,
|
||||||
timeout: 15000,
|
timeout: 15000,
|
||||||
}).then(result => {
|
}).then(result => {
|
||||||
@@ -6209,7 +6209,7 @@ module.exports = {
|
|||||||
|
|
||||||
const aggiornatoimg = await downloader.downloadImage(link, savePath,
|
const aggiornatoimg = await downloader.downloadImage(link, savePath,
|
||||||
{
|
{
|
||||||
maxRetries: 3,
|
maxRetries: 1,
|
||||||
initialDelay: 300,
|
initialDelay: 300,
|
||||||
timeout: 15000,
|
timeout: 15000,
|
||||||
nomefileoriginale: true,
|
nomefileoriginale: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user