当前位置:网站首页>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 -边栏推荐
- Lex & yacc & bison & flex configuration problems
- Use Jenkins II job
- [shutter] image component (cached_network_image network image caching plug-in)
- The arm core board / development board of Feiling equipped with Ti am62x made its debut in embedded world 2022
- Shell implements basic file operations (SED edit, awk match)
- 世平信息首席科学家吕喆:构建以数据和人员为中心的安全能力
- 1038 Recover the Smallest Number
- 瑞萨电子RZ/G2L开发板上手评测
- Linux Software: how to install redis service
- 1.12 - Instructions
猜你喜欢

(C language) data storage

数据分析思维分析犯法和业务知识——分析方法(一)

全志A40i/T3如何通过SPI转CAN

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
![[shutter] image component (configure local GIF image resources | load placeholder with local resources)](/img/73/19e2e0fc5ea6f05e34584ba40a452d.jpg)
[shutter] image component (configure local GIF image resources | load placeholder with local resources)

Initial order of pointer (basic)

【AutoSAR 十二 模式管理】

Rust string slicing, structs, and enumeration classes

1.12 - 指令

Foundations of data science is free to download
随机推荐
lex && yacc && bison && flex 配置的問題
Leetcode-2115: find all the dishes that can be made from the given raw materials
递归处理组织的几种情况
【AutoSAR 八 OS】
[love crash] neglected details of gibaro
lex && yacc && bison && flex 配置的问题
腾讯云免费SSL证书扩展文件含义
机器学习:numpy版本线性回归预测波士顿房价
2022 list of manufacturers of Chinese 3D vision enterprises (guided positioning and sorting scenes)
利亚德:Micro LED 产品消费端首先针对 100 英寸以上电视,现阶段进入更小尺寸还有难度
Baidu AI Cloud takes the lead in building a comprehensive and standardized platform for smart cloud
Thread start and priority
[overview of AUTOSAR four BSW]
Leetcode-224: basic calculator
[shutter] image component (configure local GIF image resources | load placeholder with local resources)
测试右移:线上质量监控 ELK 实战
How to systematically learn machine learning
【AutoSAR 十 IO架构】
文件操作IO-Part2
[AUTOSAR twelve mode management]