ruoyi-common/src/main/java/com/ruoyi/common/constant/UserConstants.java
@@ -28,6 +28,11 @@ String USER_DISABLE = "1"; /** * 角色正常状态 */ String ROLE_NORMAL = "0"; /** * 角色封禁状态 */ String ROLE_DISABLE = "1"; ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMapper.java
@@ -1,5 +1,7 @@ package com.ruoyi.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 com.ruoyi.common.annotation.DataColumn; import com.ruoyi.common.annotation.DataPermission; @@ -19,18 +21,18 @@ @DataPermission({ @DataColumn(key = "deptName", value = "d.dept_id") }) Page<SysRole> selectPageRoleList(@Param("page") Page<SysRole> page, @Param("role") SysRole role); Page<SysRole> selectPageRoleList(@Param("page") Page<SysRole> page, @Param(Constants.WRAPPER) Wrapper<SysRole> queryWrapper); /** * 根据条件分页查询角色数据 * * @param role 角色信息 * @param queryWrapper 查询条件 * @return 角色数据集合信息 */ @DataPermission({ @DataColumn(key = "deptName", value = "d.dept_id") }) List<SysRole> selectRoleList(SysRole role); List<SysRole> selectRoleList(@Param(Constants.WRAPPER) Wrapper<SysRole> queryWrapper); /** * 根据用户ID查询角色 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java
@@ -2,7 +2,11 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.constant.UserConstants; import com.ruoyi.common.core.domain.PageQuery; @@ -40,7 +44,7 @@ @Override public TableDataInfo<SysRole> selectPageRoleList(SysRole role, PageQuery pageQuery) { Page<SysRole> page = baseMapper.selectPageRoleList(pageQuery.build(), role); Page<SysRole> page = baseMapper.selectPageRoleList(pageQuery.build(), this.buildQueryWrapper(role)); return TableDataInfo.build(page); } @@ -52,7 +56,21 @@ */ @Override public List<SysRole> selectRoleList(SysRole role) { return baseMapper.selectRoleList(role); return baseMapper.selectRoleList(this.buildQueryWrapper(role)); } private Wrapper<SysRole> buildQueryWrapper(SysRole role) { Map<String, Object> params = role.getParams(); QueryWrapper<SysRole> wrapper = Wrappers.query(); wrapper.eq("r.del_flag", UserConstants.ROLE_NORMAL) .eq(ObjectUtil.isNotNull(role.getRoleId()), "r.role_id", role.getRoleId()) .like(StringUtils.isNotBlank(role.getRoleName()), "r.role_name", role.getRoleName()) .eq(StringUtils.isNotBlank(role.getStatus()), "r.status", role.getStatus()) .like(StringUtils.isNotBlank(role.getRoleKey()), "r.role_key", role.getRoleKey()) .between(params.get("beginTime") != null && params.get("endTime") != null, "r.create_time", params.get("beginTime"), params.get("endTime")) .orderByAsc("r.role_sort"); return wrapper; } /** ruoyi-system/src/main/resources/mapper/system/SysRoleMapper.xml
@@ -39,46 +39,14 @@ left join sys_dept d on u.dept_id = d.dept_id </sql> <select id="selectPageRoleList" parameterType="SysRole" resultMap="SysRoleResult"> <select id="selectPageRoleList" resultMap="SysRoleResult"> <include refid="selectRoleVo"/> where r.del_flag = '0' <if test="role.roleId != null and role.roleId != 0"> AND r.role_id = #{role.roleId} </if> <if test="role.roleName != null and role.roleName != ''"> AND r.role_name like concat('%', #{role.roleName}, '%') </if> <if test="role.status != null and role.status != ''"> AND r.status = #{role.status} </if> <if test="role.roleKey != null and role.roleKey != ''"> AND r.role_key like concat('%', #{role.roleKey}, '%') </if> <if test="role.params.beginTime != null and role.params.endTime != null"> AND r.create_time between #{role.params.beginTime} and #{role.params.endTime} </if> order by r.role_sort ${ew.getCustomSqlSegment} </select> <select id="selectRoleList" parameterType="SysRole" resultMap="SysRoleResult"> <select id="selectRoleList" resultMap="SysRoleResult"> <include refid="selectRoleVo"/> where r.del_flag = '0' <if test="roleId != null and roleId != 0"> AND r.role_id = #{roleId} </if> <if test="roleName != null and roleName != ''"> AND r.role_name like concat('%', #{roleName}, '%') </if> <if test="status != null and status != ''"> AND r.status = #{status} </if> <if test="roleKey != null and roleKey != ''"> AND r.role_key like concat('%', #{roleKey}, '%') </if> <if test="params.beginTime != null and params.endTime != null"> AND r.create_time between #{params.beginTime} and #{params.endTime} </if> order by r.role_sort ${ew.getCustomSqlSegment} </select> <select id="selectRolePermissionByUserId" parameterType="Long" resultMap="SysRoleResult">