SysMenuMapper.xml 9.7 KB

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