fix: 部门人数统计包含部门负责人(即使负责人dept_id在其他部门)
This commit is contained in:
parent
fceb14e00c
commit
456282ce98
@ -1080,6 +1080,44 @@ public class AnalyticsService {
|
||||
return deptIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计部门负责人中,dept_id 不在该部门内的人数
|
||||
* 用于部门人数统计时,把"挂靠"在其他部门但实际负责该部门的负责人算进去
|
||||
*/
|
||||
private int countLeadersNotInDept(List<Long> deptIds) {
|
||||
if (deptIds == null || deptIds.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 获取这些部门的所有负责人ID
|
||||
List<Department> depts = departmentMapper.selectList(
|
||||
new LambdaQueryWrapper<Department>()
|
||||
.in(Department::getId, deptIds)
|
||||
.isNotNull(Department::getLeaderId)
|
||||
);
|
||||
|
||||
if (depts.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Set<Long> 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<User>()
|
||||
.in(User::getId, leaderIds)
|
||||
.notIn(User::getDeptId, deptIds)
|
||||
.eq(User::getStatus, 1));
|
||||
|
||||
return count.intValue();
|
||||
}
|
||||
|
||||
// ==================== 流程效率统计 ====================
|
||||
|
||||
/**
|
||||
@ -2052,7 +2090,7 @@ public class AnalyticsService {
|
||||
Map<Long, String> deptNames = departments.stream()
|
||||
.collect(Collectors.toMap(d -> d.getId(), d -> d.getDeptName(), (a, b) -> a));
|
||||
|
||||
// 🔥 获取每个部门的人数
|
||||
// 🔥 获取每个部门的人数(包含部门负责人)
|
||||
Map<Long, Integer> deptMemberCounts = new HashMap<>();
|
||||
for (Long deptId : tasksByDept.keySet()) {
|
||||
// 查询该部门及其子部门的所有用户数量
|
||||
@ -2060,7 +2098,10 @@ public class AnalyticsService {
|
||||
Long memberCount = userMapper.selectCount(new LambdaQueryWrapper<User>()
|
||||
.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<Long, List<Task>> entry : tasksByDept.entrySet()) {
|
||||
@ -2163,7 +2204,7 @@ public class AnalyticsService {
|
||||
Map<Long, String> deptNames = departments.stream()
|
||||
.collect(Collectors.toMap(d -> d.getId(), d -> d.getDeptName(), (a, b) -> a));
|
||||
|
||||
// 🔥 获取每个部门的人数
|
||||
// 🔥 获取每个部门的人数(包含部门负责人)
|
||||
Map<Long, Integer> deptMemberCounts = new HashMap<>();
|
||||
for (Long deptId : tasksByDept.keySet()) {
|
||||
// 查询该部门及其子部门的所有用户数量
|
||||
@ -2171,7 +2212,10 @@ public class AnalyticsService {
|
||||
Long memberCount = userMapper.selectCount(new LambdaQueryWrapper<User>()
|
||||
.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<Long, List<Task>> entry : tasksByDept.entrySet()) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user