From 1ba5e86262b1925d53ba64ab80e7a50f22959fd6 Mon Sep 17 00:00:00 2001 From: RuoYi <yzz_ivy@163.com> Date: 星期六, 28 五月 2022 09:32:50 +0800 Subject: [PATCH] 新增Anonymous匿名访问不鉴权注解 --- src/main/java/com/ruoyi/project/system/service/impl/SysDeptServiceImpl.java | 30 ++++++++++++++++++++++++++---- 1 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ruoyi/project/system/service/impl/SysDeptServiceImpl.java b/src/main/java/com/ruoyi/project/system/service/impl/SysDeptServiceImpl.java index aae3800..31b291a 100644 --- a/src/main/java/com/ruoyi/project/system/service/impl/SysDeptServiceImpl.java +++ b/src/main/java/com/ruoyi/project/system/service/impl/SysDeptServiceImpl.java @@ -9,11 +9,14 @@ import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.text.Convert; import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.framework.aspectj.lang.annotation.DataScope; import com.ruoyi.framework.web.domain.TreeSelect; import com.ruoyi.project.system.domain.SysDept; import com.ruoyi.project.system.domain.SysRole; +import com.ruoyi.project.system.domain.SysUser; import com.ruoyi.project.system.mapper.SysDeptMapper; import com.ruoyi.project.system.mapper.SysRoleMapper; import com.ruoyi.project.system.service.ISysDeptService; @@ -60,9 +63,8 @@ { tempList.add(dept.getDeptId()); } - for (Iterator<SysDept> iterator = depts.iterator(); iterator.hasNext();) + for (SysDept dept : depts) { - SysDept dept = (SysDept) iterator.next(); // 濡傛灉鏄《绾ц妭鐐�, 閬嶅巻璇ョ埗鑺傜偣鐨勬墍鏈夊瓙鑺傜偣 if (!tempList.contains(dept.getParentId())) { @@ -97,7 +99,7 @@ * @return 閫変腑閮ㄩ棬鍒楄〃 */ @Override - public List<Integer> selectDeptListByRoleId(Long roleId) + public List<Long> selectDeptListByRoleId(Long roleId) { SysRole role = roleMapper.selectRoleById(roleId); return deptMapper.selectDeptListByRoleId(roleId, role.isDeptCheckStrictly()); @@ -150,7 +152,7 @@ public boolean checkDeptExistUser(Long deptId) { int result = deptMapper.checkDeptExistUser(deptId); - return result > 0 ? true : false; + return result > 0; } /** @@ -172,6 +174,26 @@ } /** + * 鏍¢獙閮ㄩ棬鏄惁鏈夋暟鎹潈闄� + * + * @param deptId 閮ㄩ棬id + */ + @Override + public void checkDeptDataScope(Long deptId) + { + if (!SysUser.isAdmin(SecurityUtils.getUserId())) + { + SysDept dept = new SysDept(); + dept.setDeptId(deptId); + List<SysDept> depts = SpringUtils.getAopProxy(this).selectDeptList(dept); + if (StringUtils.isEmpty(depts)) + { + throw new ServiceException("娌℃湁鏉冮檺璁块棶閮ㄩ棬鏁版嵁锛�"); + } + } + } + + /** * 鏂板淇濆瓨閮ㄩ棬淇℃伅 * * @param dept 閮ㄩ棬淇℃伅 -- Gitblit v1.9.3