递归查:



@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));