|  |  | 
 |  |  |  | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 
 |  |  | import com.zy.asrs.common.wms.entity.Tag; | 
 |  |  | import com.zy.asrs.common.wms.service.ManTagService; | 
 |  |  | import com.zy.asrs.common.wms.service.TagService; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.cache.annotation.Cacheable; | 
 |  |  | import org.springframework.stereotype.Component; | 
 |  |  | 
 |  |  | public class TreeUtils { | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private ManTagService tagService; | 
 |  |  |     private TagService tagService; | 
 |  |  |  | 
 |  |  |     /******************************** 归类树 *********************************/ | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 获取树图数据结构 | 
 |  |  |      */ | 
 |  |  |     @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()); | 
 |  |  | 
 |  |  |         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()); | 
 |  |  | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     /** | 
 |  |  |      * 递归获取节点以及子节点数据 | 
 |  |  |      */ | 
 |  |  |     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); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     // ------------------------------------------------------------------------------------------------------- | 
 |  |  |  |