fix: 修复接单部门筛选支持部门层级
当用户选择父部门筛选时,同时匹配该部门及其所有子部门 - TaskService.getTaskHall 支持部门层级筛选 - TaskItemService.getAvailableItems 支持部门层级筛选
This commit is contained in:
parent
2e74f609c5
commit
172d1b1cde
@ -65,6 +65,10 @@ public class TaskItemService {
|
||||
return taskItemMapper.selectAvailableItems(pageParam, taskTypeId, keyword);
|
||||
}
|
||||
|
||||
// 🔥 获取筛选部门及其所有子部门的ID列表
|
||||
Set<Long> filterDeptAndChildIds = getDeptAndChildIds(filterDeptId);
|
||||
log.info("筛选部门ID: {}, 包含子部门: {}", filterDeptId, filterDeptAndChildIds);
|
||||
|
||||
// 获取该部门可接单的任务类型ID列表
|
||||
List<com.designhub.entity.DemandType> allDemandTypes = demandTypeMapper.selectList(null);
|
||||
Map<Long, com.designhub.entity.DemandType> demandTypeMap = allDemandTypes.stream()
|
||||
@ -79,14 +83,20 @@ public class TaskItemService {
|
||||
allowedDepts = parentType.getAllowedDeptIds();
|
||||
}
|
||||
}
|
||||
// 只筛选明确指定了该部门的任务类型
|
||||
// 只筛选明确指定了该部门(或其子部门)的任务类型
|
||||
if (allowedDepts == null || allowedDepts.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
String[] deptIds = allowedDepts.split(",");
|
||||
for (String deptId : deptIds) {
|
||||
if (deptId.trim().equals(String.valueOf(filterDeptId))) {
|
||||
return true;
|
||||
for (String deptIdStr : deptIds) {
|
||||
try {
|
||||
Long deptId = Long.parseLong(deptIdStr.trim());
|
||||
// 🔥 检查是否匹配筛选部门或其子部门
|
||||
if (filterDeptAndChildIds.contains(deptId)) {
|
||||
return true;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
// 忽略无效的部门ID
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -94,6 +104,8 @@ public class TaskItemService {
|
||||
.map(com.designhub.entity.DemandType::getId)
|
||||
.collect(java.util.stream.Collectors.toList());
|
||||
|
||||
log.info("匹配的任务类型ID: {}", filterDeptAllowedTypeIds);
|
||||
|
||||
// 如果没有找到匹配的任务类型,返回空结果
|
||||
if (filterDeptAllowedTypeIds.isEmpty()) {
|
||||
return new Page<>(page, pageSize);
|
||||
@ -102,6 +114,35 @@ public class TaskItemService {
|
||||
// 查询并筛选
|
||||
return taskItemMapper.selectAvailableItemsByTaskTypes(pageParam, taskTypeId, keyword, filterDeptAllowedTypeIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定部门及其所有子部门的ID集合
|
||||
*/
|
||||
private Set<Long> getDeptAndChildIds(Long deptId) {
|
||||
Set<Long> result = new HashSet<>();
|
||||
result.add(deptId);
|
||||
|
||||
// 获取所有部门
|
||||
List<com.designhub.entity.Department> allDepts = departmentMapper.selectList(null);
|
||||
|
||||
// 递归获取子部门
|
||||
addChildDeptIds(result, deptId, allDepts);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归添加子部门ID
|
||||
*/
|
||||
private void addChildDeptIds(Set<Long> result, Long parentId, List<com.designhub.entity.Department> allDepts) {
|
||||
for (com.designhub.entity.Department dept : allDepts) {
|
||||
if (parentId.equals(dept.getParentId())) {
|
||||
result.add(dept.getId());
|
||||
// 递归获取子部门的子部门
|
||||
addChildDeptIds(result, dept.getId(), allDepts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取进行中的子任务列表
|
||||
|
||||
@ -1070,6 +1070,11 @@ public class TaskService {
|
||||
// 🔥 如果指定了筛选部门,进一步过滤只显示该部门可接单的任务类型
|
||||
List<Long> filteredTaskTypeIds = allowedTaskTypeIds;
|
||||
if (filterDeptId != null) {
|
||||
// 🔥 获取筛选部门及其所有子部门的ID列表
|
||||
List<Long> filterDeptAndChildIds = getDeptAndChildIds(filterDeptId);
|
||||
Set<Long> filterDeptAndChildSet = new HashSet<>(filterDeptAndChildIds);
|
||||
log.info("筛选部门ID: {}, 包含子部门: {}", filterDeptId, filterDeptAndChildIds);
|
||||
|
||||
List<Long> filterDeptAllowedIds = allDemandTypes.stream()
|
||||
.filter(dt -> {
|
||||
String allowedDepts = dt.getAllowedDeptIds();
|
||||
@ -1079,14 +1084,20 @@ public class TaskService {
|
||||
allowedDepts = parentType.getAllowedDeptIds();
|
||||
}
|
||||
}
|
||||
// 只筛选明确指定了该部门的任务类型(不包括所有部门可接单的)
|
||||
// 只筛选明确指定了该部门(或其子部门)的任务类型(不包括所有部门可接单的)
|
||||
if (allowedDepts == null || allowedDepts.isEmpty()) {
|
||||
return false; // 所有部门都可接单的不纳入筛选结果
|
||||
}
|
||||
String[] deptIds = allowedDepts.split(",");
|
||||
for (String deptId : deptIds) {
|
||||
if (deptId.trim().equals(String.valueOf(filterDeptId))) {
|
||||
return true;
|
||||
for (String deptIdStr : deptIds) {
|
||||
try {
|
||||
Long deptId = Long.parseLong(deptIdStr.trim());
|
||||
// 🔥 检查是否匹配筛选部门或其子部门
|
||||
if (filterDeptAndChildSet.contains(deptId)) {
|
||||
return true;
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
// 忽略无效的部门ID
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -1094,6 +1105,8 @@ public class TaskService {
|
||||
.map(DemandType::getId)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
log.info("匹配的任务类型ID: {}", filterDeptAllowedIds);
|
||||
|
||||
// 取交集:用户可接单的 ∩ 筛选部门可接单的
|
||||
if (allowedTaskTypeIds != null) {
|
||||
filteredTaskTypeIds = allowedTaskTypeIds.stream()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user