From 28334f6c9a66d6904674af9688a9389e4b40901d Mon Sep 17 00:00:00 2001 From: Charles7c Date: Sun, 26 Mar 2023 13:51:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=83=A8=E9=97=A8=E7=9A=84=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.如果存在下级部门,不允许删除 --- .../system/service/impl/DeptServiceImpl.java | 19 +++++++++++++++++-- .../src/views/system/dept/index.vue | 5 ++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/impl/DeptServiceImpl.java b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/impl/DeptServiceImpl.java index 0d2a9ba0..5dd381f7 100644 --- a/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/impl/DeptServiceImpl.java +++ b/continew-admin-system/src/main/java/top/charles7c/cnadmin/system/service/impl/DeptServiceImpl.java @@ -119,12 +119,11 @@ public class DeptServiceImpl extends BaseServiceImpl isSystemData = list.stream().filter(d -> DataTypeEnum.SYSTEM.equals(d.getType())).findFirst(); CheckUtils.throwIf(isSystemData::isPresent, "所选部门 [{}] 是系统内置部门,不允许删除", isSystemData.orElseGet(DeptDO::new).getName()); + CheckUtils.throwIf(this.countChildren(ids) > 0, "所选部门存在下级部门,不允许删除"); CheckUtils.throwIf(userService.countByDeptIds(ids) > 0, "所选部门存在用户关联,请解除关联后重试"); // 删除角色和部门关联 roleDeptService.deleteByDeptIds(ids); - // 删除子部门 - baseMapper.lambdaUpdate().in(DeptDO::getParentId, ids).remove(); // 删除部门 super.delete(ids); } @@ -193,6 +192,22 @@ public class DeptServiceImpl extends BaseServiceImpl ids) { + if (CollUtil.isEmpty(ids)) { + return 0L; + } + return ids.stream() + .mapToLong(id -> baseMapper.lambdaQuery().apply(String.format("find_in_set(%s, `ancestors`)", id)).count()) + .sum(); + } + /** * 更新子部门祖级列表 * diff --git a/continew-admin-ui/src/views/system/dept/index.vue b/continew-admin-ui/src/views/system/dept/index.vue index f56ccabc..b59de1d5 100644 --- a/continew-admin-ui/src/views/system/dept/index.vue +++ b/continew-admin-ui/src/views/system/dept/index.vue @@ -158,7 +158,7 @@ 修改 @@ -490,8 +490,7 @@ proxy.$modal.warning({ title: '警告', titleAlign: 'start', - content: - '确定要删除当前选中的数据吗?如果存在下级部门则一并删除,此操作不能撤销!', + content: '确定要删除当前选中的数据吗?', hideCancel: false, onOk: () => { handleDelete(ids.value);