Kaynağa Gözat

获取部门及用户树列表新版

chenshudong 2 hafta önce
ebeveyn
işleme
71932dd0a7

+ 14 - 0
airport-admin/src/main/java/com/sundot/airport/web/controller/system/SysUserController.java

@@ -511,6 +511,20 @@ public class SysUserController extends BaseController {
511 511
     }
512 512
 
513 513
     /**
514
+     * 获取部门及用户树列表新版
515
+     */
516
+    @Cacheable(
517
+            value = "dept_and_user_tree",
518
+            keyGenerator = "statisticsKeyGenerator",
519
+            unless = "!T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isSuccess(#result) ||T(com.sundot.airport.common.cache.StatisticsCacheConditionUtil).isEmptyData(#result)"
520
+    )
521
+    @PreAuthorize("@ss.hasPermi('system:user:list')")
522
+    @GetMapping("/deptAndUserTree")
523
+    public AjaxResult deptAndUserTree(SysDept dept) {
524
+        return success(deptService.selectDeptAndUserTreeList(dept));
525
+    }
526
+
527
+    /**
514 528
      * 获取全部用户列表
515 529
      */
516 530
     @PreAuthorize("@ss.hasPermi('system:user:list')")

+ 96 - 0
airport-common/src/main/java/com/sundot/airport/common/core/domain/DeptAndUserTreeSelect.java

@@ -0,0 +1,96 @@
1
+package com.sundot.airport.common.core.domain;
2
+
3
+import com.fasterxml.jackson.annotation.JsonInclude;
4
+import com.sundot.airport.common.constant.UserConstants;
5
+import com.sundot.airport.common.core.domain.entity.SysDept;
6
+import com.sundot.airport.common.core.domain.entity.SysUser;
7
+import com.sundot.airport.common.utils.StringUtils;
8
+import lombok.Data;
9
+
10
+import java.util.List;
11
+
12
+/**
13
+ * 部门用户树结构实体类新版
14
+ *
15
+ * @author ruoyi
16
+ */
17
+@Data
18
+public class DeptAndUserTreeSelect {
19
+
20
+    /**
21
+     * 节点类型(dept-部门 user-用户)
22
+     * */
23
+    private String nodeType;
24
+
25
+    /**
26
+     * 节点ID
27
+     */
28
+    private Long id;
29
+
30
+    /**
31
+     * 节点名称
32
+     */
33
+    private String label;
34
+
35
+    /**
36
+     * 节点code
37
+     */
38
+    private String code;
39
+
40
+    /**
41
+     * 节点禁用
42
+     */
43
+    private boolean disabled = false;
44
+
45
+    /**
46
+     * 上级
47
+     */
48
+    private Long parentId;
49
+
50
+    /**
51
+     * 部门类型
52
+     */
53
+    private String deptType;
54
+
55
+    /**
56
+     * 部门用户列表
57
+     */
58
+    private List<DeptAndUserTreeSelect> userList;
59
+
60
+    /**
61
+     * 子节点
62
+     */
63
+    @JsonInclude(JsonInclude.Include.NON_EMPTY)
64
+    private List<DeptAndUserTreeSelect> children;
65
+
66
+    public DeptAndUserTreeSelect() {
67
+
68
+    }
69
+
70
+    /**
71
+     * 部门节点构造方法
72
+     *
73
+     * @param dept 部门信息
74
+     */
75
+    public DeptAndUserTreeSelect(SysDept dept) {
76
+        this.setId(dept.getDeptId());
77
+        this.setLabel(dept.getDeptName());
78
+        this.setParentId(dept.getParentId());
79
+        this.setDeptType(dept.getDeptType());
80
+        this.setNodeType("dept");
81
+        this.setDisabled(StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus()));
82
+    }
83
+
84
+    /**
85
+     * 用户节点构造方法
86
+     *
87
+     * @param user 用户信息
88
+     */
89
+    public DeptAndUserTreeSelect(SysUser user) {
90
+        this.setId(user.getUserId());
91
+        this.setLabel(user.getNickName());
92
+        this.setParentId(user.getDeptId());
93
+        this.setNodeType("user");
94
+    }
95
+
96
+}

+ 9 - 0
airport-system/src/main/java/com/sundot/airport/system/service/ISysDeptService.java

@@ -2,6 +2,7 @@ package com.sundot.airport.system.service;
2 2
 
3 3
 import java.util.List;
4 4
 
5
+import com.sundot.airport.common.core.domain.DeptAndUserTreeSelect;
5 6
 import com.sundot.airport.common.core.domain.TreeSelect;
6 7
 import com.sundot.airport.common.core.domain.DeptUserTreeSelect;
7 8
 import com.sundot.airport.common.core.domain.entity.SysDept;
