diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/UserConstants.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/UserConstants.java index 61be17c8..14245b2b 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/UserConstants.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/UserConstants.java @@ -26,6 +26,11 @@ public interface UserConstants { */ String USER_DISABLE = "1"; + /** + * 角色正常状态 + */ + String ROLE_NORMAL = "0"; + /** * 角色封禁状态 */ diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMapper.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMapper.java index 07abc11c..732e94b5 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysRoleMapper.java +++ b/ruoyi-modules/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.mybatis.annotation.DataColumn; import com.ruoyi.common.mybatis.annotation.DataPermission; @@ -19,18 +21,18 @@ public interface SysRoleMapper extends BaseMapperPlus selectPageRoleList(@Param("page") Page page, @Param("role") SysRole role); + Page selectPageRoleList(@Param("page") Page page, @Param(Constants.WRAPPER) Wrapper queryWrapper); /** * 根据条件分页查询角色数据 * - * @param role 角色信息 + * @param queryWrapper 查询条件 * @return 角色数据集合信息 */ @DataPermission({ @DataColumn(key = "deptName", value = "d.dept_id") }) - List selectRoleList(SysRole role); + List selectRoleList(@Param(Constants.WRAPPER) Wrapper queryWrapper); /** * 根据用户ID查询角色 diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java index e2242814..f7636f69 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysRoleServiceImpl.java @@ -2,7 +2,11 @@ package com.ruoyi.system.service.impl; 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.core.constant.UserConstants; import com.ruoyi.common.core.exception.ServiceException; @@ -40,7 +44,7 @@ public class SysRoleServiceImpl implements ISysRoleService { @Override public TableDataInfo selectPageRoleList(SysRole role, PageQuery pageQuery) { - Page page = baseMapper.selectPageRoleList(pageQuery.build(), role); + Page page = baseMapper.selectPageRoleList(pageQuery.build(), this.buildQueryWrapper(role)); return TableDataInfo.build(page); } @@ -52,7 +56,21 @@ public class SysRoleServiceImpl implements ISysRoleService { */ @Override public List selectRoleList(SysRole role) { - return baseMapper.selectRoleList(role); + return baseMapper.selectRoleList(this.buildQueryWrapper(role)); + } + + private Wrapper buildQueryWrapper(SysRole role) { + Map params = role.getParams(); + QueryWrapper 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; } /** 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 0dc16b3c..2d5ec7bf 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 @@ -39,47 +39,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" left join sys_dept d on u.dept_id = d.dept_id - - where r.del_flag = '0' - - AND r.role_id = #{role.roleId} - - - AND r.role_name like concat('%', #{role.roleName}, '%') - - - AND r.status = #{role.status} - - - AND r.role_key like concat('%', #{role.roleKey}, '%') - - - AND r.create_time between #{role.params.beginTime} and #{role.params.endTime} - - order by r.role_sort + ${ew.getCustomSqlSegment} - +