效果图
根据输入的id为2查询出所有的红色框起来的节点
mapper接口
java
TSystemOrg getOrgByorgId(String orgId);
List<TSystemOrg> getOrgListByParentId(String parentId);
mapper.xml
xml
<!--根据id查询org-->
<select id="getOrgByorgId" resultType="com.iflytek.core.entity.TSystemOrg">
SELECT
*
FROM
t_system_org
WHERE
id=#{orgId}
and
is_delete = '0'
</select>
<!--根据parentId查询orgList-->
<select id="getOrgListByParentId" resultType="com.iflytek.core.entity.TSystemOrg">
SELECT
*
FROM
t_system_org
WHERE
parent_id=#{parentId}
and
is_delete = '0'
</select>
service接口
java
List<TSystemOrg> getOrgListByOrgId(String orgId);
serviceImpl实现
java
@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
java
@ApiOperation(value = "根据orgId获取所有子节点",tags = "机构")
@PostMapping("getOrgListByOrgId")
public ResultDto getOrgListByOrgId(String orgId){
return ResultUtil.success("success", service.getOrgListByOrgId(orgId));
}