#
luxiaotao1123
2021-03-04 16fea9a478c5c0f0c38a84b476083c8473f90eb8
src/main/java/zy/cloud/wms/common/utils/TreeUtils.java
@@ -4,7 +4,9 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
import zy.cloud.wms.manager.entity.Node;
import zy.cloud.wms.manager.entity.Tag;
import zy.cloud.wms.manager.service.NodeService;
import zy.cloud.wms.manager.service.TagService;
import java.util.*;
@@ -18,6 +20,8 @@
    @Autowired
    private TagService tagService;
    @Autowired
    private NodeService nodeService;
    /**
     * 获取树图数据结构
@@ -41,6 +45,27 @@
    }
    /**
     * 获取树图数据结构
     */
    @Cacheable(cacheNames="nodeTree",key="#id")
    public ArrayList<Map> getNodeTree(String id){
        ArrayList<Map> result = new ArrayList<>();
        Node node = nodeService.selectById(id);
        // 主节点
        Map<String, Object> map = new HashMap<>();
        map.put("title", node.getName());
        map.put("id", node.getId());
        map.put("spread", true);
        List<Map> childrens = new ArrayList<>();
        map.put("children", childrens);
        dealNode(node, childrens);
        result.add(map);
        // 开始处理字节点
//        deal(tag, childrens);
        return result;
    }
    /**
     * 递归获取子节点数据
     */
    public void deal(Tag parent, List<Map> list) {
@@ -60,6 +85,26 @@
        }
    }
    /**
     * 递归获取子节点数据
     */
    public void dealNode(Node parent, List<Map> list) {
        List<Node> nodes = nodeService.selectList(
                new EntityWrapper<Node>()
                        .eq("parent_id", parent.getId())
                        .eq("status", "1"));
        for (Node node : nodes) {
            Map<String, Object> map = new HashMap<>();
            map.put("title", node.getName());
            map.put("id", node.getId());
            map.put("spread", true);
            List<Map> childrens = new ArrayList<>();
            map.put("children", childrens);
            dealNode(node, childrens);
            list.add(map);
        }
    }