From e7e3864b4c93f30c44abc6d5dccf8f8833cfd343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20F=C3=BCrderer?= Date: Sat, 30 May 2020 18:25:23 +0200 Subject: [PATCH] Store the cheapest supplier for each offered article in the database --- .../hso/ecommerce/action/cronjob/UpdateOffersAction.java | 6 +++++- .../org/hso/ecommerce/entities/supplier/ArticleOffer.java | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/prototype/src/main/java/org/hso/ecommerce/action/cronjob/UpdateOffersAction.java b/prototype/src/main/java/org/hso/ecommerce/action/cronjob/UpdateOffersAction.java index f095381..e21869e 100644 --- a/prototype/src/main/java/org/hso/ecommerce/action/cronjob/UpdateOffersAction.java +++ b/prototype/src/main/java/org/hso/ecommerce/action/cronjob/UpdateOffersAction.java @@ -30,9 +30,10 @@ public class UpdateOffersAction { public List finish() { HashMap availableOffers = mapOffers(); - // Reset all advertise-flags first. They are set again below. + // Reset all advertise-flags and supplier relations first. They are set again below. for (ArticleOffer offer : availableOffers.values()) { offer.shouldBeAdvertised = false; + offer.cheapestSupplier = null; } for (Entry cheapestOffer : cheapestOffer.entrySet()) { @@ -47,7 +48,10 @@ public class UpdateOffersAction { } Article currentOfferedArticle = cheapestOffer.getValue().apiSupplier.findArticle(manufacturer, articleNumber); + currentOffer.title = currentOfferedArticle.title; currentOffer.vatPercent = currentOfferedArticle.vatPercent; + currentOffer.cheapestSupplier = cheapestOffer.getValue().dbSupplier; + currentOffer.pricePerUnitNet = currentOfferedArticle.pricePerUnitNet; // Set advertise-flag if any supplier wants it to be set if (currentOfferedArticle.shouldBeAdvertised) { diff --git a/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java b/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java index 405fb4a..41296ba 100644 --- a/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java +++ b/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java @@ -28,5 +28,6 @@ public class ArticleOffer { public boolean shouldBeAdvertised; - + @ManyToOne(optional = true) + public Supplier cheapestSupplier; }