Small changes according to comments on the pullrequest
This commit is contained in:
parent
e1df56147b
commit
d5540c1979
|
@ -2,7 +2,6 @@ package org.hso.ecommerce.action.cronjob;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.hso.ecommerce.action.cronjob.ReadSupplierDataAction.ArticleIdentifier;
|
import org.hso.ecommerce.action.cronjob.ReadSupplierDataAction.ArticleIdentifier;
|
||||||
import org.hso.ecommerce.action.cronjob.ReadSupplierDataAction.Offer;
|
import org.hso.ecommerce.action.cronjob.ReadSupplierDataAction.Offer;
|
||||||
|
@ -12,7 +11,6 @@ import org.hso.ecommerce.api.data.OrderConfirmation;
|
||||||
import org.hso.ecommerce.entities.shop.Article;
|
import org.hso.ecommerce.entities.shop.Article;
|
||||||
import org.hso.ecommerce.entities.supplier.ArticleOffer;
|
import org.hso.ecommerce.entities.supplier.ArticleOffer;
|
||||||
import org.hso.ecommerce.entities.supplier.SupplierOrder;
|
import org.hso.ecommerce.entities.supplier.SupplierOrder;
|
||||||
import org.hso.ecommerce.entities.warehouse.WarehouseBookingPositionSlotEntry;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -22,21 +20,21 @@ public class ReorderAction {
|
||||||
private Article article;
|
private Article article;
|
||||||
private Integer[] orderedAmounts;
|
private Integer[] orderedAmounts;
|
||||||
private Integer undeliveredReorders;
|
private Integer undeliveredReorders;
|
||||||
private List<WarehouseBookingPositionSlotEntry> inStock;
|
private int amountInStock;
|
||||||
private HashMap<ArticleIdentifier, Offer> cheapestOffer;
|
private HashMap<ArticleIdentifier, Offer> cheapestOffer;
|
||||||
private HashMap<ArticleIdentifier, ArticleOffer> articleOffers;
|
private HashMap<ArticleIdentifier, ArticleOffer> articleOffers;
|
||||||
|
|
||||||
public ReorderAction(
|
public ReorderAction(
|
||||||
Article article, Integer[] orderedAmounts,
|
Article article, Integer[] orderedAmounts,
|
||||||
Integer undeliveredReorders,
|
Integer undeliveredReorders,
|
||||||
List<WarehouseBookingPositionSlotEntry> inStock,
|
int amountInStock,
|
||||||
HashMap<ArticleIdentifier, Offer> cheapestOffer,
|
HashMap<ArticleIdentifier, Offer> cheapestOffer,
|
||||||
HashMap<ArticleIdentifier, ArticleOffer> articleOffers
|
HashMap<ArticleIdentifier, ArticleOffer> articleOffers
|
||||||
) {
|
) {
|
||||||
this.article = article;
|
this.article = article;
|
||||||
this.orderedAmounts = orderedAmounts;
|
this.orderedAmounts = orderedAmounts;
|
||||||
this.undeliveredReorders = undeliveredReorders;
|
this.undeliveredReorders = undeliveredReorders;
|
||||||
this.inStock = inStock;
|
this.amountInStock = amountInStock;
|
||||||
this.cheapestOffer = cheapestOffer;
|
this.cheapestOffer = cheapestOffer;
|
||||||
this.articleOffers = articleOffers;
|
this.articleOffers = articleOffers;
|
||||||
}
|
}
|
||||||
|
@ -45,14 +43,6 @@ public class ReorderAction {
|
||||||
return input == null ? 0 : input;
|
return input == null ? 0 : input;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getAmountInStock() {
|
|
||||||
int sum = 0;
|
|
||||||
for (WarehouseBookingPositionSlotEntry entry : inStock) {
|
|
||||||
sum += entry.newSumSlot;
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int calculateAmountToReorder() {
|
private int calculateAmountToReorder() {
|
||||||
// Algorithm as described in the documentation
|
// Algorithm as described in the documentation
|
||||||
int a = null_to_zero(orderedAmounts[0]);
|
int a = null_to_zero(orderedAmounts[0]);
|
||||||
|
@ -68,11 +58,9 @@ public class ReorderAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = null_to_zero(undeliveredReorders);
|
int i = null_to_zero(undeliveredReorders);
|
||||||
int l = getAmountInStock();
|
int l = amountInStock;
|
||||||
|
|
||||||
int o = n - i - l;
|
return n - i - l;
|
||||||
|
|
||||||
return o;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SupplierOrder finish() {
|
public SupplierOrder finish() {
|
||||||
|
|
|
@ -24,7 +24,6 @@ import org.hso.ecommerce.entities.shop.Article;
|
||||||
import org.hso.ecommerce.entities.supplier.ArticleOffer;
|
import org.hso.ecommerce.entities.supplier.ArticleOffer;
|
||||||
import org.hso.ecommerce.entities.supplier.Supplier;
|
import org.hso.ecommerce.entities.supplier.Supplier;
|
||||||
import org.hso.ecommerce.entities.supplier.SupplierOrder;
|
import org.hso.ecommerce.entities.supplier.SupplierOrder;
|
||||||
import org.hso.ecommerce.entities.warehouse.WarehouseBookingPositionSlotEntry;
|
|
||||||
import org.hso.ecommerce.repos.booking.BookingAccountEntryRepository;
|
import org.hso.ecommerce.repos.booking.BookingAccountEntryRepository;
|
||||||
import org.hso.ecommerce.repos.booking.BookingRepository;
|
import org.hso.ecommerce.repos.booking.BookingRepository;
|
||||||
import org.hso.ecommerce.repos.cronjob.BackgroundJobRepository;
|
import org.hso.ecommerce.repos.cronjob.BackgroundJobRepository;
|
||||||
|
@ -68,8 +67,6 @@ interface ICronjob {
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
class Reorder implements ICronjob {
|
class Reorder implements ICronjob {
|
||||||
private static final Logger log = LoggerFactory.getLogger(Reorder.class);
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Calendar nextExecution(Calendar reference) {
|
public Calendar nextExecution(Calendar reference) {
|
||||||
if (reference.get(Calendar.HOUR_OF_DAY) >= 8) {
|
if (reference.get(Calendar.HOUR_OF_DAY) >= 8) {
|
||||||
|
@ -162,12 +159,12 @@ class Reorder implements ICronjob {
|
||||||
Integer undeliveredReorders = controller.supplierOrderRepository
|
Integer undeliveredReorders = controller.supplierOrderRepository
|
||||||
.countUndeliveredReorders(article.related.articleNumber);
|
.countUndeliveredReorders(article.related.articleNumber);
|
||||||
|
|
||||||
List<WarehouseBookingPositionSlotEntry> inStock = controller.warehouseBookingPositionSlotEntryRepository
|
int amountInStock = controller.warehouseBookingPositionSlotEntryRepository.getArticleStock(article.id)
|
||||||
.getByArticle(article.id);
|
.orElse(0);
|
||||||
|
|
||||||
ReorderAction action = new ReorderAction(article, orderedAmounts,
|
ReorderAction action = new ReorderAction(article, orderedAmounts,
|
||||||
undeliveredReorders,
|
undeliveredReorders,
|
||||||
inStock,
|
amountInStock,
|
||||||
supplierData.cheapestOffer, mappedOffers);
|
supplierData.cheapestOffer, mappedOffers);
|
||||||
SupplierOrder order = action.finish();
|
SupplierOrder order = action.finish();
|
||||||
if (order != null) {
|
if (order != null) {
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class ConfigurationReader {
|
||||||
try {
|
try {
|
||||||
String jsonData = Files.readString(path, StandardCharsets.UTF_8);
|
String jsonData = Files.readString(path, StandardCharsets.UTF_8);
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
Supplier sup = (Supplier)objectMapper.readValue(jsonData, Supplier.class);
|
Supplier sup = objectMapper.readValue(jsonData, Supplier.class);
|
||||||
System.out.println("Loaded " + sup.id);
|
System.out.println("Loaded " + sup.id);
|
||||||
return sup;
|
return sup;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
Reference in New Issue