From 1aee4ad00f9f9d304423960e7fe53148c6b98a78 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 29 Dec 2022 20:18:59 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91DeptService?= =?UTF-8?q?=20=E7=9A=84=20getDeptsByParentIdFromCache=20=E5=9C=A8=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E9=83=A8=E9=97=A8=E5=88=97=E8=A1=A8=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E6=9C=AA=E5=A4=84=E7=90=86=E5=A4=9A=E7=A7=9F=E6=88=B7=E5=9C=BA?= =?UTF-8?q?=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/module/system/dal/dataobject/dept/DeptDO.java | 4 ++-- .../yudao/module/system/service/dept/DeptServiceImpl.java | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/dept/DeptDO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/dept/DeptDO.java index 647eb1eeb5..31f90cfc40 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/dept/DeptDO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/dept/DeptDO.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.system.dal.dataobject.dept; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableId; @@ -19,7 +19,7 @@ import lombok.EqualsAndHashCode; @KeySequence("system_dept_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data @EqualsAndHashCode(callSuper = true) -public class DeptDO extends BaseDO { +public class DeptDO extends TenantBaseDO { /** * 部门ID diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java index dbdedd2f8e..049a6415aa 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; @@ -198,12 +199,19 @@ public class DeptServiceImpl implements DeptService { if (recursiveCount == 0) { return; } + // 获得子部门 Collection depts = parentDeptMap.get(parentId); if (CollUtil.isEmpty(depts)) { return; } + // 针对多租户,过滤掉非当前租户的部门 + Long tenantId = TenantContextHolder.getTenantId(); + if (tenantId != null) { + depts = CollUtil.filterNew(depts, dept -> tenantId.equals(dept.getTenantId())); + } result.addAll(depts); + // 继续递归 depts.forEach(dept -> getDeptsByParentIdFromCache(result, dept.getId(), recursiveCount - 1, parentDeptMap));