代码提交-部门/岗位删除,校验是否存在人员
parent
de5a1a4dc6
commit
ae447d4d24
|
|
@ -41,6 +41,17 @@ function findDeptNode(nodes = [], id) {
|
|||
return null;
|
||||
}
|
||||
|
||||
function collectSelfAndDescendantIds(node) {
|
||||
if (!node) {
|
||||
return [];
|
||||
}
|
||||
const ids = [asId(node.id)].filter(Boolean);
|
||||
(node.children || []).forEach((child) => {
|
||||
ids.push(...collectSelfAndDescendantIds(child));
|
||||
});
|
||||
return ids;
|
||||
}
|
||||
|
||||
function toSelectedDept(node) {
|
||||
if (!node) {
|
||||
return null;
|
||||
|
|
@ -180,6 +191,30 @@ function DepartmentPositionPage(props) {
|
|||
okText: "是",
|
||||
cancelText: "否",
|
||||
onOk: async () => {
|
||||
try {
|
||||
const node = findDeptNode(treeData, id);
|
||||
const deptIds = collectSelfAndDescendantIds(node);
|
||||
const countRes = await props.staffInfoDeptPersonCount?.();
|
||||
const countMap = {};
|
||||
(countRes?.data || []).forEach((item) => {
|
||||
const deptId = asId(item.deptId);
|
||||
if (deptId) {
|
||||
countMap[deptId] = Number(item.personCount) || 0;
|
||||
}
|
||||
});
|
||||
const personCount = deptIds.reduce(
|
||||
(sum, deptId) => sum + (countMap[deptId] || 0),
|
||||
0,
|
||||
);
|
||||
if (personCount > 0) {
|
||||
message.warning("该部门(含子部门)下存在人员,无法删除");
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn("[DepartmentPosition] check dept personnel failed:", err);
|
||||
message.warning("校验部门人员失败,请稍后重试");
|
||||
return;
|
||||
}
|
||||
const res = await props.orgDepartmentRemove({ data: id });
|
||||
if (res?.success !== false) {
|
||||
message.success("删除成功");
|
||||
|
|
@ -199,6 +234,22 @@ function DepartmentPositionPage(props) {
|
|||
okText: "是",
|
||||
cancelText: "否",
|
||||
onOk: async () => {
|
||||
try {
|
||||
const res = await props.staffInfoList?.({
|
||||
postId: asId(id),
|
||||
current: 1,
|
||||
size: 1,
|
||||
});
|
||||
const total = Number(res?.total ?? res?.totalCount ?? 0);
|
||||
if (total > 0) {
|
||||
message.warning("该岗位下存在人员,无法删除");
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn("[DepartmentPosition] check position personnel failed:", err);
|
||||
message.warning("校验岗位人员失败,请稍后重试");
|
||||
return;
|
||||
}
|
||||
const res = await props.orgPositionRemove({ data: id });
|
||||
if (res?.success !== false) {
|
||||
message.success("删除成功");
|
||||
|
|
|
|||
Loading…
Reference in New Issue