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 getCompTreeList() { // 获取所有启用数据 List allList = getCompMapper().list().stream().filter(item -> 0 == item.getForbiddenTag()).collect(Collectors.toList()); List parentList = allList.stream().filter(item -> (null == item.getParentCompany() || 0 == item.getParentCompany())).collect(Collectors.toList()); Map> compMap = allList.stream().filter(item -> (null != item.getParentCompany() && 0 != item.getParentCompany())).collect(Collectors.groupingBy(CompPO::getParentCompany)); List returnList = new ArrayList<>(); dealChildren(parentList, returnList, compMap); return returnList; } /** * 处理分部子节点 * * @param parentList * @param returnList * @param compMap */ private void dealChildren(List parentList, List returnList, Map> compMap) { if (CollectionUtils.isEmpty(parentList)) { return; } for (CompPO compPO : parentList) { returnList.add(compPO); dealChildren(compMap.get(compPO.getId()), returnList, compMap); } } }