自动化立体仓库 - WMS系统
zhangchao
2024-11-04 59f80df1e377e8775969ca4acadfa2eadd6e37ae
src/main/java/com/zy/common/utils/TreeUtils.java
@@ -1,7 +1,10 @@
package com.zy.common.utils;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.zy.asrs.entity.Node;
import com.zy.asrs.entity.Tag;
import com.zy.asrs.service.NodeService;
import com.zy.asrs.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
@@ -18,6 +21,8 @@
    @Autowired
    private TagService tagService;
    @Autowired
    private NodeService nodeService;
    /******************************** 归类树 *********************************/
@@ -86,4 +91,51 @@
        }
    }
    /**
     * 获取树图数据结构
     */
    @Cacheable(cacheNames="nodeTree",key="#id")
    public ArrayList<Map> getNodeTree(String id, Long hostId){
        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, hostId);
        result.add(map);
        // 开始处理字节点
//        deal(tag, childrens);
        return result;
    }
    /**
     * 递归获取子节点数据
     */
    public void dealNode(Node parent, List<Map> list, Long hostId) {
        Wrapper<Node> wrapper = new EntityWrapper<Node>()
                .eq("parent_id", parent.getId())
                .eq("status", "1")
                .ne("type",3);
        if (hostId != null) {
            wrapper.eq("host_id", hostId);
        }
        List<Node> nodes = nodeService.selectList(wrapper);
        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, hostId);
            list.add(map);
        }
    }
}