zoukankan      html  css  js  c++  java
  • 递归查询

    select id,name from sys_dept where pids like '%1067246875800000065%' and del_flag = 0

    select id,name from sys_dept where pid ='1067246875800000065' and del_flag = 0


    /**
    * getChildSubDeptIdList
    * @return
    */
    @GetMapping("getChildSubDeptIdList")
    @ApiOperation("getChildSubDeptIdList")
    public Result<List<Long>> getChildSubDeptIdList(){
    List<Long> idList =new ArrayList<>();
    List<Long> data = sysDeptService.getChildSubDeptIdList(1067246875800000065L,idList);
    return new Result<List<Long>>().ok(data);
    }



    /**
    *
    * @param id 部门ID
    * @return
    */
    @Override
    public List<Long> getChildSubDeptIdList(Long id,List<Long> idList) {
    List<Long> deptIdList = baseDao.getChildSubDeptIdList(id);
    for (int i=0;i<deptIdList.size();i++){
    Long deptId= deptIdList.get(i);
    idList.add(deptId);
    getChildSubDeptIdList(deptId,idList);
    }
    deptIdList.add(id);
    return idList;
    }

    /**
    * 根据部门ID,获取所有子部门ID列表
    * @param id 部门ID
    */
    List<Long> getChildSubDeptIdList(Long id);


    <select id="getChildSubDeptIdList" resultType="long">
    select id from sys_dept where pid = #{id} and del_flag = 0
    </select>


    子查询父级
    /**
    * getParentPidById
    * @return
    */
    @GetMapping("getParentPidById")
    @ApiOperation("getParentPidById")
    public Result<List<Long>> getParentPidById(){
    List<Long> idList =new ArrayList<>();
    List<Long> data = sysDeptService.getParentPidById(1425390890702680066L,idList);
    return new Result<List<Long>>().ok(data);
    }

    /**
    * 根据部门ID,获取本部门及父部门ID列
    * @param id
    * @param idList
    * @return
    */
    List<Long> getParentPidById(Long id,List<Long> idList);


    /**
    * getParentPidById
    * @param id
    * @param idList
    * @return
    */
    @Override
    public List<Long> getParentPidById(Long id,List<Long> idList) {
    Long deptId = baseDao.getParentPidById(id);
    if (deptId!=null && deptId!=0L){
    idList.add(deptId);
    getParentPidById(deptId,idList);
    }
    return idList;
    }

    /**
    * 根据部门ID,获取所有父部门ID列表
    * @param id
    * @return
    */
    Long getParentPidById(Long id);

    <select id="getParentPidById" resultType="long">
    select pid from sys_dept where id = #{id} and del_flag = 0
    </select>






    /**
    * 获取所有上级部门ID
    * @param pid 上级ID
    */
    private String getPidList(Long pid){
    //顶级部门,无上级部门
    if(Constant.DEPT_ROOT.equals(pid)){
    return Constant.DEPT_ROOT + "";
    }

    //所有部门的id、pid列表
    List<SysDeptEntity> deptList = baseDao.getIdAndPidList();

    //list转map
    Map<Long, SysDeptEntity> map = new HashMap<>(deptList.size());
    for(SysDeptEntity entity : deptList){
    map.put(entity.getId(), entity);
    }

    //递归查询所有上级部门ID列表
    List<Long> pidList = new ArrayList<>();
    getPidTree(pid, map, pidList);

    return StringUtils.join(pidList, ",");
    }


    /**
    * 递归查询
    * @param pid
    * @param map
    * @param pidList
    */
    private void getPidTree(Long pid, Map<Long, SysDeptEntity> map, List<Long> pidList) {
    //顶级部门,无上级部门
    if(Constant.DEPT_ROOT.equals(pid)){
    return ;
    }

    //上级部门存在
    SysDeptEntity parent = map.get(pid);
    if(parent != null){
    getPidTree(parent.getPid(), map, pidList);
    }

    pidList.add(pid);
    }
    小蚊子大人
  • 相关阅读:
    jquery easyui-datagrid手动增加删除重置行
    jsp中一行多条数据情况
    JQuery操作下拉框
    解决juqery easyui combobox只能选择问题
    oracle中WMSYS.WM_CONCAT函数的版本差异
    oracle wm_concat(column)函数的使用
    Javascript九大排序算法详解
    C#和VB新版本的最新特性列表
    Oracle中如何区别用户和模式
    远程控制数据库实用SQL重启功能
  • 原文地址:https://www.cnblogs.com/ywsheng/p/15132372.html
Copyright © 2011-2022 走看看