SysRoleMapper.xml 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.ruoyi.system.mapper.SysRoleMapper">
  6. <resultMap type="SysRole" id="SysRoleResult">
  7. <id property="roleId" column="role_id"/>
  8. <result property="roleName" column="role_name"/>
  9. <result property="roleKey" column="role_key"/>
  10. <result property="roleSort" column="role_sort"/>
  11. <result property="dataScope" column="data_scope"/>
  12. <result property="menuCheckStrictly" column="menu_check_strictly"/>
  13. <result property="deptCheckStrictly" column="dept_check_strictly"/>
  14. <result property="status" column="status"/>
  15. <result property="delFlag" column="del_flag"/>
  16. <result property="createBy" column="create_by"/>
  17. <result property="createTime" column="create_time"/>
  18. <result property="updateBy" column="update_by"/>
  19. <result property="updateTime" column="update_time"/>
  20. <result property="remark" column="remark"/>
  21. </resultMap>
  22. <sql id="selectRoleVo">
  23. 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,
  24. r.status, r.del_flag, r.create_time, r.remark
  25. from sys_role r
  26. left join sys_user_role ur on ur.role_id = r.role_id
  27. left join sys_user u on u.user_id = ur.user_id
  28. left join sys_dept d on u.dept_id = d.dept_id
  29. </sql>
  30. <select id="selectRoleList" parameterType="SysRole" resultMap="SysRoleResult">
  31. <include refid="selectRoleVo"/>
  32. where r.del_flag = '0'
  33. <if test="roleName != null and roleName != ''">
  34. AND r.role_name like concat('%', #{roleName}, '%')
  35. </if>
  36. <if test="status != null and status != ''">
  37. AND r.status = #{status}
  38. </if>
  39. <if test="roleKey != null and roleKey != ''">
  40. AND r.role_key like concat('%', #{roleKey}, '%')
  41. </if>
  42. <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
  43. and date_format(r.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
  44. </if>
  45. <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
  46. and date_format(r.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
  47. </if>
  48. <!-- 数据范围过滤 -->
  49. ${params.dataScope}
  50. order by r.role_sort
  51. </select>
  52. <select id="auditGetRolelist" parameterType="SysRole" resultType="Map">
  53. select
  54. role_id AS userId,
  55. role_name AS actualname
  56. from
  57. sys_role
  58. where
  59. status = '0'
  60. AND del_flag = '0'
  61. </select>
  62. <select id="selectRolePermissionByUserId" parameterType="Long" resultMap="SysRoleResult">
  63. <include refid="selectRoleVo"/>
  64. WHERE r.del_flag = '0' and ur.user_id = #{userId}
  65. </select>
  66. <select id="selectRoleAll" resultMap="SysRoleResult">
  67. <include refid="selectRoleVo"/>
  68. </select>
  69. <select id="selectRoleListByUserId" parameterType="Long" resultType="Integer">
  70. select r.role_id
  71. from sys_role r
  72. left join sys_user_role ur on ur.role_id = r.role_id
  73. left join sys_user u on u.user_id = ur.user_id
  74. where u.user_id = #{userId}
  75. </select>
  76. <select id="selectRoleById" parameterType="Long" resultMap="SysRoleResult">
  77. <include refid="selectRoleVo"/>
  78. where r.role_id = #{roleId}
  79. </select>
  80. <select id="selectRolesByUserName" parameterType="String" resultMap="SysRoleResult">
  81. <include refid="selectRoleVo"/>
  82. WHERE r.del_flag = '0' and u.user_name = #{userName}
  83. </select>
  84. <select id="checkRoleNameUnique" parameterType="String" resultMap="SysRoleResult">
  85. <include refid="selectRoleVo"/>
  86. where r.role_name=#{roleName} limit 1
  87. </select>
  88. <select id="checkRoleKeyUnique" parameterType="String" resultMap="SysRoleResult">
  89. <include refid="selectRoleVo"/>
  90. where r.role_key=#{roleKey} limit 1
  91. </select>
  92. <insert id="insertRole" parameterType="SysRole" useGeneratedKeys="true" keyProperty="roleId">
  93. insert into sys_role(
  94. <if test="roleId != null and roleId != 0">role_id,</if>
  95. <if test="roleName != null and roleName != ''">role_name,</if>
  96. <if test="roleKey != null and roleKey != ''">role_key,</if>
  97. <if test="roleSort != null and roleSort != ''">role_sort,</if>
  98. <if test="dataScope != null and dataScope != ''">data_scope,</if>
  99. <if test="menuCheckStrictly != null">menu_check_strictly,</if>
  100. <if test="deptCheckStrictly != null">dept_check_strictly,</if>
  101. <if test="status != null and status != ''">status,</if>
  102. <if test="remark != null and remark != ''">remark,</if>
  103. <if test="createBy != null and createBy != ''">create_by,</if>
  104. create_time
  105. )values(
  106. <if test="roleId != null and roleId != 0">#{roleId},</if>
  107. <if test="roleName != null and roleName != ''">#{roleName},</if>
  108. <if test="roleKey != null and roleKey != ''">#{roleKey},</if>
  109. <if test="roleSort != null and roleSort != ''">#{roleSort},</if>
  110. <if test="dataScope != null and dataScope != ''">#{dataScope},</if>
  111. <if test="menuCheckStrictly != null">#{menuCheckStrictly},</if>
  112. <if test="deptCheckStrictly != null">#{deptCheckStrictly},</if>
  113. <if test="status != null and status != ''">#{status},</if>
  114. <if test="remark != null and remark != ''">#{remark},</if>
  115. <if test="createBy != null and createBy != ''">#{createBy},</if>
  116. sysdate()
  117. )
  118. </insert>
  119. <update id="updateRole" parameterType="SysRole">
  120. update sys_role
  121. <set>
  122. <if test="roleName != null and roleName != ''">role_name = #{roleName},</if>
  123. <if test="roleKey != null and roleKey != ''">role_key = #{roleKey},</if>
  124. <if test="roleSort != null and roleSort != ''">role_sort = #{roleSort},</if>
  125. <if test="dataScope != null and dataScope != ''">data_scope = #{dataScope},</if>
  126. <if test="menuCheckStrictly != null">menu_check_strictly = #{menuCheckStrictly},</if>
  127. <if test="deptCheckStrictly != null">dept_check_strictly = #{deptCheckStrictly},</if>
  128. <if test="status != null and status != ''">status = #{status},</if>
  129. <if test="remark != null">remark = #{remark},</if>
  130. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  131. update_time = sysdate()
  132. </set>
  133. where role_id = #{roleId}
  134. </update>
  135. <update id="updateRoleStatus" parameterType="SysRole">
  136. update sys_user set status = #{status} where user_id = #{userId}
  137. </update>
  138. <delete id="deleteRoleById" parameterType="Long">
  139. delete from sys_role where role_id = #{roleId}
  140. </delete>
  141. <delete id="deleteRoleByIds" parameterType="Long">
  142. update sys_role set del_flag = '2' where role_id in
  143. <foreach collection="array" item="roleId" open="(" separator="," close=")">
  144. #{roleId}
  145. </foreach>
  146. </delete>
  147. </mapper>