- Cataloghi: parte finale... prima bozza 9 dic

This commit is contained in:
Surya Paolo
2024-12-09 12:32:09 +01:00
parent 8803190313
commit 14bca3e282
5 changed files with 78 additions and 24 deletions

View File

@@ -63,6 +63,7 @@ const catalogo = new Schema(
pdf: { type: Boolean },
pdf_filename: { type: String },
printable: { type: Boolean },
indebug: { type: Boolean },
first_page: IDimensioni,
last_page: IDimensioni,

View File

@@ -66,6 +66,7 @@ const IAreaDiStampa = new Schema({
orientation: String,
compress: Boolean,
scale: Number,
scale_printable: Number,
scalecanvas: Number,
});

View File

@@ -221,6 +221,7 @@ async function convertPDF_PdfLib(inputFile, outputFile, width, height, compressi
console.log(`PDF convertito e salvato come '${outputFile}'`);
const comprimi = false;
const mostrainfo = true;
let fileout = outputFile;
@@ -229,7 +230,9 @@ async function convertPDF_PdfLib(inputFile, outputFile, width, height, compressi
await compressPdf(outputFile, compressed, compressione);
extractPdfInfo(compressed);
if (mostrainfo)
extractPdfInfo(compressed);
fileout = compressed;
}
@@ -262,10 +265,6 @@ router.post('/convert-pdf', upload.single('pdf'), async (req, res) => {
await fs.promises.mkdir(DIR_PDF_IN, { recursive: true });
await fs.promises.mkdir(DIR_PDF_OUT, { recursive: true });
// console.log('File:', req.file);
// console.log('Width:', width);
// console.log('Height:', height);
// Converti il PDF
// await convertPDF_GS(inputFile, outputFile, width, height);
const fileout = await convertPDF_PdfLib(inputFile, outputFile, width, height, compressione);
@@ -713,17 +712,29 @@ router.post('/import', authenticate, async (req, res) => {
code: product.code,
}
const myproductInfo = await ProductInfo.findOne({ code: productInfo.code });
// IMPOSTA I VALORI SOLO SE NON ESISTONO ! ALTRIMENTI LASCIA QUELLI GIA' IMPORTATI (O MODIFICATI)
if (getvalueByJsonText(product.url)) {
productInfo.link_macro = getvalueByJsonText(product.url);
if (!myproductInfo.link_macro)
productInfo.link_macro = getvalueByJsonText(product.url);
}
if (getvalueByJsonText(product.descrizione)) {
productInfo.descrizione_breve_macro = getvalueByJsonText(product.descrizione);
if (!myproductInfo.descrizione_completa_macro)
productInfo.descrizione_breve_macro = getvalueByJsonText(product.descrizione);
}
if (getvalueByJsonText(product.descrizione_completa)) {
productInfo.descrizione_completa_macro = getvalueByJsonText(product.descrizione_completa)
if (!myproductInfo.descrizione_completa_macro)
productInfo.descrizione_completa_macro = getvalueByJsonText(product.descrizione_completa)
}
if (getvalueByJsonText(product.sottotitolo)) {
productInfo.sottotitolo = getvalueByJsonText(product.sottotitolo);
if (!myproductInfo.sottotitolo)
productInfo.sottotitolo = getvalueByJsonText(product.sottotitolo);
}
if (getvalueByJsonText(product.titolo)) {
if (!myproductInfo.name)
productInfo.name = getvalueByJsonText(product.titolo);
}
const pagine = getvalueByJsonText(product.pagine);
@@ -770,12 +781,15 @@ router.post('/import', authenticate, async (req, res) => {
dataObjects = null;
}
if (dataObjects && dataObjects[0]) {
// Cancella la collection ImportaMacros
await ImportaIsbn.deleteMany({ idapp });
const numtot = dataObjects[0].length
console.log('Numero di RECORD da Importare = ', numtot);
// Aggiungi i record su ImportaMacros
for (const recinv of dataObjects[0]) {
let recmacro = recinv;
@@ -783,7 +797,7 @@ router.post('/import', authenticate, async (req, res) => {
recmacro.idapp = idapp;
//recmacro._id = recmacro.id;
recmacro.sku = recmacro.idArticolo;
recmacro.sku = recmacro.IdArticolo;
if (recmacro.DataPubblicazione) {
@@ -795,7 +809,8 @@ router.post('/import', authenticate, async (req, res) => {
let risrec = await ImportaIsbn.findOneAndUpdate(queryprod, { $set: recmacro }, { new: true, upsert: true, strict: false });
if (risrec) {
imported++;
console.log('Importati dir TEMPORANEA ... ', imported + '/' + numtot);
if ((imported % 10) === 0)
console.log('Importati dir TEMPORANEA ... ', imported + '/' + numtot);
}
} catch (e) {
@@ -810,12 +825,30 @@ router.post('/import', authenticate, async (req, res) => {
// Rileggi tutti i record di ImportaIsbn
dataObjects = await ImportaIsbn.find({ idapp }).lean();
console.log('*** INIZIO IMPORT RANKING ... ');
let numprod = dataObjects.length;
console.log('*** INIZIO IMPORT RANKING ... NUMRECORD = ', numprod);
let indprod = 0;
let newprod = 0;
let numprod = dataObjects.length;
if (numprod) {
// Rimuove prima tutti i valori precedenti
let risupdate = await ProductInfo.updateMany({ idapp }, {
$set: {
totaleVenduti: 0,
venditeLastM: 0,
venditeLast6M: 0,
venditeLastY: 0,
venditeLast2Y: 0,
rank3M: 0,
rank6M: 0,
rank1Y: 0,
}
});
}
imported = 0;
@@ -843,14 +876,14 @@ router.post('/import', authenticate, async (req, res) => {
// id_wp: product._id,
// name: product.title,
totaleVenduti: product.totaleaVenduti,
venditeLastM: product.venditeLastM,
venditeLast6M: product.venditeLast6M,
venditeLastY: product.venditeLastY,
venditeLast2Y: product.venditeLast2Y,
rank3M: product.rank3M,
rank6M: product.rank6M,
rank1Y: product.rank1Y,
totaleVenduti: product.totaleVenduti || 0,
venditeLastM: product.venditeLastM || 0,
venditeLast6M: product.venditeLast6M || 0,
venditeLastY: product.venditeLastY || 0,
venditeLast2Y: product.venditeLast2Y || 0,
rank3M: product.rank3M || 0,
rank6M: product.rank6M || 0,
rank1Y: product.rank1Y || 0,
}
if (product.DataPubblicazione) {
@@ -862,11 +895,13 @@ router.post('/import', authenticate, async (req, res) => {
productInfo.dataUltimoOrdine = new Date(product.dataUltimoOrdine);
}
// Update ProductInfo
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: true });
if (risrecInfo) {
imported++;
console.log('Importati... ', imported + '/' + numprod);
if (imported % 10 === 0)
console.log('Importati... ', imported + '/' + numprod);
}
}
}

View File

@@ -841,7 +841,7 @@ async function duplicatePage(pageId, newpath) {
_id: new mongoose.Types.ObjectId(), // Genera un nuovo ID
// modifiche ai campi se necessario, per esempio:
path: newpath,
title: newpath,
title: newpath,
date_updated: new Date()
});
@@ -935,7 +935,7 @@ router.patch('/chval', authenticate, async (req, res) => {
try {
const mytable = globalTables.getTableByTableName(mydata.table);
const fieldsvalue = mydata.fieldsvalue;
let fieldsvalue = mydata.fieldsvalue;
const unset = mydata.unset;
const { Account } = require('../models/account');
@@ -1032,6 +1032,21 @@ router.patch('/chval', authenticate, async (req, res) => {
precRec = await mytable.findById(id);
}
if (mydata.table === 'arrvariazioni') {
let chiave = null;
let valore = null;
for (const [key, value] of Object.entries(fieldsvalue)) {
chiave = key;
valore = value;
}
if (chiave) {
// Costruiamo la stringa di assegnazione dinamica
fieldsvalue = { [`arrvariazioni.0.${chiave}`]: valore };
}
}
return await mytable.findByIdAndUpdate(id, { $set: fieldsvalue }, { new: true }).
then(async (rec) => {
// tools.mylogshow(' REC TO MODIFY: ', rec);

View File

@@ -112,6 +112,8 @@ module.exports = {
mytable = Operator;
else if (tablename === 'products')
mytable = Product;
else if (tablename === 'arrvariazioni')
mytable = Product;
else if (tablename === 'productinfos')
mytable = ProductInfo;
else if (tablename === 'storehouses')