You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.8 KiB
Java
54 lines
1.8 KiB
Java
package com.engine.organization.webservice;
|
|
|
|
import com.engine.organization.entity.comp.po.CompPO;
|
|
import com.engine.organization.mapper.comp.CompMapper;
|
|
import com.engine.organization.util.db.MapperProxyFactory;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* @description: TODO
|
|
* @author:dxfeng
|
|
* @createTime: 2022/05/23
|
|
* @version: 1.0
|
|
*/
|
|
public class CustomBrowserServiceImpl implements CustomBrowserService {
|
|
private CompMapper getCompMapper() {
|
|
return MapperProxyFactory.getProxy(CompMapper.class);
|
|
}
|
|
|
|
@Override
|
|
public List<CompPO> getCompTreeList() {
|
|
// 获取所有启用数据
|
|
List<CompPO> allList = getCompMapper().list().stream().filter(item -> 0 == item.getForbiddenTag()).collect(Collectors.toList());
|
|
|
|
List<CompPO> parentList = allList.stream().filter(item -> (null == item.getParentCompany() || 0 == item.getParentCompany())).collect(Collectors.toList());
|
|
Map<Long, List<CompPO>> compMap = allList.stream().filter(item -> (null != item.getParentCompany() && 0 != item.getParentCompany())).collect(Collectors.groupingBy(CompPO::getParentCompany));
|
|
List<CompPO> returnList = new ArrayList<>();
|
|
dealChildren(parentList, returnList, compMap);
|
|
|
|
return returnList;
|
|
}
|
|
|
|
/**
|
|
* 处理分部子节点
|
|
*
|
|
* @param parentList
|
|
* @param returnList
|
|
* @param compMap
|
|
*/
|
|
private void dealChildren(List<CompPO> parentList, List<CompPO> returnList, Map<Long, List<CompPO>> compMap) {
|
|
if (CollectionUtils.isEmpty(parentList)) {
|
|
return;
|
|
}
|
|
for (CompPO compPO : parentList) {
|
|
returnList.add(compPO);
|
|
dealChildren(compMap.get(compPO.getId()), returnList, compMap);
|
|
}
|
|
}
|
|
}
|