SysRoleMapper.xml 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. <result property="tenantId" column="tenant_id" />
  22. <result property="tenantName" column="tenant_name" />
  23. </resultMap>
  24. <sql id="selectRoleVo">
  25. 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,
  26. r.status, r.del_flag, r.create_time, r.remark ,t.tenant_id,t.tenant_name
  27. from sys_role r
  28. left join sys_user_role ur on ur.role_id = r.role_id
  29. left join sys_user u on u.user_id = ur.user_id
  30. left join sys_dept d on u.dept_id = d.dept_id
  31. LEFT JOIN sys_tenant t ON r.tenant_id = t.tenant_id
  32. </sql>
  33. <select id="selectRoleList" parameterType="SysRole" resultMap="SysRoleResult">
  34. <include refid="selectRoleVo"/>
  35. where r.del_flag = '0'
  36. <if test="roleId != null and roleId != 0">
  37. AND r.role_id = #{roleId}
  38. </if>
  39. <if test="roleName != null and roleName != ''">
  40. AND r.role_name like concat('%', #{roleName}, '%')
  41. </if>
  42. <if test="status != null and status != ''">
  43. AND r.status = #{status}
  44. </if>
  45. <if test="roleKey != null and roleKey != ''">
  46. AND r.role_key like concat('%', #{roleKey}, '%')
  47. </if>
  48. <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
  49. and date_format(r.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
  50. </if>
  51. <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
  52. and date_format(r.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
  53. </if>
  54. <if test="tenantId != null and tenantId != 0">
  55. AND r.tenant_id = #{tenantId}
  56. </if>
  57. <!-- 数据范围过滤 -->
  58. ${params.dataScope}
  59. order by r.role_sort
  60. </select>
  61. <select id="selectRolePermissionByUserId" parameterType="Long" resultMap="SysRoleResult">
  62. <include refid="selectRoleVo"/>
  63. WHERE r.del_flag = '0' and ur.user_id = #{userId}
  64. </select>
  65. <select id="selectRoleAll" resultMap="SysRoleResult">
  66. <include refid="selectRoleVo"/>
  67. </select>
  68. <select id="selectRoleListByUserId" parameterType="Long" resultType="Long">
  69. select r.role_id
  70. from sys_role r
  71. left join sys_user_role ur on ur.role_id = r.role_id
  72. left join sys_user u on u.user_id = ur.user_id
  73. where u.user_id = #{userId}
  74. </select>
  75. <select id="selectRoleById" parameterType="Long" resultMap="SysRoleResult">
  76. <include refid="selectRoleVo"/>
  77. where r.role_id = #{roleId}
  78. </select>
  79. <select id="selectRolesByUserName" parameterType="String" resultMap="SysRoleResult">
  80. <include refid="selectRoleVo"/>
  81. WHERE r.del_flag = '0' and u.user_name = #{userName}
  82. </select>
  83. <select id="checkRoleNameUnique" parameterType="String" resultMap="SysRoleResult">
  84. <include refid="selectRoleVo"/>
  85. where r.role_name=#{roleName} and r.del_flag = '0' and r.tenant_id = #{tenantId} limit 1
  86. </select>
  87. <select id="checkRoleKeyUnique" parameterType="String" resultMap="SysRoleResult">
  88. <include refid="selectRoleVo"/>
  89. where r.role_key=#{roleKey} and r.del_flag = '0' and r.tenant_id = #{tenantId} limit 1
  90. </select>
  91. <insert id="insertRole" parameterType="SysRole" useGeneratedKeys="true" keyProperty="roleId">
  92. insert into sys_role(
  93. <if test="roleId != null and roleId != 0">role_id,</if>
  94. <if test="roleName != null and roleName != ''">role_name,</if>
  95. <if test="roleKey != null and roleKey != ''">role_key,</if>
  96. <if test="roleSort != null">role_sort,</if>
  97. <if test="dataScope != null and dataScope != ''">data_scope,</if>
  98. <if test="menuCheckStrictly != null">menu_check_strictly,</if>
  99. <if test="deptCheckStrictly != null">dept_check_strictly,</if>
  100. <if test="status != null and status != ''">status,</if>
  101. <if test="remark != null and remark != ''">remark,</if>
  102. <if test="tenantId != null and tenantId != 0">tenant_id,</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">#{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="tenantId != null and tenantId != 0">#{tenantId},</if>
  116. <if test="createBy != null and createBy != ''">#{createBy},</if>
  117. sysdate()
  118. )
  119. </insert>
  120. <update id="updateRole" parameterType="SysRole">
  121. update sys_role
  122. <set>
  123. <if test="roleName != null and roleName != ''">role_name = #{roleName},</if>
  124. <if test="roleKey != null and roleKey != ''">role_key = #{roleKey},</if>
  125. <if test="roleSort != null">role_sort = #{roleSort},</if>
  126. <if test="dataScope != null and dataScope != ''">data_scope = #{dataScope},</if>
  127. <if test="menuCheckStrictly != null">menu_check_strictly = #{menuCheckStrictly},</if>
  128. <if test="deptCheckStrictly != null">dept_check_strictly = #{deptCheckStrictly},</if>
  129. <if test="status != null and status != ''">status = #{status},</if>
  130. <if test="remark != null">remark = #{remark},</if>
  131. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  132. update_time = sysdate()
  133. </set>
  134. where role_id = #{roleId}
  135. </update>
  136. <delete id="deleteRoleById" parameterType="Long">
  137. update sys_role set del_flag = '2' where role_id = #{roleId}
  138. </delete>
  139. <delete id="deleteRoleByIds" parameterType="Long">
  140. update sys_role set del_flag = '2' where role_id in
  141. <foreach collection="array" item="roleId" open="(" separator="," close=")">
  142. #{roleId}
  143. </foreach>
  144. </delete>
  145. </mapper>