| | |
| | | import java.util.stream.Collectors; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.ruoyi.common.core.domain.TreeDeptWell; |
| | | import com.ruoyi.common.core.domain.TreeSelectWell; |
| | | import org.springframework.stereotype.Service; |
| | | import com.ruoyi.common.annotation.DataScope; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<TreeSelectWell> wellTree(List<SysDept> depts) { |
| | | List<SysDept> deptTrees = buildDeptTree(depts); |
| | | public List<SysDept> allByUser(List<Long> deptList) { |
| | | QueryWrapper<SysDept> queryWrapper = new QueryWrapper(); |
| | | queryWrapper.in("dept_id",deptList); |
| | | return deptMapper.selectList(queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | public List<TreeSelectWell> wellTree(List<TreeDeptWell> depts) { |
| | | List<TreeDeptWell> deptTrees = buildDeptWellTree(depts); |
| | | return deptTrees.stream().map(TreeSelectWell::new).collect(Collectors.toList()); |
| | | } |
| | | |
| | | @Override |
| | | public List<TreeDeptWell> buildDeptWellTree(List<TreeDeptWell> depts) |
| | | { |
| | | List<TreeDeptWell> returnList = new ArrayList<TreeDeptWell>(); |
| | | List<Long> tempList = depts.stream().map(TreeDeptWell::getDeptId).collect(Collectors.toList()); |
| | | for (TreeDeptWell dept : depts) |
| | | { |
| | | // 如果是顶级节点, 遍历该父节点的所有子节点 |
| | | if (!tempList.contains(dept.getParentId())) |
| | | { |
| | | recursionFnWell(depts, dept); |
| | | returnList.add(dept); |
| | | } |
| | | } |
| | | if (returnList.isEmpty()) |
| | | { |
| | | returnList = depts; |
| | | } |
| | | return returnList; |
| | | } |
| | | |
| | | private void recursionFnWell(List<TreeDeptWell> list, TreeDeptWell t) |
| | | { |
| | | // 得到子节点列表 |
| | | List<TreeDeptWell> childList = getChildListWell(list, t); |
| | | t.setChildren(childList); |
| | | for (TreeDeptWell tChild : childList) |
| | | { |
| | | if (hasChildWell(list, tChild)) |
| | | { |
| | | recursionFnWell(list, tChild); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private List<TreeDeptWell> getChildListWell(List<TreeDeptWell> list, TreeDeptWell t) |
| | | { |
| | | List<TreeDeptWell> tlist = new ArrayList<TreeDeptWell>(); |
| | | Iterator<TreeDeptWell> it = list.iterator(); |
| | | while (it.hasNext()) |
| | | { |
| | | TreeDeptWell n = (TreeDeptWell) it.next(); |
| | | if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) |
| | | { |
| | | tlist.add(n); |
| | | } |
| | | } |
| | | return tlist; |
| | | } |
| | | |
| | | private boolean hasChildWell(List<TreeDeptWell> list, TreeDeptWell t) |
| | | { |
| | | return getChildListWell(list, t).size() > 0; |
| | | } |
| | | } |