diff --git a/prototype/src/main/java/org/hso/ecommerce/action/cronjob/ReorderAction.java b/prototype/src/main/java/org/hso/ecommerce/action/cronjob/ReorderAction.java index 23599d8..7a329d5 100644 --- a/prototype/src/main/java/org/hso/ecommerce/action/cronjob/ReorderAction.java +++ b/prototype/src/main/java/org/hso/ecommerce/action/cronjob/ReorderAction.java @@ -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; } } diff --git a/prototype/src/main/java/org/hso/ecommerce/action/shop/EnableTrackingAction.java b/prototype/src/main/java/org/hso/ecommerce/action/shop/EnableTrackingAction.java index d608dea..6726ee2 100644 --- a/prototype/src/main/java/org/hso/ecommerce/action/shop/EnableTrackingAction.java +++ b/prototype/src/main/java/org/hso/ecommerce/action/shop/EnableTrackingAction.java @@ -4,10 +4,13 @@ import org.hso.ecommerce.api.RestServiceForDelivery; import org.hso.ecommerce.entities.shop.CustomerOrder; import org.springframework.web.client.ResourceAccessException; +import java.sql.Timestamp; +import java.util.Date; + public class EnableTrackingAction { - public static void addTrackingInfo(CustomerOrder customerOrder) throws ResourceAccessException { - - customerOrder.trackingId = new RestServiceForDelivery().getDeliveryID(customerOrder); + public static void addTrackingInfo(RestServiceForDelivery deliveryService, CustomerOrder customerOrder) throws ResourceAccessException { + customerOrder.inDeliverySince = new Timestamp(new Date().getTime()); + customerOrder.trackingId = deliveryService.getDeliveryID(customerOrder); } } diff --git a/prototype/src/main/java/org/hso/ecommerce/api/data/OrderConfirmation.java b/prototype/src/main/java/org/hso/ecommerce/api/data/OrderConfirmation.java index 78c8285..f52fbf4 100644 --- a/prototype/src/main/java/org/hso/ecommerce/api/data/OrderConfirmation.java +++ b/prototype/src/main/java/org/hso/ecommerce/api/data/OrderConfirmation.java @@ -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; } diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/LoginController.java b/prototype/src/main/java/org/hso/ecommerce/controller/LoginController.java index b5ccd43..56d9dc4 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/LoginController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/LoginController.java @@ -1,13 +1,11 @@ package org.hso.ecommerce.controller; +import org.hso.ecommerce.entities.shop.ShoppingCart; import org.hso.ecommerce.entities.user.User; import org.hso.ecommerce.repos.user.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -63,8 +61,10 @@ public class LoginController { } @PostMapping("logout") - public String logoutPost(HttpServletResponse response, HttpSession session) { + public String logoutPost(@RequestAttribute(value = "shoppingCart") ShoppingCart shoppingCart, HttpSession session) { session.removeAttribute("userId"); + shoppingCart.clear(); + return "redirect:/"; } } diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/UserController.java b/prototype/src/main/java/org/hso/ecommerce/controller/UserController.java index 45c4d32..b4ffc25 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/UserController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/UserController.java @@ -3,6 +3,7 @@ package org.hso.ecommerce.controller; import org.hso.ecommerce.action.user.CreateDeliveryData; import org.hso.ecommerce.action.user.UpdateUserSettingsAction; 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.user.User; import org.hso.ecommerce.repos.shop.CustomerOrderRepository; @@ -31,6 +32,9 @@ public class UserController { @Autowired private final RestServiceForDelivery restServiceForDelivery = null; + @Autowired + private final AppSettings appSettings = null; + @GetMapping("/") public String user() { return "redirect:/user/settings"; @@ -58,6 +62,7 @@ public class UserController { .collect(Collectors.toList()); model.addAttribute("orderDeliveryDataMap", customerOrderDeliveryDataMap); + model.addAttribute("deliveryService", appSettings.getParcelServiceName()); return "user/orders/index"; } diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOrderController.java b/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOrderController.java index 3259a17..b50006e 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOrderController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/intern/suppliers/SupplierOrderController.java @@ -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; } diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/intern/warehouse/TodoController.java b/prototype/src/main/java/org/hso/ecommerce/controller/intern/warehouse/TodoController.java index c8fb54f..93ed323 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/intern/warehouse/TodoController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/intern/warehouse/TodoController.java @@ -1,6 +1,7 @@ package org.hso.ecommerce.controller.intern.warehouse; import org.hso.ecommerce.action.shop.EnableTrackingAction; +import org.hso.ecommerce.api.RestServiceForDelivery; import org.hso.ecommerce.entities.warehouse.WarehouseBooking; import org.hso.ecommerce.repos.warehouse.WarehouseBookingRepository; import org.springframework.beans.factory.annotation.Autowired; @@ -23,6 +24,9 @@ public class TodoController { @Autowired private final WarehouseBookingRepository warehouseBookingRepository = null; + @Autowired + private final RestServiceForDelivery deliveryService = null; + @GetMapping("todo") public String accountingWarehouseTodo( Model model @@ -77,7 +81,7 @@ public class TodoController { // Update Delivery Date if (booking.get().reason.customerOrder != null) { try{ - EnableTrackingAction.addTrackingInfo(booking.get().reason.customerOrder); + EnableTrackingAction.addTrackingInfo(deliveryService, booking.get().reason.customerOrder); } catch(ResourceAccessException e) { diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java index b1df109..9345e83 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java @@ -52,7 +52,11 @@ public class ShopArticleController { } 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); } else { model.addAttribute("inStock", false); diff --git a/prototype/src/main/java/org/hso/ecommerce/entities/supplier/SupplierOrder.java b/prototype/src/main/java/org/hso/ecommerce/entities/supplier/SupplierOrder.java index e92339c..af59500 100644 --- a/prototype/src/main/java/org/hso/ecommerce/entities/supplier/SupplierOrder.java +++ b/prototype/src/main/java/org/hso/ecommerce/entities/supplier/SupplierOrder.java @@ -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; diff --git a/prototype/src/main/java/org/hso/ecommerce/entities/warehouse/WarehouseBookingReason.java b/prototype/src/main/java/org/hso/ecommerce/entities/warehouse/WarehouseBookingReason.java deleted file mode 100644 index e287141..0000000 --- a/prototype/src/main/java/org/hso/ecommerce/entities/warehouse/WarehouseBookingReason.java +++ /dev/null @@ -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; - } -} diff --git a/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java b/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java index d0a6ab1..b8be714 100644 --- a/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java +++ b/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java @@ -23,7 +23,7 @@ public interface ArticleRepository extends JpaRepository { @Query("SELECT a FROM Article a") List
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
getAdvertisedArticles(); @Query("SELECT a FROM CustomerOrderPosition cop JOIN cop.order co JOIN co.customer c JOIN cop.article a ORDER BY co.id DESC") diff --git a/prototype/src/main/resources/templates/intern/supplierOrders/index.html b/prototype/src/main/resources/templates/intern/supplierOrders/index.html index 84b58ec..27aa28e 100644 --- a/prototype/src/main/resources/templates/intern/supplierOrders/index.html +++ b/prototype/src/main/resources/templates/intern/supplierOrders/index.html @@ -47,7 +47,8 @@ - + € @@ -57,10 +58,13 @@
- Unterwegs
-
- + Unterwegs: ,
+ +
+ Geschätzte Ankunft: .
diff --git a/prototype/src/main/resources/templates/shop/checkout.html b/prototype/src/main/resources/templates/shop/checkout.html index 786885f..a627549 100644 --- a/prototype/src/main/resources/templates/shop/checkout.html +++ b/prototype/src/main/resources/templates/shop/checkout.html @@ -135,7 +135,7 @@ Musterstraße 4
- Einloggen und forfahren. + Einloggen und fortfahren.
diff --git a/prototype/src/main/resources/templates/user/orders/index.html b/prototype/src/main/resources/templates/user/orders/index.html index d54074e..354e213 100644 --- a/prototype/src/main/resources/templates/user/orders/index.html +++ b/prototype/src/main/resources/templates/user/orders/index.html @@ -27,6 +27,10 @@
+ + + + - + diff --git a/supplier/src/main/java/org/hso/ecommerce/supplier/RequestController.java b/supplier/src/main/java/org/hso/ecommerce/supplier/RequestController.java index 013daaa..7c50401 100644 --- a/supplier/src/main/java/org/hso/ecommerce/supplier/RequestController.java +++ b/supplier/src/main/java/org/hso/ecommerce/supplier/RequestController.java @@ -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 dailySalesVolumeCent = new HashMap<>(); - private final HashMap knownSuppliers = new HashMap<>(); + private final HashMap 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); diff --git a/supplier/src/main/java/org/hso/ecommerce/supplier/carrier/Avian.java b/supplier/src/main/java/org/hso/ecommerce/supplier/carrier/Avian.java new file mode 100644 index 0000000..281739d --- /dev/null +++ b/supplier/src/main/java/org/hso/ecommerce/supplier/carrier/Avian.java @@ -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); + } +} diff --git a/supplier/src/main/java/org/hso/ecommerce/supplier/carrier/Carrier.java b/supplier/src/main/java/org/hso/ecommerce/supplier/carrier/Carrier.java new file mode 100644 index 0000000..1804618 --- /dev/null +++ b/supplier/src/main/java/org/hso/ecommerce/supplier/carrier/Carrier.java @@ -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(); +} + diff --git a/supplier/src/main/java/org/hso/ecommerce/supplier/carrier/Posaidon.java b/supplier/src/main/java/org/hso/ecommerce/supplier/carrier/Posaidon.java new file mode 100644 index 0000000..0f4caf4 --- /dev/null +++ b/supplier/src/main/java/org/hso/ecommerce/supplier/carrier/Posaidon.java @@ -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); + } +} diff --git a/supplier/src/main/java/org/hso/ecommerce/supplier/carrier/Shredder.java b/supplier/src/main/java/org/hso/ecommerce/supplier/carrier/Shredder.java new file mode 100644 index 0000000..f91ddf3 --- /dev/null +++ b/supplier/src/main/java/org/hso/ecommerce/supplier/carrier/Shredder.java @@ -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)) + "-"; + } +} diff --git a/supplier/src/main/java/org/hso/ecommerce/supplier/data/OrderConfirmation.java b/supplier/src/main/java/org/hso/ecommerce/supplier/data/OrderConfirmation.java index f5e8101..5bce892 100644 --- a/supplier/src/main/java/org/hso/ecommerce/supplier/data/OrderConfirmation.java +++ b/supplier/src/main/java/org/hso/ecommerce/supplier/data/OrderConfirmation.java @@ -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; }
Bestelldatum
Lieferstatus @@ -48,7 +52,7 @@
Sendeverfolgungsnummer