PermissionMapper.xml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.prac.simple.mapper.PermissionMapper">
  4. <resultMap id="BaseResultMap" type="Permission">
  5. <id column="id" jdbcType="VARCHAR" property="id" />
  6. <result column="pid" jdbcType="VARCHAR" property="pid" />
  7. <result column="title" jdbcType="VARCHAR" property="title" />
  8. <result column="type" jdbcType="CHAR" property="type" />
  9. <result column="url" jdbcType="VARCHAR" property="url" />
  10. <result column="description" jdbcType="VARCHAR"
  11. property="description" />
  12. <result column="orders" jdbcType="INTEGER" property="orders" />
  13. </resultMap>
  14. <sql id="Base_Column_List">
  15. id, pid, title, type, url, description, orders
  16. </sql>
  17. <select id="selectByPrimaryKey" parameterType="java.lang.String"
  18. resultMap="BaseResultMap">
  19. select
  20. <include refid="Base_Column_List" />
  21. from permission
  22. where id = #{id,jdbcType=VARCHAR}
  23. </select>
  24. <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
  25. delete from permission
  26. where id = #{id,jdbcType=VARCHAR}
  27. </delete>
  28. <insert id="insert" parameterType="Permission">
  29. insert into permission (id, pid, title,
  30. type, url, description,
  31. orders)
  32. values (#{id,jdbcType=VARCHAR}, #{pid,jdbcType=VARCHAR},
  33. #{title,jdbcType=VARCHAR},
  34. #{type,jdbcType=CHAR}, #{url,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR},
  35. #{orders,jdbcType=INTEGER})
  36. </insert>
  37. <insert id="insertSelective" parameterType="Permission">
  38. insert into permission
  39. <trim prefix="(" suffix=")" suffixOverrides=",">
  40. <if test="id != null">
  41. id,
  42. </if>
  43. <if test="pid != null">
  44. pid,
  45. </if>
  46. <if test="title != null">
  47. title,
  48. </if>
  49. <if test="type != null">
  50. type,
  51. </if>
  52. <if test="url != null">
  53. url,
  54. </if>
  55. <if test="description != null">
  56. description,
  57. </if>
  58. <if test="orders != null">
  59. orders,
  60. </if>
  61. </trim>
  62. <trim prefix="values (" suffix=")" suffixOverrides=",">
  63. <if test="id != null">
  64. #{id,jdbcType=VARCHAR},
  65. </if>
  66. <if test="pid != null">
  67. #{pid,jdbcType=VARCHAR},
  68. </if>
  69. <if test="title != null">
  70. #{title,jdbcType=VARCHAR},
  71. </if>
  72. <if test="type != null">
  73. #{type,jdbcType=CHAR},
  74. </if>
  75. <if test="url != null">
  76. #{url,jdbcType=VARCHAR},
  77. </if>
  78. <if test="description != null">
  79. #{description,jdbcType=VARCHAR},
  80. </if>
  81. <if test="orders != null">
  82. #{orders,jdbcType=INTEGER},
  83. </if>
  84. </trim>
  85. </insert>
  86. <update id="updateByPrimaryKeySelective"
  87. parameterType="Permission">
  88. update permission
  89. <set>
  90. <if test="pid != null">
  91. pid = #{pid,jdbcType=VARCHAR},
  92. </if>
  93. <if test="title != null">
  94. title = #{title,jdbcType=VARCHAR},
  95. </if>
  96. <if test="type != null">
  97. type = #{type,jdbcType=CHAR},
  98. </if>
  99. <if test="url != null">
  100. url = #{url,jdbcType=VARCHAR},
  101. </if>
  102. <if test="description != null">
  103. description = #{description,jdbcType=VARCHAR},
  104. </if>
  105. <if test="orders != null">
  106. orders = #{orders,jdbcType=INTEGER},
  107. </if>
  108. </set>
  109. where id = #{id,jdbcType=VARCHAR}
  110. </update>
  111. <update id="updateByPrimaryKey" parameterType="Permission">
  112. update permission
  113. set pid = #{pid,jdbcType=VARCHAR},
  114. title = #{title,jdbcType=VARCHAR},
  115. type = #{type,jdbcType=CHAR},
  116. url = #{url,jdbcType=VARCHAR},
  117. description = #{description,jdbcType=VARCHAR},
  118. orders = #{orders,jdbcType=INTEGER}
  119. where id = #{id,jdbcType=VARCHAR}
  120. </update>
  121. <select id="selectPermission" resultMap="BaseResultMap" parameterType="PermissionReq">
  122. select
  123. <include refid="Base_Column_List" />
  124. from permission
  125. <where>
  126. <if test="pid != null and pid != ''">
  127. pid = #{pid}
  128. </if>
  129. </where>
  130. order by pid,orders
  131. </select>
  132. <select id="selectAllMenu" resultMap="BaseResultMap" >
  133. select
  134. <include refid="Base_Column_List" />
  135. from permission
  136. where type <![CDATA[<>]]> '03'
  137. </select>
  138. <select id="selectRolePermissions" resultType="RolePermission">
  139. select p.url, r.id roleId
  140. from role_permission rp
  141. inner join permission p on rp.permission_id = p.id
  142. inner join role r on rp.role_id=r.id
  143. </select>
  144. <select id="selectPermissionByUserId"
  145. parameterType="java.lang.String" resultMap="BaseResultMap">
  146. select distinct p.*
  147. from permission p
  148. inner join role_permission rp on rp.permission_id = p.id
  149. inner join user_role ur on ur.role_id=rp.role_id
  150. where ur.user_id=#{userId}
  151. </select>
  152. <select id="selectPermissionByRoleId"
  153. parameterType="java.lang.String" resultMap="BaseResultMap">
  154. select p.*
  155. from permission p
  156. inner join role_permission rp on rp.permission_id = p.id
  157. where rp.role_id=#{roleId}
  158. </select>
  159. <select id="selectPermissionByUrl"
  160. parameterType="java.lang.String" resultMap="BaseResultMap">
  161. select
  162. <include refid="Base_Column_List" />
  163. from permission
  164. where url=#{url} limit 1
  165. </select>
  166. <select id="selectPermissionByTitle"
  167. parameterType="java.lang.String" resultMap="BaseResultMap">
  168. select
  169. <include refid="Base_Column_List" />
  170. from permission
  171. where title=#{title} limit 1
  172. </select>
  173. <select id="selectExistPermissionByUrl"
  174. parameterType="java.lang.String" resultMap="BaseResultMap">
  175. select
  176. <include refid="Base_Column_List" />
  177. from permission
  178. where url=#{url} and id <![CDATA[<>]]>
  179. #{id} limit 1
  180. </select>
  181. <select id="selectChildrenPermission"
  182. parameterType="java.lang.String" resultMap="BaseResultMap">
  183. select
  184. <include refid="Base_Column_List" />
  185. from permission
  186. where pid=#{id}
  187. </select>
  188. <select id="selectAllPermissionUrl" parameterType="java.lang.String" resultType="java.lang.String" >
  189. select url from permission where url is not null and url <![CDATA[<>]]> ''
  190. </select>
  191. <delete id="batchDeletePermission" parameterType="list">
  192. delete from permission where id userId
  193. <foreach collection="list" item="id" open="(" close=")"
  194. separator=",">
  195. #{id,jdbcType=INTEGER}
  196. </foreach>
  197. </delete>
  198. </mapper>