当前位置:网站首页>Several cases of recursive processing organization
Several cases of recursive processing organization
2022-07-03 00:59:00 【It snows at night when the boat is moored, and he can expect it】
Recursively handle several cases of organization
Preface
A little summary of recent work , Record here .
Recursive encapsulation tree structure organization
/**
* Tree structure encapsulation
*
* @param root
* @param all
* @return
*/
private List<OrgVO> getChildren(OrgVO root, List<OrgVO> all) {
return all.stream().filter(orgVO ->
root.getId().equals(orgVO.getParentId())).map(orgVO -> {
orgVO.setChildrenEntity(getChildren(orgVO, all));
return orgVO;
}).sorted(Comparator.comparingInt(c -> (c.getSort() == null ? 0 : c.getSort()))).collect(Collectors.toList());
}
Recursively obtain descendants
/**
* Recursively obtain descendants
* @param orgCode
* @return
*/
private List<Org> getAllChildren(String orgCode){
List<Org> allChildren = new ArrayList<>();
List<Org> orgListByParent = OrgService.getOrgListByParent(orgCode);
// Judge here size Greater than 1 The reason is that getOrgListByParent() Method if the descendant institution is not obtained, the current institution information is returned
if (CollectionUtils.isNotEmpty(orgListByParent) && orgListByParent.size() > 1){
allChildren.addAll(orgListByParent);
for (Org org : orgListByParent) {
List<Org> children = getAllChildren(organization.getOrgCode());
allChildren.addAll(children);
}
}
return allChildren;
}
Recursively accumulate the number of descendants
/**
* Recursive statistics current + Number of descendants , And return to the current department and sub level
* @param root
* @param data
* @return
*/
private List<UserDTO> getUserNum(UserDTO root, List<UserDTO> data){
Integer userCount = root.getUserCount();
data.forEach(dto -> {
if (root.getOrgCode().equals(dto.getParentCode())){
root.setUserCount(userCount+dto.getUserCount());
List<UserDTO> collect = data.stream().filter(dto1 -> dto1.getParentCode().equals(dto.getOrgCode())).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(collect)){
getUserNum(dto,collect);
}
}
});
List<UserDTO> collect = data.stream().filter(userDTO -> userDTO.getParentCode().equals(root.getOrgCode())).collect(Collectors.toList());
root.userCount(collect.stream().map(UserDTO::getUserCount).mapToInt(Integer::intValue).sum()+userCount);
collect.add(0,root);
return collect;
}
summary
Recursively count the number of people. Exceptions may occur in this method , Pay attention to .
- END -边栏推荐
- Hdu3507 (slope DP entry)
- matlab将数字矩阵保存为地理空间数据出错,显示下标索引必须为正整数类型或逻辑类型,解决
- 1.11 - 总线
- 12_微信小程序之微信视频号滚动自动播放视频效果实现
- 【AutoSAR 十二 模式管理】
- lex && yacc && bison && flex 配置的問題
- In the first half of 2022, there are 10 worth seeing, and each sentence can bring you strength!
- 1038 Recover the Smallest Number
- Reading and writing speed of Reza rz/g2l arm development board storage and network measurement
- 机器学习:numpy版本线性回归预测波士顿房价
猜你喜欢

Leetcode-2280: represents the minimum number of line segments of a line graph

Nacos+openfeign error reporting solution

leetcode-849:到最近的人的最大距离

Teach you JDBC hand in hand -- structure separation

Liad: the consumer end of micro LED products is first targeted at TVs above 100 inches. At this stage, it is still difficult to enter a smaller size

【AutoSAR 十 IO架构】

Win10 can't be installed in many ways Problems with NET3.5

【AutoSAR 十二 模式管理】

University of Toronto: Anthony coach | the conditions of deep reinforcement learning can induce dynamic risk measurement
![[AUTOSAR eight OS]](/img/ac/fbc84c077ff9c94c840e1871171d19.png)
[AUTOSAR eight OS]
随机推荐
Set up nacos2 X cluster steps and problems encountered
[flutter] icons component (load the built-in icon of flutter | display the material design icon completely)
Leetcode-241: designing priorities for operational expressions
leetcode-849:到最近的人的最大距离
Advanced pointer (I)
Test shift right: Elk practice of online quality monitoring
[overview of AUTOSAR three RTE]
Rust string slicing, structs, and enumeration classes
[AUTOSAR five methodology]
[introduction to AUTOSAR seven tool chain]
FPGA - 7系列 FPGA内部结构之Clocking -04- 多区域时钟
Lu Zhe, chief scientist of Shiping information: building data and personnel centered security capabilities
[love crash] neglected details of gibaro
matlab将数字矩阵保存为地理空间数据出错,显示下标索引必须为正整数类型或逻辑类型,解决
Thank you for being together for these extraordinary two years!
Win10 can't be installed in many ways Problems with NET3.5
First hand evaluation of Reza electronics rz/g2l development board
递归处理组织的几种情况
leetcode-934:最短的桥
百度智能云牵头打造智能云综合标准化平台