Quellcode durchsuchen

【组织架构/模糊搜索】:没有挂靠通道/小组的人要展示出来;屹动班组的苏晓丹属于该班组,不属于任何一个小组,但是这个人也要在组织架构里体现出来;

wangxx vor 2 Wochen
Ursprung
Commit
ae93498091

+ 2 - 1
airport-admin/src/main/java/com/sundot/airport/web/controller/system/SysUserController.java

@@ -505,6 +505,7 @@ public class SysUserController extends BaseController {
505 505
      */
506 506
     @PreAuthorize("@ss.hasPermi('system:user:list')")
507 507
     @GetMapping("/deptUserTree")
508
+    @Cacheable(value = "dept_user_tree", key = "#dept.deptId ?: 'all'")
508 509
     public AjaxResult deptUserTree(SysDept dept) {
509 510
         return success(deptService.selectDeptUserTreeList(dept));
510 511
     }
@@ -924,4 +925,4 @@ public class SysUserController extends BaseController {
924 925
 
925 926
         return result;
926 927
     }
927
-}
928
+}

+ 142 - 10
airport-system/src/main/java/com/sundot/airport/system/service/impl/SysDeptServiceImpl.java

@@ -2,8 +2,10 @@ package com.sundot.airport.system.service.impl;
2 2
 
3 3
 import java.util.ArrayList;
4 4
 import java.util.Collections;
5
+import java.util.HashSet;
5 6
 import java.util.Iterator;
6 7
 import java.util.List;
8
+import java.util.Set;
7 9
 import java.util.stream.Collectors;
8 10
 
9 11
 import cn.hutool.core.collection.CollUtil;
