- Estrazione dei dati da Amazon

- Ciclo di Estrapolazione di tutti i prodotti ed aggiornamento dei campi scraped e scraped_updated
- Creazione file CSV con i campi modificati.
This commit is contained in:
Surya Paolo
2025-05-19 17:33:18 +02:00
parent 859ba022fa
commit 8ff204657e
13 changed files with 2200 additions and 572 deletions

View File

@@ -1,9 +1,18 @@
import { PropType, computed, defineComponent, onMounted, ref, watch } from 'vue';
import {
PropType,
computed,
defineComponent,
onMounted,
ref,
watch,
} from 'vue';
import draggable from 'vuedraggable';
import { tools } from '@tools';
import { useRouter } from 'vue-router'
import { useQuasar } from 'quasar';
import { useRouter } from 'vue-router';
import { useGlobalStore } from '@src/store/globalStore';
import { useProducts } from '@src/store/productStore';
@@ -58,12 +67,14 @@ export default defineComponent({
// Copia locale della lista_prodotti per manipolazione interna
const internalProducts = ref([...(props.lista_prodotti || [])]);
const productStore = useProducts()
const productStore = useProducts();
const $router = useRouter()
const $router = useRouter();
const { t } = useI18n();
const $q = useQuasar();
const globalStore = useGlobalStore();
const products = useProducts();
@@ -117,7 +128,24 @@ export default defineComponent({
// Colonne della tabella
const allColumns_Raccolta = ref([
{ name: 'pos', label: 'Ind', field: 'pos', align: 'left', style: 'width: 50px', notsortable: true },
{
name: 'pos',
label: 'Ind',
field: 'pos',
align: 'left',
style: 'width: 50px',
notsortable: true,
},
{
name: 'edit',
label: 'Mod',
field: '',
align: 'left',
style: 'width: 50px',
edit: true,
noexp: true,
notsortable: true,
},
{
name: 'drag',
label: 'Ord',
@@ -128,16 +156,63 @@ export default defineComponent({
noexp: true,
notsortable: true,
},
{ name: 'image', label: 'Foto', field: 'image', align: 'center', noexp: true, notsortable: true },
{
name: 'image',
label: 'Foto',
field: 'image',
align: 'center',
noexp: true,
notsortable: true,
},
{ name: 'title', label: 'Titolo', field: 'title', align: 'left' },
{ name: 'pdf_generato', label: 'Generato', field: 'pdf_generato', align: 'center' },
{ name: 'data_generato', label: 'Data Generato', field: 'data_generato', align: 'center' },
{ name: 'pdf_generato_stampa', label: 'Generato Stampa', field: 'pdf_generato_stampa', align: 'center' },
{ name: 'data_generato_stampa', label: 'Data Generato Stampa', field: 'data_generato_stampa', align: 'center' },
{ name: 'pdf_online', label: 'PDF OnLine', field: 'pdf_online', align: 'center' },
{ name: 'pdf_online_stampa', label: 'PDF OnLine Stampa', field: 'pdf_online_stampa', align: 'center' },
{ name: 'data_online', label: 'Data Online', field: 'data_online', align: 'center' },
{ name: 'data_online_stampa', label: 'Data Online Stampa', field: 'data_online_stampa', align: 'center' },
{
name: 'pdf_generato',
label: 'Generato',
field: 'pdf_generato',
align: 'center',
},
{
name: 'data_generato',
label: 'Data Generato',
field: 'data_generato',
align: 'center',
},
{
name: 'pdf_generato_stampa',
label: 'Generato Stampa',
field: 'pdf_generato_stampa',
align: 'center',
},
{
name: 'data_generato_stampa',
label: 'Data Generato Stampa',
field: 'data_generato_stampa',
align: 'center',
},
{
name: 'pdf_online',
label: 'PDF OnLine',
field: 'pdf_online',
align: 'center',
},
{
name: 'pdf_online_stampa',
label: 'PDF OnLine Stampa',
field: 'pdf_online_stampa',
align: 'center',
},
{
name: 'data_online',
label: 'Data Online',
field: 'data_online',
align: 'center',
},
{
name: 'data_online_stampa',
label: 'Data Online Stampa',
field: 'data_online_stampa',
align: 'center',
},
{
name: 'actions',
label: 'Azioni',
@@ -150,7 +225,24 @@ export default defineComponent({
]);
const allColumns_Catalog = ref([
{ name: 'pos', label: 'Ind', field: 'pos', align: 'left', style: 'width: 50px', notsortable: true },
{
name: 'pos',
label: 'Ind',
field: 'pos',
align: 'left',
style: 'width: 50px',
notsortable: true,
},
{
name: 'edit',
label: 'Mod',
field: '',
align: 'left',
style: 'width: 50px',
edit: true,
noexp: true,
notsortable: true,
},
{
name: 'drag',
label: 'Ord',
@@ -161,37 +253,156 @@ export default defineComponent({
noexp: true,
notsortable: true,
},
{ name: 'validato', label: 'Val', field: 'validato', align: 'left', style: '' },
{ name: 'scraped', label: 'Estratto', field: 'scraped', align: 'left', style: '' },
{ name: 'image', label: 'Foto', field: 'image', align: 'center', noexp: true, notsortable: true },
{
name: 'validato',
label: 'Val',
field: 'validato',
align: 'left',
style: '',
},
{
name: 'scraped',
label: 'Estratto',
field: 'scraped',
align: 'left',
style: '',
},
{
name: 'scraped_error',
label: 'Err estrazione',
field: 'scraped_error',
align: 'left',
style: '',
},
{
name: 'image',
label: 'Foto',
field: 'image',
align: 'center',
noexp: true,
notsortable: true,
},
{ name: 'name', label: 'Titolo', field: 'name', align: 'left' },
{ name: 'sottotitolo', label: 'Sottotitolo', field: 'sottotitolo', align: 'left' },
{
name: 'sottotitolo',
label: 'Sottotitolo',
field: 'sottotitolo',
align: 'left',
},
{ name: 'authors', label: 'Autore', field: 'authors', align: 'left' },
{ name: 'isbn', label: 'ISBN', field: 'isbn', align: 'left' },
{ name: 'trafiletto', label: 'Sinossi', field: 'trafiletto', align: 'left' },
{ name: 'catprods', label: 'Argomento', field: 'catprods', align: 'left' },
{
name: 'trafiletto',
label: 'Sinossi',
field: 'trafiletto',
align: 'left',
},
{
name: 'catprods',
label: 'Argomento',
field: 'catprods',
align: 'left',
},
{ name: 'edizione', label: 'Edizione', field: 'edizione', align: 'left' },
{ name: 'casaeditrice', label: 'Casa Editrice', field: 'casaeditrice', align: 'left' },
{ name: 'idCollana', label: 'Collana', field: 'idCollana', align: 'left' },
{
name: 'casaeditrice',
label: 'Casa Editrice',
field: 'casaeditrice',
align: 'left',
},
{
name: 'idCollana',
label: 'Collana',
field: 'idCollana',
align: 'left',
},
{ name: 'stato', label: 'Stato', field: 'stato', align: 'left' },
{ name: 'tipologia', label: 'Tipologia', field: 'tipologia', align: 'left' },
{ name: 'tipoformato', label: 'Formato', field: 'tipoformato', align: 'left' },
{
name: 'tipologia',
label: 'Tipologia',
field: 'tipologia',
align: 'left',
},
{
name: 'tipoformato',
label: 'Formato',
field: 'tipoformato',
align: 'left',
},
{ name: 'pagine', label: 'Pag.', field: 'pagine', align: 'right' },
{ name: 'prezzo', label: '€', field: 'prezzo', align: 'right' },
{ name: 'prezzo_sconto', label: '€ (sconto)', field: 'prezzo_sconto', align: 'right' },
{ name: 'date_pub', label: 'Pubblicato', field: 'date_pub', align: 'left' },
{
name: 'prezzo_sconto',
label: '€ (sconto)',
field: 'prezzo_sconto',
align: 'right',
},
{
name: 'date_pub',
label: 'Pubblicato',
field: 'date_pub',
align: 'left',
},
//{ name: "ranking", label: "Class.", field: "ranking", align: "right" },
//{ name: "rank3M", label: "Class. 3M", field: "rank3M", align: "right", visu: costanti.VISUCAMPI.PER_EDITORE },
//{ name: "rank6M", label: "Class. 6M", field: "rank6M", align: "right", visu: costanti.VISUCAMPI.PER_EDITORE },
//{ name: "rank1Y", label: "Class. 1Y", field: "rank1Y", align: "right", visu: costanti.VISUCAMPI.PER_EDITORE },
{ name: 'totVen', label: 'Vend', field: 'totVen', align: 'right', visu: costanti.VISUCAMPI.PER_EDITORE },
{ name: 'vLast6M', label: 'Ven 6M', field: 'vLast6M', align: 'right', visu: costanti.VISUCAMPI.PER_EDITORE },
{ name: 'fatLast6M', label: 'Fat 6M', field: 'fatLast6M', align: 'right', visu: costanti.VISUCAMPI.PER_EDITORE },
{ name: 'fatLast1Y', label: 'Fat 1A', field: 'fatLast1Y', align: 'right', visu: costanti.VISUCAMPI.PER_EDITORE },
{ name: 'fatLast2Y', label: 'Fat 2A', field: 'fatLast2Y', align: 'right', visu: costanti.VISUCAMPI.PER_EDITORE },
{ name: 'totFat', label: 'Fat 5A', field: 'totFat', align: 'right', visu: costanti.VISUCAMPI.PER_EDITORE },
{ name: 'ult_ord', label: 'Ult. Ordine', field: 'ult_ord', align: 'left', visu: costanti.VISUCAMPI.PER_EDITORE },
{ name: 'quantity', label: 'Magazz.', field: 'quantity', align: 'right', visu: costanti.VISUCAMPI.PER_EDITORE },
{
name: 'totVen',
label: 'Vend',
field: 'totVen',
align: 'right',
visu: costanti.VISUCAMPI.PER_EDITORE,
},
{
name: 'vLast6M',
label: 'Ven 6M',
field: 'vLast6M',
align: 'right',
visu: costanti.VISUCAMPI.PER_EDITORE,
},
{
name: 'fatLast6M',
label: 'Fat 6M',
field: 'fatLast6M',
align: 'right',
visu: costanti.VISUCAMPI.PER_EDITORE,
},
{
name: 'fatLast1Y',
label: 'Fat 1A',
field: 'fatLast1Y',
align: 'right',
visu: costanti.VISUCAMPI.PER_EDITORE,
},
{
name: 'fatLast2Y',
label: 'Fat 2A',
field: 'fatLast2Y',
align: 'right',
visu: costanti.VISUCAMPI.PER_EDITORE,
},
{
name: 'totFat',
label: 'Fat 5A',
field: 'totFat',
align: 'right',
visu: costanti.VISUCAMPI.PER_EDITORE,
},
{
name: 'ult_ord',
label: 'Ult. Ordine',
field: 'ult_ord',
align: 'left',
visu: costanti.VISUCAMPI.PER_EDITORE,
},
{
name: 'quantity',
label: 'Magazz.',
field: 'quantity',
align: 'right',
visu: costanti.VISUCAMPI.PER_EDITORE,
},
{
name: 'actions',
label: 'Azioni',
@@ -210,7 +421,9 @@ export default defineComponent({
if (props.table === shared_consts.TABLES_CATALOG) {
selectedColumns.value = selectedColumns_Catalogs.value;
} else {
selectedColumns.value = tools.isUtente() ? selectedColumns_Utenti.value : selectedColumns_Editori.value;
selectedColumns.value = tools.isUtente()
? selectedColumns_Utenti.value
: selectedColumns_Editori.value;
}
addstr.value = tools.addstrCookie(props.table);
@@ -295,7 +508,10 @@ export default defineComponent({
switch (field.field) {
case 'image':
return element.productInfo?.imagefile
? tools.getFullFileNameByImageFile('productInfos', element.productInfo?.imagefile)
? tools.getFullFileNameByImageFile(
'productInfos',
element.productInfo?.imagefile
)
: element.productInfo?.image_link;
case 'name':
@@ -318,12 +534,19 @@ export default defineComponent({
return element.scraped === true
? '<span class="text-bold">SI</span>'
: '';
case 'scraped_error':
return element.scraped_error === true
? '<span class="text-bold text-red">ERR</span>'
: '';
case 'isbn':
return element.isbn;
case 'trafiletto':
return element.productInfo?.descr_trafiletto_catalogo?.length > 100 ? 'SI' : 'NO';
return element.productInfo?.descr_trafiletto_catalogo?.length >
100
? 'SI'
: 'NO';
case 'catprods':
return tools.formatCatProds(element.productInfo?.catprods);
@@ -332,19 +555,27 @@ export default defineComponent({
return element.arrvariazioni?.[0]?.edizione;
case 'casaeditrice':
return products.getCasaEditriceByIdPublisher(element.productInfo?.idPublisher);
return products.getCasaEditriceByIdPublisher(
element.productInfo?.idPublisher
);
case 'idCollana':
return tools.formatCollane(element.productInfo?.idCollana);
case 'stato':
return products.getDescrStatiProdottoByIdStatoProdotto(element.productInfo?.idStatoProdotto || '');
return products.getDescrStatiProdottoByIdStatoProdotto(
element.productInfo?.idStatoProdotto || ''
);
case 'tipologia':
return products.getDescrByIdTipologia(element.arrvariazioni?.[0]?.idTipologia || '');
return products.getDescrByIdTipologia(
element.arrvariazioni?.[0]?.idTipologia || ''
);
case 'tipoformato':
return products.getDescrByIdTipoFormato(element.arrvariazioni?.[0]?.idTipoFormato || '');
return products.getDescrByIdTipoFormato(
element.arrvariazioni?.[0]?.idTipoFormato || ''
);
case 'date_pub':
return tools.getstrDate(element.productInfo?.date_pub);
@@ -353,7 +584,9 @@ export default defineComponent({
return element.price ? '€ ' + element.price.toFixed(2) : '';
case 'prezzo_sconto':
return element.sale_price ? '€ ' + element.sale_price.toFixed(2) : '';
return element.sale_price
? '€ ' + element.sale_price.toFixed(2)
: '';
case 'rank3M':
return element.productInfo?.rank3M;
@@ -386,7 +619,10 @@ export default defineComponent({
return tools.getstrDate(element.productInfo?.dataUltimoOrdine);
case 'quantity':
if (tools.isUtente()) return tools.getDescrQuantitàByQuantity(element.arrvariazioni?.[0]?.quantita);
if (tools.isUtente())
return tools.getDescrQuantitàByQuantity(
element.arrvariazioni?.[0]?.quantita
);
else return element.arrvariazioni?.[0]?.quantita;
default:
@@ -403,7 +639,9 @@ export default defineComponent({
if (!element) return '';
switch (field.field) {
case 'trafiletto':
return element.productInfo?.descr_trafiletto_catalogo?.length > 100 ? 'text-green' : 'text-red';
return element.productInfo?.descr_trafiletto_catalogo?.length > 100
? 'text-green'
: 'text-red';
case 'stato':
if (products.isProssimaUscita(element.productInfo)) {
@@ -420,7 +658,9 @@ export default defineComponent({
case 'validato':
if (element.validaprod?.esito === costanti.VALIDATO.SI) {
return 'bg-green';
} else if (element.validaprod?.esito === costanti.VALIDATO.TO_RESOLV) {
} else if (
element.validaprod?.esito === costanti.VALIDATO.TO_RESOLV
) {
return 'bg-red';
} else {
return 'bg-grey';
@@ -514,6 +754,7 @@ export default defineComponent({
: [
'pos',
'drag',
'edit',
'validato',
'image',
'name',
@@ -547,7 +788,9 @@ export default defineComponent({
]
);
const selectedColumns_Catalogs = ref(
cookieValue.length > 0 ? cookieValue : ['pos', 'drag', 'image', 'title', 'pdf_generato', 'actions']
cookieValue.length > 0
? cookieValue
: ['pos', 'drag', 'image', 'title', 'pdf_generato', 'actions']
);
const selectedColumns = ref([]);
@@ -564,7 +807,8 @@ export default defineComponent({
}
const ok =
allColumns.value.some((col) => col.name === column) &&
(!props.optcatalogo.showListaArgomenti || (props.optcatalogo.showListaArgomenti && !column.edit));
(!props.optcatalogo.showListaArgomenti ||
(props.optcatalogo.showListaArgomenti && !column.edit));
return selectedColumns.value.includes(column) && ok;
};
@@ -575,13 +819,32 @@ export default defineComponent({
// Funzione per eliminare un prodotto
const removeProduct = (product) => {
internalProducts.value = internalProducts.value.filter((p: any) => p._id !== product._id);
emit('update:lista_prodotti', internalProducts.value); // Notifica il parent del cambiamento
return $q
.dialog({
message: t('scheda.removeProduct'),
html: true,
ok: {
label: t('dialog.yes'),
push: false,
},
title: '',
cancel: true,
persistent: false,
})
.onOk(() => {
internalProducts.value = internalProducts.value.filter(
(p: any) => p._id !== product._id
);
emit('update:lista_prodotti', internalProducts.value); // Notifica il parent del cambiamento
});
};
// 8. Salvataggio delle colonne selezionate in un cookie
const saveSelectedColumns = () => {
tools.setCookie(addstr.value + 'selColCat_2', JSON.stringify(selectedColumns.value));
tools.setCookie(
addstr.value + 'selColCat_2',
JSON.stringify(selectedColumns.value)
);
};
// 9. Watcher per salvare automaticamente le preferenze quando cambiano
@@ -688,11 +951,12 @@ export default defineComponent({
loading.value = true;
updatefromgm.value = true;
field_updated_fromGM.value = '';
field_updated_fromGM.value = await globalStore.getGM_FieldOf_T_Web_Articoli(
selProd.value.productInfo.sku!,
field,
shared_consts.CmdQueryMs.GET
);
field_updated_fromGM.value =
await globalStore.getGM_FieldOf_T_Web_Articoli(
selProd.value.productInfo.sku!,
field,
shared_consts.CmdQueryMs.GET
);
loading.value = false;
}
}
@@ -707,32 +971,40 @@ export default defineComponent({
sortAttribute.value = sortAttributeToSort;
sortDirection.value = 1;
}
internalProducts.value = internalProducts.value.sort((a: any, b: any) => {
const aVal = getFieldValue(a, { field: sortAttributeToSort });
const bVal = getFieldValue(b, { field: sortAttributeToSort });
if (aVal instanceof Date && bVal instanceof Date) {
return sortDirection.value === 1 ? aVal.getTime() - bVal.getTime() : bVal.getTime() - aVal.getTime();
internalProducts.value = internalProducts.value.sort(
(a: any, b: any) => {
const aVal = getFieldValue(a, { field: sortAttributeToSort });
const bVal = getFieldValue(b, { field: sortAttributeToSort });
if (aVal instanceof Date && bVal instanceof Date) {
return sortDirection.value === 1
? aVal.getTime() - bVal.getTime()
: bVal.getTime() - aVal.getTime();
}
if (
typeof aVal === 'string' &&
typeof bVal === 'string' &&
aVal.match(/^\d{1,2}\/\d{1,2}\/\d{4}$/) &&
bVal.match(/^\d{1,2}\/\d{1,2}\/\d{4}$/)
) {
const aDate = new Date(aVal.split('/').reverse().join('-'));
const bDate = new Date(bVal.split('/').reverse().join('-'));
return sortDirection.value === 1
? aDate.getTime() - bDate.getTime()
: bDate.getTime() - aDate.getTime();
}
if (typeof aVal === 'number' && typeof bVal === 'number') {
return sortDirection.value === 1 ? aVal - bVal : bVal - aVal;
}
if (typeof aVal === 'string' && typeof bVal === 'string') {
return sortDirection.value === 1
? aVal.localeCompare(bVal)
: bVal.localeCompare(aVal);
}
return sortDirection.value === 1
? String(aVal).localeCompare(String(bVal))
: String(bVal).localeCompare(String(aVal));
}
if (
typeof aVal === 'string' &&
typeof bVal === 'string' &&
aVal.match(/^\d{1,2}\/\d{1,2}\/\d{4}$/) &&
bVal.match(/^\d{1,2}\/\d{1,2}\/\d{4}$/)
) {
const aDate = new Date(aVal.split('/').reverse().join('-'));
const bDate = new Date(bVal.split('/').reverse().join('-'));
return sortDirection.value === 1 ? aDate.getTime() - bDate.getTime() : bDate.getTime() - aDate.getTime();
}
if (typeof aVal === 'number' && typeof bVal === 'number') {
return sortDirection.value === 1 ? aVal - bVal : bVal - aVal;
}
if (typeof aVal === 'string' && typeof bVal === 'string') {
return sortDirection.value === 1 ? aVal.localeCompare(bVal) : bVal.localeCompare(aVal);
}
return sortDirection.value === 1
? String(aVal).localeCompare(String(bVal))
: String(bVal).localeCompare(String(aVal));
});
);
}
};
@@ -772,7 +1044,9 @@ export default defineComponent({
.join('|'),
...internalProducts.value.map((product: any) => {
return selectedColumns.value
.filter((col) => !allColumns.value.find((c) => c.name === col)?.noexp)
.filter(
(col) => !allColumns.value.find((c) => c.name === col)?.noexp
)
.map((col: string) => {
const field = { field: col };
return field.field === 'pos'
@@ -783,7 +1057,8 @@ export default defineComponent({
}),
].join('\r\n');
const filename = 'prodotti_' + new Date().toISOString().slice(0, 10) + '.csv';
const filename =
'prodotti_' + new Date().toISOString().slice(0, 10) + '.csv';
const blob = new Blob([csvContent], { type: 'text/csv;charset=utf-8;' });
const link = document.createElement('a');
const url = URL.createObjectURL(blob);
@@ -798,7 +1073,10 @@ export default defineComponent({
}
function isSortable(field: string): boolean {
return allColumns && !allColumns.value.find((col) => col.name === field)?.notsortable;
return (
allColumns &&
!allColumns.value.find((col) => col.name === field)?.notsortable
);
}
function getImageByElement(element) {