public AjaxResult getSysCustomerTree(SysCustomer sysCustomer) {
QueryWrapper<SysCustomer> queryWrapper=new QueryWrapper<>();
queryWrapper.orderByAsc("order_num");
List<SysCustomer> sysCustomerList = this.list(queryWrapper);
SysCustomer paraentSysCustomer = sysCustomerList.stream().filter(item -> item.getParentId().equals("0")).collect(Collectors.toList()).get(0);
getSysCustomerChild(paraentSysCustomer,sysCustomerList);
return AjaxResult.success(paraentSysCustomer);
}
//递归获取该父节点的子集
public void getSysCustomerChild(SysCustomer sysCustomer, List<SysCustomer> sysCustomerList) {
for (SysCustomer customer : sysCustomerList) {
if (sysCustomer.getUuid().equals(customer.getParentId())) {
List<SysCustomer> tempChilds = sysCustomer.getChildren();
tempChilds.add(customer);
getSysCustomerChild(customer,sysCustomerList);
}
}
}
最终结果