Explorar el Código

角色分页添加数据权限

gao.qiang hace 2 años
padre
commit
b5aeac943d

+ 4 - 0
base-system/src/main/java/com/ozs/system/mapper/SysRoleMapper.java

@@ -3,6 +3,8 @@ package com.ozs.system.mapper;
 import java.util.List;
 
 import com.ozs.common.core.domain.entity.SysRole;
+import com.ozs.common.core.domain.entity.SysUser;
+import com.ozs.common.core.domain.vo.SysRoleRequestVo;
 import icu.mhb.mybatisplus.plugln.base.mapper.JoinBaseMapper;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -115,4 +117,6 @@ public interface SysRoleMapper extends JoinBaseMapper<SysRole> {
      * @return 结果
      */
     public int deleteRoleByIds(Long[] roleIds);
+
+    List<SysRole> selectSysRoleList(SysRoleRequestVo sysRoleRequestVo);
 }

+ 6 - 0
base-system/src/main/java/com/ozs/system/service/ISysRoleService.java

@@ -3,7 +3,11 @@ package com.ozs.system.service;
 import java.util.List;
 import java.util.Set;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.ozs.common.core.domain.entity.SysRole;
+import com.ozs.common.core.domain.entity.SysUser;
+import com.ozs.common.core.domain.vo.SysRoleRequestVo;
+import com.ozs.common.core.domain.vo.SysUserVo;
 import com.ozs.system.domain.SysUserRole;
 import icu.mhb.mybatisplus.plugln.base.service.JoinIService;
 
@@ -171,4 +175,6 @@ public interface ISysRoleService extends JoinIService<SysRole> {
      * @return 结果
      */
     public int insertAuthUsers(Long roleId, Long[] Ids);
+
+    IPage<SysRole> queryPage(SysRoleRequestVo sysRoleRequestVo);
 }

+ 16 - 0
base-system/src/main/java/com/ozs/system/service/impl/SysRoleServiceImpl.java

@@ -6,6 +6,9 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.github.pagehelper.PageHelper;
+import com.ozs.common.core.domain.vo.SysRoleRequestVo;
 import icu.mhb.mybatisplus.plugln.base.service.impl.JoinServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -383,4 +386,17 @@ public class SysRoleServiceImpl extends JoinServiceImpl<SysRoleMapper, SysRole>
         }
         return userRoleMapper.batchUserRole(list);
     }
+
+    @Override
+    public IPage<SysRole> queryPage(SysRoleRequestVo sysRoleRequestVo) {
+        int pageNum = Integer.parseInt(sysRoleRequestVo.getPageNum().toString());
+        int pageSize = Integer.parseInt(sysRoleRequestVo.getPageSize().toString());
+        com.github.pagehelper.Page<SysRole> page = PageHelper.startPage(pageNum, pageSize)
+                .doSelectPage(() -> roleMapper.selectSysRoleList(sysRoleRequestVo));
+        com.baomidou.mybatisplus.extension.plugins.pagination.Page<SysRole> pageR =
+                new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(pageNum, pageSize);
+        pageR.setRecords(page.getResult());
+        pageR.setTotal(page.getTotal());
+        return pageR;
+    }
 }

+ 36 - 0
base-system/src/main/resources/mapper/system/SysRoleMapper.xml

@@ -95,6 +95,42 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
 	<select id="getRoleId" resultType="java.lang.Long">
 		select role_id from sys_role where role_name = #{roleName}
 	</select>
+	<select id="selectSysRoleList" resultMap="SysRoleResult" parameterType="com.ozs.common.core.domain.vo.SysRoleRequestVo">
+		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
+	         join sys_user_role ur on ur.role_id = r.role_id
+	         join sys_user u on u.id = ur.user_id
+	         join sys_dept d on u.dept_id = d.dept_id
+		<where>
+			<if test="roleName != null and roleName != ''">
+				and r.role_name like concat('%', #{roleName}, '%')
+			</if>
+			<if test="roleId != null and roleId != 0">
+				and r.role_id like concat('%', #{roleId}, '%')
+			</if>
+			<if test="status != null and status != 0">
+				and r.status=#{status}
+			</if>
+			<if test="!dsFlay">
+				and (
+				<if test="dsUserId != null and dsUserId != ''">
+					r.create_by=#{dsUserId}  or
+				</if>
+				<if test="dsDeptId != null and dsDeptId != 0">
+					u.dept_id=#{dsDeptId}  or
+				</if>
+				<if test="dsDeptIds != null">
+					u.dept_id in
+					<foreach item="item" collection="dsDeptIds" separator="," open="(" close=")" index="">
+						#{item}
+					</foreach>
+				</if>
+				)
+			</if>
+			and r.del_flag = '1'
+		</where>     
+	</select>
 
 	<insert id="insertRole" parameterType="SysRole" useGeneratedKeys="true" keyProperty="roleId">
  		insert into sys_role(