List<CostSubjectsSettingExcelVo> finalList = list;
list.stream().filter(item -> item.getParentId().equals("0")).map(a -> {
int andIncrement = sort.getAndIncrement();
a.setLevel(String.valueOf(andIncrement));
a.setSort(andIncrement);
List<CostSubjectsSettingExcelVo> engineeringLedgerNodeLists1 = RecursiveAccumulationOfAmount(a, finalList);
costSubjectsSettingExcelVos.addAll(engineeringLedgerNodeLists1);
costSubjectsSettingExcelVos.add(a);
return a;
}).collect(Collectors.toList());
}
Collections.sort(costSubjectsSettingExcelVos, Comparator.comparing(CostSubjectsSettingExcelVo::getLevel));
public List<CostSubjectsSettingExcelVo> RecursiveAccumulationOfAmount(CostSubjectsSettingExcelVo root, List<CostSubjectsSettingExcelVo> all) {
ArrayList<CostSubjectsSettingExcelVo> engineeringLedgerNodeListsall = new ArrayList<>();
List<CostSubjectsSettingExcelVo> children = all.stream().filter(xs ->
xs.getParentId().equals(root.getId())
).collect(Collectors.toList());
for (int i = 0; i < children.size(); i++) {
CostSubjectsSettingExcelVo treeVO = children.get(i);
int index = i + 1;
treeVO.setLevel(String.valueOf(index));
if (StringUtil.isNotEmpty(treeVO.getLevel())) {
String childSeqNum = root.getLevel() + "-" + (i + 1);
treeVO.setLevel(childSeqNum);
}
Integer childSeqNum = root.getSort() + 1;
treeVO.setSort(childSeqNum);
List<CostSubjectsSettingExcelVo> engineeringLedgerNodeLists = RecursiveAccumulationOfAmount(treeVO, all);
engineeringLedgerNodeListsall.addAll(engineeringLedgerNodeLists);
}
root.setSize(children.size());
engineeringLedgerNodeListsall.addAll(children);
return engineeringLedgerNodeListsall;
}