update 简化查询角色功能

2.X
疯狂的狮子li 3 years ago
parent 04a5001fc8
commit fe43c94810

@ -26,6 +26,11 @@ public interface UserConstants {
*/
String USER_DISABLE = "1";
/**
*
*/
String ROLE_NORMAL = "0";
/**
*
*/

@ -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<SysRoleMapper, SysRole, Sy
@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

@ -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<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 @@ public class SysRoleServiceImpl implements ISysRoleService {
*/
@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;
}
/**

@ -39,47 +39,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
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">
<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
</select>
<select id="selectRoleList" resultMap="SysRoleResult">
<include refid="selectRoleVo"/>
${ew.getCustomSqlSegment}
</select>
<select id="selectRolePermissionByUserId" parameterType="Long" resultMap="SysRoleResult">
<include refid="selectRoleVo"/>

Loading…
Cancel
Save