|
|
@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Objects; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -134,10 +135,63 @@ public class SysColumnServiceImpl extends ServiceImpl<SysColumnMapper, SysColumn |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public R getsTheSubColumn(Integer parentId,String ids) { |
|
|
|
public R getsTheSubColumn(Integer pid, String ids) { |
|
|
|
return R.success(baseMapper.getsTheSubColumn(parentId,ids)); |
|
|
|
|
|
|
|
|
|
|
|
List<SysColumn> getsTheSubColumn = baseMapper.getsTheSubColumn(pid, ids); |
|
|
|
|
|
|
|
//用来保存父节点
|
|
|
|
|
|
|
|
List<SysColumn> rootColumn = new ArrayList<>(); |
|
|
|
|
|
|
|
//用来保存子节点
|
|
|
|
|
|
|
|
List<SysColumn> childList = new ArrayList<>(); |
|
|
|
|
|
|
|
//遍历所有栏目,将所有栏目的父栏目id为0的栏目放入父节点集合中
|
|
|
|
|
|
|
|
for (SysColumn column1 : getsTheSubColumn) { |
|
|
|
|
|
|
|
Integer parentId = column1.getFatherId(); |
|
|
|
|
|
|
|
if (parentId == 0) { |
|
|
|
|
|
|
|
rootColumn.add(column1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (SysColumn sysColumn : rootColumn) { |
|
|
|
|
|
|
|
Integer theColumnId = sysColumn.getId(); |
|
|
|
|
|
|
|
//调用工具类获取子节点
|
|
|
|
|
|
|
|
childList = getChildren(theColumnId, getsTheSubColumn); |
|
|
|
|
|
|
|
sysColumn.setChildren(childList); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return R.success(rootColumn); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//return R.success(baseMapper.getsTheSubColumn(parentId, ids));
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public R getsSublevelColumnsUnderALevel(Integer parentId, String ids) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<SysColumn> getsTheSubColumn = baseMapper.getsTheSubColumn(parentId, ids); |
|
|
|
|
|
|
|
List<SysColumn> buildTree= buildTree(getsTheSubColumn, parentId); |
|
|
|
|
|
|
|
return R.success(buildTree); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//把一个List转成树
|
|
|
|
|
|
|
|
static List<SysColumn> buildTree(List<SysColumn> list,Integer pid){ |
|
|
|
|
|
|
|
List<SysColumn> tree=new ArrayList<>(); |
|
|
|
|
|
|
|
for(SysColumn node:list){ |
|
|
|
|
|
|
|
if(Objects.equals(node.getFatherId(),pid)){ |
|
|
|
|
|
|
|
tree.add(findChild(node,list)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return tree; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static SysColumn findChild(SysColumn node, List<SysColumn> list){ |
|
|
|
|
|
|
|
for(SysColumn n:list){ |
|
|
|
|
|
|
|
if(Objects.equals(n.getFatherId(),node.getId())){ |
|
|
|
|
|
|
|
if(node.getChildren() == null){ |
|
|
|
|
|
|
|
node.setChildren(new ArrayList<SysColumn>()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
node.getChildren().add(findChild(n,list)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return node; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static List<SysColumn> getChildren(Integer id, List<SysColumn> allDept) { |
|
|
|
public static List<SysColumn> getChildren(Integer id, List<SysColumn> allDept) { |
|
|
|
//存放子节点
|
|
|
|
//存放子节点
|
|
|
|