From bb37b3401d811fcf787f1b606c0061d5ecdb06ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90Li?= <15040126243@163.com> Date: Tue, 26 Dec 2023 23:54:34 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E4=BC=98=E5=8C=96=20=E6=A1=86?= =?UTF-8?q?=E6=9E=B6=E6=95=B4=E4=BD=93=E6=8F=90=E9=AB=98=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/core/constant/CacheNames.java | 5 ++ .../system/SysClientController.java | 2 +- .../system/SysProfileController.java | 7 +- .../controller/system/SysUserController.java | 6 +- .../system/dubbo/RemoteUserServiceImpl.java | 33 +++++----- .../dromara/system/mapper/SysDeptMapper.java | 2 +- .../dromara/system/mapper/SysPostMapper.java | 12 +--- .../dromara/system/mapper/SysRoleMapper.java | 15 +---- .../dromara/system/mapper/SysUserMapper.java | 36 +--------- .../system/service/ISysClientService.java | 2 +- .../system/service/ISysRoleService.java | 9 +++ .../system/service/ISysUserService.java | 8 +-- .../service/impl/SysClientServiceImpl.java | 11 +++- .../service/impl/SysDeptServiceImpl.java | 6 +- .../impl/SysLogininforServiceImpl.java | 8 --- .../service/impl/SysNoticeServiceImpl.java | 5 +- .../service/impl/SysPostServiceImpl.java | 6 +- .../service/impl/SysRoleServiceImpl.java | 16 ++++- .../service/impl/SysUserServiceImpl.java | 27 ++++---- .../resources/mapper/system/SysDeptMapper.xml | 4 +- .../resources/mapper/system/SysPostMapper.xml | 12 +--- .../resources/mapper/system/SysRoleMapper.xml | 16 ++--- .../resources/mapper/system/SysUserMapper.xml | 65 +------------------ 23 files changed, 110 insertions(+), 203 deletions(-) diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/constant/CacheNames.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/constant/CacheNames.java index e59277aa..28ba1773 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/constant/CacheNames.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/constant/CacheNames.java @@ -35,6 +35,11 @@ public interface CacheNames { */ String SYS_TENANT = GlobalConstants.GLOBAL_REDIS_KEY + "sys_tenant#30d"; + /** + * 客户端 + */ + String SYS_CLIENT = GlobalConstants.GLOBAL_REDIS_KEY + "sys_client#30d"; + /** * 用户账户 */ diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysClientController.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysClientController.java index c8938e50..c22e2895 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysClientController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysClientController.java @@ -97,7 +97,7 @@ public class SysClientController extends BaseController { @Log(title = "客户端管理", businessType = BusinessType.UPDATE) @PutMapping("/changeStatus") public R changeStatus(@RequestBody SysClientBo bo) { - return toAjax(sysClientService.updateUserStatus(bo.getId(), bo.getStatus())); + return toAjax(sysClientService.updateUserStatus(bo.getClientId(), bo.getStatus())); } /** diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysProfileController.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysProfileController.java index 5e1a0e74..ddef6265 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysProfileController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysProfileController.java @@ -22,6 +22,7 @@ import org.dromara.system.domain.bo.SysUserProfileBo; import org.dromara.system.domain.vo.AvatarVo; import org.dromara.system.domain.vo.ProfileVo; import org.dromara.system.domain.vo.SysUserVo; +import org.dromara.system.service.ISysRoleService; import org.dromara.system.service.ISysUserService; import org.springframework.http.MediaType; import org.springframework.validation.annotation.Validated; @@ -43,6 +44,7 @@ import java.util.Arrays; public class SysProfileController extends BaseController { private final ISysUserService userService; + private final ISysRoleService roleService; @DubboReference private RemoteFileService remoteFileService; @@ -53,10 +55,11 @@ public class SysProfileController extends BaseController { @GetMapping public R profile() { SysUserVo user = userService.selectUserById(LoginHelper.getUserId()); + user.setRoles(roleService.selectRolesByUserId(user.getUserId())); ProfileVo profileVo = new ProfileVo(); profileVo.setUser(user); - profileVo.setRoleGroup(userService.selectUserRoleGroup(user.getUserName())); - profileVo.setPostGroup(userService.selectUserPostGroup(user.getUserName())); + profileVo.setRoleGroup(userService.selectUserRoleGroup(user.getUserId())); + profileVo.setPostGroup(userService.selectUserPostGroup(user.getUserId())); return R.ok(profileVo); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysUserController.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysUserController.java index 08dfaeaf..22b35e12 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysUserController.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/controller/system/SysUserController.java @@ -116,6 +116,7 @@ public class SysUserController extends BaseController { if (ObjectUtil.isNull(user)) { return R.fail("没有权限访问用户数据!"); } + user.setRoles(roleService.selectRolesByUserId(user.getUserId())); userInfoVo.setUser(user); userInfoVo.setPermissions(loginUser.getMenuPermission()); userInfoVo.setRoles(loginUser.getRolePermission()); @@ -142,7 +143,7 @@ public class SysUserController extends BaseController { if (ObjectUtil.isNotNull(userId)) { SysUserVo sysUser = userService.selectUserById(userId); userInfoVo.setUser(sysUser); - userInfoVo.setRoleIds(StreamUtils.toList(sysUser.getRoles(), SysRoleVo::getRoleId)); + userInfoVo.setRoleIds(roleService.selectRoleListByUserId(userId)); userInfoVo.setPostIds(postService.selectPostListByUserId(userId)); } return R.ok(userInfoVo); @@ -241,8 +242,9 @@ public class SysUserController extends BaseController { @SaCheckPermission("system:user:query") @GetMapping("/authRole/{userId}") public R authRole(@PathVariable Long userId) { + userService.checkUserDataScope(userId); SysUserVo user = userService.selectUserById(userId); - List roles = roleService.selectRolesByUserId(userId); + List roles = roleService.selectRolesAuthByUserId(userId); SysUserInfoVo userInfoVo = new SysUserInfoVo(); userInfoVo.setUser(user); userInfoVo.setRoles(LoginHelper.isSuperAdmin(userId) ? roles : StreamUtils.filter(roles, r -> !r.isSuperAdmin())); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteUserServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteUserServiceImpl.java index b3287f38..aa65ded4 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteUserServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/dubbo/RemoteUserServiceImpl.java @@ -19,10 +19,12 @@ import org.dromara.system.api.model.RoleDTO; import org.dromara.system.api.model.XcxLoginUser; import org.dromara.system.domain.SysUser; import org.dromara.system.domain.bo.SysUserBo; +import org.dromara.system.domain.vo.SysRoleVo; import org.dromara.system.domain.vo.SysUserVo; import org.dromara.system.mapper.SysUserMapper; import org.dromara.system.service.ISysConfigService; import org.dromara.system.service.ISysPermissionService; +import org.dromara.system.service.ISysRoleService; import org.dromara.system.service.ISysUserService; import org.springframework.stereotype.Service; @@ -41,14 +43,13 @@ public class RemoteUserServiceImpl implements RemoteUserService { private final ISysUserService userService; private final ISysPermissionService permissionService; private final ISysConfigService configService; + private final ISysRoleService roleService; private final SysUserMapper userMapper; @Override public LoginUser getUserInfo(String username, String tenantId) throws UserException { return TenantHelper.dynamic(tenantId, () -> { - SysUser sysUser = userMapper.selectOne(new LambdaQueryWrapper() - .select(SysUser::getUserName, SysUser::getStatus) - .eq(SysUser::getUserName, username)); + SysUserVo sysUser = userMapper.selectVoOne(new LambdaQueryWrapper().eq(SysUser::getUserName, username)); if (ObjectUtil.isNull(sysUser)) { throw new UserException("user.not.exists", username); } @@ -57,16 +58,14 @@ public class RemoteUserServiceImpl implements RemoteUserService { } // 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可 // 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了 - return buildLoginUser(userMapper.selectUserByUserName(username)); + return buildLoginUser(sysUser); }); } @Override public LoginUser getUserInfo(Long userId, String tenantId) throws UserException { return TenantHelper.dynamic(tenantId, () -> { - SysUser sysUser = userMapper.selectOne(new LambdaQueryWrapper() - .select(SysUser::getUserName, SysUser::getStatus) - .eq(SysUser::getUserId, userId)); + SysUserVo sysUser = userMapper.selectVoById(userId); if (ObjectUtil.isNull(sysUser)) { throw new UserException("user.not.exists", ""); } @@ -75,16 +74,14 @@ public class RemoteUserServiceImpl implements RemoteUserService { } // 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可 // 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了 - return buildLoginUser(userMapper.selectUserByUserName(sysUser.getUserName())); + return buildLoginUser(sysUser); }); } @Override public LoginUser getUserInfoByPhonenumber(String phonenumber, String tenantId) throws UserException { return TenantHelper.dynamic(tenantId, () -> { - SysUser sysUser = userMapper.selectOne(new LambdaQueryWrapper() - .select(SysUser::getPhonenumber, SysUser::getStatus) - .eq(SysUser::getPhonenumber, phonenumber)); + SysUserVo sysUser = userMapper.selectVoOne(new LambdaQueryWrapper().eq(SysUser::getPhonenumber, phonenumber)); if (ObjectUtil.isNull(sysUser)) { throw new UserException("user.not.exists", phonenumber); } @@ -93,16 +90,14 @@ public class RemoteUserServiceImpl implements RemoteUserService { } // 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可 // 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了 - return buildLoginUser(userMapper.selectUserByPhonenumber(phonenumber)); + return buildLoginUser(sysUser); }); } @Override public LoginUser getUserInfoByEmail(String email, String tenantId) throws UserException { return TenantHelper.dynamic(tenantId, () -> { - SysUser user = userMapper.selectOne(new LambdaQueryWrapper() - .select(SysUser::getEmail, SysUser::getStatus) - .eq(SysUser::getEmail, email)); + SysUserVo user = userMapper.selectVoOne(new LambdaQueryWrapper().eq(SysUser::getEmail, email)); if (ObjectUtil.isNull(user)) { throw new UserException("user.not.exists", email); } @@ -111,7 +106,7 @@ public class RemoteUserServiceImpl implements RemoteUserService { } // 框架登录不限制从什么表查询 只要最终构建出 LoginUser 即可 // 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了 - return buildLoginUser(userMapper.selectUserByEmail(email)); + return buildLoginUser(user); }); } @@ -179,8 +174,10 @@ public class RemoteUserServiceImpl implements RemoteUserService { loginUser.setMenuPermission(permissionService.getMenuPermission(userVo.getUserId())); loginUser.setRolePermission(permissionService.getRolePermission(userVo.getUserId())); loginUser.setDeptName(ObjectUtil.isNull(userVo.getDept()) ? "" : userVo.getDept().getDeptName()); - List roles = BeanUtil.copyToList(userVo.getRoles(), RoleDTO.class); - loginUser.setRoles(roles); + List roles = DataPermissionHelper.ignore(() -> { + return roleService.selectRolesByUserId(userVo.getUserId()); + }); + loginUser.setRoles(BeanUtil.copyToList(roles, RoleDTO.class)); return loginUser; } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysDeptMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysDeptMapper.java index 45ad77e9..08dda662 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysDeptMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysDeptMapper.java @@ -32,7 +32,7 @@ public interface SysDeptMapper extends BaseMapperPlus { @DataPermission({ @DataColumn(key = "deptName", value = "dept_id") }) - SysDeptVo selectDeptById(Long deptId); + long countDeptById(Long deptId); /** * 根据角色ID查询部门树信息 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysPostMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysPostMapper.java index 48e6a121..d6d27596 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysPostMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysPostMapper.java @@ -13,20 +13,12 @@ import java.util.List; */ public interface SysPostMapper extends BaseMapperPlus { - /** - * 根据用户ID获取岗位选择框列表 - * - * @param userId 用户ID - * @return 选中岗位ID列表 - */ - List selectPostListByUserId(Long userId); - /** * 查询用户所属岗位组 * - * @param userName 用户名 + * @param userId 用户ID * @return 结果 */ - List selectPostsByUserName(String userName); + List selectPostsByUserId(Long userId); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysRoleMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysRoleMapper.java index 55ca7697..ac5a47e5 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysRoleMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysRoleMapper.java @@ -3,12 +3,12 @@ package org.dromara.system.mapper; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.toolkit.Constants; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import org.apache.ibatis.annotations.Param; import org.dromara.common.mybatis.annotation.DataColumn; import org.dromara.common.mybatis.annotation.DataPermission; import org.dromara.common.mybatis.core.mapper.BaseMapperPlus; import org.dromara.system.domain.SysRole; import org.dromara.system.domain.vo.SysRoleVo; -import org.apache.ibatis.annotations.Param; import java.util.List; @@ -51,21 +51,12 @@ public interface SysRoleMapper extends BaseMapperPlus { */ List selectRolePermissionByUserId(Long userId); - - /** - * 根据用户ID获取角色选择框列表 - * - * @param userId 用户ID - * @return 选中角色ID列表 - */ - List selectRoleListByUserId(Long userId); - /** * 根据用户ID查询角色 * - * @param userName 用户名 + * @param userId 用户ID * @return 角色列表 */ - List selectRolesByUserName(String userName); + List selectRolesByUserId(Long userId); } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysUserMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysUserMapper.java index 43222253..d349832d 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysUserMapper.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/mapper/SysUserMapper.java @@ -61,41 +61,11 @@ public interface SysUserMapper extends BaseMapperPlus { }) Page selectUnallocatedList(@Param("page") Page page, @Param(Constants.WRAPPER) Wrapper queryWrapper); - /** - * 通过用户名查询用户 - * - * @param userName 用户名 - * @return 用户对象信息 - */ - SysUserVo selectUserByUserName(String userName); - - /** - * 通过手机号查询用户 - * - * @param phonenumber 手机号 - * @return 用户对象信息 - */ - SysUserVo selectUserByPhonenumber(String phonenumber); - - /** - * 通过邮箱查询用户 - * - * @param email 邮箱 - * @return 用户对象信息 - */ - SysUserVo selectUserByEmail(String email); - - /** - * 通过用户ID查询用户 - * - * @param userId 用户ID - * @return 用户对象信息 - */ @DataPermission({ - @DataColumn(key = "deptName", value = "d.dept_id"), - @DataColumn(key = "userName", value = "u.user_id") + @DataColumn(key = "deptName", value = "dept_id"), + @DataColumn(key = "userName", value = "user_id") }) - SysUserVo selectUserById(Long userId); + long countUserById(Long userId); @Override @DataPermission({ diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysClientService.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysClientService.java index 43828445..9ec478da 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysClientService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysClientService.java @@ -48,7 +48,7 @@ public interface ISysClientService { /** * 修改状态 */ - int updateUserStatus(Long id, String status); + int updateUserStatus(String clientId, String status); /** * 校验并批量删除客户端管理信息 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysRoleService.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysRoleService.java index d2ee61f8..f98a5673 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysRoleService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysRoleService.java @@ -35,6 +35,14 @@ public interface ISysRoleService { */ List selectRolesByUserId(Long userId); + /** + * 根据用户ID查询角色列表(包含被授权状态) + * + * @param userId 用户ID + * @return 角色列表 + */ + List selectRolesAuthByUserId(Long userId); + /** * 根据用户ID查询角色权限 * @@ -180,4 +188,5 @@ public interface ISysRoleService { int insertAuthUsers(Long roleId, Long[] userIds); void cleanOnlineUserByRole(Long roleId); + } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysUserService.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysUserService.java index 32ae8fca..7cd6502f 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysUserService.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/ISysUserService.java @@ -68,18 +68,18 @@ public interface ISysUserService { /** * 根据用户ID查询用户所属角色组 * - * @param userName 用户名 + * @param userId 用户ID * @return 结果 */ - String selectUserRoleGroup(String userName); + String selectUserRoleGroup(Long userId); /** * 根据用户ID查询用户所属岗位组 * - * @param userName 用户名 + * @param userId 用户ID * @return 结果 */ - String selectUserPostGroup(String userName); + String selectUserPostGroup(Long userId); /** * 校验用户名称是否唯一 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysClientServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysClientServiceImpl.java index 9ed56af3..1833e024 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysClientServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysClientServiceImpl.java @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.dromara.common.core.constant.CacheNames; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.page.PageQuery; @@ -16,6 +17,8 @@ import org.dromara.system.domain.bo.SysClientBo; import org.dromara.system.domain.vo.SysClientVo; import org.dromara.system.mapper.SysClientMapper; import org.dromara.system.service.ISysClientService; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import java.util.Collection; @@ -47,6 +50,7 @@ public class SysClientServiceImpl implements ISysClientService { /** * 查询客户端管理 */ + @Cacheable(cacheNames = CacheNames.SYS_CLIENT, key = "#clientId") @Override public SysClientVo queryByClientId(String clientId) { return baseMapper.selectVoOne(new LambdaQueryWrapper().eq(SysClient::getClientId, clientId)); @@ -104,6 +108,7 @@ public class SysClientServiceImpl implements ISysClientService { /** * 修改客户端管理 */ + @CacheEvict(cacheNames = CacheNames.SYS_CLIENT, key = "#bo.clientId") @Override public Boolean updateByBo(SysClientBo bo) { SysClient update = MapstructUtils.convert(bo, SysClient.class); @@ -115,12 +120,13 @@ public class SysClientServiceImpl implements ISysClientService { /** * 修改状态 */ + @CacheEvict(cacheNames = CacheNames.SYS_CLIENT, key = "#clientId") @Override - public int updateUserStatus(Long id, String status) { + public int updateUserStatus(String clientId, String status) { return baseMapper.update(null, new LambdaUpdateWrapper() .set(SysClient::getStatus, status) - .eq(SysClient::getId, id)); + .eq(SysClient::getClientId, clientId)); } /** @@ -133,6 +139,7 @@ public class SysClientServiceImpl implements ISysClientService { /** * 批量删除客户端管理 */ + @CacheEvict(cacheNames = CacheNames.SYS_CLIENT, allEntries = true) @Override public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) { if (isValid) { diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java index 44383a5b..9f75dc02 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysDeptServiceImpl.java @@ -42,7 +42,7 @@ import java.util.List; */ @RequiredArgsConstructor @Service -public class SysDeptServiceImpl implements ISysDeptService{ +public class SysDeptServiceImpl implements ISysDeptService { private final SysDeptMapper baseMapper; private final SysRoleMapper roleMapper; @@ -143,6 +143,7 @@ public class SysDeptServiceImpl implements ISysDeptService{ * @param deptIds 部门ID串逗号分隔 * @return 部门名称串逗号分隔 */ + @Override public String selectDeptNameByIds(String deptIds) { List list = new ArrayList<>(); for (Long id : StringUtils.splitTo(deptIds, Convert::toLong)) { @@ -219,8 +220,7 @@ public class SysDeptServiceImpl implements ISysDeptService{ if (LoginHelper.isSuperAdmin()) { return; } - SysDeptVo dept = baseMapper.selectDeptById(deptId); - if (ObjectUtil.isNull(dept)) { + if (baseMapper.countDeptById(deptId) == 0) { throw new ServiceException("没有权限访问部门数据!"); } } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysLogininforServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysLogininforServiceImpl.java index ebea956f..4ed39ee1 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysLogininforServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysLogininforServiceImpl.java @@ -32,14 +32,6 @@ public class SysLogininforServiceImpl implements ISysLogininforService { private final SysLogininforMapper baseMapper; - - private String getBlock(Object msg) { - if (msg == null) { - msg = ""; - } - return "[" + msg.toString() + "]"; - } - @Override public TableDataInfo selectPageLogininforList(SysLogininforBo logininfor, PageQuery pageQuery) { Map params = logininfor.getParams(); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysNoticeServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysNoticeServiceImpl.java index 87f0dd2f..18b7a08d 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysNoticeServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysNoticeServiceImpl.java @@ -4,18 +4,19 @@ import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import lombok.RequiredArgsConstructor; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.system.domain.SysNotice; +import org.dromara.system.domain.SysUser; import org.dromara.system.domain.bo.SysNoticeBo; import org.dromara.system.domain.vo.SysNoticeVo; import org.dromara.system.domain.vo.SysUserVo; import org.dromara.system.mapper.SysNoticeMapper; import org.dromara.system.mapper.SysUserMapper; import org.dromara.system.service.ISysNoticeService; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import java.util.Arrays; @@ -68,7 +69,7 @@ public class SysNoticeServiceImpl implements ISysNoticeService { lqw.like(StringUtils.isNotBlank(bo.getNoticeTitle()), SysNotice::getNoticeTitle, bo.getNoticeTitle()); lqw.eq(StringUtils.isNotBlank(bo.getNoticeType()), SysNotice::getNoticeType, bo.getNoticeType()); if (StringUtils.isNotBlank(bo.getCreateByName())) { - SysUserVo sysUser = userMapper.selectUserByUserName(bo.getCreateByName()); + SysUserVo sysUser = userMapper.selectVoOne(new LambdaQueryWrapper().eq(SysUser::getUserName, bo.getCreateByName())); lqw.eq(SysNotice::getCreateBy, ObjectUtil.isNotNull(sysUser) ? sysUser.getUserId() : null); } lqw.orderByAsc(SysNotice::getNoticeId); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysPostServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysPostServiceImpl.java index 1c65a489..9e2912dc 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysPostServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysPostServiceImpl.java @@ -5,9 +5,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import lombok.RequiredArgsConstructor; import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.MapstructUtils; +import org.dromara.common.core.utils.StreamUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.page.PageQuery; import org.dromara.common.mybatis.core.page.TableDataInfo; @@ -18,6 +18,7 @@ import org.dromara.system.domain.vo.SysPostVo; import org.dromara.system.mapper.SysPostMapper; import org.dromara.system.mapper.SysUserPostMapper; import org.dromara.system.service.ISysPostService; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import java.util.Arrays; @@ -92,7 +93,8 @@ public class SysPostServiceImpl implements ISysPostService { */ @Override public List selectPostListByUserId(Long userId) { - return baseMapper.selectPostListByUserId(userId); + List list = baseMapper.selectPostsByUserId(userId); + return StreamUtils.toList(list, SysPostVo::getPostId); } /** diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysRoleServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysRoleServiceImpl.java index ad1065d4..e54c65bc 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysRoleServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysRoleServiceImpl.java @@ -79,7 +79,7 @@ public class SysRoleServiceImpl implements ISysRoleService { .like(StringUtils.isNotBlank(bo.getRoleKey()), "r.role_key", bo.getRoleKey()) .between(params.get("beginTime") != null && params.get("endTime") != null, "r.create_time", params.get("beginTime"), params.get("endTime")) - .orderByAsc("r.role_sort").orderByAsc("r.create_time");; + .orderByAsc("r.role_sort").orderByAsc("r.create_time"); return wrapper; } @@ -91,6 +91,17 @@ public class SysRoleServiceImpl implements ISysRoleService { */ @Override public List selectRolesByUserId(Long userId) { + return baseMapper.selectRolesByUserId(userId); + } + + /** + * 根据用户ID查询角色列表(包含被授权状态) + * + * @param userId 用户ID + * @return 角色列表 + */ + @Override + public List selectRolesAuthByUserId(Long userId) { List userRoles = baseMapper.selectRolePermissionByUserId(userId); List roles = selectRoleAll(); for (SysRoleVo role : roles) { @@ -140,7 +151,8 @@ public class SysRoleServiceImpl implements ISysRoleService { */ @Override public List selectRoleListByUserId(Long userId) { - return baseMapper.selectRoleListByUserId(userId); + List list = baseMapper.selectRolesByUserId(userId); + return StreamUtils.toList(list, SysRoleVo::getRoleId); } /** diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysUserServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysUserServiceImpl.java index 4ffc5c2f..089f493d 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysUserServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysUserServiceImpl.java @@ -35,7 +35,6 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Arrays; import java.util.List; import java.util.Map; @@ -141,7 +140,7 @@ public class SysUserServiceImpl implements ISysUserService { */ @Override public SysUserVo selectUserByUserName(String userName) { - return baseMapper.selectUserByUserName(userName); + return baseMapper.selectVoOne(new LambdaQueryWrapper().eq(SysUser::getUserName, userName)); } /** @@ -152,7 +151,7 @@ public class SysUserServiceImpl implements ISysUserService { */ @Override public SysUserVo selectUserByPhonenumber(String phonenumber) { - return baseMapper.selectUserByPhonenumber(phonenumber); + return baseMapper.selectVoOne(new LambdaQueryWrapper().eq(SysUser::getPhonenumber, phonenumber)); } /** @@ -163,18 +162,18 @@ public class SysUserServiceImpl implements ISysUserService { */ @Override public SysUserVo selectUserById(Long userId) { - return baseMapper.selectUserById(userId); + return baseMapper.selectVoById(userId); } /** * 查询用户所属角色组 * - * @param userName 用户名 + * @param userId 用户ID * @return 结果 */ @Override - public String selectUserRoleGroup(String userName) { - List list = roleMapper.selectRolesByUserName(userName); + public String selectUserRoleGroup(Long userId) { + List list = roleMapper.selectRolesByUserId(userId); if (CollUtil.isEmpty(list)) { return StringUtils.EMPTY; } @@ -184,12 +183,12 @@ public class SysUserServiceImpl implements ISysUserService { /** * 查询用户所属岗位组 * - * @param userName 用户名 + * @param userId 用户ID * @return 结果 */ @Override - public String selectUserPostGroup(String userName) { - List list = postMapper.selectPostsByUserName(userName); + public String selectUserPostGroup(Long userId) { + List list = postMapper.selectPostsByUserId(userId); if (CollUtil.isEmpty(list)) { return StringUtils.EMPTY; } @@ -261,7 +260,7 @@ public class SysUserServiceImpl implements ISysUserService { if (LoginHelper.isSuperAdmin()) { return; } - if (ObjectUtil.isNull(baseMapper.selectUserById(userId))) { + if (baseMapper.countUserById(userId) == 0) { throw new ServiceException("没有权限访问用户数据!"); } } @@ -421,7 +420,7 @@ public class SysUserServiceImpl implements ISysUserService { userPostMapper.delete(new LambdaQueryWrapper().eq(SysUserPost::getUserId, user.getUserId())); } // 新增用户与岗位管理 - List list = StreamUtils.toList(Arrays.asList(posts), postId -> { + List list = StreamUtils.toList(List.of(posts), postId -> { SysUserPost up = new SysUserPost(); up.setUserId(user.getUserId()); up.setPostId(postId); @@ -449,7 +448,7 @@ public class SysUserServiceImpl implements ISysUserService { if (!LoginHelper.isSuperAdmin(userId)) { roleList.remove(UserConstants.SUPER_ADMIN_ID); } - List canDoRoleList = StreamUtils.filter(Arrays.asList(roleIds), roleList::contains); + List canDoRoleList = StreamUtils.filter(List.of(roleIds), roleList::contains); if (CollUtil.isEmpty(canDoRoleList)) { throw new ServiceException("没有权限访问角色的数据"); } @@ -502,7 +501,7 @@ public class SysUserServiceImpl implements ISysUserService { checkUserAllowed(userId); checkUserDataScope(userId); } - List ids = Arrays.asList(userIds); + List ids = List.of(userIds); // 删除用户与角色关联 userRoleMapper.delete(new LambdaQueryWrapper().in(SysUserRole::getUserId, ids)); // 删除用户与岗位表 diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml index bba949d7..55c9b37c 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml @@ -11,8 +11,8 @@ select * from sys_dept ${ew.getCustomSqlSegment} - + select count(*) from sys_dept where del_flag = '0' and dept_id = #{deptId} - select p.post_id - from sys_post p - left join sys_user_post up on up.post_id = p.post_id - left join sys_user u on u.user_id = up.user_id - where u.user_id = #{userId} - - - select p.post_id, p.post_name, p.post_code from sys_post p left join sys_user_post up on up.post_id = p.post_id left join sys_user u on u.user_id = up.user_id - where u.user_name = #{userName} + where u.user_id = #{userId} diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml index b1916985..7b8bba76 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml @@ -40,23 +40,17 @@ WHERE r.del_flag = '0' and sur.user_id = #{userId} - - - select r.role_id, r.role_name, r.role_key, - r.role_sort + r.role_sort, + r.data_scope, + r.status from sys_role r left join sys_user_role sur on sur.role_id = r.role_id left join sys_user u on u.user_id = sur.user_id - WHERE r.del_flag = '0' and u.user_name = #{userName} + WHERE r.del_flag = '0' and sur.user_id = #{userId} select u.user_id, u.dept_id, u.nick_name, u.user_name, u.email, u.avatar, u.phonenumber, u.sex, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.remark, @@ -101,24 +56,8 @@ ${ew.getCustomSqlSegment} - - - - - - - + select count(*) from sys_user where del_flag = '0' and user_id = #{userId}