fix: exclude inactive parent departments from publishing
This commit is contained in:
parent
f0387a6a65
commit
6635a248e6
@ -868,7 +868,8 @@ public class DepartmentService {
|
|||||||
continue;
|
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);
|
result.add(dept);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -881,6 +882,7 @@ public class DepartmentService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
childDepts.stream()
|
childDepts.stream()
|
||||||
|
.filter(child -> isDepartmentActiveWithAncestors(child.getId()))
|
||||||
.filter(child -> "demand".equals(child.getDeptType()) || "primary_demand".equals(child.getDeptType()))
|
.filter(child -> "demand".equals(child.getDeptType()) || "primary_demand".equals(child.getDeptType()))
|
||||||
.forEach(result::add);
|
.forEach(result::add);
|
||||||
}
|
}
|
||||||
@ -893,4 +895,29 @@ public class DepartmentService {
|
|||||||
map -> new ArrayList<>(map.values())
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1332,6 +1332,7 @@ public class TaskService {
|
|||||||
.filter(java.util.Objects::nonNull)
|
.filter(java.util.Objects::nonNull)
|
||||||
.filter(dept -> dept.getStatus() != null && dept.getStatus() == 1)
|
.filter(dept -> dept.getStatus() != null && dept.getStatus() == 1)
|
||||||
.filter(dept -> dept.getDeleted() == null || dept.getDeleted() == 0)
|
.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()))
|
.filter(dept -> "demand".equals(dept.getDeptType()) || "primary_demand".equals(dept.getDeptType()))
|
||||||
.distinct()
|
.distinct()
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
@ -1350,6 +1351,9 @@ public class TaskService {
|
|||||||
if (requestedDept == null) {
|
if (requestedDept == null) {
|
||||||
throw new BusinessException(ResultCode.PARAM_ERROR, "发起部门不存在");
|
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())) {
|
if (!"demand".equals(requestedDept.getDeptType()) && !"primary_demand".equals(requestedDept.getDeptType())) {
|
||||||
throw new BusinessException(ResultCode.PARAM_ERROR, "发起部门必须是需求部门或一级需求部门");
|
throw new BusinessException(ResultCode.PARAM_ERROR, "发起部门必须是需求部门或一级需求部门");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -698,6 +698,7 @@ const availablePublishingDepartments = computed<PublishingDepartmentOption[]>(()
|
|||||||
departments.forEach((dept) => {
|
departments.forEach((dept) => {
|
||||||
if (!dept?.deptId || seen.has(dept.deptId)) return
|
if (!dept?.deptId || seen.has(dept.deptId)) return
|
||||||
if (dept.deptType !== 'demand' && dept.deptType !== 'primary_demand') return
|
if (dept.deptType !== 'demand' && dept.deptType !== 'primary_demand') return
|
||||||
|
if (!isDepartmentActiveWithAncestors(dept.deptId)) return
|
||||||
result.push({
|
result.push({
|
||||||
deptId: dept.deptId,
|
deptId: dept.deptId,
|
||||||
deptName: dept.deptName,
|
deptName: dept.deptName,
|
||||||
@ -711,6 +712,7 @@ const availablePublishingDepartments = computed<PublishingDepartmentOption[]>(()
|
|||||||
managedDepartments.forEach((dept) => {
|
managedDepartments.forEach((dept) => {
|
||||||
if (!dept?.deptId || seen.has(dept.deptId)) return
|
if (!dept?.deptId || seen.has(dept.deptId)) return
|
||||||
if (dept.deptType !== 'demand' && dept.deptType !== 'primary_demand') return
|
if (dept.deptType !== 'demand' && dept.deptType !== 'primary_demand') return
|
||||||
|
if (!isDepartmentActiveWithAncestors(dept.deptId)) return
|
||||||
result.push({
|
result.push({
|
||||||
deptId: dept.deptId,
|
deptId: dept.deptId,
|
||||||
deptName: dept.deptName,
|
deptName: dept.deptName,
|
||||||
@ -723,6 +725,7 @@ const availablePublishingDepartments = computed<PublishingDepartmentOption[]>(()
|
|||||||
if (
|
if (
|
||||||
userInfo.deptId &&
|
userInfo.deptId &&
|
||||||
!seen.has(userInfo.deptId) &&
|
!seen.has(userInfo.deptId) &&
|
||||||
|
isDepartmentActiveWithAncestors(userInfo.deptId) &&
|
||||||
(userInfo.deptType === 'demand' || userInfo.deptType === 'primary_demand')
|
(userInfo.deptType === 'demand' || userInfo.deptType === 'primary_demand')
|
||||||
) {
|
) {
|
||||||
result.unshift({
|
result.unshift({
|
||||||
@ -1048,6 +1051,27 @@ const getDepartmentById = (deptId?: number | null) => {
|
|||||||
return departmentList.value.find(d => d.id === deptId)
|
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 = (
|
const getDepartmentDisplayName = (
|
||||||
dept?: departmentApi.DepartmentOverview | null,
|
dept?: departmentApi.DepartmentOverview | null,
|
||||||
duplicateNames?: Set<string>
|
duplicateNames?: Set<string>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user