- Cataloghi: BestSeller, Novità

This commit is contained in:
Surya Paolo
2024-11-28 16:05:00 +01:00
parent a42c365052
commit 351b81308a
12 changed files with 290 additions and 5 deletions

View File

@@ -64,6 +64,7 @@
"validator": "^13.7.0",
"vhost": "^3.0.2",
"web-push": "^3.6.7",
"xml2js": "^0.6.2",
"xoauth2": "^1.2.0"
},
"devDependencies": {

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 678 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 MiB

View File

@@ -59,6 +59,7 @@ const catalogo = new Schema(
productTypes: [{ type: Number }],
excludeproductTypes: [{ type: Number }],
Editore: [{ type: String }],
sort: { type: Number },
pdf: { type: Boolean },
pdf_filename: { type: String },
printable: { type: Boolean },
@@ -74,7 +75,7 @@ const catalogo = new Schema(
{
scheda: MySchedaSchema,
order: { type: Number },
numSchede: { type: Number },
numPagineMax: { type: Number },
/*arrProdToShow: {
type: [[mongoose.Schema.Types.Mixed]], // Definizione tipo
select: false // Imposta il campo come non selezionabile
@@ -343,7 +344,7 @@ MyElemSchema.statics.findallSchedeTemplate = async function (idapp) {
// Estrai le schede che hanno isTemplate = true
const schedeTemplate = ris.flatMap(elem =>
elem.catalogo && elem.catalogo.arrSchede ? elem.catalogo.arrSchede.filter(scheda => scheda.scheda.isTemplate) : []
elem.catalogo && elem.catalogo.arrSchede ? elem.catalogo.arrSchede.filter(scheda => scheda.scheda?.isTemplate) : []
);
/*

View File

@@ -22,6 +22,9 @@ const ISize = new Schema({
const IFont = new Schema({
name: { type: String },
size: { type: String },
line_height: { type: Number },
posiz_text: { type: Number },
perc_text: { type: String },
});
const IBorders = new Schema({
@@ -50,6 +53,11 @@ const IDimensioni = new Schema({
imgsfondo: IImg,
text_html: IText,
});
const IPagina = new Schema({
dimensioni: IDimensioni,
testo_up: IText,
testo_down: IText,
});
const IAreaDiStampa = new Schema({
margini: IBorders,
@@ -61,6 +69,27 @@ const IAreaDiStampa = new Schema({
scalecanvas: Number,
});
const INovita = new Schema(
{
show: Boolean,
months: Number,
}
);
const IBestseller = new Schema(
{
show: Boolean,
primiNInClassifica: Number,
}
);
const IEtichette = new Schema(
{
novita: INovita,
bestseller: IBestseller,
}
);
const IBarCode = new Schema(
{
show: Boolean,
@@ -72,7 +101,7 @@ const IBarCode = new Schema(
);
const IElementiScheda = new Schema({
pagina: IDimensioni,
pagina: IPagina,
riga: IDimensioni,
scheda_prodotto: IDimensioni,
immagine_prodotto: IDimensioni,
@@ -81,15 +110,15 @@ const IElementiScheda = new Schema({
const scheletroScheda = {
idapp: { type: String },
isTemplate: { type: Boolean },
linkIdTemplate: { type: String },
name: { type: String },
line_height: { type: Number },
numschede_perRiga: { type: Number },
numschede_perCol: { type: Number },
show_separatore: { type: Boolean },
testo_right: IText,
testo_bottom: IText,
posiz_text: { type: Number },
barcode: IBarCode,
etichette: IEtichette,
dimensioni: IElementiScheda,

View File

@@ -129,6 +129,20 @@ const productInfoSchema = new Schema({
productTypes: [{
type: Number,
}],
totaleVenduti: Number,
venditeLastM: Number,
venditeLast6M: Number,
venditeLastY: Number,
venditeLast2Y: Number,
dataUltimoOrdine: Date,
rank3M: Number,
rank6M: Number,
rank1Y: Number,
descrizione_breve_macro: String,
descrizione_completa_macro: String,
sottotitolo: String,
link_macro: String,
});

View File

@@ -307,6 +307,17 @@ function extractNameAndSurnameByComplete(name_complete) {
}
}
function getvalueByJsonText(valore) {
if (valore && valore['#text']) {
if (valore['#text'])
return valore['#text'];
else
return value;
}
return null;
}
router.post('/import', authenticate, async (req, res) => {
try {
@@ -339,6 +350,209 @@ router.post('/import', authenticate, async (req, res) => {
let risrec = await Inventariogm.findOneAndUpdate(queryprod, { $set: inventario }, { new: true, upsert: true });
}
} else if (cmd === shared_consts.Cmd.MACRO_DESCRELINKSITOWEB) {
let updated = 0;
let imported = 0;
let errors = 0;
dataObjects = null;
let myarr = null;
try {
dataObjects = JSON.parse(`[${data.arrdata}]`);
myarr = dataObjects[0].item_list.item;
} catch (e) {
dataObjects = null;
}
if (myarr) {
// Cancella la collection ImportaMacros
await Importamacro.deleteMany({ idapp });
// Aggiungi i record su ImportaMacros
for (const recinv of myarr) {
let isnuovo = false
let setta = false
let recmacro = recinv;
recmacro.idapp = idapp;
if (recmacro.ean && recmacro.ean['#text']) {
recmacro._id = recmacro.ean['#text'];
recmacro.code = recmacro._id;
let queryprod = { idapp, code: recmacro._id };
try {
let risrec = await Importamacro.findOneAndUpdate(queryprod, { $set: recmacro }, { new: true, upsert: true, strict: false });
if (risrec) {
imported++;
// if (imported > 1000)
// break;
console.log('importato ', imported, 'su ', myarr.length);
}
} catch (e) {
console.error(e);
errors++;
}
}
}
}
// Rileggi tutti i record di ImportaMacros
dataObjects = await Importamacro.find({ idapp }).lean();
console.log('*** INIZIO IMPORT PRODOTTI ... ');
let indprod = 0;
let newprod = 0;
let numprod = dataObjects.length;
for (const product of dataObjects) {
let isnuovo = false
let setta = false
let importa = true;
if (!product.code)
importa = false;
if (importa) {
let productInfo = {
idapp: product.idapp,
code: product.code,
}
if (getvalueByJsonText(product.url)) {
productInfo.link_macro = getvalueByJsonText(product.url);
}
if (getvalueByJsonText(product.descrizione)) {
productInfo.descrizione_breve_macro = getvalueByJsonText(product.descrizione);
}
if (getvalueByJsonText(product.descrizione_completa)) {
productInfo.descrizione_completa_macro = getvalueByJsonText(product.descrizione_completa)
}
if (getvalueByJsonText(product.sottotitolo)) {
productInfo.sottotitolo = getvalueByJsonText(product.sottotitolo);
}
// Update ProductInfo
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: true });
indprod++;
console.log(indprod + '/' + numprod);
}
}
} else if (cmd === shared_consts.Cmd.MACRO_RANKING) {
let updated = 0;
let imported = 0;
let errors = 0;
dataObjects = null;
try {
dataObjects = JSON.parse(`[${data.arrdata}]`);
} catch (e) {
dataObjects = null;
}
if (dataObjects && dataObjects[0]) {
// Cancella la collection ImportaMacros
await Importamacro.deleteMany({ idapp });
// Aggiungi i record su ImportaMacros
for (const recinv of dataObjects[0]) {
let isnuovo = false
let setta = false
let recmacro = recinv;
recmacro.idapp = idapp;
recmacro._id = recmacro.id;
delete recmacro.id;
let queryprod = { idapp, _id: recmacro._id };
try {
let risrec = await Importamacro.findOneAndUpdate(queryprod, { $set: recmacro }, { new: true, upsert: true, strict: false });
if (risrec) {
imported++;
}
} catch (e) {
console.error(e);
errors++;
}
}
}
// Rileggi tutti i record di ImportaMacros
dataObjects = await Importamacro.find({ idapp }).lean();
console.log('*** INIZIO IMPORT PRODOTTI ... ');
let indprod = 0;
let newprod = 0;
let numprod = dataObjects.length;
for (const product of dataObjects) {
let isnuovo = false
let setta = false
let importa = true;
if (!product.title || !product.isbn)
importa = false;
if (importa) {
let versGM = product.Versione ? product.Versione : '';
// split versioneGM in array with separated ","
let arrversGM = versGM.split(",").map(x => x.trim());
let productInfo = {
idapp: product.idapp,
code: product.isbn,
id_wp: product._id,
// name: product.title,
totaleVenduti: product.totaleVenduti,
venditeLastM: product.venditeLastM,
venditeLast6M: product.venditeLast6M,
venditeLastY: product.venditeLastY,
venditeLast2Y: product.venditeLast2Y,
dataUltimoOrdine: product.dataUltimoOrdine,
rank3M: product.rank3M,
rank6M: product.rank6M,
rank1Y: product.rank1Y,
}
console.log(indprod + '/' + numprod);
// Update ProductInfo
let risrecInfo = await ProductInfo.findOneAndUpdate({ code: productInfo.code }, { $set: productInfo }, { new: true, upsert: true });
indprod++;
}
}
} else if (cmd === shared_consts.Cmd.MACRO_CATALOGO_JSON) {
let updated = 0;
let imported = 0;
@@ -420,6 +634,7 @@ router.post('/import', authenticate, async (req, res) => {
idapp: product.idapp,
code: product.isbn,
id_wp: product._id,
name: product.title,
description: product.description,
short_descr: product.short_descr,

View File

@@ -1,5 +1,6 @@
const os = require('os');
const fs = require('fs');
const xml2js = require('xml2js');
const path = require('path');
const WebSocket = require('ws');
@@ -5824,6 +5825,20 @@ module.exports = {
}
return myurl;
},
// Funzione per convertire XML in JSON
convertXMLToJSON(xml) {
const parser = new xml2js.Parser();
parser.parseString(xml, (err, result) => {
if (err) {
console.error('Error parsing XML:', err);
} else {
console.log(JSON.stringify(result, null, 2)); // Stampa il risultato in formato JSON
}
});
}
};

View File

@@ -322,6 +322,8 @@ module.exports = {
PRODUCTS_V2: 22,
INVENTARIO: 30,
MACRO_CATALOGO_JSON: 40,
MACRO_RANKING: 50,
MACRO_DESCRELINKSITOWEB: 60,
},
WalletFinalStatusType: {

View File

@@ -11989,6 +11989,14 @@ xml2js@^0.5.0:
sax ">=0.6.0"
xmlbuilder "~11.0.0"
xml2js@^0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.6.2.tgz#dd0b630083aa09c161e25a4d0901e2b2a929b499"
integrity sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA==
dependencies:
sax ">=0.6.0"
xmlbuilder "~11.0.0"
xmlbuilder@~11.0.0:
version "11.0.1"
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-11.0.1.tgz#be9bae1c8a046e76b31127726347d0ad7002beb3"