接口:
EntityResult getOrgReal(Map<String, Object> mapParam);
实现类:
@PMethodHandle(runMethodName = "TQmsZjxmzbImpl.getOrgReal", timeout = 600) @Override public EntityResult getOrgReal(Map<String, Object> mapParam) { String mapStr = JSON.toJSONString(mapParam); TOrganizationRealVo resultVo = JSON.parseObject(mapStr, TOrganizationRealVo.class); List<TOrganizationRealVo> result =libraryList(resultVo); return ResultHelper.okEntity(result, "成功"); }
/**
* 获取第一级的元素
*/
public List<TOrganizationRealVo> libraryList(TOrganizationRealVo sysLibrary) {
List<TOrganizationRealVo> sysLibraries = qmsZjxmzbMapper.queryOrgReal(sysLibrary);
return sysLibraries.stream()
//过滤父id为0的分类
.filter(l -> l.getParentOrgRealationId().equals("-1"))
//将上面的过滤后得到的分类list获取子分类进行封装,
//peek()是过程流,不会进行输出,只会对list中的每一元素都执行一次Consumer。
.peek(c -> c.setChildren(getChildren(sysLibraries, c.getOrgRealationId())))
//按照id进行排序
// .sorted(Comparator.comparingLong(TOrganizationRealVo::getLibraryId))
.collect(Collectors.toList());
}
/**
* 获取子分类
*
* @param sysLibraries
* @return
*/
public List<TOrganizationRealVo> getChildren(List<TOrganizationRealVo> sysLibraries, String parentId) {
return sysLibraries.stream()
.filter(l -> l.getParentOrgRealationId().equals(parentId))
.peek(c -> c.setChildren(getChildren(sysLibraries, c.getOrgRealationId())))
// .sorted(Comparator.comparingLong(TOrganizationRealVo::getOrgRealationId))
.collect(Collectors.toList());
}
实体类:
/**
* 组织
*/
@Data
public class TOrganizationRealVo {
private String orgRealationId;
private String orgId;
private String parentOrgRealationId;
private String orgName;
private String orgCode;
private String orgRelationCode;
private String orgRealationType;
private List<TOrganizationRealVo> children;
数据库直接查询所有就可以
展现效果: