package org.jeecg.modules.dnc.service.support; import org.jeecg.modules.dnc.dto.ComponentExt; import org.jeecg.modules.dnc.entity.ComponentInfo; import org.jeecg.modules.dnc.response.CommonGenericTree; import org.springframework.beans.BeanUtils; import java.util.HashMap; import java.util.List; import java.util.Map; public class ComponentTreeWrapper { public static List loadTree(List componentInfoList) { Map treeMap = new HashMap<>(); for(ComponentExt ext : componentInfoList) { treeMap = getBaseNodeMap(ext, treeMap); } return CommonGenericTree.convertMapToList(treeMap); } private static CommonGenericTree loadChildrenNodes(ComponentExt info, CommonGenericTree node) { if(info.hasChild()) { List children = info.getChildren(); CommonGenericTree childNode; ComponentInfo componentInfo; for (ComponentExt ext : children) { childNode = new CommonGenericTree(); childNode.setId(ext.getComponentId()); childNode.setLabel(ext.getComponentName()); childNode.setParentId(info.getComponentId()); //设置菜单节点图标 Start String iconStr = ""; /*判断是否设置了菜单导航图标样式*/ if (!ext.hasChild()) {//导航页面的菜单节点 iconStr = "";//默认图标 } childNode.setIconClass(iconStr); childNode.setType(2); componentInfo = new ComponentInfo(); BeanUtils.copyProperties(ext, componentInfo); childNode.setEntity(componentInfo); node.setRField(ext.getProductId()); childNode = loadChildrenNodes(ext, childNode); node.addChildren(childNode); } } return node; } private static Map getBaseNodeMap(ComponentExt ext, Map allNodeMap) { CommonGenericTree node; ComponentInfo componentInfo; if(ext.getRankLevel() == 1) { node = new CommonGenericTree(); node.setId(ext.getComponentId()); node.setLabel("[" + ext.getComponentCode()+ "]" + ext.getComponentName()); node.setParentId(null); //设置菜单节点图标 Start String iconStr = ""; /*判断是否设置了菜单导航图标样式*/ if (!ext.hasChild()) {//导航页面的菜单节点 iconStr = "";//默认图标 } node.setIconClass(iconStr); node.setType(2); node.setRField(ext.getProductId()); componentInfo = new ComponentInfo(); BeanUtils.copyProperties(ext, componentInfo); node.setEntity(componentInfo); allNodeMap.put(node.getId(), node); }else { node = new CommonGenericTree(); node.setId(ext.getComponentId()); node.setLabel("[" + ext.getComponentCode()+ "]" + ext.getComponentName()); node.setParentId(ext.getParentId()); //设置菜单节点图标 Start String iconStr = ""; /*判断是否设置了菜单导航图标样式*/ if (!ext.hasChild()) {//导航页面的菜单节点 iconStr = "";//默认图标 } node.setIconClass(iconStr); node.setType(2); node.setRField(ext.getProductId()); componentInfo = new ComponentInfo(); BeanUtils.copyProperties(ext, componentInfo); node.setEntity(componentInfo); allNodeMap.put(node.getId(), node); } return allNodeMap; } }