Stream流分组,统计,求和
public class Test {
public static void main(String[] args) {
List<OrdersDO> list = new ArrayList<>();//查询昨天⼀天的所有交易
OrdersDO o1 = new OrdersDO();
o1.setAppId(1L);
o1.setTradeAmount(100L);
o1.setStatus(1);
list.add(o1);
OrdersDO o2 = new OrdersDO();
o2.setAppId(5L);
o2.setTradeAmount(300L);
o2.setStatus(2);
list.add(o2);
OrdersDO o3 = new OrdersDO();
o3.setAppId(1L);
o3.setTradeAmount(100L);
o3.setStatus(3);
list.add(o3);
OrdersDO o4 = new OrdersDO();
o4.setAppId(5L);
o4.setTradeAmount(300L);sortedlist
o4.setStatus(4);
list.add(o4);
OrdersDO o5 = new OrdersDO();
o5.setAppId(5L);
o5.setTradeAmount(300L);
o5.setStatus(4);
list.add(o5);
//统计每个应⽤实际⽀付总额
Map<Long, Long> tradeAmountMap = list.stream().filter(o-&Status()==2)
.upingBy(OrdersDO::getAppId,
Collectors.summingLong(OrdersDO::getTradeAmount)));
System.out.println(tradeAmountMap);
//统计每个应⽤取消总额
Map<Long, Long> cancelAmountMap = list.stream()
.upingBy(OrdersDO::getAppId,
Collectors.summingLong(OrdersDO::getTradeAmount)));
System.out.println(cancelAmountMap);
//统计每个应⽤下交易笔数
Map<Long, Long> appTradeNum = list.stream().upingBy(OrdersDO::getAppId, unting()));
System.out.println(appTradeNum);
//统计每个应⽤每种状态下交易笔数
Map<Long, Map<Integer, Long>> tradeNumMap = list.stream().
upingBy(OrdersDO::getAppId,
System.out.println(tradeNumMap);
//每个应⽤下交易笔数按数量排序
Map<Long,Long> finalMap = new LinkedHashMap<>();
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。