当前位置:网站首页>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 -边栏推荐
- 2022上半年值得被看见的10条文案,每一句都能带给你力量!
- Vulkan practice first bullet
- cordova-plugin-device获取设备信息插件导致华为审核不通过
- What is needed to develop a domestic arm intelligent edge computing gateway
- [overview of AUTOSAR three RTE]
- Lex & yacc & bison & flex configuration problems
- Problèmes de configuration lex & yacc & Bison & Flex
- 【AutoSAR 一 概述】
- 数组与集合性能比较
- [introduction to AUTOSAR seven tool chain]
猜你喜欢

Unity learns from spaceshooter to record the difference between fixedupdate and update in unity for the second time

Foundations of data science is free to download

The difference between tail -f, tail -f and tail

Sentry developer contribution Guide - configure pycharm

RK3568开发板评测篇(二):开发环境搭建

Illustrated network: what is virtual router redundancy protocol VRRP?
![[applet project development -- JD mall] user defined search component of uni app (middle) -- search suggestions](/img/ea/ee1ad50a497478b9d080bb5e4bdfb5.png)
[applet project development -- JD mall] user defined search component of uni app (middle) -- search suggestions

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

飞凌搭载TI AM62x的ARM核心板/开发板首发上市,亮相Embedded World 2022

安全运营四要素之资产、脆弱性、威胁和事件
随机推荐
Set up nacos2 X cluster steps and problems encountered
【爱死机】《吉巴罗》被忽略的细节
There is an unknown problem in inserting data into the database
FPGA - 7系列 FPGA内部结构之Clocking -04- 多区域时钟
Vulkan-性能及精细化
In the first half of 2022, there are 10 worth seeing, and each sentence can bring you strength!
Overlay of shutter (Pop-Up)
[shutter] image component (load network pictures | load static pictures | load local pictures | path | provider plug-in)
[introduction to AUTOSAR seven tool chain]
[daily training] 871 Minimum refueling times
Callback event after the antv X6 node is dragged onto the canvas (stepping on a big hole record)
leetcode-934:最短的桥
【AutoSAR 八 OS】
[Luogu p4320] road meets (round square tree)
Rust string slicing, structs, and enumeration classes
正确甄别API、REST API、RESTful API和Web Service之间的异同
leetcode-2115:从给定原材料中找到所有可以做出的菜
Leetcode-224: basic calculator
Initial order of pointer (basic)
[AUTOSAR 11 communication related mechanism]