获取部门及其子部门树

获取部门及其子部门树,返回map结构

public R getDepOrgWithChildrenTreeMap() {
        SysUserEntity employee=getUser();
        List<DepNode> depNodes=new ArrayList<>();
        if(StringUtils.isNotBlank(employee.getDepOrg())){
        //查询父级
            DepNode depNode= departmentDao.getSelfNode(employee.getDepOrg());
            //查询子节点
            depNode.setChildren(departmentService.getTreeByDep(employee.getDepOrg()));
            //添加子节点
            depNodes.add(depNode);
        }else {
            return R.error("未获取到当前用户的部门编号");
        }
        return R.ok().put("data",depNodes);
    }
public List<DepNode> getTreeByDep(String depOrg) {

       List<DepNode> depNodes= departmentDao.getChildrenNodeByPid(depOrg);

       for(DepNode depNode:depNodes)
       {
           depNode.setChildren(this.getTreeByDep(depNode.getDepOrg()));
       }

        return depNodes;
    }

定义一个实体类

private  Integer id;
    private  String name;

    private  boolean open;
    private List<DepNode>  children;
    private  String depOrg;
<select id="getSelfNode" resultType="io.athena.modules.ins.entity.DepNode">
        select  guid as id,dep_name as name,false as open,dep_org  from t_department where dep_org=#{depOrg}
    </select>

    <select id="getChildrenNodeByPid" resultType="io.athena.modules.ins.entity.DepNode">
        select  guid as id,dep_name as name,false as open,dep_org from t_department where dep_parent=#{depOrg}
    </select>

    <!--查询所有部门的名称与代码-->
    <select id="queryAllDepOrg" resultType="com.alibaba.fastjson.JSONObject">
        select dep_name,dep_org from t_department
    </select>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值