MenuMapper.xml 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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.juxiao.xchat.module.system.mapper.MenuMapper">
  6. <resultMap type="com.juxiao.xchat.module.system.domain.Menu" id="MenuResult">
  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="url" column="url" />
  13. <result property="target" column="target" />
  14. <result property="menuType" column="menu_type" />
  15. <result property="visible" column="visible" />
  16. <result property="perms" column="perms" />
  17. <result property="icon" column="icon" />
  18. <result property="createBy" column="create_by" />
  19. <result property="createTime" column="create_time" />
  20. <result property="updateTime" column="update_time" />
  21. <result property="updateBy" column="update_by" />
  22. <result property="remark" column="remark" />
  23. </resultMap>
  24. <sql id="selectMenuVo">
  25. select menu_id, menu_name, parent_id, order_num, url, target, menu_type, visible, ifnull(perms,'') as perms, icon, create_by, create_time
  26. from sys_menu
  27. </sql>
  28. <select id="selectMenusByUserId" parameterType="java.lang.Long" resultMap="MenuResult">
  29. select distinct m.menu_id, m.parent_id, m.menu_name, m.url, m.perms, m.target, m.menu_type, m.icon, m.order_num, m.create_time
  30. from sys_menu m
  31. left join sys_role_menu rm on m.menu_id = rm.menu_id
  32. left join sys_user_role ur on rm.role_id = ur.role_id
  33. LEFT JOIN sys_role ro on ur.role_id = ro.role_id
  34. where ur.user_id = #{userId} and m.menu_type in ('M', 'C') and m.visible = 0 AND ro.status = 0
  35. order by m.parent_id, m.order_num
  36. </select>
  37. <select id="selectMenuNormalAll" resultMap="MenuResult">
  38. select distinct m.menu_id, m.parent_id, m.menu_name, m.url, m.perms, m.target, m.menu_type, m.icon, m.order_num, m.create_time
  39. from sys_menu m
  40. where m.menu_type in ('M', 'C') and m.visible = 0
  41. order by m.parent_id, m.order_num
  42. </select>
  43. <select id="selectMenuAll" resultMap="MenuResult">
  44. <include refid="selectMenuVo"/>
  45. order by parent_id, order_num
  46. </select>
  47. <select id="selectPermsByUserId" parameterType="java.lang.Long" resultType="java.lang.String">
  48. select distinct m.perms
  49. from sys_menu m
  50. left join sys_role_menu rm on m.menu_id = rm.menu_id
  51. left join sys_user_role ur on rm.role_id = ur.role_id
  52. where ur.user_id = #{userId}
  53. </select>
  54. <select id="selectMenuTree" parameterType="java.lang.Long" resultType="java.lang.String">
  55. select concat(m.menu_id, ifnull(m.perms,'')) as perms
  56. from sys_menu m
  57. left join sys_role_menu rm on m.menu_id = rm.menu_id
  58. where rm.role_id = #{roleId}
  59. order by m.parent_id, m.order_num
  60. </select>
  61. <select id="selectMenuList" parameterType="com.juxiao.xchat.module.system.domain.Menu" resultMap="MenuResult">
  62. <include refid="selectMenuVo"/>
  63. <where>
  64. <if test="menuName != null and menuName != ''">
  65. AND menu_name like concat('%', #{menuName}, '%')
  66. </if>
  67. <if test="visible != null and visible != ''">
  68. AND visible = #{visible}
  69. </if>
  70. </where>
  71. order by parent_id, order_num
  72. </select>
  73. <delete id="deleteMenuById" parameterType="java.lang.Long">
  74. delete from sys_menu where menu_id = #{menuId} or parent_id = #{menuId}
  75. </delete>
  76. <select id="selectMenuById" parameterType="java.lang.Long" resultMap="MenuResult">
  77. SELECT t.menu_id, t.parent_id, t.menu_name, t.order_num, t.url, t.target, t.menu_type, t.visible, t.perms, t.icon, t.remark,
  78. (SELECT menu_name FROM sys_menu WHERE menu_id = t.parent_id) parent_name
  79. FROM sys_menu t
  80. where t.menu_id = #{menuId}
  81. </select>
  82. <select id="selectCountMenuByParentId" resultType="java.lang.Integer">
  83. select count(1) from sys_menu where parent_id=#{menuId}
  84. </select>
  85. <select id="checkMenuNameUnique" parameterType="com.juxiao.xchat.module.system.domain.Menu" resultMap="MenuResult">
  86. <include refid="selectMenuVo"/>
  87. where menu_name=#{menuName} and parent_id = #{parentId}
  88. </select>
  89. <update id="updateMenu" parameterType="com.juxiao.xchat.module.system.domain.Menu">
  90. update sys_menu
  91. <set>
  92. <if test="menuName != null and menuName != ''">menu_name = #{menuName},</if>
  93. <if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
  94. <if test="orderNum != null and orderNum != ''">order_num = #{orderNum},</if>
  95. <if test="url != null and url != ''">url = #{url},</if>
  96. <if test="target != null and target != ''">target = #{target},</if>
  97. <if test="menuType != null and menuType != ''">menu_type = #{menuType},</if>
  98. <if test="visible != null">visible = #{visible},</if>
  99. <if test="perms !=null">perms = #{perms},</if>
  100. <if test="icon !=null and icon != ''">icon = #{icon},</if>
  101. <if test="remark != null and remark != ''">remark = #{remark},</if>
  102. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  103. update_time = sysdate()
  104. </set>
  105. where menu_id = #{menuId}
  106. </update>
  107. <insert id="insertMenu" parameterType="com.juxiao.xchat.module.system.domain.Menu">
  108. insert into sys_menu(
  109. <if test="menuId != null and menuId != 0">menu_id,</if>
  110. <if test="parentId != null and parentId != 0">parent_id,</if>
  111. <if test="menuName != null and menuName != ''">menu_name,</if>
  112. <if test="orderNum != null and orderNum != ''">order_num,</if>
  113. <if test="url != null and url != ''">url,</if>
  114. <if test="target != null and target != ''">target,</if>
  115. <if test="menuType != null and menuType != ''">menu_type,</if>
  116. <if test="visible != null">visible,</if>
  117. <if test="perms !=null and perms != ''">perms,</if>
  118. <if test="icon != null and icon != ''">icon,</if>
  119. <if test="remark != null and remark != ''">remark,</if>
  120. <if test="createBy != null and createBy != ''">create_by,</if>
  121. create_time
  122. )values(
  123. <if test="menuId != null and menuId != 0">#{menuId},</if>
  124. <if test="parentId != null and parentId != 0">#{parentId},</if>
  125. <if test="menuName != null and menuName != ''">#{menuName},</if>
  126. <if test="orderNum != null and orderNum != ''">#{orderNum},</if>
  127. <if test="url != null and url != ''">#{url},</if>
  128. <if test="target != null and target != ''">#{target},</if>
  129. <if test="menuType != null and menuType != ''">#{menuType},</if>
  130. <if test="visible != null">#{visible},</if>
  131. <if test="perms !=null and perms != ''">#{perms},</if>
  132. <if test="icon != null and icon != ''">#{icon},</if>
  133. <if test="remark != null and remark != ''">#{remark},</if>
  134. <if test="createBy != null and createBy != ''">#{createBy},</if>
  135. sysdate()
  136. )
  137. </insert>
  138. </mapper>