- public int preferential(String username) {
- //选中的订单清单
- List<OrderItem> orderItemList = findCartList(username).stream().
- filter(cart -> (boolean) cart.get("checked") == true).
- map(cart -> (OrderItem) cart.get("item")).collect(Collectors.toList());
- //聚合统计每种category的总价格,封装为map<categoryId,totalMoney>
- Map<Integer, IntSummaryStatistics> cartMap = orderItemList.stream().
- collect(Collectors.groupingBy(OrderItem::getCategoryId3,
- Collectors.summarizingInt(OrderItem::getMoney)));
- //遍历每种category的优惠金额并累加
- int totalPreMoney = 0;
- for (Integer categoryId : cartMap.keySet()) {
- int preMoney = preferentialService.findPreMoneyByCategoryId(categoryId.longValue(),
- (int) cartMap.get(categoryId).getSum());
- System.out.println("分类:"+categoryId+"... "+"优惠:"+preMoney);
- totalPreMoney+=preMoney;
- }
- return totalPreMoney;
- }
复制代码 |
|