Merge branch 'master' into feature/employee_login_defaults
This commit is contained in:
commit
fb222c9213
@ -1,8 +1,5 @@
|
|||||||
package org.hso.ecommerce.action.cronjob;
|
package org.hso.ecommerce.action.cronjob;
|
||||||
|
|
||||||
import java.sql.Timestamp;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
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;
|
||||||
import org.hso.ecommerce.api.SupplierService;
|
import org.hso.ecommerce.api.SupplierService;
|
||||||
@ -14,6 +11,9 @@ import org.hso.ecommerce.entities.supplier.SupplierOrder;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class ReorderAction {
|
public class ReorderAction {
|
||||||
private static final Logger log = LoggerFactory.getLogger(ReorderAction.class);
|
private static final Logger log = LoggerFactory.getLogger(ReorderAction.class);
|
||||||
|
|
||||||
@ -102,6 +102,10 @@ public class ReorderAction {
|
|||||||
createdOrder.numberOfUnits = confirm.quantity;
|
createdOrder.numberOfUnits = confirm.quantity;
|
||||||
createdOrder.pricePerUnitNetCent = confirm.pricePerUnitNetCent;
|
createdOrder.pricePerUnitNetCent = confirm.pricePerUnitNetCent;
|
||||||
createdOrder.totalPriceNet = confirm.totalPriceNetCharged;
|
createdOrder.totalPriceNet = confirm.totalPriceNetCharged;
|
||||||
|
createdOrder.carrier = confirm.carrier;
|
||||||
|
createdOrder.trackingId = confirm.trackingId;
|
||||||
|
createdOrder.estimatedArrival = Timestamp.valueOf(confirm.estimatedArrival);
|
||||||
|
|
||||||
return createdOrder;
|
return createdOrder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,13 @@ import org.hso.ecommerce.api.RestServiceForDelivery;
|
|||||||
import org.hso.ecommerce.entities.shop.CustomerOrder;
|
import org.hso.ecommerce.entities.shop.CustomerOrder;
|
||||||
import org.springframework.web.client.ResourceAccessException;
|
import org.springframework.web.client.ResourceAccessException;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
public class EnableTrackingAction {
|
public class EnableTrackingAction {
|
||||||
|
|
||||||
public static void addTrackingInfo(CustomerOrder customerOrder) throws ResourceAccessException {
|
public static void addTrackingInfo(RestServiceForDelivery deliveryService, CustomerOrder customerOrder) throws ResourceAccessException {
|
||||||
|
customerOrder.inDeliverySince = new Timestamp(new Date().getTime());
|
||||||
customerOrder.trackingId = new RestServiceForDelivery().getDeliveryID(customerOrder);
|
customerOrder.trackingId = deliveryService.getDeliveryID(customerOrder);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package org.hso.ecommerce.api.data;
|
package org.hso.ecommerce.api.data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
public class OrderConfirmation {
|
public class OrderConfirmation {
|
||||||
public String manufacturer;
|
public String manufacturer;
|
||||||
public String articleNumber;
|
public String articleNumber;
|
||||||
@ -9,4 +11,8 @@ public class OrderConfirmation {
|
|||||||
public int pricePerUnitNetCent;
|
public int pricePerUnitNetCent;
|
||||||
public int discountNetCent;
|
public int discountNetCent;
|
||||||
public int totalPriceNetCharged;
|
public int totalPriceNetCharged;
|
||||||
|
|
||||||
|
public String carrier;
|
||||||
|
public String trackingId;
|
||||||
|
public LocalDateTime estimatedArrival;
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
package org.hso.ecommerce.controller;
|
package org.hso.ecommerce.controller;
|
||||||
|
|
||||||
|
import org.hso.ecommerce.entities.shop.ShoppingCart;
|
||||||
import org.hso.ecommerce.entities.user.User;
|
import org.hso.ecommerce.entities.user.User;
|
||||||
import org.hso.ecommerce.repos.user.UserRepository;
|
import org.hso.ecommerce.repos.user.UserRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
@ -63,8 +61,10 @@ public class LoginController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("logout")
|
@PostMapping("logout")
|
||||||
public String logoutPost(HttpServletResponse response, HttpSession session) {
|
public String logoutPost(@RequestAttribute(value = "shoppingCart") ShoppingCart shoppingCart, HttpSession session) {
|
||||||
session.removeAttribute("userId");
|
session.removeAttribute("userId");
|
||||||
|
shoppingCart.clear();
|
||||||
|
|
||||||
return "redirect:/";
|
return "redirect:/";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package org.hso.ecommerce.controller;
|
|||||||
import org.hso.ecommerce.action.user.CreateDeliveryData;
|
import org.hso.ecommerce.action.user.CreateDeliveryData;
|
||||||
import org.hso.ecommerce.action.user.UpdateUserSettingsAction;
|
import org.hso.ecommerce.action.user.UpdateUserSettingsAction;
|
||||||
import org.hso.ecommerce.api.RestServiceForDelivery;
|
import org.hso.ecommerce.api.RestServiceForDelivery;
|
||||||
|
import org.hso.ecommerce.app.config.AppSettings;
|
||||||
import org.hso.ecommerce.entities.shop.CustomerOrder;
|
import org.hso.ecommerce.entities.shop.CustomerOrder;
|
||||||
import org.hso.ecommerce.entities.user.User;
|
import org.hso.ecommerce.entities.user.User;
|
||||||
import org.hso.ecommerce.repos.shop.CustomerOrderRepository;
|
import org.hso.ecommerce.repos.shop.CustomerOrderRepository;
|
||||||
@ -31,6 +32,9 @@ public class UserController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private final RestServiceForDelivery restServiceForDelivery = null;
|
private final RestServiceForDelivery restServiceForDelivery = null;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private final AppSettings appSettings = null;
|
||||||
|
|
||||||
@GetMapping("/")
|
@GetMapping("/")
|
||||||
public String user() {
|
public String user() {
|
||||||
return "redirect:/user/settings";
|
return "redirect:/user/settings";
|
||||||
@ -58,6 +62,7 @@ public class UserController {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
model.addAttribute("orderDeliveryDataMap", customerOrderDeliveryDataMap);
|
model.addAttribute("orderDeliveryDataMap", customerOrderDeliveryDataMap);
|
||||||
|
model.addAttribute("deliveryService", appSettings.getParcelServiceName());
|
||||||
|
|
||||||
return "user/orders/index";
|
return "user/orders/index";
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -115,6 +114,10 @@ public class SupplierOrderController {
|
|||||||
public String quantity;
|
public String quantity;
|
||||||
public String priceTotal;
|
public String priceTotal;
|
||||||
public boolean arrived;
|
public boolean arrived;
|
||||||
|
public String carrier;
|
||||||
|
public String trackingId;
|
||||||
|
public String estimatedArrival;
|
||||||
|
|
||||||
|
|
||||||
public UImodelSupplierOrder(SupplierOrder order, Article article) {
|
public UImodelSupplierOrder(SupplierOrder order, Article article) {
|
||||||
this.id = order.id;
|
this.id = order.id;
|
||||||
@ -125,9 +128,13 @@ public class SupplierOrderController {
|
|||||||
this.quantity = String.valueOf(order.numberOfUnits);
|
this.quantity = String.valueOf(order.numberOfUnits);
|
||||||
this.priceTotal = String.format("%.2f", ((float) order.totalPriceNet / 100));
|
this.priceTotal = String.format("%.2f", ((float) order.totalPriceNet / 100));
|
||||||
|
|
||||||
Date date = new Date();
|
this.carrier = order.carrier != null ? order.carrier : " - ";
|
||||||
date.setTime(order.created.getTime());
|
this.trackingId = order.trackingId != null ? order.trackingId : " - ";
|
||||||
this.dateOrder = new SimpleDateFormat("dd.MM.yyyy").format(date);
|
this.estimatedArrival = order.estimatedArrival != null
|
||||||
|
? new SimpleDateFormat("yyyy.MM.dd HH:00").format(order.estimatedArrival) + " Uhr"
|
||||||
|
: " - ";
|
||||||
|
|
||||||
|
this.dateOrder = new SimpleDateFormat("yyyy.MM.dd").format(order.created);
|
||||||
|
|
||||||
arrived = order.delivered != null;
|
arrived = order.delivered != null;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.hso.ecommerce.controller.intern.warehouse;
|
package org.hso.ecommerce.controller.intern.warehouse;
|
||||||
|
|
||||||
import org.hso.ecommerce.action.shop.EnableTrackingAction;
|
import org.hso.ecommerce.action.shop.EnableTrackingAction;
|
||||||
|
import org.hso.ecommerce.api.RestServiceForDelivery;
|
||||||
import org.hso.ecommerce.entities.warehouse.WarehouseBooking;
|
import org.hso.ecommerce.entities.warehouse.WarehouseBooking;
|
||||||
import org.hso.ecommerce.repos.warehouse.WarehouseBookingRepository;
|
import org.hso.ecommerce.repos.warehouse.WarehouseBookingRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -23,6 +24,9 @@ public class TodoController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private final WarehouseBookingRepository warehouseBookingRepository = null;
|
private final WarehouseBookingRepository warehouseBookingRepository = null;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private final RestServiceForDelivery deliveryService = null;
|
||||||
|
|
||||||
@GetMapping("todo")
|
@GetMapping("todo")
|
||||||
public String accountingWarehouseTodo(
|
public String accountingWarehouseTodo(
|
||||||
Model model
|
Model model
|
||||||
@ -77,7 +81,7 @@ public class TodoController {
|
|||||||
// Update Delivery Date
|
// Update Delivery Date
|
||||||
if (booking.get().reason.customerOrder != null) {
|
if (booking.get().reason.customerOrder != null) {
|
||||||
try{
|
try{
|
||||||
EnableTrackingAction.addTrackingInfo(booking.get().reason.customerOrder);
|
EnableTrackingAction.addTrackingInfo(deliveryService, booking.get().reason.customerOrder);
|
||||||
}
|
}
|
||||||
catch(ResourceAccessException e)
|
catch(ResourceAccessException e)
|
||||||
{
|
{
|
||||||
|
@ -52,7 +52,11 @@ public class ShopArticleController {
|
|||||||
}
|
}
|
||||||
model.addAttribute("article", article);
|
model.addAttribute("article", article);
|
||||||
|
|
||||||
if (warehouseBookingPositionSlotEntryRepository.getByArticle(id).get(0).newSumSlot > 0) { //check if in Stock
|
if (warehouseBookingPositionSlotEntryRepository
|
||||||
|
.getByArticle(id)
|
||||||
|
.stream()
|
||||||
|
.mapToInt(e -> e.newSumSlot)
|
||||||
|
.sum() > 0) { //check if in Stock
|
||||||
model.addAttribute("inStock", true);
|
model.addAttribute("inStock", true);
|
||||||
} else {
|
} else {
|
||||||
model.addAttribute("inStock", false);
|
model.addAttribute("inStock", false);
|
||||||
|
@ -28,6 +28,15 @@ public class SupplierOrder {
|
|||||||
// Includes discounts
|
// Includes discounts
|
||||||
public int totalPriceNet;
|
public int totalPriceNet;
|
||||||
|
|
||||||
|
@Column(nullable = true)
|
||||||
|
public String carrier;
|
||||||
|
|
||||||
|
@Column(nullable = true)
|
||||||
|
public String trackingId;
|
||||||
|
|
||||||
|
@Column(nullable = true)
|
||||||
|
public Timestamp estimatedArrival;
|
||||||
|
|
||||||
@Column(nullable = true)
|
@Column(nullable = true)
|
||||||
public Timestamp delivered;
|
public Timestamp delivered;
|
||||||
|
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
package org.hso.ecommerce.entities.warehouse;
|
|
||||||
|
|
||||||
import org.hso.ecommerce.entities.shop.CustomerOrder;
|
|
||||||
import org.hso.ecommerce.entities.supplier.SupplierOrder;
|
|
||||||
|
|
||||||
import javax.persistence.*;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Table(name = "warehouse_booking_reasons")
|
|
||||||
public class WarehouseBookingReason {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
||||||
@Basic
|
|
||||||
public long id;
|
|
||||||
|
|
||||||
public String comment;
|
|
||||||
|
|
||||||
@ManyToOne(optional = true)
|
|
||||||
public SupplierOrder causeSupplierOrder;
|
|
||||||
|
|
||||||
@ManyToOne(optional = true)
|
|
||||||
public CustomerOrder customerOrder;
|
|
||||||
|
|
||||||
public boolean isManuel;
|
|
||||||
|
|
||||||
// Default Constructor is needed for construction by ORM
|
|
||||||
public WarehouseBookingReason() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public WarehouseBookingReason(CustomerOrder order) {
|
|
||||||
this.customerOrder = order;
|
|
||||||
}
|
|
||||||
}
|
|
@ -23,7 +23,7 @@ public interface ArticleRepository extends JpaRepository<Article, Long> {
|
|||||||
@Query("SELECT a FROM Article a")
|
@Query("SELECT a FROM Article a")
|
||||||
List<Article> findAll();
|
List<Article> findAll();
|
||||||
|
|
||||||
@Query(value = "Select a.* from articles as a, article_offers as ao, warehouse_booking_position_entries as wbpe where a.related_id = ao.id and wbpe.article_id = a.id and ao.should_be_advertised = true group by wbpe.slot_id having max(wbpe.id) and wbpe.new_sum_slot != 0", nativeQuery = true)
|
@Query(value = "SELECT DISTINCT a.* from articles as a, article_offers as ao, warehouse_booking_position_entries as wbpe where a.related_id = ao.id and wbpe.article_id = a.id and ao.should_be_advertised = true group by wbpe.slot_id having max(wbpe.id) and wbpe.new_sum_slot != 0", nativeQuery = true)
|
||||||
List<Article> getAdvertisedArticles();
|
List<Article> getAdvertisedArticles();
|
||||||
|
|
||||||
@Query("SELECT a FROM CustomerOrderPosition cop JOIN cop.order co JOIN co.customer c JOIN cop.article a ORDER BY co.id DESC")
|
@Query("SELECT a FROM CustomerOrderPosition cop JOIN cop.order co JOIN co.customer c JOIN cop.article a ORDER BY co.id DESC")
|
||||||
|
@ -47,7 +47,8 @@
|
|||||||
<td><span th:text="${order.id}"></span></td>
|
<td><span th:text="${order.id}"></span></td>
|
||||||
<td><span th:text="${order.dateOrder}"></span></td>
|
<td><span th:text="${order.dateOrder}"></span></td>
|
||||||
<td><span th:text="${order.supplierName}"></span></td>
|
<td><span th:text="${order.supplierName}"></span></td>
|
||||||
<td><a th:href="@{/intern/articles/{id}(id = ${order.articleId})}" class="button smaller" th:text="${order.articleName}"></a></td>
|
<td><a th:href="@{/intern/articles/{id}(id = ${order.articleId})}" class="smaller"
|
||||||
|
th:text="${order.articleName}"></a></td>
|
||||||
<td><span th:text="${order.priceNet}"></span> €</td>
|
<td><span th:text="${order.priceNet}"></span> €</td>
|
||||||
<td><span th:text="${order.quantity}"></span></td>
|
<td><span th:text="${order.quantity}"></span></td>
|
||||||
<td><span th:text="${order.priceTotal}"></span> €</td>
|
<td><span th:text="${order.priceTotal}"></span> €</td>
|
||||||
@ -57,10 +58,13 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- ELSE -->
|
<!-- ELSE -->
|
||||||
<div th:unless="${order.arrived}">
|
<div th:unless="${order.arrived}">
|
||||||
Unterwegs <br>
|
Unterwegs: <span th:text="${order.carrier}"></span>, <span
|
||||||
<form class="detailgrid" action="#" th:action="@{/intern/supplierOrders/store/{id}(id = ${order.id})}" method="POST">
|
th:text="${order.trackingId}"></span><br/>
|
||||||
<input class="button smaller" type="submit" value="Eingang verbuchen" />
|
<form class="detailgrid" action="#"
|
||||||
|
th:action="@{/intern/supplierOrders/store/{id}(id = ${order.id})}" method="POST">
|
||||||
|
<input class="button smaller" type="submit" value="Eingang verbuchen"/>
|
||||||
</form>
|
</form>
|
||||||
|
Geschätzte Ankunft: <span th:text="${order.estimatedArrival}"></span>.
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -135,7 +135,7 @@ Musterstraße 4
|
|||||||
<button class=" no-margin secondary full-width">jetzt kostenpflichtig bestellen</button>
|
<button class=" no-margin secondary full-width">jetzt kostenpflichtig bestellen</button>
|
||||||
</div>
|
</div>
|
||||||
<div th:unless="${user}">
|
<div th:unless="${user}">
|
||||||
<a th:href="@{/login}" class="button secondary no-margin full-width">Einloggen und forfahren.</a>
|
<a th:href="@{/login}" class="button secondary no-margin full-width">Einloggen und fortfahren.</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
@ -27,6 +27,10 @@
|
|||||||
<div th:if="${!orderDeliveryDataMap.isEmpty()}" th:each="order: ${orderDeliveryDataMap}">
|
<div th:if="${!orderDeliveryDataMap.isEmpty()}" th:each="order: ${orderDeliveryDataMap}">
|
||||||
<div>
|
<div>
|
||||||
<table class="key-value">
|
<table class="key-value">
|
||||||
|
<tr>
|
||||||
|
<th>Bestelldatum</th>
|
||||||
|
<td th:text="${order.customerOrder.created}"></td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Lieferstatus</th>
|
<th>Lieferstatus</th>
|
||||||
<td th:if="${order.deliveryData.allOk()}"><span th:text="${order.deliveryData.getStatus()}"/>
|
<td th:if="${order.deliveryData.allOk()}"><span th:text="${order.deliveryData.getStatus()}"/>
|
||||||
@ -48,7 +52,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Sendeverfolgungsnummer</th>
|
<th>Sendeverfolgungsnummer</th>
|
||||||
<td th:text="${order.customerOrder.trackingId!=null} ? ${order.customerOrder.trackingId} : 'Es wurde noch keine Sendungsnummer vergeben'"></td>
|
<td th:text="${order.customerOrder.trackingId!=null} ? ${deliveryService + ', ' + order.customerOrder.trackingId} : 'Es wurde noch keine Sendungsnummer vergeben'"></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th></th>
|
<th></th>
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package org.hso.ecommerce.supplier;
|
package org.hso.ecommerce.supplier;
|
||||||
|
|
||||||
|
import org.hso.ecommerce.supplier.carrier.Avian;
|
||||||
|
import org.hso.ecommerce.supplier.carrier.Carrier;
|
||||||
|
import org.hso.ecommerce.supplier.carrier.Posaidon;
|
||||||
|
import org.hso.ecommerce.supplier.carrier.Shredder;
|
||||||
import org.hso.ecommerce.supplier.data.Article;
|
import org.hso.ecommerce.supplier.data.Article;
|
||||||
import org.hso.ecommerce.supplier.data.Order;
|
import org.hso.ecommerce.supplier.data.Order;
|
||||||
import org.hso.ecommerce.supplier.data.OrderConfirmation;
|
import org.hso.ecommerce.supplier.data.OrderConfirmation;
|
||||||
@ -19,9 +23,13 @@ import java.util.List;
|
|||||||
public class RequestController {
|
public class RequestController {
|
||||||
|
|
||||||
private final HashMap<String, Integer> dailySalesVolumeCent = new HashMap<>();
|
private final HashMap<String, Integer> dailySalesVolumeCent = new HashMap<>();
|
||||||
private final HashMap<String, Supplier> knownSuppliers = new HashMap<>();
|
private final HashMap<String, Supplier> knownSuppliers = new HashMap<>();
|
||||||
private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
private final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
|
||||||
|
private final Carrier[] carriers = new Carrier[]{
|
||||||
|
new Avian(), new Posaidon(), new Shredder()
|
||||||
|
};
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() throws IOException {
|
public void init() throws IOException {
|
||||||
for (Supplier s : ConfigurationReader.read()) {
|
for (Supplier s : ConfigurationReader.read()) {
|
||||||
@ -38,7 +46,7 @@ public class RequestController {
|
|||||||
@GetMapping("/{supplier}/")
|
@GetMapping("/{supplier}/")
|
||||||
public Supplier supplier(HttpServletResponse res, @PathVariable("supplier") String supplierName) {
|
public Supplier supplier(HttpServletResponse res, @PathVariable("supplier") String supplierName) {
|
||||||
Supplier s = knownSuppliers.get(supplierName);
|
Supplier s = knownSuppliers.get(supplierName);
|
||||||
if(s == null) {
|
if (s == null) {
|
||||||
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
@ -47,16 +55,16 @@ public class RequestController {
|
|||||||
@PostMapping("/{supplier}/order")
|
@PostMapping("/{supplier}/order")
|
||||||
public OrderConfirmation order(HttpServletResponse res, @PathVariable("supplier") String supplierName, @RequestBody Order order) {
|
public OrderConfirmation order(HttpServletResponse res, @PathVariable("supplier") String supplierName, @RequestBody Order order) {
|
||||||
Supplier s = knownSuppliers.get(supplierName);
|
Supplier s = knownSuppliers.get(supplierName);
|
||||||
if(s == null) {
|
if (s == null) {
|
||||||
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String dateKey = simpleDateFormat.format(new Date());
|
String dateKey = simpleDateFormat.format(new Date());
|
||||||
int dailyVolume = dailySalesVolumeCent.getOrDefault(dateKey,0);
|
int dailyVolume = dailySalesVolumeCent.getOrDefault(dateKey, 0);
|
||||||
|
|
||||||
Article a = s.findArticle(order.manufacturer, order.articleNumber);
|
Article a = s.findArticle(order.manufacturer, order.articleNumber);
|
||||||
if(a == null) {
|
if (a == null) {
|
||||||
res.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
res.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -72,6 +80,8 @@ public class RequestController {
|
|||||||
}
|
}
|
||||||
int discount = (discountableNetAmount * s.discount.percentDiscount) / 100;
|
int discount = (discountableNetAmount * s.discount.percentDiscount) / 100;
|
||||||
|
|
||||||
|
Carrier selectedCarrier = carriers[Math.abs((supplierName + java.time.LocalDate.now()).hashCode()) % carriers.length];
|
||||||
|
|
||||||
OrderConfirmation confirmation = new OrderConfirmation();
|
OrderConfirmation confirmation = new OrderConfirmation();
|
||||||
confirmation.articleNumber = order.articleNumber;
|
confirmation.articleNumber = order.articleNumber;
|
||||||
confirmation.discountNetCent = discount;
|
confirmation.discountNetCent = discount;
|
||||||
@ -79,6 +89,9 @@ public class RequestController {
|
|||||||
confirmation.manufacturer = a.manufacturer;
|
confirmation.manufacturer = a.manufacturer;
|
||||||
confirmation.quantity = order.quantity;
|
confirmation.quantity = order.quantity;
|
||||||
confirmation.totalPriceNetCharged = priceNet - discount;
|
confirmation.totalPriceNetCharged = priceNet - discount;
|
||||||
|
confirmation.carrier = selectedCarrier.getName();
|
||||||
|
confirmation.trackingId = selectedCarrier.generateTrackingId();
|
||||||
|
confirmation.estimatedArrival = selectedCarrier.arrivalEstimate();
|
||||||
|
|
||||||
if (confirmation.totalPriceNetCharged > order.maxTotalPriceCentNet) {
|
if (confirmation.totalPriceNetCharged > order.maxTotalPriceCentNet) {
|
||||||
res.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
|
res.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
package org.hso.ecommerce.supplier.carrier;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class Avian implements Carrier {
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Avian Carriers";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String generateTrackingId() {
|
||||||
|
Random rnd = new Random();
|
||||||
|
|
||||||
|
return "2001-"
|
||||||
|
+ Integer.toHexString(rnd.nextInt(0xFFFF))
|
||||||
|
+ "--"
|
||||||
|
+ Integer.toHexString(rnd.nextInt(0xFFFF))
|
||||||
|
+ "-"
|
||||||
|
+ Integer.toHexString(rnd.nextInt(0xFFFF));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalDateTime arrivalEstimate() {
|
||||||
|
return LocalDateTime.now().plusHours(8);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package org.hso.ecommerce.supplier.carrier;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
public interface Carrier {
|
||||||
|
public String getName();
|
||||||
|
|
||||||
|
public String generateTrackingId();
|
||||||
|
|
||||||
|
public LocalDateTime arrivalEstimate();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,26 @@
|
|||||||
|
package org.hso.ecommerce.supplier.carrier;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class Posaidon implements Carrier {
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Poseidon Inc.";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String generateTrackingId() {
|
||||||
|
Random rnd = new Random();
|
||||||
|
return "WAT"
|
||||||
|
+ Integer.toString(rnd.nextInt(Short.MAX_VALUE))
|
||||||
|
+ "3"
|
||||||
|
+ Integer.toString(rnd.nextInt(Short.MAX_VALUE))
|
||||||
|
+ "R";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalDateTime arrivalEstimate() {
|
||||||
|
return LocalDateTime.now().plusHours(50);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package org.hso.ecommerce.supplier.carrier;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class Shredder implements Carrier {
|
||||||
|
|
||||||
|
private Random rnd = new Random();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Schree & Derr";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String generateTrackingId() {
|
||||||
|
return "O" + d() + d() + d() + d() + d() + d() + d() + d() + d() + d() + d() + d() + d() + d() + d() + d() + d() + d() + "0";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LocalDateTime arrivalEstimate() {
|
||||||
|
return LocalDateTime.now().plusHours(22);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a random digit followed by a dash.
|
||||||
|
*/
|
||||||
|
private String d() {
|
||||||
|
return Integer.toString(rnd.nextInt(9)) + "-";
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
package org.hso.ecommerce.supplier.data;
|
package org.hso.ecommerce.supplier.data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
public class OrderConfirmation {
|
public class OrderConfirmation {
|
||||||
public String manufacturer;
|
public String manufacturer;
|
||||||
public String articleNumber;
|
public String articleNumber;
|
||||||
@ -9,4 +11,8 @@ public class OrderConfirmation {
|
|||||||
public int pricePerUnitNetCent;
|
public int pricePerUnitNetCent;
|
||||||
public int discountNetCent;
|
public int discountNetCent;
|
||||||
public int totalPriceNetCharged;
|
public int totalPriceNetCharged;
|
||||||
|
|
||||||
|
public String carrier;
|
||||||
|
public String trackingId;
|
||||||
|
public LocalDateTime estimatedArrival;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user