package com.bonus.system.att.utils;

import com.bonus.common.core.constant.Constants;
import com.bonus.system.basic.domain.SysTree;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 树整合child工具类
 * @author zys
 */
public class TreeUtils {

    public static List<SysTree> getOrgTreeChild(SysTree tree, List<SysTree> list, int type) {
        return list.stream().filter(m -> m.getParentId() != null && m.getParentId().equals(tree.getId()))
                .peek((m) -> {
                            m.setChildren(getOrgTreeChild(m, list, type));
                            if(type == 1) {
                                if (m.getId().contains(Constants.VERTICAL)) {
                                    m.setId(m.getId().substring(0, m.getId().indexOf(Constants.VERTICAL)));
                                }
                            }
                        }
                ).collect(Collectors.toList());
    }

}
