Skip to content

Commit 5a2b836

Browse files
committed
feat: 使用工具类优化 tree 生成代码
1 parent 2f7585b commit 5a2b836

1 file changed

Lines changed: 2 additions & 13 deletions

File tree

framework/framework_svc/src/main/java/com/github/cadecode/uniboot/framework/svc/serviceimpl/SysDeptServiceImpl.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import cn.hutool.core.util.ObjUtil;
44
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
5+
import com.github.cadecode.uniboot.common.core.util.TreeUtil;
56
import com.github.cadecode.uniboot.framework.svc.bean.po.SysDept;
67
import com.github.cadecode.uniboot.framework.svc.bean.vo.SysDeptVo.SysDeptTreeReqVo;
78
import com.github.cadecode.uniboot.framework.svc.bean.vo.SysDeptVo.SysDeptTreeResVo;
@@ -31,18 +32,6 @@ public List<SysDeptTreeResVo> listTreeVo(SysDeptTreeReqVo reqVo) {
3132
.sorted(Comparator.comparing(SysDept::getOrderNum))
3233
.collect(Collectors.toList());
3334
List<SysDeptTreeResVo> treeResVoList = SysDeptConvert.INSTANCE.poToTreeResVo(poList);
34-
return geneTreeVo(treeResVoList, null);
35-
}
36-
37-
private List<SysDeptTreeResVo> geneTreeVo(List<SysDeptTreeResVo> deptList, Long rootId) {
38-
List<SysDeptTreeResVo> parentList = deptList.stream().filter(o -> ObjUtil.equals(rootId, o.getParentId())).collect(Collectors.toList());
39-
parentList.forEach(p -> {
40-
List<SysDeptTreeResVo> children = deptList.stream()
41-
.filter(c -> ObjUtil.equals(c.getParentId(), p.getId()))
42-
.peek(c -> c.setChildren(geneTreeVo(deptList, c.getId())))
43-
.collect(Collectors.toList());
44-
p.setChildren(children);
45-
});
46-
return parentList;
35+
return TreeUtil.listToTree(treeResVoList, null, SysDeptTreeResVo::getId, SysDeptTreeResVo::getParentId, SysDeptTreeResVo::setChildren);
4736
}
4837
}

0 commit comments

Comments
 (0)