SysRoleMapper.xml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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.zkqy.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. <if test="tenantId == null">
  58. and r.tenant_id is null
  59. </if>
  60. <if test="tenantName != null and tenantName != ''">
  61. and t.tenant_name like concat('%', #{tenantName}, '%')
  62. </if>
  63. <!-- 数据范围过滤 -->
  64. ${params.dataScope}
  65. order by r.role_sort
  66. </select>
  67. <select id="selectRolePermissionByUserId" parameterType="Long" resultMap="SysRoleResult">
  68. <include refid="selectRoleVo"/>
  69. WHERE r.del_flag = '0' and ur.user_id = #{userId}
  70. </select>
  71. <select id="selectRoleAll" resultMap="SysRoleResult">
  72. <include refid="selectRoleVo"/>
  73. </select>
  74. <select id="selectRoleListByUserId" parameterType="Long" resultType="Long">
  75. select r.role_id
  76. from sys_role r
  77. left join sys_user_role ur on ur.role_id = r.role_id
  78. left join sys_user u on u.user_id = ur.user_id
  79. where u.user_id = #{userId}
  80. </select>
  81. <select id="selectRoleById" parameterType="Long" resultMap="SysRoleResult">
  82. <include refid="selectRoleVo"/>
  83. where r.role_id = #{roleId}
  84. </select>
  85. <select id="selectRolesByUserName" parameterType="String" resultMap="SysRoleResult">
  86. <include refid="selectRoleVo"/>
  87. WHERE r.del_flag = '0' and u.user_name = #{userName}
  88. </select>
  89. <select id="checkRoleNameUnique" parameterType="String" resultMap="SysRoleResult">
  90. <include refid="selectRoleVo"/>
  91. where r.role_name=#{roleName} and r.del_flag = '0'
  92. <if test="tenantId != 0">
  93. and r.tenant_id = #{tenantId}
  94. </if>
  95. <if test="tenantId == 0">
  96. and r.tenant_id is null
  97. </if>
  98. limit 1
  99. </select>
  100. <select id="checkRoleKeyUnique" parameterType="String" resultMap="SysRoleResult">
  101. <include refid="selectRoleVo"/>
  102. where r.role_key=#{roleKey} and r.del_flag = '0'
  103. <if test="tenantId != 0">
  104. and r.tenant_id = #{tenantId}
  105. </if>
  106. <if test="tenantId == 0">
  107. and r.tenant_id is null
  108. </if>
  109. limit 1
  110. </select>
  111. <select id="selectUserRoleKeyByUserId" parameterType="long" resultType="string">
  112. SELECT sr.role_key FROM `sys_user` as sy
  113. inner JOIN sys_user_role sur on (sy.user_id=sur.user_id)
  114. inner join sys_role sr on (sur.role_id=sr.role_id) where sy.user_id=#{userId}
  115. </select>
  116. <insert id="insertRole" parameterType="SysRole" useGeneratedKeys="true" keyProperty="roleId">
  117. insert into sys_role(
  118. <if test="roleId != null and roleId != 0">role_id,</if>
  119. <if test="roleName != null and roleName != ''">role_name,</if>
  120. <if test="roleKey != null and roleKey != ''">role_key,</if>
  121. <if test="roleSort != null">role_sort,</if>
  122. <if test="dataScope != null and dataScope != ''">data_scope,</if>
  123. <if test="menuCheckStrictly != null">menu_check_strictly,</if>
  124. <if test="deptCheckStrictly != null">dept_check_strictly,</if>
  125. <if test="status != null and status != ''">status,</if>
  126. <if test="remark != null and remark != ''">remark,</if>
  127. <if test="tenantId != null and tenantId != 0">tenant_id,</if>
  128. <if test="createBy != null and createBy != ''">create_by,</if>
  129. create_time
  130. )values(
  131. <if test="roleId != null and roleId != 0">#{roleId},</if>
  132. <if test="roleName != null and roleName != ''">#{roleName},</if>
  133. <if test="roleKey != null and roleKey != ''">#{roleKey},</if>
  134. <if test="roleSort != null">#{roleSort},</if>
  135. <if test="dataScope != null and dataScope != ''">#{dataScope},</if>
  136. <if test="menuCheckStrictly != null">#{menuCheckStrictly},</if>
  137. <if test="deptCheckStrictly != null">#{deptCheckStrictly},</if>
  138. <if test="status != null and status != ''">#{status},</if>
  139. <if test="remark != null and remark != ''">#{remark},</if>
  140. <if test="tenantId != null and tenantId != 0">#{tenantId},</if>
  141. <if test="createBy != null and createBy != ''">#{createBy},</if>
  142. sysdate()
  143. )
  144. </insert>
  145. <update id="updateRole" parameterType="SysRole">
  146. update sys_role
  147. <set>
  148. <if test="roleName != null and roleName != ''">role_name = #{roleName},</if>
  149. <if test="roleKey != null and roleKey != ''">role_key = #{roleKey},</if>
  150. <if test="roleSort != null">role_sort = #{roleSort},</if>
  151. <if test="dataScope != null and dataScope != ''">data_scope = #{dataScope},</if>
  152. <if test="menuCheckStrictly != null">menu_check_strictly = #{menuCheckStrictly},</if>
  153. <if test="deptCheckStrictly != null">dept_check_strictly = #{deptCheckStrictly},</if>
  154. <if test="status != null and status != ''">status = #{status},</if>
  155. <if test="remark != null">remark = #{remark},</if>
  156. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  157. update_time = sysdate()
  158. </set>
  159. where role_id = #{roleId}
  160. </update>
  161. <delete id="deleteRoleById" parameterType="Long">
  162. update sys_role set del_flag = '2' where role_id = #{roleId}
  163. </delete>
  164. <delete id="deleteRoleByIds" parameterType="Long">
  165. update sys_role set del_flag = '2' where role_id in
  166. <foreach collection="array" item="roleId" open="(" separator="," close=")">
  167. #{roleId}
  168. </foreach>
  169. </delete>
  170. </mapper>