效果图
根据输入的id为2查询出所有的红色框起来的节点
mapper接口
TSystemOrg getOrgByorgId(String orgId);
List<TSystemOrg> getOrgListByParentId(String parentId);
mapper.xml
<!--根据id查询org-->
<select id="getOrgByorgId" resultType="com.iflytek.core.entity.TSystemOrg">SELECT*FROMt_system_orgWHEREid=#{orgId}andis_delete = '0'
</select><!--根据parentId查询orgList-->
<select id="getOrgListByParentId" resultType="com.iflytek.core.entity.TSystemOrg">SELECT*FROMt_system_orgWHEREparent_id=#{parentId}andis_delete = '0'
</select>
service接口
List<TSystemOrg> getOrgListByOrgId(String orgId);
serviceImpl实现
@Override
public List<TSystemOrg> getOrgListByOrgId(String orgId) {TSystemOrg org = mapper.getOrgByorgId(orgId);List<TSystemOrg> resultList = new ArrayList<>();resultList.add(org);diguiGetOrgListByParentId(org, resultList);return resultList;
}private void diguiGetOrgListByParentId(TSystemOrg org, List<TSystemOrg> resultList) {List<TSystemOrg> orgList = mapper.getOrgListByParentId(org.getId());if(orgList != null){for(TSystemOrg o : orgList){resultList.add(o);//递归调用自己diguiGetOrgListByParentId(o,resultList);}}
}
controller
@ApiOperation(value = "根据orgId获取所有子节点",tags = "机构")
@PostMapping("getOrgListByOrgId")
public ResultDto getOrgListByOrgId(String orgId){return ResultUtil.success("success", service.getOrgListByOrgId(orgId));
}