0、先来一个简单的,先分组再聚合
Map<String, Double> categoryMap = baseLevelData.stream().collect(Collectors.groupingBy(o -> o.getCategoryL2(), Collectors.summingDouble(o -> o.getBudgetOk2ship())));
1.对象二级 group
Map<String, Map<Integer, List<WoiTargetAlertRuleEntity>>> woiMap = allRuleEntity.stream().collect(Collectors.groupingBy(o -> o.getCountryCode(), Collectors.groupingBy(o -> o.getWoiTarget())));
2. 二级 group,再mapping属性
Map<String, Map<Integer, List<String>>> secondLevelMap = allRuleEntity.stream().collect(Collectors.groupingBy(o -> o.getCountryCode(), Collectors.groupingBy(o -> o.getWoiTarget(), Collectors.mapping(o -> o.getTerritory(), Collectors.toList()))));
3. group,再取每组的第一条数据
Map<String, ScMbgCalendarCmlEntity> quarterMap = calendarHeader.stream().collect(Collectors.groupingBy(ScMbgCalendarCmlEntity::getMfgQtrDesc, Collectors.collectingAndThen(Collectors.toList(), list -> list.get(0))));
4. group,再 toMap
Map<String, Map<String, String>> map = productList.stream().collect(Collectors.groupingBy(o -> o.getPmdProgramName(), Collectors.toMap(NPIBRSPMDProgramEntity::getPmdProductName, NPIBRSPMDProgramEntity::getPmdProductId)));