SysMenuMapper.xml 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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.slibra.system.mapper.SysMenuMapper">
  6. <resultMap type="SysMenu" id="SysMenuResult">
  7. <id property="menuId" column="menu_id" />
  8. <result property="menuName" column="menu_name" />
  9. <result property="parentName" column="parent_name" />
  10. <result property="parentId" column="parent_id" />
  11. <result property="orderNum" column="order_num" />
  12. <result property="path" column="path" />
  13. <result property="component" column="component" />
  14. <result property="query" column="query" />
  15. <result property="isFrame" column="is_frame" />
  16. <result property="isCache" column="is_cache" />
  17. <result property="menuType" column="menu_type" />
  18. <result property="visible" column="visible" />
  19. <result property="status" column="status" />
  20. <result property="perms" column="perms" />
  21. <result property="icon" column="icon" />
  22. <result property="createBy" column="create_by" />
  23. <result property="createTime" column="create_time" />
  24. <result property="updateTime" column="update_time" />
  25. <result property="updateBy" column="update_by" />
  26. <result property="remark" column="remark" />
  27. </resultMap>
  28. <sql id="selectMenuVo">
  29. select menu_id, menu_name, parent_id, order_num, path, component, `query`, is_frame, is_cache, menu_type, visible, status, ifnull(perms,'') as perms, icon, create_time
  30. from sys_menu
  31. </sql>
  32. <select id="selectMenuList" parameterType="SysMenu" resultMap="SysMenuResult">
  33. <include refid="selectMenuVo"/>
  34. <where>
  35. <if test="menuName != null and menuName != ''">
  36. AND menu_name like concat('%', #{menuName}, '%')
  37. </if>
  38. <if test="visible != null and visible != ''">
  39. AND visible = #{visible}
  40. </if>
  41. <if test="status != null and status != ''">
  42. AND status = #{status}
  43. </if>
  44. </where>
  45. order by parent_id, order_num
  46. </select>
  47. <select id="selectMenuTreeAll" resultMap="SysMenuResult">
  48. select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.`query`, m.visible, m.status, ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time
  49. from sys_menu m where m.menu_type in ('M', 'C') and m.status = 0
  50. order by m.parent_id, m.order_num
  51. </select>
  52. <select id="selectMenuListByUserId" parameterType="SysMenu" resultMap="SysMenuResult">
  53. select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.`query`, m.visible, m.status, ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time
  54. from sys_menu m
  55. left join sys_role_menu rm on m.menu_id = rm.menu_id
  56. left join sys_user_role ur on rm.role_id = ur.role_id
  57. left join sys_role ro on ur.role_id = ro.role_id
  58. where ur.user_id = #{params.userId}
  59. <if test="menuName != null and menuName != ''">
  60. AND m.menu_name like concat('%', #{menuName}, '%')
  61. </if>
  62. <if test="visible != null and visible != ''">
  63. AND m.visible = #{visible}
  64. </if>
  65. <if test="status != null and status != ''">
  66. AND m.status = #{status}
  67. </if>
  68. order by m.parent_id, m.order_num
  69. </select>
  70. <select id="selectMenuTreeByUserId" parameterType="Long" resultMap="SysMenuResult">
  71. select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.`query`, m.visible, m.status, ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time
  72. from sys_menu m
  73. left join sys_role_menu rm on m.menu_id = rm.menu_id
  74. left join sys_user_role ur on rm.role_id = ur.role_id
  75. left join sys_role ro on ur.role_id = ro.role_id
  76. left join sys_user u on ur.user_id = u.user_id
  77. where u.user_id = #{userId} and m.menu_type in ('M', 'C') and m.status = 0 AND ro.status = 0
  78. order by m.parent_id, m.order_num
  79. </select>
  80. <select id="selectMenuListByRoleId" resultType="Long">
  81. select m.menu_id
  82. from sys_menu m
  83. left join sys_role_menu rm on m.menu_id = rm.menu_id
  84. where rm.role_id = #{roleId}
  85. <if test="menuCheckStrictly">
  86. and m.menu_id not in (select m.parent_id from sys_menu m inner join sys_role_menu rm on m.menu_id = rm.menu_id and rm.role_id = #{roleId})
  87. </if>
  88. order by m.parent_id, m.order_num
  89. </select>
  90. <select id="selectMenuPerms" resultType="String">
  91. select distinct m.perms
  92. from sys_menu m
  93. left join sys_role_menu rm on m.menu_id = rm.menu_id
  94. left join sys_user_role ur on rm.role_id = ur.role_id
  95. </select>
  96. <select id="selectMenuPermsByUserId" parameterType="Long" resultType="String">
  97. select distinct m.perms
  98. from sys_menu m
  99. left join sys_role_menu rm on m.menu_id = rm.menu_id
  100. left join sys_user_role ur on rm.role_id = ur.role_id
  101. left join sys_role r on r.role_id = ur.role_id
  102. where m.status = '0' and r.status = '0' and ur.user_id = #{userId}
  103. </select>
  104. <select id="selectMenuPermsByRoleId" parameterType="Long" resultType="String">
  105. select distinct m.perms
  106. from sys_menu m
  107. left join sys_role_menu rm on m.menu_id = rm.menu_id
  108. where m.status = '0' and rm.role_id = #{roleId}
  109. </select>
  110. <select id="selectMenuById" parameterType="Long" resultMap="SysMenuResult">
  111. <include refid="selectMenuVo"/>
  112. where menu_id = #{menuId}
  113. </select>
  114. <select id="hasChildByMenuId" resultType="Integer">
  115. select count(1) from sys_menu where parent_id = #{menuId}
  116. </select>
  117. <select id="checkMenuNameUnique" parameterType="SysMenu" resultMap="SysMenuResult">
  118. <include refid="selectMenuVo"/>
  119. where menu_name=#{menuName} and parent_id = #{parentId} limit 1
  120. </select>
  121. <update id="updateMenu" parameterType="SysMenu">
  122. update sys_menu
  123. <set>
  124. <if test="menuName != null and menuName != ''">menu_name = #{menuName},</if>
  125. <if test="parentId != null">parent_id = #{parentId},</if>
  126. <if test="orderNum != null">order_num = #{orderNum},</if>
  127. <if test="path != null and path != ''">path = #{path},</if>
  128. <if test="component != null">component = #{component},</if>
  129. <if test="query != null">`query` = #{query},</if>
  130. <if test="isFrame != null and isFrame != ''">is_frame = #{isFrame},</if>
  131. <if test="isCache != null and isCache != ''">is_cache = #{isCache},</if>
  132. <if test="menuType != null and menuType != ''">menu_type = #{menuType},</if>
  133. <if test="visible != null">visible = #{visible},</if>
  134. <if test="status != null">status = #{status},</if>
  135. <if test="perms !=null">perms = #{perms},</if>
  136. <if test="icon !=null and icon != ''">icon = #{icon},</if>
  137. <if test="remark != null and remark != ''">remark = #{remark},</if>
  138. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  139. update_time = sysdate()
  140. </set>
  141. where menu_id = #{menuId}
  142. </update>
  143. <insert id="insertMenu" parameterType="SysMenu">
  144. insert into sys_menu(
  145. <if test="menuId != null and menuId != 0">menu_id,</if>
  146. <if test="parentId != null and parentId != 0">parent_id,</if>
  147. <if test="menuName != null and menuName != ''">menu_name,</if>
  148. <if test="orderNum != null">order_num,</if>
  149. <if test="path != null and path != ''">path,</if>
  150. <if test="component != null and component != ''">component,</if>
  151. <if test="query != null and query != ''">`query`,</if>
  152. <if test="isFrame != null and isFrame != ''">is_frame,</if>
  153. <if test="isCache != null and isCache != ''">is_cache,</if>
  154. <if test="menuType != null and menuType != ''">menu_type,</if>
  155. <if test="visible != null">visible,</if>
  156. <if test="status != null">status,</if>
  157. <if test="perms !=null and perms != ''">perms,</if>
  158. <if test="icon != null and icon != ''">icon,</if>
  159. <if test="remark != null and remark != ''">remark,</if>
  160. <if test="createBy != null and createBy != ''">create_by,</if>
  161. create_time
  162. )values(
  163. <if test="menuId != null and menuId != 0">#{menuId},</if>
  164. <if test="parentId != null and parentId != 0">#{parentId},</if>
  165. <if test="menuName != null and menuName != ''">#{menuName},</if>
  166. <if test="orderNum != null">#{orderNum},</if>
  167. <if test="path != null and path != ''">#{path},</if>
  168. <if test="component != null and component != ''">#{component},</if>
  169. <if test="query != null and query != ''">#{query},</if>
  170. <if test="isFrame != null and isFrame != ''">#{isFrame},</if>
  171. <if test="isCache != null and isCache != ''">#{isCache},</if>
  172. <if test="menuType != null and menuType != ''">#{menuType},</if>
  173. <if test="visible != null">#{visible},</if>
  174. <if test="status != null">#{status},</if>
  175. <if test="perms !=null and perms != ''">#{perms},</if>
  176. <if test="icon != null and icon != ''">#{icon},</if>
  177. <if test="remark != null and remark != ''">#{remark},</if>
  178. <if test="createBy != null and createBy != ''">#{createBy},</if>
  179. sysdate()
  180. )
  181. </insert>
  182. <delete id="deleteMenuById" parameterType="Long">
  183. delete from sys_menu where menu_id = #{menuId}
  184. </delete>
  185. </mapper>