package com.lxzn.ucenter.service.support;
|
|
import com.lxzn.framework.domain.ucenter.ObjectBase;
|
import com.lxzn.framework.domain.ucenter.ObjectButton;
|
import com.lxzn.framework.domain.ucenter.ObjectButtonPermission;
|
import com.lxzn.framework.model.response.CommonJsonTree;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
public class ObjectButtonTreeWrapper {
|
|
public static List<CommonJsonTree> loadTree(List<ObjectBase> objectBaseList, List<ObjectButton> objectButtonList, Map<String, ObjectButtonPermission> map) {
|
List<CommonJsonTree> tree = new ArrayList<CommonJsonTree>();// TreeNode集合,存放所有树对象。
|
List<CommonJsonTree> result = new ArrayList<CommonJsonTree>();// TreeNode集合,存放所有树对象。
|
Map<String, CommonJsonTree> objectTreeMap = new HashMap<>();
|
objectBaseList.forEach(item -> {
|
CommonJsonTree node = new CommonJsonTree();
|
node.setId(item.getObjectId());
|
node.setLabel(item.getObjectName());
|
node.setDisabled(false);
|
objectTreeMap.put(item.getObjectId(), node);
|
tree.add(node);
|
});
|
objectButtonList.forEach(item -> {
|
CommonJsonTree node = new CommonJsonTree();
|
node.setId(item.getObjectButtonId());
|
node.setLabel(item.getButtonAlias());
|
node.setRField(item.getButtonId());
|
node.setParentId(item.getObjectId());
|
if(map != null && !map.isEmpty() && map.containsKey(item.getObjectId() + "_" + item.getButtonId())) {
|
node.setChecked(true);
|
}
|
if(objectTreeMap.containsKey(item.getObjectId())) {
|
CommonJsonTree parent = objectTreeMap.get(item.getObjectId());
|
parent.addChildren(node);
|
}
|
});
|
for(CommonJsonTree commonJsonTree : tree) {
|
if(commonJsonTree.hasChildren()) {
|
result.add(commonJsonTree);
|
}
|
}
|
return result;
|
}
|
}
|