From 0684f00957631dcbc1be8f5964006a17c84533a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A3=B7=E5=8F=B6?= <14103883+leaf-phos@user.noreply.gitee.com> Date: Thu, 2 Jan 2025 17:33:51 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=AF=BC=E5=85=A5debug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/common/utils/SecurityUtils.java | 24 +++-- .../web/service/SysPermissionService.java | 21 +++-- .../system/role/domain/SysRoleQuery.java | 17 ++++ .../ruoyi/system/role/domain/SysRoleVO.java | 12 +++ .../{ => role}/mapper/SysRoleMapper.java | 35 +++---- .../system/role/mapper}/SysRoleMapper.xml | 71 +++++++------- .../{ => role}/service/ISysRoleService.java | 64 +++++++------ .../service/impl/SysRoleServiceImpl.java | 94 ++++++++++--------- .../service/impl/SysDeptServiceImpl.java | 20 ++-- .../service/impl/SysMenuServiceImpl.java | 71 +++++++------- .../service/impl/SysUserServiceImpl.java | 80 +++++++++------- .../ruoyi/system/user/domain/SysUserVO.java | 4 + .../ruoyi/web/system/SysRoleController.java | 38 ++++---- .../ruoyi/web/system/SysUserController.java | 52 +++++----- 14 files changed, 334 insertions(+), 269 deletions(-) create mode 100644 common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/role/domain/SysRoleQuery.java create mode 100644 common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/role/domain/SysRoleVO.java rename common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/{ => role}/mapper/SysRoleMapper.java (87%) rename common-ruoyi/ruoyi-system/src/main/{resources/mapper/system => java/com/ruoyi/system/role/mapper}/SysRoleMapper.xml (79%) rename common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/{ => role}/service/ISysRoleService.java (84%) rename common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/{ => role}/service/impl/SysRoleServiceImpl.java (89%) diff --git a/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/utils/SecurityUtils.java b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/utils/SecurityUtils.java index eb1313a..f256568 100644 --- a/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/utils/SecurityUtils.java +++ b/common-ruoyi/ruoyi-common/src/main/java/com/ruoyi/common/utils/SecurityUtils.java @@ -1,17 +1,19 @@ package com.ruoyi.common.utils; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.util.PatternMatchUtils; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.constant.HttpStatus; import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.exception.ServiceException; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContext; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.util.PatternMatchUtils; + +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; /** * 安全服务工具类 @@ -172,4 +174,12 @@ public class SecurityUtils .anyMatch(x -> Constants.SUPER_ADMIN.equals(x) || PatternMatchUtils.simpleMatch(x, role)); } + /** + * 设置当前Security上下文 + */ + public static void setAuthentication(Authentication auth) { + SecurityContext context = SecurityContextHolder.createEmptyContext(); + context.setAuthentication(auth); + SecurityContextHolder.setContext(context); + } } diff --git a/common-ruoyi/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPermissionService.java b/common-ruoyi/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPermissionService.java index 51c4dd9..7f6e8f9 100644 --- a/common-ruoyi/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPermissionService.java +++ b/common-ruoyi/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysPermissionService.java @@ -1,21 +1,22 @@ package com.ruoyi.framework.web.service; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -import org.springframework.util.CollectionUtils; import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.system.role.service.ISysRoleService; import com.ruoyi.system.service.ISysMenuService; -import com.ruoyi.system.service.ISysRoleService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.springframework.util.CollectionUtils; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; /** * 用户权限处理 - * + * * @author ruoyi */ @Component @@ -29,7 +30,7 @@ public class SysPermissionService /** * 获取角色数据权限 - * + * * @param user 用户信息 * @return 角色权限信息 */ @@ -50,7 +51,7 @@ public class SysPermissionService /** * 获取菜单数据权限 - * + * * @param user 用户信息 * @return 菜单权限信息 */ diff --git a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/role/domain/SysRoleQuery.java b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/role/domain/SysRoleQuery.java new file mode 100644 index 0000000..8ce777d --- /dev/null +++ b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/role/domain/SysRoleQuery.java @@ -0,0 +1,17 @@ +package com.ruoyi.system.role.domain; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.util.List; + +/** + * @author wjh + * 2025/1/2 + */ +@Data +public class SysRoleQuery extends SysRoleVO { + + @ApiModelProperty("名称列表") + private List names; +} diff --git a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/role/domain/SysRoleVO.java b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/role/domain/SysRoleVO.java new file mode 100644 index 0000000..dd34c0d --- /dev/null +++ b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/role/domain/SysRoleVO.java @@ -0,0 +1,12 @@ +package com.ruoyi.system.role.domain; + +import com.ruoyi.common.core.domain.entity.SysRole; +import lombok.Data; + +/** + * @author wjh + * 2025/1/2 + */ +@Data +public class SysRoleVO extends SysRole { +} diff --git a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMapper.java b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/role/mapper/SysRoleMapper.java similarity index 87% rename from common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMapper.java rename to common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/role/mapper/SysRoleMapper.java index cf2bd8c..412ff40 100644 --- a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMapper.java +++ b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/role/mapper/SysRoleMapper.java @@ -1,26 +1,29 @@ -package com.ruoyi.system.mapper; +package com.ruoyi.system.role.mapper; + +import com.ruoyi.common.core.domain.entity.SysRole; +import com.ruoyi.system.role.domain.SysRoleQuery; +import com.ruoyi.system.role.domain.SysRoleVO; import java.util.List; -import com.ruoyi.common.core.domain.entity.SysRole; /** * 角色表 数据层 - * + * * @author ruoyi */ public interface SysRoleMapper { /** * 根据条件分页查询角色数据 - * + * * @param role 角色信息 * @return 角色数据集合信息 */ - public List selectRoleList(SysRole role); + public List selectRoleList(SysRoleQuery role); /** * 根据用户ID查询角色 - * + * * @param userId 用户ID * @return 角色列表 */ @@ -28,14 +31,14 @@ public interface SysRoleMapper /** * 查询所有角色 - * + * * @return 角色列表 */ public List selectRoleAll(); /** * 根据用户ID获取角色选择框列表 - * + * * @param userId 用户ID * @return 选中角色ID列表 */ @@ -43,7 +46,7 @@ public interface SysRoleMapper /** * 通过角色ID查询角色 - * + * * @param roleId 角色ID * @return 角色对象信息 */ @@ -51,7 +54,7 @@ public interface SysRoleMapper /** * 根据用户ID查询角色 - * + * * @param userName 用户名 * @return 角色列表 */ @@ -59,7 +62,7 @@ public interface SysRoleMapper /** * 校验角色名称是否唯一 - * + * * @param roleName 角色名称 * @return 角色信息 */ @@ -67,7 +70,7 @@ public interface SysRoleMapper /** * 校验角色权限是否唯一 - * + * * @param roleKey 角色权限 * @return 角色信息 */ @@ -75,7 +78,7 @@ public interface SysRoleMapper /** * 修改角色信息 - * + * * @param role 角色信息 * @return 结果 */ @@ -83,7 +86,7 @@ public interface SysRoleMapper /** * 新增角色信息 - * + * * @param role 角色信息 * @return 结果 */ @@ -91,7 +94,7 @@ public interface SysRoleMapper /** * 通过角色ID删除角色 - * + * * @param roleId 角色ID * @return 结果 */ @@ -99,7 +102,7 @@ public interface SysRoleMapper /** * 批量删除角色信息 - * + * * @param roleIds 需要删除的角色ID * @return 结果 */ diff --git a/common-ruoyi/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/role/mapper/SysRoleMapper.xml similarity index 79% rename from common-ruoyi/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml rename to common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/role/mapper/SysRoleMapper.xml index 955d4ee..af7689a 100644 --- a/common-ruoyi/ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml +++ b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/role/mapper/SysRoleMapper.xml @@ -2,34 +2,29 @@ - + + + - - - - - - - - - - - - - - - - - - select distinct r.role_id, r.role_name, r.role_key, r.role_sort, r.data_scope, r.menu_check_strictly, r.dept_check_strictly, - r.status, r.del_flag, r.create_time, r.remark + select distinct + r.role_id, + r.role_name, + r.role_key, + r.role_sort, + r.data_scope, + r.menu_check_strictly, + r.dept_check_strictly, + r.status, + r.del_flag, + r.create_time, + r.remark from sys_role r left join sys_user_role ur on ur.role_id = r.role_id left join sys_user u on u.user_id = ur.user_id left join sys_dept d on u.dept_id = d.dept_id - + - + - + - + - + - + - + - + - + insert into sys_role( role_id, @@ -120,7 +121,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" sysdate() ) - + update sys_role @@ -137,16 +138,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where role_id = #{roleId} - + update sys_role set del_flag = '2' where role_id = #{roleId} - + update sys_role set del_flag = '2' where role_id in #{roleId} - + - - \ No newline at end of file + + diff --git a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleService.java b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/role/service/ISysRoleService.java similarity index 84% rename from common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleService.java rename to common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/role/service/ISysRoleService.java index 9185cce..e7ba41d 100644 --- a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysRoleService.java +++ b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/role/service/ISysRoleService.java @@ -1,36 +1,39 @@ -package com.ruoyi.system.service; +package com.ruoyi.system.role.service; + +import com.ruoyi.common.core.domain.entity.SysRole; +import com.ruoyi.system.domain.SysUserRole; +import com.ruoyi.system.role.domain.SysRoleQuery; +import com.ruoyi.system.role.domain.SysRoleVO; import java.util.List; import java.util.Set; -import com.ruoyi.common.core.domain.entity.SysRole; -import com.ruoyi.system.domain.SysUserRole; /** * 角色业务层 - * + * * @author ruoyi */ public interface ISysRoleService { /** * 根据条件分页查询角色数据 - * - * @param role 角色信息 + * + * @param query 角色信息 * @return 角色数据集合信息 */ - public List selectRoleList(SysRole role); + public List selectRoleList(SysRoleQuery query); /** * 根据用户ID查询角色列表 - * + * * @param userId 用户ID * @return 角色列表 */ - public List selectRolesByUserId(Long userId); + public List selectRolesByUserId(Long userId); /** * 根据用户ID查询角色权限 - * + * * @param userId 用户ID * @return 权限列表 */ @@ -38,14 +41,14 @@ public interface ISysRoleService /** * 查询所有角色 - * + * * @return 角色列表 */ - public List selectRoleAll(); + public List selectRoleAll(); /** * 根据用户ID获取角色选择框列表 - * + * * @param userId 用户ID * @return 选中角色ID列表 */ @@ -53,7 +56,7 @@ public interface ISysRoleService /** * 通过角色ID查询角色 - * + * * @param roleId 角色ID * @return 角色对象信息 */ @@ -61,7 +64,7 @@ public interface ISysRoleService /** * 校验角色名称是否唯一 - * + * * @param role 角色信息 * @return 结果 */ @@ -69,7 +72,7 @@ public interface ISysRoleService /** * 校验角色权限是否唯一 - * + * * @param role 角色信息 * @return 结果 */ @@ -77,21 +80,21 @@ public interface ISysRoleService /** * 校验角色是否允许操作 - * + * * @param role 角色信息 */ public void checkRoleAllowed(SysRole role); /** * 校验角色是否有数据权限 - * + * * @param roleIds 角色id */ public void checkRoleDataScope(Long... roleIds); /** * 通过角色ID查询角色使用数量 - * + * * @param roleId 角色ID * @return 结果 */ @@ -99,7 +102,7 @@ public interface ISysRoleService /** * 新增保存角色信息 - * + * * @param role 角色信息 * @return 结果 */ @@ -107,7 +110,7 @@ public interface ISysRoleService /** * 修改保存角色信息 - * + * * @param role 角色信息 * @return 结果 */ @@ -115,7 +118,7 @@ public interface ISysRoleService /** * 修改角色状态 - * + * * @param role 角色信息 * @return 结果 */ @@ -123,7 +126,7 @@ public interface ISysRoleService /** * 修改数据权限信息 - * + * * @param role 角色信息 * @return 结果 */ @@ -131,7 +134,7 @@ public interface ISysRoleService /** * 通过角色ID删除角色 - * + * * @param roleId 角色ID * @return 结果 */ @@ -139,7 +142,7 @@ public interface ISysRoleService /** * 批量删除角色信息 - * + * * @param roleIds 需要删除的角色ID * @return 结果 */ @@ -147,7 +150,7 @@ public interface ISysRoleService /** * 取消授权用户角色 - * + * * @param userRole 用户和角色关联信息 * @return 结果 */ @@ -155,7 +158,7 @@ public interface ISysRoleService /** * 批量取消授权用户角色 - * + * * @param roleId 角色ID * @param userIds 需要取消授权的用户数据ID * @return 结果 @@ -164,10 +167,15 @@ public interface ISysRoleService /** * 批量选择授权用户角色 - * + * * @param roleId 角色ID * @param userIds 需要删除的用户数据ID * @return 结果 */ public int insertAuthUsers(Long roleId, Long[] userIds); + + /** + * 根据名称查询角色列表 + */ + List selectListByNames(List names); } diff --git a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/role/service/impl/SysRoleServiceImpl.java similarity index 89% rename from common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java rename to common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/role/service/impl/SysRoleServiceImpl.java index e432bb1..1fb79b8 100644 --- a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java +++ b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/role/service/impl/SysRoleServiceImpl.java @@ -1,13 +1,5 @@ -package com.ruoyi.system.service.impl; +package com.ruoyi.system.role.service.impl; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; import com.ruoyi.common.annotation.DataScope; import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.domain.entity.SysRole; @@ -15,19 +7,27 @@ import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.exception.ServiceException; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.collection.CollectionUtils; import com.ruoyi.common.utils.spring.SpringUtils; import com.ruoyi.system.domain.SysRoleDept; import com.ruoyi.system.domain.SysRoleMenu; import com.ruoyi.system.domain.SysUserRole; import com.ruoyi.system.mapper.SysRoleDeptMapper; -import com.ruoyi.system.mapper.SysRoleMapper; import com.ruoyi.system.mapper.SysRoleMenuMapper; import com.ruoyi.system.mapper.SysUserRoleMapper; -import com.ruoyi.system.service.ISysRoleService; +import com.ruoyi.system.role.domain.SysRoleQuery; +import com.ruoyi.system.role.domain.SysRoleVO; +import com.ruoyi.system.role.mapper.SysRoleMapper; +import com.ruoyi.system.role.service.ISysRoleService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.*; /** * 角色 业务层处理 - * + * * @author ruoyi */ @Service @@ -47,28 +47,28 @@ public class SysRoleServiceImpl implements ISysRoleService /** * 根据条件分页查询角色数据 - * - * @param role 角色信息 + * + * @param query 角色信息 * @return 角色数据集合信息 */ @Override @DataScope(deptAlias = "d") - public List selectRoleList(SysRole role) + public List selectRoleList(SysRoleQuery query) { - return roleMapper.selectRoleList(role); + return roleMapper.selectRoleList(query); } /** * 根据用户ID查询角色 - * + * * @param userId 用户ID * @return 角色列表 */ @Override - public List selectRolesByUserId(Long userId) + public List selectRolesByUserId(Long userId) { List userRoles = roleMapper.selectRolePermissionByUserId(userId); - List roles = selectRoleAll(); + List roles = selectRoleAll(); for (SysRole role : roles) { for (SysRole userRole : userRoles) @@ -85,7 +85,7 @@ public class SysRoleServiceImpl implements ISysRoleService /** * 根据用户ID查询权限 - * + * * @param userId 用户ID * @return 权限列表 */ @@ -106,18 +106,18 @@ public class SysRoleServiceImpl implements ISysRoleService /** * 查询所有角色 - * + * * @return 角色列表 */ @Override - public List selectRoleAll() + public List selectRoleAll() { - return SpringUtils.getAopProxy(this).selectRoleList(new SysRole()); + return SpringUtils.getAopProxy(this).selectRoleList(new SysRoleQuery()); } /** * 根据用户ID获取角色选择框列表 - * + * * @param userId 用户ID * @return 选中角色ID列表 */ @@ -129,7 +129,7 @@ public class SysRoleServiceImpl implements ISysRoleService /** * 通过角色ID查询角色 - * + * * @param roleId 角色ID * @return 角色对象信息 */ @@ -141,7 +141,7 @@ public class SysRoleServiceImpl implements ISysRoleService /** * 校验角色名称是否唯一 - * + * * @param role 角色信息 * @return 结果 */ @@ -159,7 +159,7 @@ public class SysRoleServiceImpl implements ISysRoleService /** * 校验角色权限是否唯一 - * + * * @param role 角色信息 * @return 结果 */ @@ -177,7 +177,7 @@ public class SysRoleServiceImpl implements ISysRoleService /** * 校验角色是否允许操作 - * + * * @param role 角色信息 */ @Override @@ -191,7 +191,7 @@ public class SysRoleServiceImpl implements ISysRoleService /** * 校验角色是否有数据权限 - * + * * @param roleIds 角色id */ @Override @@ -201,9 +201,9 @@ public class SysRoleServiceImpl implements ISysRoleService { for (Long roleId : roleIds) { - SysRole role = new SysRole(); + SysRoleQuery role = new SysRoleQuery(); role.setRoleId(roleId); - List roles = SpringUtils.getAopProxy(this).selectRoleList(role); + List roles = SpringUtils.getAopProxy(this).selectRoleList(role); if (StringUtils.isEmpty(roles)) { throw new ServiceException("没有权限访问角色数据!"); @@ -214,7 +214,7 @@ public class SysRoleServiceImpl implements ISysRoleService /** * 通过角色ID查询角色使用数量 - * + * * @param roleId 角色ID * @return 结果 */ @@ -226,7 +226,7 @@ public class SysRoleServiceImpl implements ISysRoleService /** * 新增保存角色信息 - * + * * @param role 角色信息 * @return 结果 */ @@ -241,7 +241,7 @@ public class SysRoleServiceImpl implements ISysRoleService /** * 修改保存角色信息 - * + * * @param role 角色信息 * @return 结果 */ @@ -258,7 +258,7 @@ public class SysRoleServiceImpl implements ISysRoleService /** * 修改角色状态 - * + * * @param role 角色信息 * @return 结果 */ @@ -270,7 +270,7 @@ public class SysRoleServiceImpl implements ISysRoleService /** * 修改数据权限信息 - * + * * @param role 角色信息 * @return 结果 */ @@ -288,7 +288,7 @@ public class SysRoleServiceImpl implements ISysRoleService /** * 新增角色菜单信息 - * + * * @param role 角色对象 */ public int insertRoleMenu(SysRole role) @@ -336,7 +336,7 @@ public class SysRoleServiceImpl implements ISysRoleService /** * 通过角色ID删除角色 - * + * * @param roleId 角色ID * @return 结果 */ @@ -353,7 +353,7 @@ public class SysRoleServiceImpl implements ISysRoleService /** * 批量删除角色信息 - * + * * @param roleIds 需要删除的角色ID * @return 结果 */ @@ -380,7 +380,7 @@ public class SysRoleServiceImpl implements ISysRoleService /** * 取消授权用户角色 - * + * * @param userRole 用户和角色关联信息 * @return 结果 */ @@ -392,7 +392,7 @@ public class SysRoleServiceImpl implements ISysRoleService /** * 批量取消授权用户角色 - * + * * @param roleId 角色ID * @param userIds 需要取消授权的用户数据ID * @return 结果 @@ -405,7 +405,7 @@ public class SysRoleServiceImpl implements ISysRoleService /** * 批量选择授权用户角色 - * + * * @param roleId 角色ID * @param userIds 需要授权的用户数据ID * @return 结果 @@ -424,4 +424,14 @@ public class SysRoleServiceImpl implements ISysRoleService } return userRoleMapper.batchUserRole(list); } + + @Override + public List selectListByNames(List names) { + if (CollectionUtils.isEmptyElement(names)) { + return Collections.emptyList(); + } + SysRoleQuery query = new SysRoleQuery(); + query.setNames(names); + return selectRoleList(query); + } } diff --git a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java index 96647fb..0f1ef03 100644 --- a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java +++ b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysDeptServiceImpl.java @@ -1,15 +1,6 @@ package com.ruoyi.system.service.impl; -import java.util.*; -import java.util.stream.Collectors; - import com.alibaba.fastjson2.JSONObject; -import com.ruoyi.common.k3cloud.constants.K3FormIds; -import com.ruoyi.common.k3cloud.service.K3Service; -import com.ruoyi.common.utils.collection.CollectionUtils; -import com.ruoyi.system.domain.dto.SysDeptQuery; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; import com.ruoyi.common.annotation.DataScope; import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.domain.TreeSelect; @@ -18,12 +9,21 @@ import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.text.Convert; import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.k3cloud.constants.K3FormIds; +import com.ruoyi.common.k3cloud.service.K3Service; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.collection.CollectionUtils; import com.ruoyi.common.utils.spring.SpringUtils; +import com.ruoyi.system.domain.dto.SysDeptQuery; import com.ruoyi.system.mapper.SysDeptMapper; -import com.ruoyi.system.mapper.SysRoleMapper; +import com.ruoyi.system.role.mapper.SysRoleMapper; import com.ruoyi.system.service.ISysDeptService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.*; +import java.util.stream.Collectors; /** * 部门管理 服务实现 diff --git a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java index 78a7830..e77c0ff 100644 --- a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java +++ b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java @@ -1,15 +1,5 @@ package com.ruoyi.system.service.impl; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.domain.TreeSelect; @@ -21,13 +11,18 @@ import com.ruoyi.common.utils.StringUtils; import com.ruoyi.system.domain.vo.MetaVo; import com.ruoyi.system.domain.vo.RouterVo; import com.ruoyi.system.mapper.SysMenuMapper; -import com.ruoyi.system.mapper.SysRoleMapper; import com.ruoyi.system.mapper.SysRoleMenuMapper; +import com.ruoyi.system.role.mapper.SysRoleMapper; import com.ruoyi.system.service.ISysMenuService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.*; +import java.util.stream.Collectors; /** * 菜单 业务层处理 - * + * * @author ruoyi */ @Service @@ -46,7 +41,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 根据用户查询系统菜单列表 - * + * * @param userId 用户ID * @return 菜单列表 */ @@ -58,7 +53,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 查询系统菜单列表 - * + * * @param menu 菜单信息 * @return 菜单列表 */ @@ -81,7 +76,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 根据用户ID查询权限 - * + * * @param userId 用户ID * @return 权限列表 */ @@ -102,7 +97,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 根据角色ID查询权限 - * + * * @param roleId 角色ID * @return 权限列表 */ @@ -123,7 +118,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 根据用户ID查询菜单 - * + * * @param userId 用户名称 * @return 菜单列表 */ @@ -144,7 +139,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 根据角色ID查询菜单树信息 - * + * * @param roleId 角色ID * @return 选中菜单列表 */ @@ -157,7 +152,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 构建前端路由所需要的菜单 - * + * * @param menus 菜单列表 * @return 路由列表 */ @@ -215,7 +210,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 构建前端所需要树结构 - * + * * @param menus 菜单列表 * @return 树结构列表 */ @@ -243,7 +238,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 构建前端所需要下拉树结构 - * + * * @param menus 菜单列表 * @return 下拉树结构列表 */ @@ -256,7 +251,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 根据菜单ID查询信息 - * + * * @param menuId 菜单ID * @return 菜单信息 */ @@ -268,7 +263,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 是否存在菜单子节点 - * + * * @param menuId 菜单ID * @return 结果 */ @@ -281,7 +276,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 查询菜单使用数量 - * + * * @param menuId 菜单ID * @return 结果 */ @@ -294,7 +289,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 新增保存菜单信息 - * + * * @param menu 菜单信息 * @return 结果 */ @@ -306,7 +301,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 修改保存菜单信息 - * + * * @param menu 菜单信息 * @return 结果 */ @@ -318,7 +313,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 删除菜单管理信息 - * + * * @param menuId 菜单ID * @return 结果 */ @@ -330,7 +325,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 校验菜单名称是否唯一 - * + * * @param menu 菜单信息 * @return 结果 */ @@ -348,7 +343,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 获取路由名称 - * + * * @param menu 菜单信息 * @return 路由名称 */ @@ -364,7 +359,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 获取路由名称,如没有配置路由名称则取路由地址 - * + * * @param routerName 路由名称 * @param path 路由地址 * @return 路由名称(驼峰格式) @@ -377,7 +372,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 获取路由地址 - * + * * @param menu 菜单信息 * @return 路由地址 */ @@ -405,7 +400,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 获取组件信息 - * + * * @param menu 菜单信息 * @return 组件信息 */ @@ -429,7 +424,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 是否为菜单内部跳转 - * + * * @param menu 菜单信息 * @return 结果 */ @@ -441,7 +436,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 是否为内链组件 - * + * * @param menu 菜单信息 * @return 结果 */ @@ -452,7 +447,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 是否为parent_view组件 - * + * * @param menu 菜单信息 * @return 结果 */ @@ -463,7 +458,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 根据父节点的ID获取所有子节点 - * + * * @param list 分类表 * @param parentId 传入的父节点ID * @return String @@ -486,7 +481,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 递归列表 - * + * * @param list 分类表 * @param t 子节点 */ @@ -532,7 +527,7 @@ public class SysMenuServiceImpl implements ISysMenuService /** * 内链域名特殊字符替换 - * + * * @return 替换后的内链域名 */ public String innerLinkReplaceEach(String path) diff --git a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java index 779c279..02efbf1 100644 --- a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java +++ b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysUserServiceImpl.java @@ -1,24 +1,36 @@ package com.ruoyi.system.service.impl; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; -import javax.validation.Validator; - import com.github.pagehelper.PageHelper; +import com.ruoyi.common.annotation.DataScope; import com.ruoyi.common.auth.wx.WxAuthService; +import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.domain.entity.SysDept; +import com.ruoyi.common.core.domain.entity.SysRole; +import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.validate.ValidGroup; +import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.ServiceUtil; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.bean.BeanValidators; import com.ruoyi.common.utils.collection.CollectionUtils; +import com.ruoyi.common.utils.spring.SpringUtils; +import com.ruoyi.system.domain.SysPost; +import com.ruoyi.system.domain.SysUserPost; +import com.ruoyi.system.domain.SysUserRole; +import com.ruoyi.system.mapper.SysPostMapper; +import com.ruoyi.system.mapper.SysUserPostMapper; +import com.ruoyi.system.mapper.SysUserRoleMapper; +import com.ruoyi.system.role.domain.SysRoleVO; +import com.ruoyi.system.role.mapper.SysRoleMapper; +import com.ruoyi.system.role.service.ISysRoleService; +import com.ruoyi.system.service.ISysConfigService; +import com.ruoyi.system.service.ISysDeptService; +import com.ruoyi.system.service.ISysUserService; import com.ruoyi.system.user.domain.SysUserQuery; import com.ruoyi.system.user.domain.SysUserShiftQuery; import com.ruoyi.system.user.domain.SysUserVO; -import com.ruoyi.system.service.ISysRoleService; +import com.ruoyi.system.user.mapper.SysUserMapper; import com.ruoyi.system.user.service.UserValidator; import com.ruoyi.yh.logImport.domain.LogImportVO; import com.ruoyi.yh.logImport.domain.enums.LogImportBizType; @@ -29,30 +41,20 @@ import com.ruoyi.yh.logImportDetail.service.ILogImportDetailService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.Authentication; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import com.ruoyi.common.annotation.DataScope; -import com.ruoyi.common.constant.UserConstants; -import com.ruoyi.common.core.domain.entity.SysRole; -import com.ruoyi.common.core.domain.entity.SysUser; -import com.ruoyi.common.exception.ServiceException; -import com.ruoyi.common.utils.SecurityUtils; -import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.common.utils.bean.BeanValidators; -import com.ruoyi.common.utils.spring.SpringUtils; -import com.ruoyi.system.domain.SysPost; -import com.ruoyi.system.domain.SysUserPost; -import com.ruoyi.system.domain.SysUserRole; -import com.ruoyi.system.mapper.SysPostMapper; -import com.ruoyi.system.mapper.SysRoleMapper; -import com.ruoyi.system.user.mapper.SysUserMapper; -import com.ruoyi.system.mapper.SysUserPostMapper; -import com.ruoyi.system.mapper.SysUserRoleMapper; -import com.ruoyi.system.service.ISysConfigService; -import com.ruoyi.system.service.ISysDeptService; -import com.ruoyi.system.service.ISysUserService; import org.springframework.transaction.support.TransactionTemplate; +import javax.validation.Validator; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + /** * 用户 业务层处理 * @@ -558,12 +560,20 @@ public class SysUserServiceImpl implements ISysUserService LogImportVO importLog = logImportService.addDefaultLog(LogImportType.IMPORT, LogImportBizType.PRICE, operator); ServiceUtil.assertion(importLog == null, "创建导入日志失败"); + // 获取Security上下文 + Authentication auth = SecurityUtils.getAuthentication(); + // 开始异步导入 scheduledExecutorService.schedule(() -> { + // 设置当前Security上下文 + SecurityUtils.setAuthentication(auth); // 查询部门列表 List deptList = deptService.selectDeptListByNames(CollectionUtils.map(userList, SysUserVO::getDeptName)); SysDept defaultDept = new SysDept(); + // 查询角色列表 + List roleList = roleService.selectListByNames(CollectionUtils.map(userList, SysUserVO::getRoleName)); + SysRoleVO defaultRole = new SysRoleVO(); for (SysUserVO user : userList) { try { @@ -571,7 +581,13 @@ public class SysUserServiceImpl implements ISysUserService SysUser old = this.selectUserByUserNo(user.getUserNo()); transactionTemplate.execute(status -> { + // 关联部门 user.setDeptId(deptList.stream().filter(d -> Objects.equals(d.getDeptName(), user.getDeptName())).findFirst().orElse(defaultDept).getDeptId()); + // 关联角色 + Long roleId = roleList.stream().filter(r -> Objects.equals(r.getRoleName(), user.getRoleName())).findFirst().orElse(defaultRole).getRoleId(); + if (roleId != null) { + user.setRoleIds(new Long[]{roleId}); + } if (StringUtils.isNull(old)) { BeanValidators.validateWithException(validator, ValidGroup.Create.class); @@ -579,7 +595,7 @@ public class SysUserServiceImpl implements ISysUserService String password = configService.selectConfigByKey("sys.user.initPassword"); user.setPassword(SecurityUtils.encryptPassword(password)); user.setCreateBy(operator.getNickName()); - int insert = userMapper.insertUser(user); + int insert = this.insertUser(user); ServiceUtil.assertion(insert != 1, "新增用户失败"); logImportDetailService.addResult(importLog.getLogId(), LogImportDetailType.ADD, user, null, user.getUserId()); return insert; @@ -589,7 +605,7 @@ public class SysUserServiceImpl implements ISysUserService checkUserAllowed(old); user.setUserId(old.getUserId()); user.setUpdateBy(operator.getNickName()); - int update = userMapper.updateUser(user); + int update = this.updateUser(user); ServiceUtil.assertion(update != 1, "修改用户失败"); logImportDetailService.addResult(importLog.getLogId(), LogImportDetailType.UPDATE, user, null, user.getUserId()); return update; diff --git a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/user/domain/SysUserVO.java b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/user/domain/SysUserVO.java index 0a8b2f8..15522a7 100644 --- a/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/user/domain/SysUserVO.java +++ b/common-ruoyi/ruoyi-system/src/main/java/com/ruoyi/system/user/domain/SysUserVO.java @@ -18,4 +18,8 @@ public class SysUserVO extends SysUser { @Excel(name = "部门名称", type = Excel.Type.IMPORT) private String deptName; + @ApiModelProperty("角色名称") + @Excel(name = "角色名称", type = Excel.Type.IMPORT) + private String roleName; + } diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/system/SysRoleController.java b/ruoyi-web/src/main/java/com/ruoyi/web/system/SysRoleController.java index 1d89170..9bf2138 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/web/system/SysRoleController.java +++ b/ruoyi-web/src/main/java/com/ruoyi/web/system/SysRoleController.java @@ -1,24 +1,8 @@ package com.ruoyi.web.system; -import java.util.List; -import javax.servlet.http.HttpServletResponse; - -import com.ruoyi.system.domain.dto.SysDeptQuery; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; -import com.ruoyi.common.core.domain.entity.SysDept; import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginUser; @@ -29,9 +13,19 @@ import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.framework.web.service.SysPermissionService; import com.ruoyi.framework.web.service.TokenService; import com.ruoyi.system.domain.SysUserRole; +import com.ruoyi.system.domain.dto.SysDeptQuery; +import com.ruoyi.system.role.domain.SysRoleQuery; +import com.ruoyi.system.role.domain.SysRoleVO; +import com.ruoyi.system.role.service.ISysRoleService; import com.ruoyi.system.service.ISysDeptService; -import com.ruoyi.system.service.ISysRoleService; import com.ruoyi.system.service.ISysUserService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; /** * 角色信息 @@ -59,20 +53,20 @@ public class SysRoleController extends BaseController @PreAuthorize("@ss.hasPermi('system:role:list')") @GetMapping("/list") - public TableDataInfo list(SysRole role) + public TableDataInfo list(SysRoleQuery role) { startPage(); - List list = roleService.selectRoleList(role); + List list = roleService.selectRoleList(role); return getDataTable(list); } @Log(title = "角色管理", businessType = BusinessType.EXPORT) @PreAuthorize("@ss.hasPermi('system:role:export')") @PostMapping("/export") - public void export(HttpServletResponse response, SysRole role) + public void export(HttpServletResponse response, SysRoleQuery role) { - List list = roleService.selectRoleList(role); - ExcelUtil util = new ExcelUtil(SysRole.class); + List list = roleService.selectRoleList(role); + ExcelUtil util = new ExcelUtil(SysRoleVO.class); util.exportExcel(response, list, "角色数据"); } diff --git a/ruoyi-web/src/main/java/com/ruoyi/web/system/SysUserController.java b/ruoyi-web/src/main/java/com/ruoyi/web/system/SysUserController.java index 445080f..4e078a8 100644 --- a/ruoyi-web/src/main/java/com/ruoyi/web/system/SysUserController.java +++ b/ruoyi-web/src/main/java/com/ruoyi/web/system/SysUserController.java @@ -1,12 +1,23 @@ package com.ruoyi.web.system; -import java.util.List; -import java.util.stream.Collectors; -import javax.servlet.http.HttpServletResponse; - import com.ruoyi.common.annotation.DataScope; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.core.domain.entity.SysRole; +import com.ruoyi.common.core.domain.entity.SysUser; +import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.validate.ValidGroup; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.common.utils.SecurityUtils; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.system.domain.dto.SysDeptQuery; +import com.ruoyi.system.role.domain.SysRoleVO; +import com.ruoyi.system.role.service.ISysRoleService; +import com.ruoyi.system.service.ISysDeptService; +import com.ruoyi.system.service.ISysPostService; +import com.ruoyi.system.service.ISysUserService; import com.ruoyi.system.user.domain.SysUserQuery; import com.ruoyi.system.user.domain.SysUserShiftQuery; import com.ruoyi.system.user.domain.SysUserVO; @@ -14,29 +25,12 @@ import org.apache.commons.lang3.ArrayUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import com.ruoyi.common.annotation.Log; -import com.ruoyi.common.core.controller.BaseController; -import com.ruoyi.common.core.domain.AjaxResult; -import com.ruoyi.common.core.domain.entity.SysRole; -import com.ruoyi.common.core.domain.entity.SysUser; -import com.ruoyi.common.core.page.TableDataInfo; -import com.ruoyi.common.enums.BusinessType; -import com.ruoyi.common.utils.SecurityUtils; -import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.common.utils.poi.ExcelUtil; -import com.ruoyi.system.service.ISysDeptService; -import com.ruoyi.system.service.ISysPostService; -import com.ruoyi.system.service.ISysRoleService; -import com.ruoyi.system.service.ISysUserService; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; +import java.util.stream.Collectors; /** * 用户信息 @@ -119,7 +113,7 @@ public class SysUserController extends BaseController @PostMapping("/importTemplate") public void importTemplate(HttpServletResponse response) { - ExcelUtil util = new ExcelUtil(SysUser.class); + ExcelUtil util = new ExcelUtil(SysUserVO.class); util.importTemplateExcel(response, "用户数据"); } @@ -132,7 +126,7 @@ public class SysUserController extends BaseController { userService.checkUserDataScope(userId); AjaxResult ajax = AjaxResult.success(); - List roles = roleService.selectRoleAll(); + List roles = roleService.selectRoleAll(); ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); ajax.put("posts", postService.selectPostAll()); if (StringUtils.isNotNull(userId)) @@ -220,7 +214,7 @@ public class SysUserController extends BaseController { AjaxResult ajax = AjaxResult.success(); SysUser user = userService.selectUserById(userId); - List roles = roleService.selectRolesByUserId(userId); + List roles = roleService.selectRolesByUserId(userId); ajax.put("user", user); ajax.put("roles", SysUser.isAdmin(userId) ? roles : roles.stream().filter(r -> !r.isAdmin()).collect(Collectors.toList())); return ajax;