From 6635a248e6e79e386836da7a27d2aa8a66ae0f19 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 30 Mar 2026 18:38:36 +0800 Subject: [PATCH] fix: exclude inactive parent departments from publishing --- .../designhub/service/DepartmentService.java | 29 ++++++++++++++++++- .../com/designhub/service/TaskService.java | 4 +++ frontend/src/views/CreateTask.vue | 24 +++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/com/designhub/service/DepartmentService.java b/backend/src/main/java/com/designhub/service/DepartmentService.java index c35779d..9d34ff5 100644 --- a/backend/src/main/java/com/designhub/service/DepartmentService.java +++ b/backend/src/main/java/com/designhub/service/DepartmentService.java @@ -868,7 +868,8 @@ public class DepartmentService { continue; } - if ("demand".equals(dept.getDeptType()) || "primary_demand".equals(dept.getDeptType())) { + if (isDepartmentActiveWithAncestors(dept.getId()) + && ("demand".equals(dept.getDeptType()) || "primary_demand".equals(dept.getDeptType()))) { result.add(dept); } @@ -881,6 +882,7 @@ public class DepartmentService { ); childDepts.stream() + .filter(child -> isDepartmentActiveWithAncestors(child.getId())) .filter(child -> "demand".equals(child.getDeptType()) || "primary_demand".equals(child.getDeptType())) .forEach(result::add); } @@ -893,4 +895,29 @@ public class DepartmentService { map -> new ArrayList<>(map.values()) )); } + + /** + * 部门自身及其所有父级都必须是启用且未删除,才视为可用部门 + */ + public boolean isDepartmentActiveWithAncestors(Long deptId) { + if (deptId == null) { + return false; + } + + Department current = getDepartmentById(deptId); + while (current != null) { + if (current.getStatus() == null || current.getStatus() != 1) { + return false; + } + if (current.getDeleted() != null && current.getDeleted() == 1) { + return false; + } + if (current.getParentId() == null || current.getParentId() == 0) { + break; + } + current = getDepartmentById(current.getParentId()); + } + + return true; + } } diff --git a/backend/src/main/java/com/designhub/service/TaskService.java b/backend/src/main/java/com/designhub/service/TaskService.java index cf941d0..48fc146 100644 --- a/backend/src/main/java/com/designhub/service/TaskService.java +++ b/backend/src/main/java/com/designhub/service/TaskService.java @@ -1332,6 +1332,7 @@ public class TaskService { .filter(java.util.Objects::nonNull) .filter(dept -> dept.getStatus() != null && dept.getStatus() == 1) .filter(dept -> dept.getDeleted() == null || dept.getDeleted() == 0) + .filter(dept -> departmentService.isDepartmentActiveWithAncestors(dept.getId())) .filter(dept -> "demand".equals(dept.getDeptType()) || "primary_demand".equals(dept.getDeptType())) .distinct() .collect(Collectors.toList()); @@ -1350,6 +1351,9 @@ public class TaskService { if (requestedDept == null) { throw new BusinessException(ResultCode.PARAM_ERROR, "发起部门不存在"); } + if (!departmentService.isDepartmentActiveWithAncestors(requestedDeptId)) { + throw new BusinessException(ResultCode.PARAM_ERROR, "发起部门已停用,请选择其他部门"); + } if (!"demand".equals(requestedDept.getDeptType()) && !"primary_demand".equals(requestedDept.getDeptType())) { throw new BusinessException(ResultCode.PARAM_ERROR, "发起部门必须是需求部门或一级需求部门"); } diff --git a/frontend/src/views/CreateTask.vue b/frontend/src/views/CreateTask.vue index 1b41bee..1e46886 100644 --- a/frontend/src/views/CreateTask.vue +++ b/frontend/src/views/CreateTask.vue @@ -698,6 +698,7 @@ const availablePublishingDepartments = computed(() departments.forEach((dept) => { if (!dept?.deptId || seen.has(dept.deptId)) return if (dept.deptType !== 'demand' && dept.deptType !== 'primary_demand') return + if (!isDepartmentActiveWithAncestors(dept.deptId)) return result.push({ deptId: dept.deptId, deptName: dept.deptName, @@ -711,6 +712,7 @@ const availablePublishingDepartments = computed(() managedDepartments.forEach((dept) => { if (!dept?.deptId || seen.has(dept.deptId)) return if (dept.deptType !== 'demand' && dept.deptType !== 'primary_demand') return + if (!isDepartmentActiveWithAncestors(dept.deptId)) return result.push({ deptId: dept.deptId, deptName: dept.deptName, @@ -723,6 +725,7 @@ const availablePublishingDepartments = computed(() if ( userInfo.deptId && !seen.has(userInfo.deptId) && + isDepartmentActiveWithAncestors(userInfo.deptId) && (userInfo.deptType === 'demand' || userInfo.deptType === 'primary_demand') ) { result.unshift({ @@ -1048,6 +1051,27 @@ const getDepartmentById = (deptId?: number | null) => { return departmentList.value.find(d => d.id === deptId) } +const isDepartmentActiveWithAncestors = (deptId?: number | null) => { + if (!deptId) return false + if (!departmentList.value.length) return true + + let currentDept = getDepartmentById(deptId) + while (currentDept) { + if (currentDept.status !== undefined && currentDept.status !== 1) { + return false + } + if ((currentDept as any).deleted === 1) { + return false + } + if (!currentDept.parentId) { + break + } + currentDept = getDepartmentById(currentDept.parentId) + } + + return true +} + const getDepartmentDisplayName = ( dept?: departmentApi.DepartmentOverview | null, duplicateNames?: Set