From 6e593ec188762c363780aad8d34b8994ac4ca815 Mon Sep 17 00:00:00 2001 From: Notmoo Date: Sun, 30 Jul 2017 22:22:11 +0200 Subject: [PATCH] =?UTF-8?q?Module=20Server,=20clss=20StatisticsService=20:?= =?UTF-8?q?=20ajout=20du=20contenu=20des=20m=C3=A9thodes;=20Suppression=20?= =?UTF-8?q?du=20TODO=20associ=C3=A9=20(fait)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/statistics/StatisticsService.java | 61 +++++++++++++++---- 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/Workspace/server/src/main/WEB-INF/classes/com/pqt/server/module/statistics/StatisticsService.java b/Workspace/server/src/main/WEB-INF/classes/com/pqt/server/module/statistics/StatisticsService.java index 5c7cfef9..ff36f5d7 100644 --- a/Workspace/server/src/main/WEB-INF/classes/com/pqt/server/module/statistics/StatisticsService.java +++ b/Workspace/server/src/main/WEB-INF/classes/com/pqt/server/module/statistics/StatisticsService.java @@ -2,53 +2,92 @@ package com.pqt.server.module.statistics; import com.pqt.core.entities.product.LightweightProduct; import com.pqt.core.entities.product.Product; +import com.pqt.core.entities.sale.Sale; +import com.pqt.server.module.sale.listeners.ISaleListener; +import com.pqt.server.module.sale.listeners.SaleListenerAdapter; import com.pqt.server.module.stock.StockService; import com.pqt.server.module.sale.SaleService; +import java.util.ArrayList; +import java.util.Comparator; import java.util.List; +import java.util.stream.Collectors; //TODO écrire Javadoc //TODO Ajouter logs -//TODO écrire contenu méthodes public class StatisticsService { private StockService stockService; - private SaleService saleService; + + private int totalSaleAmount, staffSaleAmount, guestSaleAmount; + private double totalMoneyMade, totalSaleWorth, staffSaleWorth, guestSaleWorth; public StatisticsService(StockService stockService, SaleService saleService) { this.stockService = stockService; - this.saleService = saleService; + + totalSaleAmount = 0; + staffSaleAmount = 0; + guestSaleAmount = 0; + + totalMoneyMade = 0; + totalSaleWorth = 0; + staffSaleWorth = 0; + guestSaleWorth = 0; + + saleService.addListener(new SaleListenerAdapter() { + @Override + public void onSaleValidatedEvent(Sale sale) { + double price = sale.getTotalPrice(), worth = sale.getTotalWorth(); + totalSaleWorth+=worth; + totalMoneyMade+=price; + totalSaleAmount++; + switch (sale.getType()){ + case OFFERED_GUEST: + guestSaleAmount++; + guestSaleWorth+=worth; + break; + case OFFERED_STAFF_MEMBER: + staffSaleAmount++; + staffSaleWorth+=price; + break; + } + } + }); } public int getTotalAmountSale() { - return 0; + return totalSaleAmount; } public double getTotalMoneyMade() { - return 0; + return totalMoneyMade; } public double getTotalSaleWorth() { - return 0; + return totalSaleWorth; } public List getTopPopularProducts(int amount) { - return null; + return stockService.getProductList().stream() + .sorted(Comparator.comparingInt(Product::getAmountSold)) + .limit(amount) + .map(LightweightProduct::new) + .collect(Collectors.toList()); } public int getStaffSaleAmount() { - return 0; + return staffSaleAmount; } public double getStaffSaleWorth() { - return 0; + return staffSaleWorth; } public int getGuestSaleAmount() { - return 0; + return guestSaleAmount; } public double getGuestSaleWorth() { - return 0; + return guestSaleWorth; } }