- corretto scheda prodotto, record salvato
This commit is contained in:
@@ -10,7 +10,7 @@ const T_Web_Articoli = require('../models/t_web_articoli');
|
||||
const T_Web_StatiProdotto = require('../models/t_web_statiprodotto');
|
||||
const T_Web_TipiFormato = require('../models/t_web_tipiformato');
|
||||
|
||||
const SERVER_A_URL = process.env.SERVER_A_URL || "http://IP_DI_SERVER_A:3000";
|
||||
const SERVER_A_URL = process.env.SERVER_A_URL || "";
|
||||
const API_KEY = process.env.API_KEY_MSSQL;
|
||||
|
||||
const mongoose = require('mongoose').set('debug', false);
|
||||
@@ -81,15 +81,14 @@ exports.getTableContent = async (options) => {
|
||||
try {
|
||||
// Chiama getTableContent, se ritorna errore hangup, allora attendi 2 secondi e poi richiamala.
|
||||
const tableContent = await this.getTableContentBase(options);
|
||||
console.log(' uscito dalla funzione getTableContentBase ... ')
|
||||
return tableContent;
|
||||
} catch (error) {
|
||||
console.error('Error: ', error);
|
||||
console.error('Error: ', error?.message);
|
||||
if (error.message === 'socket hang up') {
|
||||
console.log('Error: hangup, waiting 2 seconds and retrying...');
|
||||
await new Promise(resolve => setTimeout(resolve, 2000));
|
||||
return await this.getTableContent(options);
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -118,11 +117,14 @@ exports.getModelByNameTable = (nameTable) => {
|
||||
|
||||
exports.getTableContentBase = async (options) => {
|
||||
try {
|
||||
const myurl = SERVER_A_URL + '/query';
|
||||
console.log('getTableContentBase...', myurl)
|
||||
// Verifica se la tabella esiste
|
||||
const checkTableQuery = `SELECT COUNT(*) as tableExists FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '${options.nameTable}'`;
|
||||
const checkResponse = await axios.post(SERVER_A_URL + '/query', { query: checkTableQuery }, {
|
||||
const checkResponse = await axios.post(myurl, { query: checkTableQuery }, {
|
||||
headers: { 'x-api-key': API_KEY }
|
||||
});
|
||||
console.log(' risposta 1...')
|
||||
if (!checkResponse?.data || checkResponse?.data.length === 0 || checkResponse?.data[0].tableExists === 0) {
|
||||
return `La tabella '${options.nameTable}' non esiste.`;
|
||||
}
|
||||
@@ -132,6 +134,7 @@ exports.getTableContentBase = async (options) => {
|
||||
const columnsResponse = await axios.post(SERVER_A_URL + '/query', { query: columnsQuery }, {
|
||||
headers: { 'x-api-key': API_KEY }
|
||||
});
|
||||
console.log(' risposta 2 (schema)...')
|
||||
const tableColumns = columnsResponse.data.map(col => col.COLUMN_NAME);
|
||||
|
||||
// Mappatura per unire i campi (ID e Descrizione)
|
||||
@@ -162,6 +165,7 @@ exports.getTableContentBase = async (options) => {
|
||||
}
|
||||
|
||||
if (options.aggregation) {
|
||||
console.log('options.aggregation', options.aggregation);
|
||||
records = await mymodel.aggregate(options.aggregation);
|
||||
|
||||
} else {
|
||||
@@ -186,10 +190,11 @@ exports.getTableContentBase = async (options) => {
|
||||
pipeline.push({ $project: { [options.fieldGM]: 1 } });
|
||||
}
|
||||
|
||||
console.log(' aggregate pipeline...', pipeline);
|
||||
records = await mymodel.aggregate(pipeline);
|
||||
}
|
||||
|
||||
console.log('results', records[0]);
|
||||
console.log('results', records ? records[0] : ' non ricevuto');
|
||||
|
||||
} else {
|
||||
|
||||
@@ -340,6 +345,7 @@ exports.getTableContentBase = async (options) => {
|
||||
}
|
||||
|
||||
if (!records || records.length === 0) {
|
||||
console.log(`Nessun record trovato per la tabella ${options.nameTable}.`);
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -879,16 +885,24 @@ exports.mssqlmigrateTables = async (req) => {
|
||||
const MssqlMigrator = require('../modules/MssqlMigrator'); // Importa la classe Macro
|
||||
|
||||
try {
|
||||
const options = req.body.options;
|
||||
const options = req.body.mydata.options;
|
||||
let listaTabelle = [];
|
||||
|
||||
|
||||
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_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 if (options?.parte1) {
|
||||
listaTabelle = ['T_WEB_TitoliOriginali', 'T_WEB_TestateOrdini', 'T_WEB_Ordini', 'T_WOO_TestateOrdini', 'T_WOO_Ordini', 'T_WEB_Articoli'];
|
||||
} else if (options?.parte2) {
|
||||
listaTabelle = ['T_WEB_Disponibile', 'T_WEB_Argomenti', 'T_WEB_ClientiInternet', 'T_WOO_Clienti', 'T_WEB_Autori'];
|
||||
} else if (options?.parte3) {
|
||||
listaTabelle = ['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_Ordini'];
|
||||
listaTabelle = ['T_WEB_Articoli'];
|
||||
}
|
||||
|
||||
const migrator = new MssqlMigrator();
|
||||
@@ -908,11 +922,11 @@ exports.updateAllBook = async (idapp, options) => {
|
||||
const macro = new Macro(idapp); // Crea un'istanza della classe Macro
|
||||
options.idapp = idapp;
|
||||
|
||||
return await macro.updateLocalDbFromGM_T_Web_Articoli(options);
|
||||
return await macro.updateLocalDbFromGM_T_Web_Articoli(options);
|
||||
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
throw e;
|
||||
return e.message;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -32,6 +32,9 @@ const CatalogSchema = new Schema({
|
||||
idCollane: [{
|
||||
type: String,
|
||||
}],
|
||||
idTipoFormato: [{
|
||||
type: Number,
|
||||
}],
|
||||
|
||||
argomenti: [{
|
||||
type: String,
|
||||
|
||||
@@ -256,7 +256,7 @@ CitySchema.statics.insertGeojsonToMongoDB = async function (nomefilejson) {
|
||||
|
||||
if (reccity) {
|
||||
const ris = await City.updateOne({ _id: reccity._id }, { $set: { geojson: citta } });
|
||||
if (ris.acknowledged === 1) {
|
||||
if (ris.acknowledged) {
|
||||
inseriti++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ const catalogo = new Schema(
|
||||
argomenti: [{ type: String }],
|
||||
idCollane: [{ type: String }],
|
||||
idTipologia: [{ type: Number }],
|
||||
idTipoFormato: [{ type: Number }],
|
||||
sort_field: { type: String },
|
||||
sort_dir: { type: Number },
|
||||
pdf: { type: Boolean },
|
||||
|
||||
@@ -130,7 +130,8 @@ const scheletroScheda = {
|
||||
|
||||
productTypes: [{ type: Number }],
|
||||
excludeproductTypes: [{ type: Number }],
|
||||
idTipologia: [{ type: Number }],
|
||||
idTipologie: [{ type: Number }],
|
||||
idTipoFormato: [{ type: Number }],
|
||||
editore: [{ type: String }],
|
||||
argomenti: [{ type: String }],
|
||||
idCollane: [{ type: String }],
|
||||
|
||||
@@ -112,6 +112,20 @@ const productSchema = new Schema({
|
||||
eta: {
|
||||
type: String
|
||||
},
|
||||
verificaprod: {
|
||||
esito: {
|
||||
type: Number,
|
||||
},
|
||||
data: {
|
||||
type: Date,
|
||||
},
|
||||
username: {
|
||||
type: String,
|
||||
},
|
||||
note: {
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
}
|
||||
],
|
||||
price_acquistato: {
|
||||
|
||||
@@ -459,12 +459,14 @@ module.exports.updateProductInfoByStats = async function (idapp) {
|
||||
const T_WEB_ArticoliFatturati = require('./t_web_articolifatturati');
|
||||
const T_WEB_Ordini = require('./t_web_ordini');
|
||||
|
||||
const statistics = await T_WEB_ArticoliFatturati.getStatistics();
|
||||
|
||||
mylog = "Inizio Aggiornamento Statistiche... \n";
|
||||
mylogtot += mylog;
|
||||
console.log(mylog);
|
||||
|
||||
let countUpdate = 0;
|
||||
|
||||
countUpdate = await T_WEB_ArticoliFatturati.updateStatisticsFatt('', idapp, true);
|
||||
|
||||
// Itera sui risultati e aggiorna productInfo
|
||||
|
||||
mylog = `Aggiornati ${countUpdate} record di productInfo`;
|
||||
|
||||
@@ -87,13 +87,16 @@ module.exports.updateStatisticsOrders = async function (CodArticoloGM, idapp, up
|
||||
try {
|
||||
let myquery = [];
|
||||
|
||||
// Query di aggregazione per calcolare le statistiche
|
||||
myquery.push(
|
||||
{
|
||||
$match: {
|
||||
CodArticoloGM: CodArticoloGM,
|
||||
},
|
||||
});
|
||||
if (CodArticoloGM) {
|
||||
// Query di aggregazione per calcolare le statistiche
|
||||
myquery.push(
|
||||
{
|
||||
$match: {
|
||||
CodArticoloGM: CodArticoloGM,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
myquery.push(
|
||||
{
|
||||
$group: {
|
||||
|
||||
@@ -26,6 +26,8 @@ class Macro {
|
||||
|
||||
async updateLocalDbFromGM_T_Web_Articoli(params) {
|
||||
|
||||
console.log('INIZIO updateLocalDbFromGM_T_Web_Articoli...', params);
|
||||
|
||||
let mylog = ''
|
||||
let numrec = 0;
|
||||
const options = {
|
||||
@@ -69,11 +71,12 @@ class Macro {
|
||||
{ DescrizioneStatoProdotto: 'Prossima uscita/pubblicazione' },
|
||||
{ DescrizioneStatoProdotto: 'In prevendita' },
|
||||
{ DescrizioneStatoProdotto: 'Vendita sito' },
|
||||
{ DescrizioneStatoProdotto: '2023 in commercio' },
|
||||
]
|
||||
|
||||
{ DescrizioneStatoProdotto: '2023 in commercio' }
|
||||
],
|
||||
Ean13: { $not: /^USATO/ }
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
1 In commercio
|
||||
3 Ristampa
|
||||
@@ -97,30 +100,18 @@ class Macro {
|
||||
} else {
|
||||
options.where = `
|
||||
(DescrizioneStatoProdotto = 'In commercio' OR
|
||||
DescrizioneStatoProdotto = 'Ristampa' OR
|
||||
DescrizioneStatoProdotto = 'Prossima uscita/pubblicazione' OR
|
||||
DescrizioneStatoProdotto = 'In promozione' OR
|
||||
DescrizioneStatoProdotto = 'In fase di valutazione' OR
|
||||
DescrizioneStatoProdotto = 'Titolo in esaurimento (in attesa Nuova Edizione)' OR
|
||||
DescrizioneStatoProdotto = 'Titolo in esaurimento' OR
|
||||
DescrizioneStatoProdotto = 'Titolo in esaurimento (in att N.E Ricopertinata)' OR
|
||||
DescrizioneStatoProdotto = 'Titolo in Esaurimento (disponibile N.E.)' OR
|
||||
DescrizioneStatoProdotto = 'In commercio (digitale)' OR
|
||||
DescrizioneStatoProdotto = 'In prevendita' OR
|
||||
DescrizioneStatoProdotto = 'Vendita sito' OR
|
||||
DescrizioneStatoProdotto = '2023 in commercio' OR
|
||||
DescrizioneStatoProdotto = 'Assoluto NO Reso' OR
|
||||
DescrizioneStatoProdotto = 'Titolo esaurito'
|
||||
DescrizioneStatoProdotto = '2023 in commercio' OR
|
||||
DescrizioneStatoProdotto = 'Vendita sito' OR
|
||||
DescrizioneStatoProdotto = 'In prevendita' OR
|
||||
DescrizioneStatoProdotto = 'Prossima uscita') AND
|
||||
DescrizioneStatoProdotto = 'Prossima uscita')
|
||||
AND
|
||||
(DescrizioneTipologia = 'Libri' OR
|
||||
DescrizioneTipologia = 'Cartolibro' OR
|
||||
DescrizioneTipologia = 'Carte')
|
||||
AND
|
||||
(Ean13 NOT LIKE 'USATO%')
|
||||
`;
|
||||
}
|
||||
|
||||
} else {
|
||||
miolimit = 1;
|
||||
miomatch = {
|
||||
@@ -432,6 +423,7 @@ class Macro {
|
||||
// if (!options.caricatutti) {
|
||||
await this.elaboraProdotto(recproduct, opt);
|
||||
|
||||
|
||||
const sku = recproduct.IdArticolo;
|
||||
|
||||
if (sku) {
|
||||
@@ -775,7 +767,6 @@ class Macro {
|
||||
|
||||
if (productGM.DescrizioneTipologia === 'Usato')
|
||||
vers = shared_consts.PRODUCTTYPE.USATO;
|
||||
|
||||
if (productGM.DescrizioneTipologia === 'Download')
|
||||
vers = shared_consts.PRODUCTTYPE.DOWNLOAD;
|
||||
else if (productGM.DescrizioneTipologia === 'DVD')
|
||||
|
||||
@@ -28,11 +28,16 @@ class MssqlMigrator {
|
||||
async migrateTables(tableNames) {
|
||||
|
||||
try {
|
||||
|
||||
const numtables = tableNames.length;
|
||||
let indtab = 0;
|
||||
let indtabok = 0;
|
||||
const logs = [];
|
||||
for (const tableName of tableNames) {
|
||||
try {
|
||||
|
||||
logs.push(`\n>> Recupero dati da MSSQL per la tabella: ${tableName}`);
|
||||
const percentuale = ((indtab / numtables) * 100).toFixed(2);
|
||||
logs.push(`\n>> Recupero dati da MSSQL per la tabella: ${tableName} - (Completamento: ${percentuale}%)`);
|
||||
console.log(logs[logs.length - 1]);
|
||||
const dataQuery = `SELECT * FROM [${tableName}]`;
|
||||
|
||||
@@ -44,7 +49,7 @@ class MssqlMigrator {
|
||||
{ query: dataQuery },
|
||||
{ headers: { 'x-api-key': this.apiKey } },
|
||||
null,
|
||||
{ timeout: 300000 });
|
||||
{ timeout: 900000 });
|
||||
} catch (error) {
|
||||
console.error('Error: ', error);
|
||||
if (error.message === 'socket hang up') {
|
||||
@@ -56,10 +61,11 @@ class MssqlMigrator {
|
||||
{ query: dataQuery },
|
||||
{ headers: { 'x-api-key': this.apiKey } },
|
||||
null,
|
||||
{ timeout: 300000 });
|
||||
{ timeout: 900000 });
|
||||
|
||||
} else {
|
||||
throw error;
|
||||
console.error('Unexpected error while fetching data from MSSQL:', error.message);
|
||||
// throw error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,14 +107,19 @@ class MssqlMigrator {
|
||||
logs.push(`✅ Inserimento di ${records.length} record nella collezione MongoDB: ${modelName}`);
|
||||
console.log(logs[logs.length - 1]);
|
||||
await DynamicModel.insertMany(records);
|
||||
|
||||
indtabok++;
|
||||
} catch (error) {
|
||||
logs.push(`❌ Errore con la tabella ${tableName}:`, error.message);
|
||||
console.log(logs[logs.length - 1]);
|
||||
}
|
||||
|
||||
indtab++;
|
||||
|
||||
|
||||
}
|
||||
|
||||
logs.push('\n🎉 Tutte le tabelle sono state migrate.');
|
||||
logs.push(`\n🎉 ${indtabok} tabelle su ${numtables} sono state migrate.`);
|
||||
console.log(logs[logs.length - 1]);
|
||||
return logs.join('\n');
|
||||
} catch (error) {
|
||||
|
||||
@@ -518,7 +518,7 @@ router.post('/settable', authenticate, async (req, res) => {
|
||||
})
|
||||
.then(async (risult) => {
|
||||
let rec = null;
|
||||
if (risult && risult.acknowledged === 1) {
|
||||
if (risult && risult.acknowledged) {
|
||||
rec = await mytable.findById(mytablerec._id).lean();
|
||||
} else {
|
||||
rec = risult;
|
||||
|
||||
@@ -99,7 +99,7 @@ router.post('/cmd', authenticate_noerror, async (req, res) => {
|
||||
}
|
||||
|
||||
|
||||
let state = (value && ris && ris.acknowledged === 1) ? 1 : ((!value && ris && ris.acknowledged === 1) ? -1 : 0);
|
||||
let state = (value && ris && ris.acknowledged) ? 1 : ((!value && ris && ris.acknowledged) ? -1 : 0);
|
||||
|
||||
const risreac = await Reaction.calcReactions(idapp, id, tab);
|
||||
if (risreac) {
|
||||
|
||||
@@ -1 +1 @@
|
||||
1.2.33
|
||||
1.2.34
|
||||
Reference in New Issue
Block a user