From 2a08b97f0aad3af5d981a722efb218fb201f821f Mon Sep 17 00:00:00 2001
From: LSH
Date: 星期五, 10 十一月 2023 11:23:34 +0800
Subject: [PATCH] #

---
 src/main/java/com/zy/crm/system/controller/DeptController.java |   85 ++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 80 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/zy/crm/system/controller/DeptController.java b/src/main/java/com/zy/crm/system/controller/DeptController.java
index aeb8487..dcbb4b1 100644
--- a/src/main/java/com/zy/crm/system/controller/DeptController.java
+++ b/src/main/java/com/zy/crm/system/controller/DeptController.java
@@ -10,12 +10,16 @@
 import com.core.common.Cools;
 import com.core.common.DateUtils;
 import com.core.common.R;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
+import com.zy.crm.common.utils.ListUtils;
+import com.zy.crm.common.utils.TreeUtils;
 import com.zy.crm.common.web.BaseController;
+import com.zy.crm.manager.utils.NodeUtils;
 import com.zy.crm.system.entity.Dept;
 import com.zy.crm.system.service.DeptService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
 
+import java.io.IOException;
 import java.util.*;
 
 @RestController
@@ -23,6 +27,8 @@
 
     @Autowired
     private DeptService deptService;
+    @Autowired
+    private TreeUtils treeUtils;
 
     @RequestMapping(value = "/dept/{id}/auth")
     @ManagerAuth
@@ -40,6 +46,7 @@
         EntityWrapper<Dept> wrapper = new EntityWrapper<>();
         excludeTrash(param);
         convert(param, wrapper);
+        hostEq(wrapper);
         if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));} {
             wrapper.orderBy("sort");
         }
@@ -62,13 +69,27 @@
     @RequestMapping(value = "/dept/add/auth")
     @ManagerAuth
     public R add(Dept dept) {
+        dept.setLevel(1);
+        if (dept.getParentId() == null || dept.getParentId() == 0) {
+            dept.setParentId(getOriginDept().getId());
+        }
+        Dept parent = deptService.selectById(dept.getParentId());
+        if (parent != null) {
+            dept.setParentName(parent.getName());
+            dept.setLevel(parent.getLevel() + 1);
+        }
+        // path
+        NodeUtils nodeUtils = new NodeUtils();
+        nodeUtils.executePath(dept);
+        dept.setHostId(getHostId());
+        dept.setPath(nodeUtils.path.toString());
+        dept.setNamePath(nodeUtils.pathName.toString());
+
         dept.setCreateBy(getUserId());
         dept.setCreateTime(new Date());
         dept.setUpdateBy(getUserId());
         dept.setUpdateTime(new Date());
-        if (dept.getParentId() == null) {
-            dept.setParentId(0L);
-        }
+        dept.setStatus(1);
         deptService.insert(dept);
         return R.ok();
     }
@@ -79,6 +100,34 @@
         if (Cools.isEmpty(dept) || null==dept.getId()){
             return R.error();
         }
+        if (dept.getParentId() != null && dept.getParentId() > 0) {
+            if (dept.getParentId().equals(dept.getId())) {
+                return R.error("鏁版嵁閿欒");
+            }
+            Dept parent = deptService.selectById(dept.getParentId());
+            if (parent != null) {
+                dept.setParentName(parent.getName());
+                dept.setLevel(parent.getLevel() + 1);
+            }
+        } else {
+            dept.setUuid(dept.getName());
+            List<Dept> depts = deptService.selectList(new EntityWrapper<Dept>().eq("parent_id",dept.getId()));
+            for(Dept one : depts){
+                one.setParentName(dept.getName());
+                one.setNamePath(dept.getName());
+                one.setUpdateBy(getUserId());
+                one.setUpdateTime(new Date());
+//                deptService.update(one,new EntityWrapper<Dept>().eq("parent_id",dept.getId()));
+                deptService.updateById(one);
+            }
+        }
+        // path
+        NodeUtils nodeUtils = new NodeUtils();
+        nodeUtils.executePath(dept);
+        dept.setPath(nodeUtils.path.toString());
+        dept.setNamePath(nodeUtils.pathName.toString());
+        dept.setUpdateBy(getUserId());
+        dept.setUpdateTime(new Date());
         deptService.updateById(dept);
         return R.ok();
     }
@@ -131,4 +180,30 @@
         return R.ok();
     }
 
+    @PostMapping(value = "/dept/tree/auth")
+    @ManagerAuth
+    public R tree(@RequestParam(required = false, defaultValue = "") String condition) throws IOException, ClassNotFoundException {
+        ArrayList<Map<String, Object>> tree = treeUtils.getDeptTree(String.valueOf(getDeptId()), getHostId());
+        // 娣辨嫹璐�
+        List<Map<String, Object>> result = ListUtils.deepCopy(tree);
+        if (!Cools.isEmpty(condition)) {
+            treeUtils.remove(condition, result);
+            treeUtils.remove(condition, result);
+        }
+        return R.ok(result);
+    }
+
+    @PostMapping(value = "/dept/user/tree/auth")
+    @ManagerAuth
+    public R deptUserTree(@RequestParam(required = false, defaultValue = "") String condition) throws IOException, ClassNotFoundException {
+        ArrayList<Map<String, Object>> tree = treeUtils.getDeptUserTree(String.valueOf(getDeptId()), getHostId(), getUserId());
+        // 娣辨嫹璐�
+        List<Map<String, Object>> result = ListUtils.deepCopy(tree);
+        if (!Cools.isEmpty(condition)) {
+            treeUtils.remove(condition, result);
+            treeUtils.remove(condition, result);
+        }
+        return R.ok(result);
+    }
+
 }

--
Gitblit v1.9.1