Module Server, clss StatisticsService : ajout du contenu des méthodes; Suppression du TODO associé (fait)

This commit is contained in:
Notmoo 2017-07-30 22:22:11 +02:00
parent ee38eb5263
commit 6e593ec188

View File

@ -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<LightweightProduct> 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;
}
}