Commit 1aee4ad00f9f9d304423960e7fe53148c6b98a78
1 parent
ac3c7511
【修复】DeptService 的 getDeptsByParentIdFromCache 在获取部门列表时,未处理多租户场景
Showing
2 changed files
with
10 additions
and
2 deletions
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/dept/DeptDO.java
| 1 | package cn.iocoder.yudao.module.system.dal.dataobject.dept; | 1 | package cn.iocoder.yudao.module.system.dal.dataobject.dept; |
| 2 | 2 | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 4 | -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 4 | +import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; |
| 5 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; | 5 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; |
| 6 | import com.baomidou.mybatisplus.annotation.KeySequence; | 6 | import com.baomidou.mybatisplus.annotation.KeySequence; |
| 7 | import com.baomidou.mybatisplus.annotation.TableId; | 7 | import com.baomidou.mybatisplus.annotation.TableId; |
| @@ -19,7 +19,7 @@ import lombok.EqualsAndHashCode; | @@ -19,7 +19,7 @@ import lombok.EqualsAndHashCode; | ||
| 19 | @KeySequence("system_dept_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | 19 | @KeySequence("system_dept_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 |
| 20 | @Data | 20 | @Data |
| 21 | @EqualsAndHashCode(callSuper = true) | 21 | @EqualsAndHashCode(callSuper = true) |
| 22 | -public class DeptDO extends BaseDO { | 22 | +public class DeptDO extends TenantBaseDO { |
| 23 | 23 | ||
| 24 | /** | 24 | /** |
| 25 | * 部门ID | 25 | * 部门ID |
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; | @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; | ||
| 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; | 4 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; | 5 | import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; |
| 6 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 6 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 7 | +import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; | ||
| 7 | import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; | 8 | import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; |
| 8 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO; | 9 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptCreateReqVO; |
| 9 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; | 10 | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; |
| @@ -198,12 +199,19 @@ public class DeptServiceImpl implements DeptService { | @@ -198,12 +199,19 @@ public class DeptServiceImpl implements DeptService { | ||
| 198 | if (recursiveCount == 0) { | 199 | if (recursiveCount == 0) { |
| 199 | return; | 200 | return; |
| 200 | } | 201 | } |
| 202 | + | ||
| 201 | // 获得子部门 | 203 | // 获得子部门 |
| 202 | Collection<DeptDO> depts = parentDeptMap.get(parentId); | 204 | Collection<DeptDO> depts = parentDeptMap.get(parentId); |
| 203 | if (CollUtil.isEmpty(depts)) { | 205 | if (CollUtil.isEmpty(depts)) { |
| 204 | return; | 206 | return; |
| 205 | } | 207 | } |
| 208 | + // 针对多租户,过滤掉非当前租户的部门 | ||
| 209 | + Long tenantId = TenantContextHolder.getTenantId(); | ||
| 210 | + if (tenantId != null) { | ||
| 211 | + depts = CollUtil.filterNew(depts, dept -> tenantId.equals(dept.getTenantId())); | ||
| 212 | + } | ||
| 206 | result.addAll(depts); | 213 | result.addAll(depts); |
| 214 | + | ||
| 207 | // 继续递归 | 215 | // 继续递归 |
| 208 | depts.forEach(dept -> getDeptsByParentIdFromCache(result, dept.getId(), | 216 | depts.forEach(dept -> getDeptsByParentIdFromCache(result, dept.getId(), |
| 209 | recursiveCount - 1, parentDeptMap)); | 217 | recursiveCount - 1, parentDeptMap)); |