Add bulk pricing retrieval for products in region: Implement getAllProductPricesInRegion method in FalukantService, update FalukantController and router to support new endpoint, and modify BranchView to utilize bulk request for improved performance.

This commit is contained in:
Torsten Schulz (local)
2026-01-28 15:18:26 +01:00
parent 8837494a06
commit 8550bd31d9
4 changed files with 126 additions and 20 deletions

View File

@@ -572,27 +572,42 @@ export default {
return;
}
// Lade Preise für alle Produkte in der aktuellen Region
const prices = {};
for (const product of this.products) {
try {
const { data } = await apiClient.get('/api/falukant/products/price-in-region', {
params: {
productId: product.id,
regionId: this.selectedBranch.regionId
}
});
prices[product.id] = data.price;
} catch (error) {
console.error(`Error loading price for product ${product.id}:`, error);
// Fallback auf Standard-Berechnung
const knowledgeFactor = product.knowledges?.[0]?.knowledge || 0;
const maxPrice = product.sellCost;
const minPrice = maxPrice * 0.6;
prices[product.id] = minPrice + (maxPrice - minPrice) * (knowledgeFactor / 100);
// Lade alle Preise für die Region auf einmal (Bulk-Request)
try {
const startTime = performance.now();
const { data } = await apiClient.get('/api/falukant/products/prices-in-region', {
params: {
regionId: this.selectedBranch.regionId
}
});
const loadTime = performance.now() - startTime;
console.log(`[BranchView] Product prices loaded in ${loadTime.toFixed(2)}ms`);
this.productPricesCache = data.prices || {};
} catch (error) {
console.error(`Error loading product prices for region ${this.selectedBranch.regionId}:`, error);
// Fallback: Lade Preise einzeln (alte Methode)
console.warn('[BranchView] Falling back to individual product price requests');
const prices = {};
for (const product of this.products) {
try {
const { data } = await apiClient.get('/api/falukant/products/price-in-region', {
params: {
productId: product.id,
regionId: this.selectedBranch.regionId
}
});
prices[product.id] = data.price;
} catch (err) {
console.error(`Error loading price for product ${product.id}:`, err);
// Fallback auf Standard-Berechnung
const knowledgeFactor = product.knowledges?.[0]?.knowledge || 0;
const maxPrice = product.sellCost;
const minPrice = maxPrice * 0.6;
prices[product.id] = minPrice + (maxPrice - minPrice) * (knowledgeFactor / 100);
}
}
this.productPricesCache = prices;
}
this.productPricesCache = prices;
},
formatPercent(value) {