当前位置:网站首页>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 -边栏推荐
- Deep analysis of data storage in memory
- What is needed to develop a domestic arm intelligent edge computing gateway
- 文件操作IO-Part2
- Machine learning: numpy version linear regression predicts Boston house prices
- About qbytearray storage hexadecimal and hexadecimal conversion
- [shutter] image component (configure local GIF image resources | load placeholder with local resources)
- 解决ReactNative使用webView存在缓存问题
- Leetcode-2280: represents the minimum number of line segments of a line graph
- How to convert Quanzhi a40i/t3 to can through SPI
- Leetcode-2115: find all the dishes that can be made from the given raw materials
猜你喜欢

The arm core board / development board of Feiling equipped with Ti am62x made its debut in embedded world 2022

Infrared thermography temperature detection system based on arm rk3568

研发一款国产ARM智能边缘计算网关需要什么

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

【AutoSAR 九 C/S原理架构】

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

1.11 - bus

Vulkan performance and refinement

How to systematically learn machine learning
![[overview of AUTOSAR four BSW]](/img/19/c2273bbedb7f8d859e5a3805ed5740.png)
[overview of AUTOSAR four BSW]
随机推荐
Key detection and sinusoidal signal output developed by Arduino
AEM: Nanlin fan Ben et al. - plant rhizosphere growth promoting bacteria control soybean blight
There is an unknown problem in inserting data into the database
[love crash] neglected details of gibaro
Teach you JDBC hand in hand -- structure separation
深度剖析数据在内存中的存储
【小程序项目开发-- 京东商城】uni-app之自定义搜索组件(中)-- 搜索建议
[AUTOSAR eight OS]
Cordova plugin device obtains the device information plug-in, which causes Huawei to fail the audit
【AutoSAR 三 RTE概述】
Tensorflow 2.x(keras)源码详解之第十五章:迁移学习与微调
University of Toronto: Anthony coach | the conditions of deep reinforcement learning can induce dynamic risk measurement
2022上半年值得被看见的10条文案,每一句都能带给你力量!
MySQL multi table joint deletion
【AutoSAR 四 BSW概述】
Set up nacos2 X cluster steps and problems encountered
【AutoSAR 五 方法论】
Callback event after the antv X6 node is dragged onto the canvas (stepping on a big hole record)
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
(C language) data storage