SysPermissionDao.xml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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.pine.admin.modules.system.dao.SysPermissionDao">
  4. <!-- 可根据自己的需求,是否要使用 -->
  5. <resultMap type="com.pine.admin.modules.system.entity.SysPermission" id="sysPermissionMap">
  6. <result property="id" column="id"/>
  7. <result property="name" column="name"/>
  8. <result property="type" column="type"/>
  9. <result property="url" column="url"/>
  10. <result property="percode" column="percode"/>
  11. <result property="parentid" column="parentid"/>
  12. <result property="parentids" column="parentids"/>
  13. <result property="sortstring" column="sortstring"/>
  14. <result property="available" column="available"/>
  15. <result property="createTime" column="create_time"/>
  16. <result property="updateTime" column="update_time"/>
  17. </resultMap>
  18. <sql id="Base_Column_List">
  19. id,
  20. name,
  21. type,
  22. url,
  23. percode,
  24. parentid,
  25. parentids,
  26. sortstring,
  27. available,
  28. create_time,
  29. update_time </sql>
  30. <!-- 根据Id查询-->
  31. <select id="selectByPrimaryKey" resultMap="sysPermissionMap" parameterType="java.lang.Integer">
  32. select
  33. <include refid="Base_Column_List"/>
  34. from sys_permission
  35. where id = #{id,jdbcType=INTEGER}
  36. </select>
  37. <!-- 根据Id删除-->
  38. <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
  39. delete from sys_permission
  40. where id = #{id,jdbcType=INTEGER}
  41. </delete>
  42. <!-- 插入数据-->
  43. <insert id="insertSelective" parameterType="com.pine.admin.modules.system.entity.SysPermission"
  44. useGeneratedKeys="true" keyProperty="id">
  45. insert into sys_permission
  46. <trim prefix="(" suffix=")" suffixOverrides=",">
  47. <if test="id !=null">id,</if>
  48. <if test="name !=null">name,</if>
  49. <if test="type !=null">type,</if>
  50. <if test="url !=null">url,</if>
  51. <if test="percode !=null">percode,</if>
  52. <if test="parentid !=null">parentid,</if>
  53. <if test="parentids !=null">parentids,</if>
  54. <if test="sortstring !=null">sortstring,</if>
  55. <if test="available !=null">available,</if>
  56. <if test="createTime !=null">create_time,</if>
  57. <if test="updateTime !=null">update_time,</if>
  58. </trim>
  59. <trim prefix="values (" suffix=")" suffixOverrides=",">
  60. <if test="id !=null">#{id},</if>
  61. <if test="name !=null">#{name},</if>
  62. <if test="type !=null">#{type},</if>
  63. <if test="url !=null">#{url},</if>
  64. <if test="percode !=null">#{percode},</if>
  65. <if test="parentid !=null">#{parentid},</if>
  66. <if test="parentids !=null">#{parentids},</if>
  67. <if test="sortstring !=null">#{sortstring},</if>
  68. <if test="available !=null">#{available},</if>
  69. <if test="createTime !=null">#{createTime},</if>
  70. <if test="updateTime !=null">#{updateTime},</if>
  71. </trim>
  72. </insert>
  73. <!-- 更新数据-->
  74. <update id="updateByPrimaryKeySelective"
  75. parameterType="com.pine.admin.modules.system.entity.SysPermission">
  76. update sys_permission
  77. <set>
  78. <if test="id != null">id = #{id},</if>
  79. <if test="name != null">name = #{name},</if>
  80. <if test="type != null">type = #{type},</if>
  81. <if test="url != null">url = #{url},</if>
  82. <if test="percode != null">percode = #{percode},</if>
  83. <if test="parentid != null">parentid = #{parentid},</if>
  84. <if test="parentids != null">parentids = #{parentids},</if>
  85. <if test="sortstring != null">sortstring = #{sortstring},</if>
  86. <if test="available != null">available = #{available},</if>
  87. <if test="createTime != null">create_time = #{createTime},</if>
  88. <if test="updateTime != null">update_time = #{updateTime},</if>
  89. </set>
  90. where id = #{id,jdbcType=INTEGER}
  91. </update>
  92. <!-- 分页查询-->
  93. <select id="querySysPermissionsByPage" parameterType="java.util.Map"
  94. resultType="com.pine.admin.modules.system.entity.SysPermission">
  95. select
  96. <include refid="Base_Column_List"/>
  97. from sys_permission
  98. <where>
  99. and del_flag = 'N'
  100. <if test="record.id != null and !&quot;&quot;.equals(record.id)">and id = #{record.id}</if>
  101. <if test="record.name != null and !&quot;&quot;.equals(record.name)">and name = #{record.name}</if>
  102. <if test="record.type != null and !&quot;&quot;.equals(record.type)">and type = #{record.type}</if>
  103. <if test="record.url != null and !&quot;&quot;.equals(record.url)">and url = #{record.url}</if>
  104. <if test="record.percode != null and !&quot;&quot;.equals(record.percode)">and percode = #{record.percode}
  105. </if>
  106. <if test="record.parentid != null and !&quot;&quot;.equals(record.parentid)">and parentid =
  107. #{record.parentid}
  108. </if>
  109. <if test="record.parentids != null and !&quot;&quot;.equals(record.parentids)">and parentids =
  110. #{record.parentids}
  111. </if>
  112. <if test="record.sortstring != null and !&quot;&quot;.equals(record.sortstring)">and sortstring =
  113. #{record.sortstring}
  114. </if>
  115. <if test="record.available != null and !&quot;&quot;.equals(record.available)">and available =
  116. #{record.available}
  117. </if>
  118. <if test="record.createTime != null and !&quot;&quot;.equals(record.createTime)">and create_time =
  119. #{record.createTime}
  120. </if>
  121. <if test="record.updateTime != null and !&quot;&quot;.equals(record.updateTime)">and update_time =
  122. #{record.updateTime}
  123. </if>
  124. </where>
  125. order by id desc
  126. </select>
  127. <!-- 全部查询 -->
  128. <select id="queryAllSysPermission" parameterType="java.util.Map"
  129. resultType="com.pine.admin.modules.system.entity.SysPermission">
  130. select
  131. <include refid="Base_Column_List"/>
  132. from sys_permission
  133. <where>
  134. and del_flag = 'N'
  135. <if test="id != null and !&quot;&quot;.equals(id)">and id = #{id}</if>
  136. <if test="name != null and !&quot;&quot;.equals(name)">and name = #{name}</if>
  137. <if test="type != null and !&quot;&quot;.equals(type)">and type = #{type}</if>
  138. <if test="url != null and !&quot;&quot;.equals(url)">and url = #{url}</if>
  139. <if test="percode != null and !&quot;&quot;.equals(percode)">and percode = #{percode}</if>
  140. <if test="parentid != null and !&quot;&quot;.equals(parentid)">and parentid = #{parentid}</if>
  141. <if test="parentids != null and !&quot;&quot;.equals(parentids)">and parentids = #{parentids}</if>
  142. <if test="sortstring != null and !&quot;&quot;.equals(sortstring)">and sortstring = #{sortstring}</if>
  143. <if test="available != null and !&quot;&quot;.equals(available)">and available = #{available}</if>
  144. <if test="createTime != null and !&quot;&quot;.equals(createTime)">and create_time = #{createTime}</if>
  145. <if test="updateTime != null and !&quot;&quot;.equals(updateTime)">and update_time = #{updateTime}</if>
  146. </where>
  147. order by id desc
  148. </select>
  149. <!-- 根据条件查询一个 -->
  150. <select id="querySysPermission" parameterType="java.util.Map"
  151. resultType="com.pine.admin.modules.system.entity.SysPermission">
  152. select
  153. <include refid="Base_Column_List"/>
  154. from sys_permission
  155. <where>
  156. and del_flag = 'N'
  157. <if test="id != null and !&quot;&quot;.equals(id)">and id = #{id}</if>
  158. <if test="name != null and !&quot;&quot;.equals(name)">and name = #{name}</if>
  159. <if test="type != null and !&quot;&quot;.equals(type)">and type = #{type}</if>
  160. <if test="url != null and !&quot;&quot;.equals(url)">and url = #{url}</if>
  161. <if test="percode != null and !&quot;&quot;.equals(percode)">and percode = #{percode}</if>
  162. <if test="parentid != null and !&quot;&quot;.equals(parentid)">and parentid = #{parentid}</if>
  163. <if test="parentids != null and !&quot;&quot;.equals(parentids)">and parentids = #{parentids}</if>
  164. <if test="sortstring != null and !&quot;&quot;.equals(sortstring)">and sortstring = #{sortstring}</if>
  165. <if test="available != null and !&quot;&quot;.equals(available)">and available = #{available}</if>
  166. <if test="createTime != null and !&quot;&quot;.equals(createTime)">and create_time = #{createTime}</if>
  167. <if test="updateTime != null and !&quot;&quot;.equals(updateTime)">and update_time = #{updateTime}</if>
  168. </where>
  169. LIMIT 1
  170. </select>
  171. <!-- 根据用户id查询菜单 -->
  172. <select id="findMenuListByUserId" parameterType="java.lang.Integer"
  173. resultType="com.pine.admin.modules.system.entity.SysPermission">
  174. SELECT
  175. *
  176. FROM
  177. sys_permission
  178. WHERE TYPE = 'menu'
  179. AND id IN
  180. (SELECT
  181. sys_permission_id
  182. FROM
  183. sys_role_permission
  184. WHERE
  185. del_flag = 'N' AND
  186. sys_role_id IN
  187. (SELECT
  188. sys_role_id
  189. FROM
  190. sys_user_role
  191. WHERE sys_user_id = #{userId}))
  192. </select>
  193. <!-- 根据用户id查询URL -->
  194. <select id="findPermissionListByUserId" parameterType="java.lang.Integer"
  195. resultType="com.pine.admin.modules.system.entity.SysPermission">
  196. SELECT
  197. *
  198. FROM
  199. sys_permission
  200. WHERE TYPE = 'permission'
  201. AND id IN
  202. (SELECT
  203. sys_permission_id
  204. FROM
  205. sys_role_permission
  206. WHERE
  207. del_flag = 'N' AND
  208. sys_role_id IN
  209. (SELECT
  210. sys_role_id
  211. FROM
  212. sys_user_role
  213. WHERE sys_user_id = #{userId}))
  214. </select>
  215. <update id="delete">
  216. UPDATE sys_permission SET del_flag = 'Y'
  217. <where>
  218. AND id = #{id}
  219. </where>
  220. </update>
  221. </mapper>