From 21aca2f55dcf181850809b4a44509f49c6641fe4 Mon Sep 17 00:00:00 2001 From: HuangLei Date: Thu, 19 Jun 2025 10:51:51 +0800 Subject: [PATCH] =?UTF-8?q?feat(system):=20=E9=80=92=E5=BD=92=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=BD=93=E5=89=8D=E7=99=BB=E5=BD=95=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=9A=84=E6=89=80=E6=9C=89=E5=AD=90=E9=83=A8=E9=97=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改了 getDeptList 方法,增加了对 --- .../system/service/dept/DeptServiceImpl.java | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java index c0d7b0eff2..aa6c8f076f 100644 --- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/dept/DeptServiceImpl.java @@ -5,6 +5,8 @@ import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.datapermission.core.annotation.DataPermission; +import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils; +import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptListReqVO; import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO; import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; @@ -18,6 +20,7 @@ import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import jakarta.annotation.Resource; + import java.util.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -164,9 +167,39 @@ public class DeptServiceImpl implements DeptService { @Override public List getDeptList(DeptListReqVO reqVO) { - List list = deptMapper.selectList(reqVO); - list.sort(Comparator.comparing(DeptDO::getSort)); - return list; + List list = DataPermissionUtils.executeIgnore(() -> { + return deptMapper.selectList(reqVO); + }); + Long loginUserDeptId = SecurityFrameworkUtils.getLoginUserDeptId(); + //从当前登录的部门开始,递归获取子部门 + // 从当前登录的部门开始, 递归获取所有子部门 + List allSubDepts = new ArrayList<>(); + if (loginUserDeptId != null) { + DeptDO currentDept = deptMapper.selectById(loginUserDeptId); + if (currentDept != null) { + allSubDepts.add(currentDept); + collectAllSubDept(allSubDepts, currentDept.getId(), list); + } + } + // 合并所有子部门到结果列表中 + allSubDepts.sort(Comparator.comparing(DeptDO::getSort)); + return allSubDepts; + } + + /** + * 递归收集所有子部门. + * + * @param allSubDepts 收集所有子部门的列表 + * @param parentId 父部门ID + * @param allDepts 所有部门的列表 + */ + private void collectAllSubDept(List allSubDepts, Long parentId, List allDepts) { + for (DeptDO dept : allDepts) { + if (parentId.equals(dept.getParentId())) { + allSubDepts.add(dept); + collectAllSubDept(allSubDepts, dept.getId(), allDepts); // 递归收集子部门 + } + } } @Override