可以使用forEach方法替代for循环来遍历stream流中的元素。下面是使用forEach方法重写上述代码的示例:

empCodeAndNameDeptNameGroup.keySet().forEach(empCodeAndNameDeptName -> { // 获取到员工所对应的建议等级数据 List suggestedLevelExportDTOS = empCodeAndNameDeptNameGroup.get(empCodeAndNameDeptName);

// empCodeAndName格式为 :”员工编号-员工名称-部门名称“
String[] empCodeAndDeptNameNames = StringUtils.split(empCodeAndNameDeptName, Constants.SPLIT_FLAG);

// 获取不同建议等级所对应的评价总人数
Map<String, Long> suggestedLevelGroup = suggestedLevelExportDTOS.stream()
        .collect(Collectors.groupingBy(SuggestedLevelExportDTO::getSuggestedLevel, Collectors.counting()));

// 获取所有建议等级评价总人数
Long otherWightLeveSuggestedLevelSum = MapUtils.emptyIfNull(suggestedLevelGroup).values().stream()
        .mapToLong(Long::longValue)
        .sum();

SuggestedLevelVO otherWightLeveSuggestedLevelVO = createSuggestedLevelVO(empCodeAndDeptNameNames, suggestedLevelGroup, otherWightLeveSuggestedLevelSum, StringUtils.EMPTY);
suggestedLevelVOS.add(otherWightLeveSuggestedLevelVO);

// 权重级别名称为key,所对应的建议等级数据为value的map
Map<String, List<SuggestedLevelExportDTO>> wightLevelNameGroup = suggestedLevelExportDTOS.stream()
        .collect(Collectors.groupingBy(SuggestedLevelExportDTO::getWightLevelName));

List<SuggestedLevelVO> suggestedLevelVOs = MapUtils.emptyIfNull(wightLevelNameGroup).keySet().stream()
        .map(wightLevelName -> getSuggestedLevelVO(empCodeAndDeptNameNames, wightLevelNameGroup, wightLevelName))
        .collect(Collectors.toList());
suggestedLevelVOS.addAll(suggestedLevelVOs);

})

for final String empCodeAndNameDeptName empCodeAndNameDeptNameGroupkeySet 获取到员工所对应的建议等级数据 final ListSuggestedLevelExportDTO suggestedLevelExportDTOS = empCodeAndNameDeptNameGr

原文地址: http://www.cveoy.top/t/topic/iVVq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录