#
Junjie
2024-01-05 1c47b33225c57a13b65fc3bc2e43a7822b23b6a3
zy-asrs-common/src/main/java/com/zy/asrs/common/utils/TreeUtils.java
@@ -24,10 +24,10 @@
    /**
     * 获取树图数据结构
     */
    @Cacheable(cacheNames="tagTree",key="#id")
    public ArrayList<Map> getTree(String id){
    @Cacheable(cacheNames = "tagTree", key = "#id")
    public ArrayList<Map> getTree(Long id, Long hostId) {
        ArrayList<Map> result = new ArrayList<>();
        Tag tag = tagService.getById(id);
        Tag tag = tagService.getOne(new LambdaQueryWrapper<Tag>().eq(Tag::getId, id).eq(Tag::getHostId, hostId));
        // 主节点
        Map<String, Object> map = new HashMap<>();
        map.put("title", tag.getName());
@@ -49,7 +49,7 @@
        List<Tag> tags = tagService.list(
                new LambdaQueryWrapper<Tag>()
                        .eq(Tag::getParentId, parent.getId())
                        .eq(Tag::getStatus, "1"));
                        .eq(Tag::getStatus, 1));
        for (Tag tag : tags) {
            Map<String, Object> map = new HashMap<>();
            map.put("title", tag.getName());
@@ -62,6 +62,22 @@
        }
    }
    /**
     * 递归获取节点以及子节点数据
     */
    public void getTagIdList(Long id, List<Long> nodes) {
        if (!nodes.contains(id)) {
            nodes.add(id);
        }
        List<Tag> tags = tagService.list(new LambdaQueryWrapper<Tag>().eq(Tag::getParentId, id).eq(Tag::getStatus, 1));
        for (Tag tag : tags) {
            if (!nodes.contains(tag.getId())) {
                nodes.add(tag.getId());
            }
            getTagIdList(tag.getId(), nodes);
        }
    }
    // -------------------------------------------------------------------------------------------------------