From 5bdba4f712b203db5acdd981922a5bc1706b29ff Mon Sep 17 00:00:00 2001
From: LSH
Date: 星期一, 11 九月 2023 19:15:43 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/crm/system/controller/DeptController.java | 71 ++++++++++++++++++++++++++++++++---
1 files changed, 64 insertions(+), 7 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 decd896..dcbb4b1 100644
--- a/src/main/java/com/zy/crm/system/controller/DeptController.java
+++ b/src/main/java/com/zy/crm/system/controller/DeptController.java
@@ -12,11 +12,12 @@
import com.core.common.R;
import com.zy.crm.common.utils.ListUtils;
import com.zy.crm.common.utils.TreeUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.*;
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.*;
@@ -45,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");
}
@@ -67,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();
}
@@ -84,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();
}
@@ -139,9 +183,22 @@
@PostMapping(value = "/dept/tree/auth")
@ManagerAuth
public R tree(@RequestParam(required = false, defaultValue = "") String condition) throws IOException, ClassNotFoundException {
- ArrayList<Map> tree = treeUtils.getDeptTree(String.valueOf(getOriginDept().getId()), getHostId());
+ ArrayList<Map<String, Object>> tree = treeUtils.getDeptTree(String.valueOf(getDeptId()), getHostId());
// 娣辨嫹璐�
- List<Map> result = ListUtils.deepCopy(tree);
+ 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);
--
Gitblit v1.9.1