From 7147fe3d070b119bd0a7fb47ad3de2eb74386c72 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@63.com>
Date: 星期一, 12 九月 2022 16:18:40 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/crm/common/utils/TreeUtils.java | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 50 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/zy/crm/common/utils/TreeUtils.java b/src/main/java/com/zy/crm/common/utils/TreeUtils.java
index eb5e668..4c97962 100644
--- a/src/main/java/com/zy/crm/common/utils/TreeUtils.java
+++ b/src/main/java/com/zy/crm/common/utils/TreeUtils.java
@@ -2,6 +2,8 @@
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
+import com.zy.crm.system.entity.Dept;
+import com.zy.crm.system.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;
@@ -23,6 +25,8 @@
private TagService tagService;
@Autowired
private NodeService nodeService;
+ @Autowired
+ private DeptService deptService;
/******************************** 褰掔被鏍� *********************************/
@@ -116,6 +120,52 @@
}
}
+ /******************************** 閮ㄩ棬鏍� *********************************/
+
+ /**
+ * 鑾峰彇鏍戝浘鏁版嵁缁撴瀯
+ */
+ @Cacheable(cacheNames="deptTree",key="#id")
+ public ArrayList<Map> getDeptTree(String id, Long hostId){
+ ArrayList<Map> result = new ArrayList<>();
+ Dept dept = deptService.selectById(id);
+ // 涓昏妭鐐�
+ Map<String, Object> map = new HashMap<>();
+ map.put("title", dept.getName());
+ map.put("id", dept.getId());
+ map.put("spread", true);
+ List<Map> childrens = new ArrayList<>();
+ map.put("children", childrens);
+ dealDept(dept, childrens, hostId);
+ result.add(map);
+ // 寮�濮嬪鐞嗗瓧鑺傜偣
+// deal(tag, childrens);
+ return result;
+ }
+
+ /**
+ * 閫掑綊鑾峰彇瀛愯妭鐐规暟鎹�
+ */
+ public void dealDept(Dept parent, List<Map> list, Long hostId) {
+ Wrapper<Dept> wrapper = new EntityWrapper<Dept>()
+ .eq("parent_id", parent.getId())
+ .eq("status", "1");
+ if (hostId != null) {
+ wrapper.eq("host_id", hostId);
+ }
+ List<Dept> depts = deptService.selectList(wrapper);
+ for (Dept dept : depts) {
+ Map<String, Object> map = new HashMap<>();
+ map.put("title", dept.getName());
+ map.put("id", dept.getId());
+ map.put("spread", true);
+ List<Map> childrens = new ArrayList<>();
+ map.put("children", childrens);
+ dealDept(dept, childrens, hostId);
+ list.add(map);
+ }
+ }
+
// -------------------------------------------------------------------------------------------------------
--
Gitblit v1.9.1