Search in sources :

Example 1 with Tree

use of io.github.tesla.ops.system.domain.Tree in project tesla by linking12.

the class MenuServiceImpl method getTree.

@Override
public Tree<MenuDO> getTree(Long id) {
    List<MenuDO> menus = menuMapper.list(new HashMap<String, Object>(16));
    List<Long> menuIds = roleMenuMapper.listMenuIdByRoleId(id);
    List<Long> temp = menuIds;
    for (MenuDO menu : menus) {
        if (temp.contains(menu.getParentId())) {
            menuIds.remove(menu.getParentId());
        }
    }
    List<Tree<MenuDO>> trees = new ArrayList<Tree<MenuDO>>();
    List<MenuDO> menuDOs = menuMapper.list(new HashMap<String, Object>(16));
    for (MenuDO sysMenuDO : menuDOs) {
        Tree<MenuDO> tree = new Tree<MenuDO>();
        tree.setId(sysMenuDO.getMenuId().toString());
        tree.setParentId(sysMenuDO.getParentId().toString());
        tree.setText(sysMenuDO.getName());
        Map<String, Object> state = new HashMap<>(16);
        Long menuId = sysMenuDO.getMenuId();
        if (menuIds.contains(menuId)) {
            state.put("selected", true);
        } else {
            state.put("selected", false);
        }
        tree.setState(state);
        trees.add(tree);
    }
    Tree<MenuDO> t = BuildTree.build(trees);
    return t;
}
Also used : MenuDO(io.github.tesla.ops.system.domain.MenuDO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Tree(io.github.tesla.ops.system.domain.Tree) BuildTree(io.github.tesla.ops.utils.BuildTree)

Example 2 with Tree

use of io.github.tesla.ops.system.domain.Tree in project tesla by linking12.

the class UserServiceImpl method getTree.

@Override
public Tree<DeptDO> getTree() {
    List<Tree<DeptDO>> trees = new ArrayList<Tree<DeptDO>>();
    List<DeptDO> depts = deptMapper.list(new HashMap<String, Object>(16));
    Long[] pDepts = deptMapper.listParentDept();
    Long[] uDepts = userMapper.listAllDept();
    Long[] allDepts = (Long[]) ArrayUtils.addAll(pDepts, uDepts);
    for (DeptDO dept : depts) {
        if (!ArrayUtils.contains(allDepts, dept.getDeptId())) {
            continue;
        }
        Tree<DeptDO> tree = new Tree<DeptDO>();
        tree.setId(dept.getDeptId().toString());
        tree.setParentId(dept.getParentId().toString());
        tree.setText(dept.getName());
        Map<String, Object> state = new HashMap<>(16);
        state.put("opened", true);
        state.put("mType", "dept");
        tree.setState(state);
        trees.add(tree);
    }
    List<UserDO> users = userMapper.list(new HashMap<String, Object>(16));
    for (UserDO user : users) {
        Tree<DeptDO> tree = new Tree<DeptDO>();
        tree.setId(user.getUserId().toString());
        tree.setParentId(user.getDeptId().toString());
        tree.setText(user.getName());
        Map<String, Object> state = new HashMap<>(16);
        state.put("opened", true);
        state.put("mType", "user");
        tree.setState(state);
        trees.add(tree);
    }
    Tree<DeptDO> t = BuildTree.build(trees);
    return t;
}
Also used : HashMap(java.util.HashMap) UserDO(io.github.tesla.ops.system.domain.UserDO) ArrayList(java.util.ArrayList) Tree(io.github.tesla.ops.system.domain.Tree) BuildTree(io.github.tesla.ops.utils.BuildTree) DeptDO(io.github.tesla.ops.system.domain.DeptDO)

Example 3 with Tree

use of io.github.tesla.ops.system.domain.Tree in project tesla by linking12.

the class DeptServiceImpl method getTree.

@Override
public Tree<DeptDO> getTree() {
    List<Tree<DeptDO>> trees = new ArrayList<Tree<DeptDO>>();
    List<DeptDO> sysDepts = sysDeptMapper.list(new HashMap<String, Object>(16));
    for (DeptDO sysDept : sysDepts) {
        Tree<DeptDO> tree = new Tree<DeptDO>();
        tree.setId(sysDept.getDeptId().toString());
        tree.setParentId(sysDept.getParentId().toString());
        tree.setText(sysDept.getName());
        Map<String, Object> state = new HashMap<>(16);
        state.put("opened", true);
        tree.setState(state);
        trees.add(tree);
    }
    // 默认顶级菜单为0,根据数据库实际情况调整
    Tree<DeptDO> t = BuildTree.build(trees);
    return t;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BuildTree(io.github.tesla.ops.utils.BuildTree) Tree(io.github.tesla.ops.system.domain.Tree) DeptDO(io.github.tesla.ops.system.domain.DeptDO)

Example 4 with Tree

use of io.github.tesla.ops.system.domain.Tree in project tesla by linking12.

the class MenuServiceImpl method getSysMenuTree.

@Cacheable
@Override
public Tree<MenuDO> getSysMenuTree(Long id) {
    List<Tree<MenuDO>> trees = new ArrayList<Tree<MenuDO>>();
    List<MenuDO> menuDOs = menuMapper.listMenuByUserId(id);
    for (MenuDO sysMenuDO : menuDOs) {
        Tree<MenuDO> tree = new Tree<MenuDO>();
        tree.setId(sysMenuDO.getMenuId().toString());
        tree.setParentId(sysMenuDO.getParentId().toString());
        tree.setText(sysMenuDO.getName());
        Map<String, Object> attributes = new HashMap<>(16);
        attributes.put("url", sysMenuDO.getUrl());
        attributes.put("icon", sysMenuDO.getIcon());
        tree.setAttributes(attributes);
        trees.add(tree);
    }
    Tree<MenuDO> t = BuildTree.build(trees);
    return t;
}
Also used : MenuDO(io.github.tesla.ops.system.domain.MenuDO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Tree(io.github.tesla.ops.system.domain.Tree) BuildTree(io.github.tesla.ops.utils.BuildTree) Cacheable(org.springframework.cache.annotation.Cacheable)

Example 5 with Tree

use of io.github.tesla.ops.system.domain.Tree in project tesla by linking12.

the class MenuServiceImpl method listMenuTree.

@Override
public List<Tree<MenuDO>> listMenuTree(Long id) {
    List<Tree<MenuDO>> trees = new ArrayList<Tree<MenuDO>>();
    List<MenuDO> menuDOs = menuMapper.listMenuByUserId(id);
    for (MenuDO sysMenuDO : menuDOs) {
        Tree<MenuDO> tree = new Tree<MenuDO>();
        tree.setId(sysMenuDO.getMenuId().toString());
        tree.setParentId(sysMenuDO.getParentId().toString());
        tree.setText(sysMenuDO.getName());
        Map<String, Object> attributes = new HashMap<>(16);
        attributes.put("url", sysMenuDO.getUrl());
        attributes.put("icon", sysMenuDO.getIcon());
        tree.setAttributes(attributes);
        trees.add(tree);
    }
    List<Tree<MenuDO>> list = BuildTree.buildList(trees, "0");
    return list;
}
Also used : MenuDO(io.github.tesla.ops.system.domain.MenuDO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Tree(io.github.tesla.ops.system.domain.Tree) BuildTree(io.github.tesla.ops.utils.BuildTree)

Aggregations

Tree (io.github.tesla.ops.system.domain.Tree)6 BuildTree (io.github.tesla.ops.utils.BuildTree)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)5 MenuDO (io.github.tesla.ops.system.domain.MenuDO)4 DeptDO (io.github.tesla.ops.system.domain.DeptDO)2 UserDO (io.github.tesla.ops.system.domain.UserDO)1 Cacheable (org.springframework.cache.annotation.Cacheable)1