package org.jeecg.modules.dnc.service.support; import org.jeecg.modules.dnc.dto.DeviceGroupExt; import org.jeecg.modules.dnc.entity.DeviceGroup; import org.jeecg.modules.dnc.response.CommonGenericTree; import org.springframework.beans.BeanUtils; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class DeviceGroupTreeWrapper { public static List loadTree(List deviceGroupExtList) { Map treeMap = new HashMap<>(); for(DeviceGroupExt ext : deviceGroupExtList) { treeMap = getBaseNodeMap(ext, treeMap); } return CommonGenericTree.convertMapToList(treeMap); } public static List loadDepartTree(List deviceGroupExtList) { List tree = new ArrayList();// TreeNode集合,存放所有树对象。 CommonGenericTree node; DeviceGroup deviceGroup; for(DeviceGroupExt ext : deviceGroupExtList) { node = new CommonGenericTree(); node.setId(ext.getGroupId()); node.setLabel(ext.getGroupName()); node.setParentId(null); //设置菜单节点图标 Start String iconStr = ""; /*判断是否设置了菜单导航图标样式*/ if (!ext.hasChild()) {//导航页面的菜单节点 iconStr = "";//默认图标 } node.setIconClass(iconStr); node.setType(1); deviceGroup = new DeviceGroup(); BeanUtils.copyProperties(ext, deviceGroup); node.setEntity(deviceGroup); node = loadChildrenNodes(ext, node); tree.add(node); } return tree; } private static CommonGenericTree loadChildrenNodes(DeviceGroupExt info, CommonGenericTree node) { if(info.hasChild()) { List children = info.getChildren(); CommonGenericTree childNode; DeviceGroup deviceGroup; for (DeviceGroupExt ext : children) { childNode = new CommonGenericTree(); childNode.setId(ext.getGroupId()); childNode.setLabel(ext.getGroupName()); childNode.setParentId(ext.getParentId()); //设置菜单节点图标 Start String iconStr = ""; /*判断是否设置了菜单导航图标样式*/ if (!ext.hasChild()) {//导航页面的菜单节点 iconStr = "";//默认图标 } childNode.setIconClass(iconStr); childNode.setType(1); deviceGroup = new DeviceGroup(); BeanUtils.copyProperties(ext, deviceGroup); childNode.setEntity(deviceGroup); childNode = loadChildrenNodes(ext, childNode); node.addChildren(childNode); } } return node; } private static Map getBaseNodeMap(DeviceGroupExt ext, Map map) { CommonGenericTree node; DeviceGroup deviceGroup; if(ext.getRankLevel() == 1) { node = new CommonGenericTree(); node.setId(ext.getGroupId()); node.setLabel(ext.getGroupName()); node.setParentId(null); //设置菜单节点图标 Start String iconStr = ""; /*判断是否设置了菜单导航图标样式*/ if (!ext.hasChild()) {//导航页面的菜单节点 iconStr = "";//默认图标 } node.setIconClass(iconStr); node.setType(1); deviceGroup = new DeviceGroup(); BeanUtils.copyProperties(ext, deviceGroup); node.setEntity(deviceGroup); map.put(node.getId(), node); return map; }else { node = new CommonGenericTree(); node.setId(ext.getGroupId()); node.setLabel(ext.getGroupName()); node.setParentId(ext.getParentId()); //设置菜单节点图标 Start String iconStr = ""; /*判断是否设置了菜单导航图标样式*/ if (!ext.hasChild()) {//导航页面的菜单节点 iconStr = "";//默认图标 } node.setIconClass(iconStr); node.setType(1); deviceGroup = new DeviceGroup(); BeanUtils.copyProperties(ext, deviceGroup); node.setEntity(deviceGroup); map.put(node.getId(), node); return getBaseNodeMap(ext.getParent(), map); } } }