From a195a18959d20590b65d6c34c5622de0b2e6839f Mon Sep 17 00:00:00 2001 From: RuoYi <yzz_ivy@163.com> Date: 星期二, 24 八月 2021 15:58:47 +0800 Subject: [PATCH] 修改时检查用户数据权限范围 --- src/main/java/com/ruoyi/project/system/service/impl/SysUserServiceImpl.java | 69 ++++++++++++++++++++++++++++++++-- 1 files changed, 65 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/ruoyi/project/system/service/impl/SysUserServiceImpl.java b/src/main/java/com/ruoyi/project/system/service/impl/SysUserServiceImpl.java index 65114a3..8a7c3e2 100644 --- a/src/main/java/com/ruoyi/project/system/service/impl/SysUserServiceImpl.java +++ b/src/main/java/com/ruoyi/project/system/service/impl/SysUserServiceImpl.java @@ -8,9 +8,10 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.ruoyi.common.constant.UserConstants; -import com.ruoyi.common.exception.CustomException; +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.project.system.domain.SysPost; import com.ruoyi.project.system.domain.SysRole; @@ -64,6 +65,32 @@ public List<SysUser> selectUserList(SysUser user) { return userMapper.selectUserList(user); + } + + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ宸插垎閰嶇敤鎴疯鑹插垪琛� + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 鐢ㄦ埛淇℃伅闆嗗悎淇℃伅 + */ + @Override + @DataScope(deptAlias = "d", userAlias = "u") + public List<SysUser> selectAllocatedList(SysUser user) + { + return userMapper.selectAllocatedList(user); + } + + /** + * 鏍规嵁鏉′欢鍒嗛〉鏌ヨ鏈垎閰嶇敤鎴疯鑹插垪琛� + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 鐢ㄦ埛淇℃伅闆嗗悎淇℃伅 + */ + @Override + @DataScope(deptAlias = "d", userAlias = "u") + public List<SysUser> selectUnallocatedList(SysUser user) + { + return userMapper.selectUnallocatedList(user); } /** @@ -197,7 +224,27 @@ { if (StringUtils.isNotNull(user.getUserId()) && user.isAdmin()) { - throw new CustomException("涓嶅厑璁告搷浣滆秴绾х鐞嗗憳鐢ㄦ埛"); + throw new ServiceException("涓嶅厑璁告搷浣滆秴绾х鐞嗗憳鐢ㄦ埛"); + } + } + + /** + * 鏍¢獙鐢ㄦ埛鏄惁鏈夋暟鎹潈闄� + * + * @param userId 鐢ㄦ埛id + */ + @Override + public void checkUserDataScope(Long userId) + { + if (!SysUser.isAdmin(SecurityUtils.getUserId())) + { + SysUser user = new SysUser(); + user.setUserId(userId); + List<SysUser> users = SpringUtils.getAopProxy(this).selectUserList(user); + if (StringUtils.isEmpty(users)) + { + throw new ServiceException("娌℃湁鏉冮檺璁块棶鐢ㄦ埛鏁版嵁锛�"); + } } } @@ -218,6 +265,18 @@ // 鏂板鐢ㄦ埛涓庤鑹茬鐞� insertUserRole(user); return rows; + } + + /** + * 娉ㄥ唽鐢ㄦ埛淇℃伅 + * + * @param user 鐢ㄦ埛淇℃伅 + * @return 缁撴灉 + */ + @Override + public boolean registerUser(SysUser user) + { + return userMapper.insertUser(user) > 0; } /** @@ -248,6 +307,8 @@ * @param userId 鐢ㄦ埛ID * @param roleIds 瑙掕壊缁� */ + @Override + @Transactional public void insertUserAuth(Long userId, Long[] roleIds) { userRoleMapper.deleteUserRoleByUserId(userId); @@ -445,7 +506,7 @@ { if (StringUtils.isNull(userList) || userList.size() == 0) { - throw new CustomException("瀵煎叆鐢ㄦ埛鏁版嵁涓嶈兘涓虹┖锛�"); + throw new ServiceException("瀵煎叆鐢ㄦ埛鏁版嵁涓嶈兘涓虹┖锛�"); } int successNum = 0; int failureNum = 0; @@ -490,7 +551,7 @@ if (failureNum > 0) { failureMsg.insert(0, "寰堟姳姝夛紝瀵煎叆澶辫触锛佸叡 " + failureNum + " 鏉℃暟鎹牸寮忎笉姝g‘锛岄敊璇涓嬶細"); - throw new CustomException(failureMsg.toString()); + throw new ServiceException(failureMsg.toString()); } else { -- Gitblit v1.9.3