From cf17bcb15c0063335c2e0687450b977ce4be378f Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期四, 03 三月 2022 14:34:13 +0800 Subject: [PATCH] fix 修复 数据权限 从 aop 切换到 拦截器 导致获取代理失败问题 --- ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java | 79 ++++++++++++++++++--------------------- 1 files changed, 36 insertions(+), 43 deletions(-) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java index cea08c8..19f3211 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java @@ -1,18 +1,15 @@ package com.ruoyi.system.service.impl; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.domain.PageQuery; import com.ruoyi.common.core.domain.entity.SysRole; -import com.ruoyi.common.core.domain.entity.SysUser; -import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.exception.ServiceException; -import com.ruoyi.common.utils.PageUtils; -import com.ruoyi.common.utils.SecurityUtils; -import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.common.utils.spring.SpringUtils; +import com.ruoyi.common.helper.LoginHelper; import com.ruoyi.system.domain.SysRoleDept; import com.ruoyi.system.domain.SysRoleMenu; import com.ruoyi.system.domain.SysUserRole; @@ -21,7 +18,7 @@ import com.ruoyi.system.mapper.SysRoleMenuMapper; import com.ruoyi.system.mapper.SysUserRoleMapper; import com.ruoyi.system.service.ISysRoleService; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -32,22 +29,19 @@ * * @author Lion Li */ +@RequiredArgsConstructor @Service -public class SysRoleServiceImpl extends ServicePlusImpl<SysRoleMapper, SysRole, SysRole> implements ISysRoleService { +public class SysRoleServiceImpl implements ISysRoleService { - @Autowired - private SysRoleMenuMapper roleMenuMapper; - - @Autowired - private SysUserRoleMapper userRoleMapper; - - @Autowired - private SysRoleDeptMapper roleDeptMapper; + private final SysRoleMapper baseMapper; + private final SysRoleMenuMapper roleMenuMapper; + private final SysUserRoleMapper userRoleMapper; + private final SysRoleDeptMapper roleDeptMapper; @Override public TableDataInfo<SysRole> selectPageRoleList(SysRole role, PageQuery pageQuery) { - Page<SysRole> page = baseMapper.selectPageRoleList(PageUtils.buildPage(pageQuery), role); - return PageUtils.buildDataInfo(page); + Page<SysRole> page = baseMapper.selectPageRoleList(pageQuery.build(), role); + return TableDataInfo.build(page); } /** @@ -93,7 +87,7 @@ List<SysRole> perms = baseMapper.selectRolePermissionByUserId(userId); Set<String> permsSet = new HashSet<>(); for (SysRole perm : perms) { - if (StringUtils.isNotNull(perm)) { + if (ObjectUtil.isNotNull(perm)) { permsSet.addAll(Arrays.asList(perm.getRoleKey().trim().split(","))); } } @@ -107,7 +101,7 @@ */ @Override public List<SysRole> selectRoleAll() { - return SpringUtils.getAopProxy(this).selectRoleList(new SysRole()); + return this.selectRoleList(new SysRole()); } /** @@ -129,7 +123,7 @@ */ @Override public SysRole selectRoleById(Long roleId) { - return getById(roleId); + return baseMapper.selectById(roleId); } /** @@ -140,11 +134,10 @@ */ @Override public String checkRoleNameUnique(SysRole role) { - Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId(); - long count = count(new LambdaQueryWrapper<SysRole>() - .eq(SysRole::getRoleName, role.getRoleName()) - .ne(SysRole::getRoleId, roleId)); - if (count > 0) { + boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysRole>() + .eq(SysRole::getRoleName, role.getRoleName()) + .ne(ObjectUtil.isNotNull(role.getRoleId()), SysRole::getRoleId, role.getRoleId())); + if (exist) { return UserConstants.NOT_UNIQUE; } return UserConstants.UNIQUE; @@ -158,11 +151,10 @@ */ @Override public String checkRoleKeyUnique(SysRole role) { - Long roleId = StringUtils.isNull(role.getRoleId()) ? -1L : role.getRoleId(); - long count = count(new LambdaQueryWrapper<SysRole>() - .eq(SysRole::getRoleKey, role.getRoleKey()) - .ne(SysRole::getRoleId, roleId)); - if (count > 0) { + boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysRole>() + .eq(SysRole::getRoleKey, role.getRoleKey()) + .ne(ObjectUtil.isNotNull(role.getRoleId()), SysRole::getRoleId, role.getRoleId())); + if (exist) { return UserConstants.NOT_UNIQUE; } return UserConstants.UNIQUE; @@ -175,7 +167,7 @@ */ @Override public void checkRoleAllowed(SysRole role) { - if (StringUtils.isNotNull(role.getRoleId()) && role.isAdmin()) { + if (ObjectUtil.isNotNull(role.getRoleId()) && role.isAdmin()) { throw new ServiceException("涓嶅厑璁告搷浣滆秴绾х鐞嗗憳瑙掕壊"); } } @@ -187,11 +179,11 @@ */ @Override public void checkRoleDataScope(Long roleId) { - if (!SysUser.isAdmin(SecurityUtils.getUserId())) { + if (!LoginHelper.isAdmin()) { SysRole role = new SysRole(); role.setRoleId(roleId); - List<SysRole> roles = SpringUtils.getAopProxy(this).selectRoleList(role); - if (StringUtils.isEmpty(roles)) { + List<SysRole> roles = this.selectRoleList(role); + if (CollUtil.isEmpty(roles)) { throw new ServiceException("娌℃湁鏉冮檺璁块棶瑙掕壊鏁版嵁锛�"); } } @@ -282,7 +274,7 @@ list.add(rm); } if (list.size() > 0) { - rows = roleMenuMapper.insertAll(list); + rows = roleMenuMapper.insertBatch(list) ? list.size() : 0; } return rows; } @@ -303,7 +295,7 @@ list.add(rd); } if (list.size() > 0) { - rows = roleDeptMapper.insertAll(list); + rows = roleDeptMapper.insertBatch(list) ? list.size() : 0; } return rows; } @@ -335,6 +327,7 @@ public int deleteRoleByIds(Long[] roleIds) { for (Long roleId : roleIds) { checkRoleAllowed(new SysRole(roleId)); + checkRoleDataScope(roleId); SysRole role = selectRoleById(roleId); if (countUserRoleByRoleId(roleId) > 0) { throw new ServiceException(String.format("%1$s宸插垎閰�,涓嶈兘鍒犻櫎", role.getRoleName())); @@ -357,8 +350,8 @@ @Override public int deleteAuthUser(SysUserRole userRole) { return userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>() - .eq(SysUserRole::getRoleId, userRole.getRoleId()) - .eq(SysUserRole::getUserId, userRole.getUserId())); + .eq(SysUserRole::getRoleId, userRole.getRoleId()) + .eq(SysUserRole::getUserId, userRole.getUserId())); } /** @@ -371,15 +364,15 @@ @Override public int deleteAuthUsers(Long roleId, Long[] userIds) { return userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>() - .eq(SysUserRole::getRoleId, roleId) - .in(SysUserRole::getUserId, Arrays.asList(userIds))); + .eq(SysUserRole::getRoleId, roleId) + .in(SysUserRole::getUserId, Arrays.asList(userIds))); } /** * 鎵归噺閫夋嫨鎺堟潈鐢ㄦ埛瑙掕壊 * * @param roleId 瑙掕壊ID - * @param userIds 闇�瑕佸垹闄ょ殑鐢ㄦ埛鏁版嵁ID + * @param userIds 闇�瑕佹巿鏉冪殑鐢ㄦ埛鏁版嵁ID * @return 缁撴灉 */ @Override @@ -394,7 +387,7 @@ list.add(ur); } if (list.size() > 0) { - rows = userRoleMapper.insertAll(list); + rows = userRoleMapper.insertBatch(list) ? list.size() : 0; } return rows; } -- Gitblit v1.9.3