SysRoleMapper.xml 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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.aidex.system.mapper.SysRoleMapper">
  6. <sql id="roleColumns">
  7. t.id as "id",
  8. t.role_name AS "roleName",
  9. t.role_key AS "roleKey",
  10. t.sort AS "sort",
  11. t.data_scope AS "dataScope",
  12. t.menu_check_strictly AS "menuCheckStrictly",
  13. t.dept_check_strictly AS "deptCheckStrictly",
  14. t.status AS "status",
  15. t.create_by AS "createBy",
  16. t.create_dept AS "createDept",
  17. t.create_time AS "createTime",
  18. t.update_by AS "updateBy",
  19. t.update_time AS "updateTime",
  20. t.update_ip AS "updateIp",
  21. t.remark AS "remark",
  22. t.version AS "version",
  23. t.del_flag AS "delFlag"
  24. </sql>
  25. <sql id="selectRoleVo">
  26. select distinct <include refid="roleColumns"/>
  27. from sys_role t
  28. left join sys_user_role ur on ur.role_id = t.id
  29. left join sys_user u on u.id = ur.user_id
  30. left join sys_dept d on u.dept_id = d.id
  31. </sql>
  32. <select id="findList" resultType="SysRole">
  33. <include refid="selectRoleVo"/>
  34. where t.del_flag = #{DEL_FLAG_NORMAL}
  35. <if test="roleName != null and roleName != ''">
  36. AND t.role_name like concat('%', #{roleName}, '%')
  37. </if>
  38. <if test="status != null and status != ''">
  39. AND t.status = #{status}
  40. </if>
  41. <if test="roleKey != null and roleKey != ''">
  42. AND t.role_key like concat('%', #{roleKey}, '%')
  43. </if>
  44. <if test="codeOrName != null and codeOrName != ''">
  45. AND (t.role_name like concat('%', #{codeOrName}, '%') or t.role_key like concat('%', #{codeOrName}, '%'))
  46. </if>
  47. <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
  48. and date_format(t.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
  49. </if>
  50. <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
  51. and date_format(t.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
  52. </if>
  53. <!-- 数据范围过滤 -->
  54. ${params.dataScope}
  55. order by t.sort, t.create_time
  56. </select>
  57. <select id="selectRolePermissionByUserId" parameterType="String" resultType="SysRole">
  58. <include refid="selectRoleVo"/>
  59. WHERE t.del_flag = #{DEL_FLAG_NORMAL} and ur.user_id = #{userId}
  60. </select>
  61. <select id="selectRoleAll" resultType="SysRole">
  62. <include refid="selectRoleVo"/>
  63. </select>
  64. <select id="selectRoleListByUserId" parameterType="String" resultType="String">
  65. select t.id
  66. from sys_role t
  67. left join sys_user_role ur on ur.role_id = t.id
  68. left join sys_user u on u.id = ur.user_id
  69. where u.id = #{userId}
  70. </select>
  71. <select id="get" resultType="SysRole">
  72. <include refid="selectRoleVo"/>
  73. where t.id = #{id}
  74. </select>
  75. <select id="selectRolesByUserName" resultType="SysRole">
  76. <include refid="selectRoleVo"/>
  77. WHERE t.del_flag = #{DEL_FLAG_NORMAL} and u.user_name = #{userName}
  78. </select>
  79. <select id="findListWithUnique" resultType="SysRole">
  80. SELECT
  81. 1
  82. FROM sys_role t
  83. where t.del_flag = #{DEL_FLAG_NORMAL}
  84. <if test="roleName != null and roleName != ''">
  85. AND t.role_name = #{roleName}
  86. </if>
  87. <if test="roleKey != null and roleKey != ''">
  88. AND t.role_key = #{roleKey}
  89. </if>
  90. <if test="notEqualId != null and notEqualId != ''">
  91. AND t.id != #{notEqualId}
  92. </if>
  93. </select>
  94. <insert id="insert" >
  95. insert into sys_role(
  96. id,
  97. role_name,
  98. role_key,
  99. sort,
  100. data_scope,
  101. menu_check_strictly,
  102. dept_check_strictly,
  103. status,
  104. create_by,
  105. create_dept,
  106. create_time,
  107. update_by,
  108. update_time,
  109. update_ip,
  110. remark,
  111. version,
  112. del_flag
  113. )values(
  114. #{id},
  115. #{roleName},
  116. #{roleKey},
  117. #{sort},
  118. #{dataScope},
  119. #{menuCheckStrictly},
  120. #{deptCheckStrictly},
  121. #{status},
  122. #{createBy},
  123. #{createDept},
  124. #{createTime},
  125. #{updateBy},
  126. #{updateTime},
  127. #{updateIp},
  128. #{remark},
  129. 1,
  130. #{DEL_FLAG_NORMAL}
  131. )
  132. </insert>
  133. <update id="update">
  134. update sys_role
  135. <set>
  136. <if test="roleName != null and roleName != ''"> role_name = #{roleName}, </if>
  137. <if test="roleKey != null and roleKey != ''"> role_key = #{roleKey}, </if>
  138. <if test="sort != null and sort != ''"> sort = #{sort}, </if>
  139. <if test="dataScope != null and dataScope != ''"> data_scope = #{dataScope}, </if>
  140. <if test="menuCheckStrictly != null">menu_check_strictly = #{menuCheckStrictly},</if>
  141. <if test="deptCheckStrictly != null">dept_check_strictly = #{deptCheckStrictly},</if>
  142. <if test="status != null and status != ''">status = #{status}, </if>
  143. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy}, </if>
  144. <if test="updateTime != null">update_time = #{updateTime}, </if>
  145. <if test="updateIp != null and updateIp != ''">update_ip = #{updateIp}, </if>
  146. <if test="remark != null and remark != ''">remark = #{remark}, </if>
  147. version = version + 1
  148. </set>
  149. where id = #{id} and version = #{version}
  150. </update>
  151. <update id="updateRoleStatus" parameterType="SysRole">
  152. update sys_user set status = #{status} where id = #{userId}
  153. </update>
  154. <delete id="delete">
  155. UPDATE sys_role SET
  156. del_flag = #{DEL_FLAG_DELETE}
  157. WHERE id = #{id}
  158. </delete>
  159. <delete id="deleteRoleByIds" parameterType="String">
  160. update sys_role set del_flag = '1' where id in
  161. <foreach collection="array" item="roleId" open="(" separator="," close=")">
  162. #{roleId}
  163. </foreach>
  164. </delete>
  165. <select id="findMaxSort" resultType="Integer">
  166. SELECT max(a.sort)
  167. FROM sys_role a
  168. WHERE del_flag = #{DEL_FLAG_NORMAL}
  169. </select>
  170. <delete id="deleteRoleById" parameterType="String">
  171. update sys_role set del_flag = '1' where id = #{roleId}
  172. </delete>
  173. </mapper>