SysRoleMapper.xml 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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.xunmei.system.mapper.SysRoleMapper">
  6. <resultMap type="com.xunmei.system.api.domain.SysRole" id="SysRoleResult">
  7. <id property="id" column="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. </resultMap>
  21. <sql id="selectRoleVo">
  22. select distinct r.id,
  23. r.org_type,
  24. r.role_name,
  25. r.role_key,
  26. r.role_sort,
  27. r.data_scope,
  28. r.menu_check_strictly,
  29. r.dept_check_strictly,
  30. r.status,
  31. r.del_flag,
  32. r.create_time,
  33. r.remark
  34. from sys_role r
  35. left join sys_user_role ur on ur.role_id = r.id
  36. left join sys_user u on u.id = ur.user_id
  37. left join sys_dept d on u.dept_id = d.dept_id
  38. </sql>
  39. <select id="selectRoleList" parameterType="com.xunmei.system.api.domain.SysRole" resultMap="SysRoleResult">
  40. <include refid="selectRoleVo"/>
  41. where r.del_flag = '0'
  42. <if test="roleId != null and roleId != 0">
  43. AND r.role_id = #{roleId}
  44. </if>
  45. <if test="roleName != null and roleName != ''">
  46. AND r.role_name like concat('%', #{roleName}, '%')
  47. </if>
  48. <if test="status != null and status != ''">
  49. AND r.status = #{status}
  50. </if>
  51. <if test="roleKey != null and roleKey != ''">
  52. AND r.role_key like concat('%', #{roleKey}, '%')
  53. </if>
  54. <if test="params.beginTime != null and params.beginTime != ''">
  55. <!-- 开始时间检索 -->
  56. and date_format(r.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
  57. </if>
  58. <if test="params.endTime != null and params.endTime != ''">
  59. <!-- 结束时间检索 -->
  60. and date_format(r.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
  61. </if>
  62. <!-- 数据范围过滤 -->
  63. ${params.dataScope}
  64. order by r.role_sort
  65. </select>
  66. <select id="selectRolePermissionByUserId" parameterType="Long" resultMap="SysRoleResult">
  67. <include refid="selectRoleVo"/>
  68. WHERE r.del_flag = '0' and ur.user_id = #{userId}
  69. </select>
  70. <select id="selectRoleAll" resultMap="SysRoleResult">
  71. <include refid="selectRoleVo"/>
  72. </select>
  73. <select id="selectRoleListByUserId" parameterType="Long" resultType="Long">
  74. select r.role_id
  75. from sys_role r
  76. left join sys_user_role ur on ur.role_id = r.role_id
  77. left join sys_user u on u.user_id = ur.user_id
  78. where u.user_id = #{userId}
  79. </select>
  80. <select id="selectRoleById" parameterType="Long" resultMap="SysRoleResult">
  81. <include refid="selectRoleVo"/>
  82. where r.id = #{roleId}
  83. </select>
  84. <select id="selectRolesByUserName" parameterType="String" resultMap="SysRoleResult">
  85. <include refid="selectRoleVo"/>
  86. WHERE r.del_flag = '0' and u.username = #{userName}
  87. </select>
  88. <select id="checkRoleNameUnique" parameterType="String" resultMap="SysRoleResult">
  89. <include refid="selectRoleVo"/>
  90. where r.role_name=#{roleName} and r.del_flag = '0' limit 1
  91. </select>
  92. <select id="checkRoleKeyUnique" parameterType="String" resultMap="SysRoleResult">
  93. <include refid="selectRoleVo"/>
  94. where r.role_key=#{roleKey} and r.del_flag = '0' limit 1
  95. </select>
  96. <select id="getRoleNameByUserId" resultType="java.lang.String">
  97. SELECT GROUP_CONCAT(sr.role_name) as roleName
  98. FROM sys_role sr
  99. LEFT JOIN sys_user_role sur ON sur.role_id = sr.id
  100. WHERE sur.user_id = #{userId}
  101. </select>
  102. <select id="selectRoleNameByUserId" resultType="java.lang.String">
  103. SELECT DISTINCT GROUP_CONCAT(sr.role_name)
  104. FROM sys_user su
  105. LEFT JOIN sys_user_role sur ON su.id = sur.user_id
  106. LEFT JOIN sys_role sr ON sur.role_id = sr.id
  107. WHERE su.id = #{userId}
  108. </select>
  109. <select id="allRole" resultType="com.xunmei.system.api.domain.SysRole">
  110. SELECT *
  111. FROM sys_role
  112. WHERE role_name !='超级管理员'
  113. </select>
  114. <insert id="insertRole" parameterType="com.xunmei.system.api.domain.SysRole" useGeneratedKeys="true"
  115. keyProperty="id">
  116. insert into sys_role(
  117. <if test="id != null and id != 0">
  118. id,
  119. </if>
  120. <if test="orgType !=null and orgType != ''">
  121. org_type,
  122. </if>
  123. <if test="roleName != null and roleName != ''">
  124. role_name,
  125. </if>
  126. <if test="roleKey != null and roleKey != ''">
  127. role_key,
  128. </if>
  129. <if test="roleSort != null">
  130. role_sort,
  131. </if>
  132. <if test="dataScope != null and dataScope != ''">
  133. data_scope,
  134. </if>
  135. <if test="menuCheckStrictly != null">
  136. menu_check_strictly,
  137. </if>
  138. <if test="deptCheckStrictly != null">
  139. dept_check_strictly,
  140. </if>
  141. <if test="status != null and status != ''">
  142. status,
  143. </if>
  144. <if test="remark != null and remark != ''">
  145. remark,
  146. </if>
  147. <if test="createBy != null and createBy != ''">
  148. create_by,
  149. </if>
  150. create_time
  151. )values(
  152. <if test="id != null and id != 0">
  153. #{id},
  154. </if>
  155. <if test="orgType !=null and orgType != ''">
  156. #{orgType},
  157. </if>
  158. <if test="roleName != null and roleName != ''">
  159. #{roleName},
  160. </if>
  161. <if test="roleKey != null and roleKey != ''">
  162. #{roleKey},
  163. </if>
  164. <if test="roleSort != null">
  165. #{roleSort},
  166. </if>
  167. <if test="dataScope != null and dataScope != ''">
  168. #{dataScope},
  169. </if>
  170. <if test="menuCheckStrictly != null">
  171. #{menuCheckStrictly},
  172. </if>
  173. <if test="deptCheckStrictly != null">
  174. #{deptCheckStrictly},
  175. </if>
  176. <if test="status != null and status != ''">
  177. #{status},
  178. </if>
  179. <if test="remark != null and remark != ''">
  180. #{remark},
  181. </if>
  182. <if test="createBy != null and createBy != ''">
  183. #{createBy},
  184. </if>
  185. sysdate()
  186. )
  187. </insert>
  188. <update id="updateRole" parameterType="com.xunmei.system.api.domain.SysRole">
  189. update sys_role
  190. <set>
  191. <if test="roleName != null and roleName != ''">
  192. role_name = #{roleName},
  193. </if>
  194. <if test="orgType !=null and orgType != ''">
  195. org_type =#{orgType},
  196. </if>
  197. <if test="roleKey != null and roleKey != ''">
  198. role_key = #{roleKey},
  199. </if>
  200. <if test="roleSort != null">
  201. role_sort = #{roleSort},
  202. </if>
  203. <if test="dataScope != null and dataScope != ''">
  204. data_scope = #{dataScope},
  205. </if>
  206. <if test="menuCheckStrictly != null">
  207. menu_check_strictly = #{menuCheckStrictly},
  208. </if>
  209. <if test="deptCheckStrictly != null">
  210. dept_check_strictly = #{deptCheckStrictly},
  211. </if>
  212. <if test="status != null and status != ''">
  213. status = #{status},
  214. </if>
  215. <if test="remark != null">
  216. remark = #{remark},
  217. </if>
  218. <if test="updateBy != null and updateBy != ''">
  219. update_by = #{updateBy},
  220. </if>
  221. update_time = sysdate()
  222. </set>
  223. where id = #{id}
  224. </update>
  225. <delete id="deleteRoleById" parameterType="Long">
  226. update sys_role
  227. set del_flag = '2'
  228. where role_id = #{roleId}
  229. </delete>
  230. <delete id="deleteRoleByIds" parameterType="Long">
  231. update sys_role set del_flag = '2' where id in
  232. <foreach collection="array" item="roleId" open="(" separator="," close=")">
  233. #{roleId}
  234. </foreach>
  235. </delete>
  236. <select id="selectUserByRoleNameAndOrgId" resultType="com.xunmei.system.api.domain.SysUser">
  237. select u.id, u.username
  238. from sys_user u
  239. inner join sys_org o on u.org_id = o.id
  240. inner join sys_user_role ur on u.id = ur.user_id
  241. inner join sys_role r on ur.role_id = r.id
  242. where r.role_name = #{roleName}
  243. and o.id = #{orgId}
  244. </select>
  245. </mapper>