Merge pull request 'Add & generate tracking information to (Supplier-)OrderConfirmation. Fixes #110' (#114) from feature/supplier_tracking into master
Reviewed-on: #114 Reviewed-by: Jannik Seiler <seil0@mosad.xyz>
This commit is contained in:
commit
3bc0996c73
|
@ -1,8 +1,5 @@
|
|||
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.Offer;
|
||||
import org.hso.ecommerce.api.SupplierService;
|
||||
|
@ -14,6 +11,9 @@ import org.hso.ecommerce.entities.supplier.SupplierOrder;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ReorderAction {
|
||||
private static final Logger log = LoggerFactory.getLogger(ReorderAction.class);
|
||||
|
||||
|
@ -102,6 +102,10 @@ public class ReorderAction {
|
|||
createdOrder.numberOfUnits = confirm.quantity;
|
||||
createdOrder.pricePerUnitNetCent = confirm.pricePerUnitNetCent;
|
||||
createdOrder.totalPriceNet = confirm.totalPriceNetCharged;
|
||||
createdOrder.carrier = confirm.carrier;
|
||||
createdOrder.trackingId = confirm.trackingId;
|
||||
createdOrder.estimatedArrival = Timestamp.valueOf(confirm.estimatedArrival);
|
||||
|
||||
return createdOrder;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.hso.ecommerce.api.data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class OrderConfirmation {
|
||||
public String manufacturer;
|
||||
public String articleNumber;
|
||||
|
@ -9,4 +11,8 @@ public class OrderConfirmation {
|
|||
public int pricePerUnitNetCent;
|
||||
public int discountNetCent;
|
||||
public int totalPriceNetCharged;
|
||||
|
||||
public String carrier;
|
||||
public String trackingId;
|
||||
public LocalDateTime estimatedArrival;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -115,6 +114,10 @@ public class SupplierOrderController {
|
|||
public String quantity;
|
||||
public String priceTotal;
|
||||
public boolean arrived;
|
||||
public String carrier;
|
||||
public String trackingId;
|
||||
public String estimatedArrival;
|
||||
|
||||
|
||||
public UImodelSupplierOrder(SupplierOrder order, Article article) {
|
||||
this.id = order.id;
|
||||
|
@ -125,9 +128,13 @@ public class SupplierOrderController {
|
|||
this.quantity = String.valueOf(order.numberOfUnits);
|
||||
this.priceTotal = String.format("%.2f", ((float) order.totalPriceNet / 100));
|
||||
|
||||
Date date = new Date();
|
||||
date.setTime(order.created.getTime());
|
||||
this.dateOrder = new SimpleDateFormat("dd.MM.yyyy").format(date);
|
||||
this.carrier = order.carrier != null ? order.carrier : " - ";
|
||||
this.trackingId = order.trackingId != null ? order.trackingId : " - ";
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,15 @@ public class SupplierOrder {
|
|||
// Includes discounts
|
||||
public int totalPriceNet;
|
||||
|
||||
@Column(nullable = true)
|
||||
public String carrier;
|
||||
|
||||
@Column(nullable = true)
|
||||
public String trackingId;
|
||||
|
||||
@Column(nullable = true)
|
||||
public Timestamp estimatedArrival;
|
||||
|
||||
@Column(nullable = true)
|
||||
public Timestamp delivered;
|
||||
|
||||
|
|
|
@ -47,7 +47,8 @@
|
|||
<td><span th:text="${order.id}"></span></td>
|
||||
<td><span th:text="${order.dateOrder}"></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.quantity}"></span></td>
|
||||
<td><span th:text="${order.priceTotal}"></span> €</td>
|
||||
|
@ -57,10 +58,13 @@
|
|||
</div>
|
||||
<!-- ELSE -->
|
||||
<div th:unless="${order.arrived}">
|
||||
Unterwegs <br>
|
||||
<form class="detailgrid" action="#" th:action="@{/intern/supplierOrders/store/{id}(id = ${order.id})}" method="POST">
|
||||
<input class="button smaller" type="submit" value="Eingang verbuchen" />
|
||||
Unterwegs: <span th:text="${order.carrier}"></span>, <span
|
||||
th:text="${order.trackingId}"></span><br/>
|
||||
<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>
|
||||
Geschätzte Ankunft: <span th:text="${order.estimatedArrival}"></span>.
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
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.Order;
|
||||
import org.hso.ecommerce.supplier.data.OrderConfirmation;
|
||||
|
@ -19,9 +23,13 @@ import java.util.List;
|
|||
public class RequestController {
|
||||
|
||||
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 Carrier[] carriers = new Carrier[]{
|
||||
new Avian(), new Posaidon(), new Shredder()
|
||||
};
|
||||
|
||||
@PostConstruct
|
||||
public void init() throws IOException {
|
||||
for (Supplier s : ConfigurationReader.read()) {
|
||||
|
@ -38,7 +46,7 @@ public class RequestController {
|
|||
@GetMapping("/{supplier}/")
|
||||
public Supplier supplier(HttpServletResponse res, @PathVariable("supplier") String supplierName) {
|
||||
Supplier s = knownSuppliers.get(supplierName);
|
||||
if(s == null) {
|
||||
if (s == null) {
|
||||
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
}
|
||||
return s;
|
||||
|
@ -47,16 +55,16 @@ public class RequestController {
|
|||
@PostMapping("/{supplier}/order")
|
||||
public OrderConfirmation order(HttpServletResponse res, @PathVariable("supplier") String supplierName, @RequestBody Order order) {
|
||||
Supplier s = knownSuppliers.get(supplierName);
|
||||
if(s == null) {
|
||||
if (s == null) {
|
||||
res.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||
return null;
|
||||
}
|
||||
|
||||
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);
|
||||
if(a == null) {
|
||||
if (a == null) {
|
||||
res.setStatus(HttpServletResponse.SC_BAD_REQUEST);
|
||||
return null;
|
||||
}
|
||||
|
@ -72,6 +80,8 @@ public class RequestController {
|
|||
}
|
||||
int discount = (discountableNetAmount * s.discount.percentDiscount) / 100;
|
||||
|
||||
Carrier selectedCarrier = carriers[Math.abs((supplierName + java.time.LocalDate.now()).hashCode()) % carriers.length];
|
||||
|
||||
OrderConfirmation confirmation = new OrderConfirmation();
|
||||
confirmation.articleNumber = order.articleNumber;
|
||||
confirmation.discountNetCent = discount;
|
||||
|
@ -79,6 +89,9 @@ public class RequestController {
|
|||
confirmation.manufacturer = a.manufacturer;
|
||||
confirmation.quantity = order.quantity;
|
||||
confirmation.totalPriceNetCharged = priceNet - discount;
|
||||
confirmation.carrier = selectedCarrier.getName();
|
||||
confirmation.trackingId = selectedCarrier.generateTrackingId();
|
||||
confirmation.estimatedArrival = selectedCarrier.arrivalEstimate();
|
||||
|
||||
if (confirmation.totalPriceNetCharged > order.maxTotalPriceCentNet) {
|
||||
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;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public class OrderConfirmation {
|
||||
public String manufacturer;
|
||||
public String articleNumber;
|
||||
|
@ -9,4 +11,8 @@ public class OrderConfirmation {
|
|||
public int pricePerUnitNetCent;
|
||||
public int discountNetCent;
|
||||
public int totalPriceNetCharged;
|
||||
|
||||
public String carrier;
|
||||
public String trackingId;
|
||||
public LocalDateTime estimatedArrival;
|
||||
}
|
||||
|
|
Reference in New Issue