SysMenuMapper.xml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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.usky.system.mapper.SysMenuMapper">
  6. <resultMap type="com.usky.system.domain.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="isFrame" column="is_frame"/>
  15. <result property="isCache" column="is_cache"/>
  16. <result property="menuType" column="menu_type"/>
  17. <result property="visible" column="visible"/>
  18. <result property="status" column="status"/>
  19. <result property="perms" column="perms"/>
  20. <result property="icon" column="icon"/>
  21. <result property="createBy" column="create_by"/>
  22. <result property="createTime" column="create_time"/>
  23. <result property="updateTime" column="update_time"/>
  24. <result property="updateBy" column="update_by"/>
  25. <result property="remark" column="remark"/>
  26. </resultMap>
  27. <sql id="selectMenuVo">
  28. select menu_id,
  29. menu_name,
  30. parent_id,
  31. order_num,
  32. path,
  33. component,
  34. is_frame,
  35. is_cache,
  36. menu_type,
  37. visible,
  38. status,
  39. ifnull(perms, '') as perms,
  40. icon,
  41. create_time
  42. from sys_menu
  43. </sql>
  44. <select id="selectMenuList" parameterType="com.usky.system.domain.SysMenu" resultMap="SysMenuResult">
  45. <include refid="selectMenuVo"/>
  46. <where>
  47. <if test="menuName != null and menuName != ''">
  48. AND menu_name like concat('%', #{menuName}, '%')
  49. </if>
  50. <if test="visible != null and visible != ''">
  51. AND visible = #{visible}
  52. </if>
  53. <if test="status != null and status != ''">
  54. AND status = #{status}
  55. </if>
  56. </where>
  57. order by parent_id, order_num
  58. </select>
  59. <select id="selectMenuListOne" resultType="com.usky.system.domain.SysMenu">
  60. SELECT
  61. b.menu_id,
  62. b.menu_name,
  63. b.parent_id,
  64. b.order_num,
  65. b.path,
  66. b.component,
  67. b.is_frame,
  68. b.is_cache,
  69. b.menu_type,
  70. b.visible,
  71. b.status,
  72. ifnull(b.perms, '') as perms,
  73. b.icon,
  74. b.create_time
  75. FROM
  76. sys_tenant_menu AS a
  77. JOIN sys_menu AS b ON a.menu_id = b.menu_id
  78. <where>
  79. a.tenant_id = #{tenantId}
  80. <if test="menuName != null and menuName != ''">
  81. AND b.menu_name like concat('%', #{menuName}, '%')
  82. </if>
  83. AND b.visible = 0
  84. AND b.status = 0
  85. </where>
  86. order by parent_id, order_num
  87. </select>
  88. <select id="selectMenuTreeAll" resultMap="SysMenuResult">
  89. select distinct m.menu_id,
  90. m.parent_id,
  91. m.menu_name,
  92. m.path,
  93. m.component,
  94. m.visible,
  95. m.status,
  96. ifnull(m.perms, '') as perms,
  97. m.is_frame,
  98. m.is_cache,
  99. m.menu_type,
  100. m.icon,
  101. m.order_num,
  102. m.create_time
  103. from sys_menu m
  104. where m.menu_type in ('M', 'C')
  105. and m.status = 0
  106. order by m.parent_id, m.order_num
  107. </select>
  108. <select id="selectMenuListByUserId" parameterType="com.usky.system.domain.SysMenu" resultMap="SysMenuResult">
  109. select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.visible, m.status,
  110. ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time
  111. from sys_menu m
  112. left join sys_role_menu rm on m.menu_id = rm.menu_id
  113. left join sys_user_role ur on rm.role_id = ur.role_id
  114. left join sys_role ro on ur.role_id = ro.role_id
  115. where ur.user_id = #{params.userId}
  116. <if test="menuName != null and menuName != ''">
  117. AND menu_name like concat('%', #{menuName}, '%')
  118. </if>
  119. <if test="visible != null and visible != ''">
  120. AND visible = #{visible}
  121. </if>
  122. <if test="status != null and status != ''">
  123. AND status = #{status}
  124. </if>
  125. order by m.parent_id, m.order_num
  126. </select>
  127. <select id="selectMenuListByUserIdOne" resultMap="SysMenuResult">
  128. select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.visible, m.status,
  129. ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num, m.create_time
  130. from sys_menu m
  131. order by m.parent_id, m.order_num
  132. </select>
  133. <select id="selectMenuTreeByUserId" parameterType="Long" resultMap="SysMenuResult">
  134. select distinct m.menu_id,
  135. m.parent_id,
  136. m.menu_name,
  137. m.path,
  138. m.component,
  139. m.visible,
  140. m.status,
  141. ifnull(m.perms, '') as perms,
  142. m.is_frame,
  143. m.is_cache,
  144. m.menu_type,
  145. m.icon,
  146. m.order_num,
  147. m.create_time
  148. from sys_menu m
  149. left join sys_role_menu rm on m.menu_id = rm.menu_id
  150. left join sys_user_role ur on rm.role_id = ur.role_id
  151. left join sys_role ro on ur.role_id = ro.role_id
  152. left join sys_user u on ur.user_id = u.user_id
  153. where u.user_id = #{userId}
  154. and m.menu_type in ('M', 'C')
  155. and m.status = 0
  156. AND ro.status = 0
  157. order by m.parent_id, m.order_num
  158. </select>
  159. <select id="selectMenuTreeByUserIdOne" resultMap="SysMenuResult">
  160. SELECT
  161. m.menu_id,
  162. m.parent_id,
  163. m.menu_name,
  164. m.path,
  165. m.component,
  166. m.visible,
  167. m. STATUS,
  168. ifnull(m.perms, '') AS perms,
  169. m.is_frame,
  170. m.is_cache,
  171. m.menu_type,
  172. m.icon,
  173. m.order_num,
  174. m.create_time
  175. FROM
  176. sys_menu m
  177. JOIN sys_tenant_menu t
  178. WHERE
  179. m.menu_id = t.menu_id
  180. AND m.menu_type IN ('M', 'C')
  181. AND m. STATUS = 0
  182. AND t.tenant_id=#{tenantId}
  183. ORDER BY
  184. m.parent_id,
  185. m.order_num
  186. </select>
  187. <select id="selectMenuListByRoleId" resultType="Integer">
  188. select m.menu_id
  189. from sys_menu m
  190. left join sys_role_menu rm on m.menu_id = rm.menu_id
  191. where rm.role_id = #{roleId}
  192. <if test="menuCheckStrictly">
  193. and m.menu_id not in (select m.parent_id from sys_menu m inner join sys_role_menu rm on m.menu_id =
  194. rm.menu_id and rm.role_id = #{roleId})
  195. </if>
  196. order by m.parent_id, m.order_num
  197. </select>
  198. <select id="selectMenuPerms" resultType="String">
  199. select distinct m.perms
  200. from sys_menu m
  201. left join sys_role_menu rm on m.menu_id = rm.menu_id
  202. left join sys_user_role ur on rm.role_id = ur.role_id
  203. </select>
  204. <select id="selectMenuPermsByUserId" parameterType="Long" resultType="String">
  205. select distinct m.perms
  206. from sys_menu m
  207. left join sys_role_menu rm on m.menu_id = rm.menu_id
  208. left join sys_user_role ur on rm.role_id = ur.role_id
  209. left join sys_role r on r.role_id = ur.role_id
  210. where m.status = '0'
  211. and r.status = '0'
  212. and ur.user_id = #{userId}
  213. </select>
  214. <select id="selectMenuPermsByUserIdOne" resultType="String">
  215. select distinct m.perms
  216. from sys_menu m
  217. join sys_tenant_menu t on m.menu_id = t.menu_id
  218. where m.status = '0'
  219. and t.tenant_id = #{tenantId}
  220. </select>
  221. <select id="selectMenuById" parameterType="Long" resultMap="SysMenuResult">
  222. <include refid="selectMenuVo"/>
  223. where menu_id = #{menuId}
  224. </select>
  225. <select id="hasChildByMenuId" resultType="Integer">
  226. select count(1)
  227. from sys_menu
  228. where parent_id = #{menuId}
  229. </select>
  230. <select id="checkMenuNameUnique" parameterType="com.usky.system.domain.SysMenu" resultMap="SysMenuResult">
  231. <include refid="selectMenuVo"/>
  232. where menu_name=#{menuName} and parent_id = #{parentId} limit 1
  233. </select>
  234. <update id="updateMenu" parameterType="com.usky.system.domain.SysMenu">
  235. update sys_menu
  236. <set>
  237. <if test="menuName != null and menuName != ''">menu_name = #{menuName},</if>
  238. <if test="parentId != null">parent_id = #{parentId},</if>
  239. <if test="orderNum != null and orderNum != ''">order_num = #{orderNum},</if>
  240. <if test="path != null and path != ''">path = #{path},</if>
  241. <if test="component != null">component = #{component},</if>
  242. <if test="isFrame != null and isFrame != ''">is_frame = #{isFrame},</if>
  243. <if test="isCache != null and isCache != ''">is_cache = #{isCache},</if>
  244. <if test="menuType != null and menuType != ''">menu_type = #{menuType},</if>
  245. <if test="visible != null">visible = #{visible},</if>
  246. <if test="status != null">status = #{status},</if>
  247. <if test="perms !=null">perms = #{perms},</if>
  248. <if test="icon !=null and icon != ''">icon = #{icon},</if>
  249. <if test="remark != null and remark != ''">remark = #{remark},</if>
  250. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  251. update_time = sysdate()
  252. </set>
  253. where menu_id = #{menuId}
  254. </update>
  255. <insert id="insertMenu" parameterType="com.usky.system.domain.SysMenu">
  256. insert into sys_menu(
  257. <if test="menuId != null and menuId != 0">menu_id,</if>
  258. <if test="parentId != null and parentId != 0">parent_id,</if>
  259. <if test="menuName != null and menuName != ''">menu_name,</if>
  260. <if test="orderNum != null and orderNum != ''">order_num,</if>
  261. <if test="path != null and path != ''">path,</if>
  262. <if test="component != null and component != ''">component,</if>
  263. <if test="isFrame != null and isFrame != ''">is_frame,</if>
  264. <if test="isCache != null and isCache != ''">is_cache,</if>
  265. <if test="menuType != null and menuType != ''">menu_type,</if>
  266. <if test="visible != null">visible,</if>
  267. <if test="status != null">status,</if>
  268. <if test="perms !=null and perms != ''">perms,</if>
  269. <if test="icon != null and icon != ''">icon,</if>
  270. <if test="remark != null and remark != ''">remark,</if>
  271. <if test="createBy != null and createBy != ''">create_by,</if>
  272. create_time
  273. )values(
  274. <if test="menuId != null and menuId != 0">#{menuId},</if>
  275. <if test="parentId != null and parentId != 0">#{parentId},</if>
  276. <if test="menuName != null and menuName != ''">#{menuName},</if>
  277. <if test="orderNum != null and orderNum != ''">#{orderNum},</if>
  278. <if test="path != null and path != ''">#{path},</if>
  279. <if test="component != null and component != ''">#{component},</if>
  280. <if test="isFrame != null and isFrame != ''">#{isFrame},</if>
  281. <if test="isCache != null and isCache != ''">#{isCache},</if>
  282. <if test="menuType != null and menuType != ''">#{menuType},</if>
  283. <if test="visible != null">#{visible},</if>
  284. <if test="status != null">#{status},</if>
  285. <if test="perms !=null and perms != ''">#{perms},</if>
  286. <if test="icon != null and icon != ''">#{icon},</if>
  287. <if test="remark != null and remark != ''">#{remark},</if>
  288. <if test="createBy != null and createBy != ''">#{createBy},</if>
  289. sysdate()
  290. )
  291. </insert>
  292. <delete id="deleteMenuById" parameterType="Long">
  293. delete
  294. from sys_menu
  295. where menu_id = #{menuId}
  296. </delete>
  297. <select id="getSysMenuList" resultType="com.usky.system.domain.SysMenu" >
  298. SELECT
  299. *
  300. FROM
  301. sys_menu
  302. WHERE
  303. STATUS = 0
  304. <if test="menuType != null and menuType != ''">
  305. AND menu_type = #{menuType}
  306. </if>
  307. GROUP BY
  308. menu_id
  309. ORDER BY
  310. parent_id,
  311. order_num
  312. </select>
  313. </mapper>