package com.jwipc.util;

import cn.hutool.core.collection.CollUtil;
import com.jwipc.dto.ZTreeDTO;
import com.jwipc.dto.ZTreeDataDTO;

import java.util.List;

/**
 * <p> </p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
public class ZTreeUtil {
    public static List<ZTreeDTO<ZTreeDataDTO>> listToZtree(List<ZTreeDataDTO> organizations) {
        final List<ZTreeDTO<ZTreeDataDTO>> zTreeVOList = CollUtil.newArrayList();
        for (ZTreeDataDTO treeDataVO : organizations) {
            final String parentId = treeDataVO.getParentId();
            final ZTreeDTO<ZTreeDataDTO> zTreeVO = ZTreeDTO.<ZTreeDataDTO>builder()
                    .data(treeDataVO)
                    .id(treeDataVO.getId())
                    .pid(parentId == null ? "" : parentId)
                    .name(treeDataVO.getName())
                    .build();
            zTreeVOList.add(zTreeVO);
        }
        return zTreeVOList;
    }
}
