SysRoleMapper.xml 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. order by r.role_sort
  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.id = #{roleId}
  84. order by r.role_sort
  85. </select>
  86. <select id="selectRolesByUserName" parameterType="String" resultMap="SysRoleResult">
  87. <include refid="selectRoleVo"/>
  88. WHERE r.del_flag = '0' and u.username = #{userName}
  89. </select>
  90. <select id="checkRoleNameUnique" parameterType="String" resultMap="SysRoleResult">
  91. <include refid="selectRoleVo"/>
  92. where r.role_name=#{roleName} and r.del_flag = '0' limit 1
  93. </select>
  94. <select id="checkRoleKeyUnique" parameterType="String" resultMap="SysRoleResult">
  95. <include refid="selectRoleVo"/>
  96. where r.role_key=#{roleKey} and r.del_flag = '0' limit 1
  97. </select>
  98. <select id="getRoleNameByUserId" resultType="java.lang.String">
  99. SELECT GROUP_CONCAT(sr.role_name) as roleName
  100. FROM sys_role sr
  101. LEFT JOIN sys_user_role sur ON sur.role_id = sr.id
  102. WHERE sur.user_id = #{userId}
  103. </select>
  104. <select id="selectRoleNameByUserId" resultType="java.lang.String">
  105. SELECT DISTINCT GROUP_CONCAT(sr.role_name)
  106. FROM sys_user su
  107. LEFT JOIN sys_user_role sur ON su.id = sur.user_id
  108. LEFT JOIN sys_role sr ON sur.role_id = sr.id
  109. WHERE su.id = #{userId}
  110. </select>
  111. <select id="allRole" resultType="com.xunmei.system.api.domain.SysRole">
  112. SELECT *
  113. FROM sys_role
  114. WHERE role_name !='超级管理员' and del_flag=0
  115. order by role_sort
  116. </select>
  117. <insert id="insertRole" parameterType="com.xunmei.system.api.domain.SysRole" useGeneratedKeys="true"
  118. keyProperty="id">
  119. insert into sys_role(
  120. <if test="id != null and id != 0">
  121. id,
  122. </if>
  123. <if test="orgType !=null and orgType != ''">
  124. org_type,
  125. </if>
  126. <if test="roleName != null and roleName != ''">
  127. role_name,
  128. </if>
  129. <if test="roleKey != null and roleKey != ''">
  130. role_key,
  131. </if>
  132. <if test="roleSort != null">
  133. role_sort,
  134. </if>
  135. <if test="dataScope != null and dataScope != ''">
  136. data_scope,
  137. </if>
  138. <if test="menuCheckStrictly != null">
  139. menu_check_strictly,
  140. </if>
  141. <if test="deptCheckStrictly != null">
  142. dept_check_strictly,
  143. </if>
  144. <if test="status != null and status != ''">
  145. status,
  146. </if>
  147. <if test="remark != null and remark != ''">
  148. remark,
  149. </if>
  150. <if test="createBy != null and createBy != ''">
  151. create_by,
  152. </if>
  153. create_time
  154. )values(
  155. <if test="id != null and id != 0">
  156. #{id},
  157. </if>
  158. <if test="orgType !=null and orgType != ''">
  159. #{orgType},
  160. </if>
  161. <if test="roleName != null and roleName != ''">
  162. #{roleName},
  163. </if>
  164. <if test="roleKey != null and roleKey != ''">
  165. #{roleKey},
  166. </if>
  167. <if test="roleSort != null">
  168. #{roleSort},
  169. </if>
  170. <if test="dataScope != null and dataScope != ''">
  171. #{dataScope},
  172. </if>
  173. <if test="menuCheckStrictly != null">
  174. #{menuCheckStrictly},
  175. </if>
  176. <if test="deptCheckStrictly != null">
  177. #{deptCheckStrictly},
  178. </if>
  179. <if test="status != null and status != ''">
  180. #{status},
  181. </if>
  182. <if test="remark != null and remark != ''">
  183. #{remark},
  184. </if>
  185. <if test="createBy != null and createBy != ''">
  186. #{createBy},
  187. </if>
  188. sysdate()
  189. )
  190. </insert>
  191. <update id="updateRole" parameterType="com.xunmei.system.api.domain.SysRole">
  192. update sys_role
  193. <set>
  194. <if test="roleName != null and roleName != ''">
  195. role_name = #{roleName},
  196. </if>
  197. <if test="orgType !=null and orgType != ''">
  198. org_type =#{orgType},
  199. </if>
  200. <if test="roleKey != null and roleKey != ''">
  201. role_key = #{roleKey},
  202. </if>
  203. <if test="roleSort != null">
  204. role_sort = #{roleSort},
  205. </if>
  206. <if test="dataScope != null and dataScope != ''">
  207. data_scope = #{dataScope},
  208. </if>
  209. <if test="menuCheckStrictly != null">
  210. menu_check_strictly = #{menuCheckStrictly},
  211. </if>
  212. <if test="deptCheckStrictly != null">
  213. dept_check_strictly = #{deptCheckStrictly},
  214. </if>
  215. <if test="status != null and status != ''">
  216. status = #{status},
  217. </if>
  218. <if test="remark != null">
  219. remark = #{remark},
  220. </if>
  221. <if test="updateBy != null and updateBy != ''">
  222. update_by = #{updateBy},
  223. </if>
  224. update_time = sysdate()
  225. </set>
  226. where id = #{id}
  227. </update>
  228. <delete id="deleteRoleById" parameterType="Long">
  229. update sys_role
  230. set del_flag = '2'
  231. where role_id = #{roleId}
  232. </delete>
  233. <delete id="deleteRoleByIds" parameterType="Long">
  234. update sys_role set del_flag = '2' where id in
  235. <foreach collection="array" item="roleId" open="(" separator="," close=")">
  236. #{roleId}
  237. </foreach>
  238. </delete>
  239. <select id="selectUserByRoleNameAndOrgId" resultType="com.xunmei.system.api.domain.SysUser">
  240. select u.id, u.username
  241. from sys_user u
  242. inner join sys_org o on u.org_id = o.id
  243. inner join sys_user_role ur on u.id = ur.user_id
  244. inner join sys_role r on ur.role_id = r.id
  245. where r.role_name = #{roleName}
  246. and o.id = #{orgId}
  247. <if test="isLock != null">
  248. and u.is_Lock= #{isLock}
  249. </if>
  250. </select>
  251. <select id="getNamesByOrgId" resultType="com.xunmei.common.core.vo.IdNameVo">
  252. select r.id,r.role_name as name
  253. from sys_role r
  254. inner join sys_org o on r.org_type = o.type and o.id=#{orgId}
  255. where r.status=0
  256. </select>
  257. </mapper>