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 loadTree(List objectBaseList, List objectButtonList, Map map) { List tree = new ArrayList();// TreeNode集合,存放所有树对象。 List result = new ArrayList();// TreeNode集合,存放所有树对象。 Map 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; } }