java 递归查子菜单
2024-10-21 18:42:54
递归查:
@Override
public List<PromotionOrgInfoPO> queryOrgInfo() {
List<PromotionOrgInfoPO> promotionOrgInfoPOS = pointExchangeDAO.queryOrgInfo();
List<PromotionOrgInfoPO> rootInfo = new ArrayList<>();
if (CollectionUtils.isNotEmpty(promotionOrgInfoPOS)) {
promotionOrgInfoPOS.forEach(promotionOrgInfoPO -> {
if (Objects.isNull(promotionOrgInfoPO.getParentId())) {
rootInfo.add(promotionOrgInfoPO);
}
});
rootInfo.forEach(menu -> {
List<PromotionOrgInfoPO> childList = getChildMenu(menu.getId(), promotionOrgInfoPOS);
menu.setChildOrgInfos(childList);
});
}
return rootInfo;
} private List<PromotionOrgInfoPO> getChildMenu(Long id, List<PromotionOrgInfoPO> allMenu) {
//子菜单
List<PromotionOrgInfoPO> childList = new ArrayList<>();
allMenu.forEach(all -> {
// 遍历所有节点,将所有的父id与传过来的根节点的id比较
if (all.getParentId().equals(id)) {
childList.add(all);
}
});
//递归
childList.forEach(child -> child.setChildOrgInfos(getChildMenu(child.getId(), allMenu)));
//如果节点下没有子节点,返回一个空List(递归退出)
if (childList.size() == 0) {
return new ArrayList<>();
}
return childList;
}
常用求和:
Map<String, BigDecimal> currencyCard = paymentVOS.stream().distinct().collect(Collectors.groupingBy(InternalPaymentVO::getDeductCardNo,
Collectors.mapping(InternalPaymentVO::getDeductAmount,
Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
int points = internalPaymentVOS.stream().filter(v -> v.getType().equals(92)).mapToInt(InternalPaymentVO::getPmUsedPoints).sum(); BigDecimal pointsMoney = internalPaymentVOS.stream().filter(v -> v.getType().equals(92)).map(InternalPaymentVO::getPmUsedMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
paymentVOS = internalPaymentVOS.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(InternalPaymentVO::getType))), ArrayList::new));
最新文章
- NOIP模板整理计划
- Thinkphp3.2.3使用Ajax一定注意 数据返回
- android 下载文件,file的读写应用
- xlat指令...
- Js杂谈-DOM
- Java api 入门教程 之 JAVA的文件操作
- 用jackson封装的JSON工具类
- matlab实现分水岭算法处理图像分割
- 容器--Collection和AbstractCollection
- php:mysqli扩展
- css3 动画 执行一次
- 【转】【iOS系列】-iOS查看沙盒文件图文教程(真机+模拟器)
- Map集合案例
- Rust 学习 0
- Hyper-V 测试
- yii 使用renderPartial调用另外一个控制器的视图
- 使用 Windows Media Center 远程控制
- [Angular Tutorial] 9 -Routing &; Multiple Views
- JFinal 极速开发框架的优点和不足的地方
- PHP常见错误汇总