@@ -40,6 +41,14 @@ public interface ISysDeptService {
40 41
     public List<DeptUserTreeSelect> selectDeptUserTreeList(SysDept dept);
41 42
 
42 43
     /**
44
+     * 查询部门及用户树结构信息新版
45
+     *
46
+     * @param dept 部门信息
47
+     * @return 部门及用户树信息集合
48
+     */
49
+    public List<DeptAndUserTreeSelect> selectDeptAndUserTreeList(SysDept dept);
50
+
51
+    /**
43 52
      * 根据角色ID查询部门树信息
44 53
      *
45 54
      * @param roleId 角色ID

+ 86 - 0
airport-system/src/main/java/com/sundot/airport/system/service/impl/SysDeptServiceImpl.java

@@ -13,6 +13,7 @@ import cn.hutool.core.collection.CollectionUtil;
13 13
 import cn.hutool.core.util.ObjectUtil;
14 14
 import cn.hutool.core.util.StrUtil;
15 15
 import com.sundot.airport.common.config.LevelConfig;
16
+import com.sundot.airport.common.core.domain.DeptAndUserTreeSelect;
16 17
 import com.sundot.airport.common.dto.DeptInfo;
17 18
 import com.sundot.airport.common.dto.UserOrgInfo;
18 19
 import com.sundot.airport.common.enums.DeptType;
@@ -759,4 +760,89 @@ public class SysDeptServiceImpl implements ISysDeptService {
759 760
         result.setDeptInfo(getDeptInfoByDeptId(user.getDeptId()));
760 761
         return result;
761 762
     }
763
+
764
+    /**
765
+     * 查询部门及用户树结构信息新版
766
+     *
767
+     * @param dept 部门信息
768
+     * @return 部门及用户树信息集合
769
+     */
770
+    @Override
771
+    public List<DeptAndUserTreeSelect> selectDeptAndUserTreeList(SysDept dept) {
772
+        List<SysDept> depts;
773
+        // 如果指定了部门ID,则查询该部门及其所有子部门
774
+        if (dept.getDeptId() != null && dept.getDeptId() != 0) {
775
+            SysDept targetDept = deptMapper.selectDeptById(dept.getDeptId());
776
+            if (targetDept != null) {
777
+                // 查询所有部门
778
+                SysDept queryDept = new SysDept();
779
+                List<SysDept> allDepts = SpringUtils.getAopProxy(this).selectDeptList(queryDept);
780
+                // 构建完整的部门树
781
+                List<SysDept> deptTree = buildCompleteDeptTree(allDepts);
782
+                // 查找目标部门及其所有子部门
783
+                SysDept foundDept = findDeptWithChildren(deptTree, dept.getDeptId());
784
+                if (foundDept != null) {
785
+                    List<SysDept> targetList = new ArrayList<>();
786
+                    targetList.add(foundDept);
787
+                    depts = targetList;
788
+                } else {
789
+                    // 如果没找到,返回只包含目标部门的列表
790
+                    List<SysDept> singleList = new ArrayList<>();
791
+                    singleList.add(targetDept);
792
+                    depts = singleList;
793
+                }
794
+            } else {
795
+                // 如果部门不存在,返回空列表
796
+                depts = new ArrayList<>();
797
+            }
798
+        } else {
799
+            // 如果没有指定部门ID,查询所有部门
800
+            depts = SpringUtils.getAopProxy(this).selectDeptList(dept);
801
+        }
802
+        return buildDeptAndUserTreeSelect(depts);
803
+    }
804
+
805
+    /**
806
+     * 构建前端所需要下拉树结构(包含用户)新版
807
+     *
808
+     * @param depts 部门列表
809
+     * @return 下拉树结构列表(包含用户)
810
+     */
811
+    public List<DeptAndUserTreeSelect> buildDeptAndUserTreeSelect(List<SysDept> depts) {
812
+        List<SysDept> deptTrees = buildCompleteDeptTree(depts);
813
+        return deptTrees.stream().map(this::convertDeptToDeptAndUserTreeSelect).collect(Collectors.toList());
814
+    }
815
+
816
+    /**
817
+     * 将部门转换为包含用户的树节点新版
818
+     *
819
+     * @param dept 部门信息
820
+     * @return 树节点
821
+     */
822
+    private DeptAndUserTreeSelect convertDeptToDeptAndUserTreeSelect(SysDept dept) {
823
+        DeptAndUserTreeSelect treeSelect = new DeptAndUserTreeSelect(dept);
824
+
825
+        List<DeptAndUserTreeSelect> children = new ArrayList<>();
826
+
827
+        // 处理子部门
828
+        if (dept.getChildren() != null && !dept.getChildren().isEmpty()) {
829
+            children.addAll(dept.getChildren().stream()
830
+                    .map(this::convertDeptToDeptAndUserTreeSelect)
831
+                    .collect(Collectors.toList()));
832
+        }
833
+
834
+        List<SysUser> users = userMapper.selectUsersByDeptId(dept.getDeptId());
835
+        if (users != null && !users.isEmpty()) {
836
+            List<DeptAndUserTreeSelect> userChildren = users.stream()
837
+                    .map(DeptAndUserTreeSelect::new)
838
+                    .collect(Collectors.toList());
839
+            treeSelect.setUserList(userChildren);
840
+        }
841
+
842
+        if (!children.isEmpty()) {
843
+            treeSelect.setChildren(new ArrayList<>(children));
844
+        }
845
+
846
+        return treeSelect;
847
+    }
762 848
 }