| | |
| | | return collect; |
| | | } |
| | | |
| | | @Override |
| | | public List<Long> selectChildrenIdsById(Long id) { |
| | | List<SysDistrict> districts = this.selectAll(); |
| | | if (CollectionUtils.isEmpty(districts)){ |
| | | throw new BusinessException(this.getClass(), ResultConstants.SYSTEM_ERROR_DATABASE_FAIL,"区划信息获取失败"); |
| | | } |
| | | List<Long> list = new ArrayList<>(); |
| | | districts.stream() |
| | | //父节点的id = 0,根据它开始进行实现。 |
| | | .filter(e -> e.getId().equals(id)) |
| | | .map(e ->{ |
| | | list.add(e.getId()); |
| | | getchildrenIds(list,e,districts); |
| | | return e; |
| | | }).collect(Collectors.toList()); |
| | | return list; |
| | | } |
| | | |
| | | private void getchildrenIds(List<Long> list,SysDistrict root,List<SysDistrict> districts){ |
| | | //root为每次最新的传递过来的数据,也就是上面过滤之后的 e ; |
| | | List<SysDistrict> collect = districts.stream() |
| | | //根据传递过来的 e ,拿到他的id,来查询出他的子节点id 这里有个特点 e.id = 子节点的父节点id |
| | | .filter(e -> Objects.equals(e.getParentcode(), root.getCode())) |
| | | .map(e -> { |
| | | list.add(e.getId()); |
| | | getchildrenIds(list,e,districts); |
| | | //递归找到他的子节点,直到找到最后一个子节点为止,饼进行封装。 |
| | | return e; |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | } |
| | | |