From c1c4db6170a51f809862ff94393f0612f72645ec Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期四, 17 十一月 2022 21:11:42 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/crm/common/utils/TreeUtils.java | 156 ++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 139 insertions(+), 17 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..591604d 100644
--- a/src/main/java/com/zy/crm/common/utils/TreeUtils.java
+++ b/src/main/java/com/zy/crm/common/utils/TreeUtils.java
@@ -2,13 +2,19 @@
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.cache.annotation.Cacheable;
-import org.springframework.stereotype.Component;
import com.zy.crm.manager.entity.Node;
import com.zy.crm.manager.entity.Tag;
import com.zy.crm.manager.service.NodeService;
import com.zy.crm.manager.service.TagService;
+import com.zy.crm.system.entity.Dept;
+import com.zy.crm.system.entity.Role;
+import com.zy.crm.system.entity.User;
+import com.zy.crm.system.service.DeptService;
+import com.zy.crm.system.service.RoleService;
+import com.zy.crm.system.service.UserService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.annotation.Cacheable;
+import org.springframework.stereotype.Component;
import java.util.*;
@@ -23,6 +29,12 @@
private TagService tagService;
@Autowired
private NodeService nodeService;
+ @Autowired
+ private DeptService deptService;
+ @Autowired
+ private UserService userService;
+ @Autowired
+ private RoleService roleService;
/******************************** 褰掔被鏍� *********************************/
@@ -30,15 +42,15 @@
* 鑾峰彇鏍戝浘鏁版嵁缁撴瀯
*/
@Cacheable(cacheNames="tagTree",key="#id")
- public ArrayList<Map> getTree(String id, Long hostId){
- ArrayList<Map> result = new ArrayList<>();
+ public ArrayList<Map<String, Object>> getTree(String id, Long hostId){
+ ArrayList<Map<String, Object>> result = new ArrayList<>();
Tag tag = tagService.selectById(id);
// 涓昏妭鐐�
Map<String, Object> map = new HashMap<>();
map.put("title", tag.getName());
map.put("id", tag.getId());
map.put("spread", true);
- List<Map> childrens = new ArrayList<>();
+ List<Map<String, Object>> childrens = new ArrayList<>();
map.put("children", childrens);
dealTag(tag, childrens, hostId);
result.add(map);
@@ -50,7 +62,7 @@
/**
* 閫掑綊鑾峰彇瀛愯妭鐐规暟鎹�
*/
- public void dealTag(Tag parent, List<Map> list, Long hostId) {
+ public void dealTag(Tag parent, List<Map<String, Object>> list, Long hostId) {
Wrapper<Tag> wrapper = new EntityWrapper<Tag>()
.eq("parent_id", parent.getId())
.eq("status", "1");
@@ -63,7 +75,7 @@
map.put("title", tag.getName());
map.put("id", tag.getId());
map.put("spread", true);
- List<Map> childrens = new ArrayList<>();
+ List<Map<String, Object>> childrens = new ArrayList<>();
map.put("children", childrens);
dealTag(tag, childrens, hostId);
list.add(map);
@@ -76,15 +88,15 @@
* 鑾峰彇鏍戝浘鏁版嵁缁撴瀯
*/
@Cacheable(cacheNames="nodeTree",key="#id")
- public ArrayList<Map> getNodeTree(String id, Long hostId){
- ArrayList<Map> result = new ArrayList<>();
+ public ArrayList<Map<String, Object>> getNodeTree(String id, Long hostId){
+ ArrayList<Map<String, Object>> 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<>();
+ List<Map<String, Object>> childrens = new ArrayList<>();
map.put("children", childrens);
dealNode(node, childrens, hostId);
result.add(map);
@@ -96,7 +108,7 @@
/**
* 閫掑綊鑾峰彇瀛愯妭鐐规暟鎹�
*/
- public void dealNode(Node parent, List<Map> list, Long hostId) {
+ public void dealNode(Node parent, List<Map<String, Object>> list, Long hostId) {
Wrapper<Node> wrapper = new EntityWrapper<Node>()
.eq("parent_id", parent.getId())
.eq("status", "1");
@@ -109,13 +121,123 @@
map.put("title", node.getName());
map.put("id", node.getId());
map.put("spread", true);
- List<Map> childrens = new ArrayList<>();
+ List<Map<String, Object>> childrens = new ArrayList<>();
map.put("children", childrens);
dealNode(node, childrens, hostId);
list.add(map);
}
}
+ /******************************** 閮ㄩ棬鏍� *********************************/
+
+ /**
+ * 鑾峰彇鏍戝浘鏁版嵁缁撴瀯
+ */
+ @Cacheable(cacheNames="deptTree",key="#id")
+ public ArrayList<Map<String, Object>> getDeptTree(String id, Long hostId){
+ ArrayList<Map<String, Object>> 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<String, Object>> 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<String, Object>> 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<String, Object>> childrens = new ArrayList<>();
+ map.put("children", childrens);
+ dealDept(dept, childrens, hostId);
+ list.add(map);
+ }
+ }
+
+ /******************************** 閮ㄩ棬 + 鍛樺伐 鏍� *********************************/
+
+ /**
+ * 鑾峰彇鏍戝浘鏁版嵁缁撴瀯
+ */
+ @Cacheable(cacheNames="deptUserTree",key="#id")
+ public ArrayList<Map<String, Object>> getDeptUserTree(String id, Long hostId, Long userId){
+ ArrayList<Map<String, Object>> result = new ArrayList<>();
+ User user = userService.selectById(userId);
+ Role role = roleService.selectById(user.getRoleId());
+ if (role.getCode().equals("salesman")) {
+ Map<String, Object> map = new HashMap<>();
+ map.put("title", user.getNickname());
+ map.put("id", user.getId());
+ map.put("key", "user_id");
+ map.put("icon", "layui-icon layui-icon-friends");
+ result.add(map);
+ } else {
+ 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);
+ map.put("key", "dept_id");
+ List<Map<String, Object>> childrens = new ArrayList<>();
+ map.put("children", childrens);
+ dealUserDept(dept, childrens, hostId, userId);
+ result.add(map);
+ }
+ return result;
+ }
+
+ public void dealUserDept(Dept parent, List<Map<String, Object>> list, Long hostId, Long userId) {
+ // 浜哄憳
+ List<User> users = roleService.getUserByRoleCode(hostId, parent.getId(), userId);
+ for (User user : users) {
+ Map<String, Object> map = new HashMap<>();
+ map.put("title", user.getNickname());
+ map.put("id", user.getId());
+ map.put("key", "user_id");
+ map.put("icon", "layui-icon layui-icon-friends");
+ list.add(map);
+ }
+ // 閮ㄩ棬
+ 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);
+ map.put("key", "dept_id");
+ List<Map<String, Object>> childrens = new ArrayList<>();
+ map.put("children", childrens);
+ dealUserDept(dept, childrens, hostId, userId);
+ list.add(map);
+ }
+ }
// -------------------------------------------------------------------------------------------------------
@@ -123,12 +245,12 @@
* 鏉′欢绛涢��
*/
@SuppressWarnings("unchecked")
- public void remove(String condition, List<Map> list) {
- Iterator<Map> iterator = list.iterator();
+ public void remove(String condition, List<Map<String, Object>> list) {
+ Iterator<Map<String, Object>> iterator = list.iterator();
while (iterator.hasNext()) {
- Map map = iterator.next();
+ Map<String, Object> map = iterator.next();
if (map.get("children") != null) {
- List<Map> children = (List<Map>) map.get("children");
+ List<Map<String, Object>> children = (List<Map<String, Object>>) map.get("children");
if (children.size() > 0) {
remove(condition, children);
} else {
--
Gitblit v1.9.1