From 456282ce98165af37ff7b6c80843e1bf0489bb03 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 17 Jan 2026 10:11:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=83=A8=E9=97=A8=E4=BA=BA=E6=95=B0?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E5=8C=85=E5=90=AB=E9=83=A8=E9=97=A8=E8=B4=9F?= =?UTF-8?q?=E8=B4=A3=E4=BA=BA=EF=BC=88=E5=8D=B3=E4=BD=BF=E8=B4=9F=E8=B4=A3?= =?UTF-8?q?=E4=BA=BAdept=5Fid=E5=9C=A8=E5=85=B6=E4=BB=96=E9=83=A8=E9=97=A8?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../designhub/service/AnalyticsService.java | 52 +++++++++++++++++-- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/com/designhub/service/AnalyticsService.java b/backend/src/main/java/com/designhub/service/AnalyticsService.java index 9880c24..2a02fbc 100644 --- a/backend/src/main/java/com/designhub/service/AnalyticsService.java +++ b/backend/src/main/java/com/designhub/service/AnalyticsService.java @@ -1080,6 +1080,44 @@ public class AnalyticsService { return deptIds; } + /** + * 统计部门负责人中,dept_id 不在该部门内的人数 + * 用于部门人数统计时,把"挂靠"在其他部门但实际负责该部门的负责人算进去 + */ + private int countLeadersNotInDept(List deptIds) { + if (deptIds == null || deptIds.isEmpty()) { + return 0; + } + + // 获取这些部门的所有负责人ID + List depts = departmentMapper.selectList( + new LambdaQueryWrapper() + .in(Department::getId, deptIds) + .isNotNull(Department::getLeaderId) + ); + + if (depts.isEmpty()) { + return 0; + } + + Set leaderIds = depts.stream() + .map(Department::getLeaderId) + .filter(id -> id != null) + .collect(Collectors.toSet()); + + if (leaderIds.isEmpty()) { + return 0; + } + + // 统计这些负责人中,dept_id 不在 deptIds 内的人数(且状态为启用) + Long count = userMapper.selectCount(new LambdaQueryWrapper() + .in(User::getId, leaderIds) + .notIn(User::getDeptId, deptIds) + .eq(User::getStatus, 1)); + + return count.intValue(); + } + // ==================== 流程效率统计 ==================== /** @@ -2052,7 +2090,7 @@ public class AnalyticsService { Map deptNames = departments.stream() .collect(Collectors.toMap(d -> d.getId(), d -> d.getDeptName(), (a, b) -> a)); - // 🔥 获取每个部门的人数 + // 🔥 获取每个部门的人数(包含部门负责人) Map deptMemberCounts = new HashMap<>(); for (Long deptId : tasksByDept.keySet()) { // 查询该部门及其子部门的所有用户数量 @@ -2060,7 +2098,10 @@ public class AnalyticsService { Long memberCount = userMapper.selectCount(new LambdaQueryWrapper() .in(User::getDeptId, deptAndChildIds) .eq(User::getStatus, 1)); // 只统计启用状态的用户 - deptMemberCounts.put(deptId, memberCount.intValue()); + + // 🔥 检查部门负责人是否已被统计,如果负责人的dept_id不在该部门内,则额外加上 + int leaderCount = countLeadersNotInDept(deptAndChildIds); + deptMemberCounts.put(deptId, memberCount.intValue() + leaderCount); } for (Map.Entry> entry : tasksByDept.entrySet()) { @@ -2163,7 +2204,7 @@ public class AnalyticsService { Map deptNames = departments.stream() .collect(Collectors.toMap(d -> d.getId(), d -> d.getDeptName(), (a, b) -> a)); - // 🔥 获取每个部门的人数 + // 🔥 获取每个部门的人数(包含部门负责人) Map deptMemberCounts = new HashMap<>(); for (Long deptId : tasksByDept.keySet()) { // 查询该部门及其子部门的所有用户数量 @@ -2171,7 +2212,10 @@ public class AnalyticsService { Long memberCount = userMapper.selectCount(new LambdaQueryWrapper() .in(User::getDeptId, deptAndChildIds) .eq(User::getStatus, 1)); // 只统计启用状态的用户 - deptMemberCounts.put(deptId, memberCount.intValue()); + + // 🔥 检查部门负责人是否已被统计,如果负责人的dept_id不在该部门内,则额外加上 + int leaderCount = countLeadersNotInDept(deptAndChildIds); + deptMemberCounts.put(deptId, memberCount.intValue() + leaderCount); } for (Map.Entry> entry : tasksByDept.entrySet()) {