From d3bf3d3917d8201d64e8e2c66e99afb7099487f9 Mon Sep 17 00:00:00 2001 From: zhang <zc857179121@qq.com> Date: 星期四, 23 十月 2025 17:01:23 +0800 Subject: [PATCH] 13 --- src/main/java/com/zy/common/utils/TreeUtils.java | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/zy/common/utils/TreeUtils.java b/src/main/java/com/zy/common/utils/TreeUtils.java index 271ee28..2b1327d 100644 --- a/src/main/java/com/zy/common/utils/TreeUtils.java +++ b/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,14 +21,16 @@ @Autowired private TagService tagService; + @Autowired + private NodeService nodeService; /******************************** 褰掔被鏍� *********************************/ /** * 鑾峰彇鏍戝浘鏁版嵁缁撴瀯 */ - @Cacheable(cacheNames="tagTree",key="#id") - public ArrayList<Map> getTree(String id){ + @Cacheable(cacheNames = "tagTree", key = "#id") + public ArrayList<Map> getTree(String id) { ArrayList<Map> result = new ArrayList<>(); Tag tag = tagService.selectById(id); // 涓昏妭鐐� @@ -54,7 +59,7 @@ Map<String, Object> map = new HashMap<>(); map.put("title", tag.getName()); map.put("id", tag.getId()); - map.put("spread", true); + map.put("spread", false); List<Map> childrens = new ArrayList<>(); map.put("children", childrens); dealTag(tag, childrens); @@ -85,5 +90,53 @@ } } } + /******************************** 鑺傜偣鏍� *********************************/ + + /** + * 鑾峰彇鏍戝浘鏁版嵁缁撴瀯 + */ + @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"); + 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); + } + } + + + // ------------------------------------------------------------------------------------------------------- } -- Gitblit v1.9.1