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<CommonGenericTree> loadTree(List<DeviceGroupExt> deviceGroupExtList) {
|
Map<String, CommonGenericTree> treeMap = new HashMap<>();
|
for(DeviceGroupExt ext : deviceGroupExtList) {
|
treeMap = getBaseNodeMap(ext, treeMap);
|
}
|
return CommonGenericTree.convertMapToList(treeMap);
|
}
|
|
public static List<CommonGenericTree> loadDepartTree(List<DeviceGroupExt> deviceGroupExtList) {
|
List<CommonGenericTree> tree = new ArrayList<CommonGenericTree>();// TreeNode集合,存放所有树对象。
|
CommonGenericTree<DeviceGroup> node;
|
DeviceGroup deviceGroup;
|
for(DeviceGroupExt ext : deviceGroupExtList) {
|
node = new CommonGenericTree<DeviceGroup>();
|
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<DeviceGroupExt> children = info.getChildren();
|
CommonGenericTree<DeviceGroup> 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<String,CommonGenericTree> getBaseNodeMap(DeviceGroupExt ext, Map<String,CommonGenericTree> map) {
|
CommonGenericTree<DeviceGroup> node;
|
DeviceGroup deviceGroup;
|
if(ext.getRankLevel() == 1) {
|
node = new CommonGenericTree<DeviceGroup>();
|
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<DeviceGroup>();
|
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);
|
}
|
}
|
}
|