OA系统部门结构树

public class DepartmentUtils {

/**
* @param topList 顶级部门列表
* @param removeId 删除部门的id
* @return
*/
public static List<Department> getTreeList(List<Department> topList,Long removeId) {
List<Department> treeList = new ArrayList<Department>();

walkTree(topList,treeList,"┣",removeId);

return treeList;
}

/**
* 组织树形部门数据
*/
public static void walkTree(Collection<Department> topList,List<Department> treeList ,String prefix ,Long removeId){
for(Department d : topList){
if(removeId != null && d.getId().equals(removeId)){
//结束本次循环,直接下一次循环
continue;
}
//为了避免修改数据库,创建出新的对象,修改新的对象,在放入到treeList里面
Department copy = new Department();
copy.setId(d.getId());
copy.setName(prefix + d.getName());

//顶点
treeList.add(copy);
//子树
Set<Department> children = d.getChildren();
walkTree(children,treeList," " + prefix,removeId);
}
}
}

 

 

在部门action里面的调用:

public String editUI(){

//准备数据:要修改的部门
Department dept = departmentService.getById(model.getId());

//准备数据:部门列表
List<Department> topList = departmentService.findTopList();//所有顶级部门列表
List<Department> treeList = DepartmentUtils.getTreeList(topList,dept.getId());

getValueStack().set("departmentList", treeList);
getValueStack().push(dept);

if(dept.getParent() != null){
parentId = dept.getParent().getId();//设置parentId的值,用于回显
}
return "editUI";
}

转载于:https://www.cnblogs.com/wxm-bk/p/5802836.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值