mirror of
				https://github.com/klmp200/PQT_Gestionnaire_vente_stock.git
				synced 2025-11-03 10:33:08 +00:00 
			
		
		
		
	[SERVEUR] #12 : Ajout d'un catch+print des exceptions lors de la composition des listes de stats; Correction du bug d'ordre des produits populaires; Correction du bug de valeur brutes des commandes du staff
This commit is contained in:
		@@ -98,15 +98,18 @@ public class SimpleMessageHandler implements IMessageHandler {
 | 
			
		||||
        }, AccountLevel.WAITER);
 | 
			
		||||
        manager.supportForConnectedAccounts(MessageType.QUERY_STAT, (message)->{
 | 
			
		||||
            Map<String, String> fields = new HashMap<>();
 | 
			
		||||
            fields.put(StatisticFields.TOTAL_SALE_WORTH.getStr(), Double.toString(statisticsService.getTotalSaleWorth()));
 | 
			
		||||
            fields.put(StatisticFields.TOTAL_SALE_AMOUNT.getStr(), Integer.toString(statisticsService.getTotalAmountSale()));
 | 
			
		||||
            fields.put(StatisticFields.TOTAL_MONEY_MADE.getStr(), Double.toString(statisticsService.getTotalMoneyMade()));
 | 
			
		||||
            fields.put(StatisticFields.TOP_POPULAR_PRODUCTS.getStr(), messageToolFactory.getListFormatter(LightweightProduct.class).format(statisticsService.getTopPopularProducts(5)));
 | 
			
		||||
            fields.put(StatisticFields.STAFF_SALE_WORTH.getStr(), Double.toString(statisticsService.getStaffSaleWorth()));
 | 
			
		||||
            fields.put(StatisticFields.STAFF_SALE_AMOUNT.getStr(), Integer.toString(statisticsService.getStaffSaleAmount()));
 | 
			
		||||
            fields.put(StatisticFields.GUEST_SALE_WORTH.getStr(), Double.toString(statisticsService.getGuestSaleWorth()));
 | 
			
		||||
            fields.put(StatisticFields.GUEST_SALE_AMOUNT.getStr(), Integer.toString(statisticsService.getGuestSaleAmount()));
 | 
			
		||||
 | 
			
		||||
            try{
 | 
			
		||||
                fields.put(StatisticFields.TOTAL_SALE_WORTH.getStr(), Double.toString(statisticsService.getTotalSaleWorth()));
 | 
			
		||||
                fields.put(StatisticFields.TOTAL_SALE_AMOUNT.getStr(), Integer.toString(statisticsService.getTotalAmountSale()));
 | 
			
		||||
                fields.put(StatisticFields.TOTAL_MONEY_MADE.getStr(), Double.toString(statisticsService.getTotalMoneyMade()));
 | 
			
		||||
                fields.put(StatisticFields.TOP_POPULAR_PRODUCTS.getStr(), messageToolFactory.getListFormatter(LightweightProduct.class).format(statisticsService.getTopPopularProducts(5)));
 | 
			
		||||
                fields.put(StatisticFields.STAFF_SALE_WORTH.getStr(), Double.toString(statisticsService.getStaffSaleWorth()));
 | 
			
		||||
                fields.put(StatisticFields.STAFF_SALE_AMOUNT.getStr(), Integer.toString(statisticsService.getStaffSaleAmount()));
 | 
			
		||||
                fields.put(StatisticFields.GUEST_SALE_WORTH.getStr(), Double.toString(statisticsService.getGuestSaleWorth()));
 | 
			
		||||
                fields.put(StatisticFields.GUEST_SALE_AMOUNT.getStr(), Integer.toString(statisticsService.getGuestSaleAmount()));
 | 
			
		||||
            }catch(Exception e){
 | 
			
		||||
                e.printStackTrace();
 | 
			
		||||
            }
 | 
			
		||||
            return new Message(MessageType.MSG_STAT, serverStateService.getServer(), message.getEmitter(), message.getUser(), message, fields);
 | 
			
		||||
        }, AccountLevel.WAITER);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -50,7 +50,7 @@ public class StatisticsService {
 | 
			
		||||
                        break;
 | 
			
		||||
                    case OFFERED_STAFF_MEMBER:
 | 
			
		||||
                        staffSaleAmount++;
 | 
			
		||||
                        staffSaleWorth+=price;
 | 
			
		||||
                        staffSaleWorth+=worth;
 | 
			
		||||
                        break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
@@ -71,7 +71,7 @@ public class StatisticsService {
 | 
			
		||||
 | 
			
		||||
	public List<LightweightProduct> getTopPopularProducts(int amount) {
 | 
			
		||||
		return stockService.getProductList().stream()
 | 
			
		||||
                .sorted(Comparator.comparingInt(Product::getAmountSold))
 | 
			
		||||
                .sorted((prod1, prod2)->prod2.getAmountSold()-prod1.getAmountSold())
 | 
			
		||||
                .limit(amount)
 | 
			
		||||
                .map(LightweightProduct::new)
 | 
			
		||||
                .collect(Collectors.toList());
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user