当前位置:网站首页>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 -边栏推荐
- 深度剖析数据在内存中的存储
- 飞凌搭载TI AM62x的ARM核心板/开发板首发上市,亮相Embedded World 2022
- [AUTOSAR eight OS]
- Vulkan practice first bullet
- [AUTOSAR I overview]
- [overview of AUTOSAR three RTE]
- 瑞萨电子RZ/G2L开发板上手评测
- Initial order of pointer (basic)
- 全志A40i/T3如何通过SPI转CAN
- Web2.0 giants have deployed VC, and tiger Dao VC may become a shortcut to Web3
猜你喜欢
[case sharing] let the development of education in the new era advance with "number"
How to convert Quanzhi a40i/t3 to can through SPI
利亚德:Micro LED 产品消费端首先针对 100 英寸以上电视,现阶段进入更小尺寸还有难度
【AutoSAR 十三 NVM】
Use Jenkins II job
What is needed to develop a domestic arm intelligent edge computing gateway
正确甄别API、REST API、RESTful API和Web Service之间的异同
[overview of AUTOSAR four BSW]
12_微信小程序之微信视频号滚动自动播放视频效果实现
2022.2.14 resumption
随机推荐
Vulkan-实践第一弹
Tensorflow 2. Chapter 15 of X (keras) source code explanation: migration learning and fine tuning
leetcode-871:最低加油次数
[AUTOSAR twelve mode management]
[AUTOSAR 11 communication related mechanism]
[case sharing] let the development of education in the new era advance with "number"
lex && yacc && bison && flex 配置的問題
[AUTOSAR + IO Architecture]
Vulkan is not a "panacea"“
MySQL multi table joint deletion
1.12 - 指令
What is needed to develop a domestic arm intelligent edge computing gateway
腾讯云免费SSL证书扩展文件含义
leetcode-849:到最近的人的最大距离
[jetcache] jetcache configuration description and annotation attribute description
Understanding and distinguishing of some noun concepts in adjustment / filtering
详解RDD基本概念、RDD五大属性
Illustrated network: what is virtual router redundancy protocol VRRP?
(C语言)数据的存储
[shutter] image component (configure local GIF image resources | load placeholder with local resources)