SysRoleMapper.xml 10 KB

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