自动化立体仓库 - WMS系统
zhangc
2024-11-28 2c638a508edf713faeda60cae92ae92cc65eb511
src/main/java/com/zy/common/web/AuthController.java
@@ -508,5 +508,47 @@
        }
        return R.ok().add(results);
    }
    @RequestMapping("/menu/pdaAll/auth")
    @ManagerAuth
    public R menuPdaAll() {
        Long userId = getUserId();
        List<RolePdaResource> rolePdaResources;
        if (userId == 9527L) {
            rolePdaResources = rolePdaResourceService.selectList(new EntityWrapper<>());
        } else {
            Long roleId = getUser().getRoleId();
            rolePdaResources = rolePdaResourceService.selectList(new EntityWrapper<RolePdaResource>().eq("role_id", roleId));
        }
        if (Cools.isEmpty(rolePdaResources)) {
            return R.ok();
        }
        List<Long> collect = rolePdaResources.stream().map(RolePdaResource::getResourceId).distinct().collect(Collectors.toList());
        List<PdaResource> pdaResources = pdaResourceService.selectBatchIds(collect);
        List<PdaResource> results = list2Tree(pdaResources, 0L);
        return R.ok().add(results);
    }
    public List<PdaResource> list2Tree(List<PdaResource> list, Long pId) {
        List<PdaResource> tree = new ArrayList<>();
        Iterator<PdaResource> it = list.iterator();
        while (it.hasNext()) {
            PdaResource m = it.next();
            if (m.getResourceId() == pId || (pId == 0L && m.getResourceId() == null)) {
                tree.add(m);
                // 已添加的元素删除掉
                it.remove();
            }
        }
        // 寻找子元素
        for (PdaResource n : tree) {
            n.setChildren(list2Tree(list, n.getId()));
        }
        return tree;
    }
}