@@ -227,7 +229,6 @@ public class SysDeptServiceImpl implements ISysDeptService {
227 229
      */
228 230
     private DeptUserTreeSelect convertDeptToDeptUserTreeSelect(SysDept dept) {
229 231
         DeptUserTreeSelect treeSelect = new DeptUserTreeSelect(dept);
230
-
231 232
         List<DeptUserTreeSelect> children = new ArrayList<>();
232 233
 
233 234
         // 处理子部门
@@ -237,15 +238,20 @@ public class SysDeptServiceImpl implements ISysDeptService {
237 238
                     .collect(Collectors.toList()));
238 239
         }
239 240
 
240
-        // 如果是班组类型,则添加用户节点
241
-        if (DeptTypeEnum.TEAMS.getCode().equals(dept.getDeptType())) {
242
-            List<SysUser> users = userMapper.selectUsersByDeptId(dept.getDeptId());
243
-            if (users != null && !users.isEmpty()) {
244
-                List<DeptUserTreeSelect> userChildren = users.stream()
245
-                        .map(DeptUserTreeSelect::new)
246
-                        .collect(Collectors.toList());
247
-                children.addAll(userChildren);
248
-            }
241
+        // 根据部门类型添加用户节点
242
+        String deptType = dept.getDeptType();
243
+        
244
+        if (DeptTypeEnum.TEAMS.getCode().equals(deptType)) {
245
+            // 小组类型:直接添加该小组下的所有用户
246
+            addUsersToChildren(dept.getDeptId(), children);
247
+            
248
+        } else if (DeptTypeEnum.MANAGER.getCode().equals(deptType)) {
249
+            // 班组类型:添加未分配到任何小组的用户
250
+            addOrphanUsersToChildren(dept, children);
251
+            
252
+        } else if (DeptTypeEnum.BRIGADE.getCode().equals(deptType)) {
253
+            // 部门类型:添加未挂靠到任何班组、小组的用户
254
+            addBrigadeOrphanUsersToChildren(dept, children);
249 255
         }
250 256
 
251 257
         if (!children.isEmpty()) {
@@ -256,6 +262,132 @@ public class SysDeptServiceImpl implements ISysDeptService {
256 262
     }
257 263
 
258 264
     /**
265
+     * 添加指定部门下的所有用户到子节点列表
266
+     *
267
+     * @param deptId   部门ID
268
+     * @param children 子节点列表
269
+     */
270
+    private void addUsersToChildren(Long deptId, List<DeptUserTreeSelect> children) {
271
+        List<SysUser> users = userMapper.selectUsersByDeptId(deptId);
272
+        if (users != null && !users.isEmpty()) {
273
+            users.stream()
274
+                    .map(DeptUserTreeSelect::new)
275
+                    .forEach(children::add);
276
+        }
277
+    }
278
+
279
+    /**
280
+     * 添加班组下未分配到任何小组的用户
281
+     *
282
+     * @param managerDept 班组部门
283
+     * @param children    子节点列表
284
+     */
285
+    private void addOrphanUsersToChildren(SysDept managerDept, List<DeptUserTreeSelect> children) {
286
+        List<SysUser> allUsers = userMapper.selectUsersByDeptId(managerDept.getDeptId());
287
+        if (allUsers == null || allUsers.isEmpty()) {
288
+            return;
289
+        }
290
+
291
+        // 获取该班组下所有小组的用户ID集合
292
+        java.util.Set<Long> usersInGroups = getUsersInChildGroups(managerDept.getChildren());
293
+
294
+        // 添加未分配到任何小组的用户
295
+        allUsers.stream()
296
+                .filter(user -> !usersInGroups.contains(user.getUserId()))
297
+                .map(DeptUserTreeSelect::new)
298
+                .forEach(children::add);
299
+    }
300
+
301
+    /**
302
+     * 添加部门下未挂靠到任何班组、小组的用户
303
+     *
304
+     * @param brigadeDept 部门
305
+     * @param children    子节点列表
306
+     */
307
+    private void addBrigadeOrphanUsersToChildren(SysDept brigadeDept, List<DeptUserTreeSelect> children) {
308
+        List<SysUser> allUsers = userMapper.selectUsersByDeptId(brigadeDept.getDeptId());
309
+        if (allUsers == null || allUsers.isEmpty()) {
310
+            return;
311
+        }
312
+
313
+        // 获取该部门下所有班组和小组的用户ID集合
314
+        java.util.Set<Long> usersInSubDepts = getUsersInChildDepts(brigadeDept.getChildren());
315
+
316
+        // 添加未挂靠到任何班组、小组的用户
317
+        allUsers.stream()
318
+                .filter(user -> !usersInSubDepts.contains(user.getUserId()))
319
+                .map(DeptUserTreeSelect::new)
320
+                .forEach(children::add);
321
+    }
322
+
323
+    /**
324
+     * 获取子部门中所有小组的用户ID集合
325
+     *
326
+     * @param childDepts 子部门列表
327
+     * @return 用户ID集合
328
+     */
329
+    private java.util.Set<Long> getUsersInChildGroups(List<SysDept> childDepts) {
330
+        java.util.Set<Long> userIds = new java.util.HashSet<>();
331
+        if (childDepts == null || childDepts.isEmpty()) {
332
+            return userIds;
333
+        }
334
+
335
+        // 只筛选小组类型的子部门
336
+        childDepts.stream()
337
+                .filter(child -> DeptTypeEnum.TEAMS.getCode().equals(child.getDeptType()))
338
+                .forEach(group -> {
339
+                    List<SysUser> groupUsers = userMapper.selectUsersByDeptId(group.getDeptId());
340
+                    if (groupUsers != null) {
341
+                        groupUsers.forEach(user -> userIds.add(user.getUserId()));
342
+                    }
343
+                });
344
+
345
+        return userIds;
346
+    }
347
+
348
+    /**
349
+     * 获取子部门中所有班组和小组的用户ID集合
350
+     *
351
+     * @param childDepts 子部门列表
352
+     * @return 用户ID集合
353
+     */
354
+    private java.util.Set<Long> getUsersInChildDepts(List<SysDept> childDepts) {
355
+        java.util.Set<Long> userIds = new java.util.HashSet<>();
356
+        if (childDepts == null || childDepts.isEmpty()) {
357
+            return userIds;
358
+        }
359
+
360
+        // 递归获取所有子部门的用户
361
+        collectUsersFromDepts(childDepts, userIds);
362
+        return userIds;
363
+    }
364
+
365
+    /**
366
+     * 递归收集部门树中的所有用户ID
367
+     *
368
+     * @param depts   部门列表
369
+     * @param userIds 用户ID集合(累加结果)
370
+     */
371
+    private void collectUsersFromDepts(List<SysDept> depts, java.util.Set<Long> userIds) {
372
+        if (depts == null || depts.isEmpty()) {
373
+            return;
374
+        }
375
+
376
+        for (SysDept dept : depts) {
377
+            // 添加当前部门的用户
378
+            List<SysUser> deptUsers = userMapper.selectUsersByDeptId(dept.getDeptId());
379
+            if (deptUsers != null) {
380
+                deptUsers.forEach(user -> userIds.add(user.getUserId()));
381
+            }
382
+
383
+            // 递归处理子部门
384
+            if (dept.getChildren() != null && !dept.getChildren().isEmpty()) {
385
+                collectUsersFromDepts(dept.getChildren(), userIds);
386
+            }
387
+        }
388
+    }
389
+
390
+    /**
259 391
      * 根据角色ID查询部门树信息
260 392
      *
261 393
      * @param roleId 角色ID