SysMenuMapper.xml 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  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.zkqy.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. <result property="tenantName" column="tenant_name"/>
  28. </resultMap>
  29. <sql id="selectMenuVo">
  30. select menu_id,
  31. menu_name,
  32. parent_id,
  33. order_num,
  34. path,
  35. component,
  36. `query`,
  37. is_frame,
  38. is_cache,
  39. menu_type,
  40. visible,
  41. status,
  42. ifnull(perms, '') as perms,
  43. icon,
  44. create_time
  45. from sys_menu
  46. </sql>
  47. <select id="selectMenuList" parameterType="SysMenu" resultMap="SysMenuResult">
  48. SELECT
  49. m.menu_id,
  50. m.menu_name,
  51. m.parent_id,
  52. m.order_num,
  53. m.path,
  54. m.component,
  55. m.`query`,
  56. m.is_frame,
  57. m.is_cache,
  58. m.menu_type,
  59. m.visible,
  60. m.STATUS,
  61. ifnull( m.perms, '' ) AS perms,
  62. m.icon,
  63. m.create_time,
  64. t.tenant_name
  65. FROM
  66. sys_menu m
  67. LEFT JOIN sys_user u on m.create_by = u.user_name
  68. LEFT JOIN sys_tenant t on t.tenant_id = u.tenant_id
  69. where
  70. m.menu_id not in (select DISTINCT menu_id from sys_tenant_menu)
  71. <if test="menuName != null and menuName != ''">
  72. AND m.menu_name like concat('%', #{menuName}, '%')
  73. </if>
  74. <if test="visible != null and visible != ''">
  75. AND m.visible = #{visible}
  76. </if>
  77. <if test="status != null and status != ''">
  78. AND m.status = #{status}
  79. </if>
  80. <if test="tenantName != null and tenantName != ''">
  81. AND t.tenant_name like concat('%', #{tenantName}, '%')
  82. </if>
  83. order by parent_id, order_num
  84. </select>
  85. <select id="selectTenantMenuList" parameterType="Long" resultMap="SysMenuResult">
  86. select m.menu_id,
  87. menu_name,
  88. parent_id,
  89. order_num,
  90. path,
  91. component,
  92. `query`,
  93. is_frame,
  94. is_cache,
  95. menu_type,
  96. visible,
  97. status,
  98. ifnull(perms, '') as perms,
  99. icon,
  100. create_time,
  101. tm.`tenant_id`
  102. from sys_menu m
  103. left join sys_tenant_menu tm on tm.menu_id = m.menu_id
  104. where tm.tenant_id = #{tenantId}
  105. and m.menu_name not in ('数据引擎', '流程引擎', '表单引擎')
  106. and parent_id not in (select menu_id from sys_menu where menu_name in ("数据引擎", "流程引擎", "表单引擎"))
  107. order by parent_id, order_num
  108. </select>
  109. <select id="selectMenuTreeAll" resultMap="SysMenuResult">
  110. select distinct m.menu_id,
  111. m.parent_id,
  112. m.menu_name,
  113. m.path,
  114. m.component,
  115. m.`query`,
  116. m.visible,
  117. m.status,
  118. ifnull(m.perms, '') as perms,
  119. m.is_frame,
  120. m.is_cache,
  121. m.menu_type,
  122. m.icon,
  123. m.order_num,
  124. m.create_time
  125. from sys_menu m
  126. where m.menu_type in ('M', 'C')
  127. and m.status = 0
  128. and m.menu_id not in (select DISTINCT menu_id from sys_tenant_menu)
  129. order by m.parent_id, m.order_num
  130. </select>
  131. <select id="selectTenantMenuTreeAll" parameterType="Long" resultMap="SysMenuResult">
  132. select distinct m.menu_id,
  133. m.parent_id,
  134. m.menu_name,
  135. m.path,
  136. m.component,
  137. m.`query`,
  138. m.visible,
  139. m.status,
  140. ifnull(m.perms, '') as perms,
  141. m.is_frame,
  142. m.is_cache,
  143. m.menu_type,
  144. m.icon,
  145. m.order_num,
  146. m.create_time
  147. from sys_tenant_menu tm
  148. left join sys_menu m on
  149. tm.menu_id = m.menu_id
  150. where m.menu_type in ('M', 'C')
  151. and m.status = 0
  152. and tm.tenant_id = #{tenantId}
  153. and m.menu_name in ('数据引擎', '流程引擎', '表单引擎')
  154. UNION
  155. select distinct m.menu_id,
  156. m.parent_id,
  157. m.menu_name,
  158. m.path,
  159. m.component,
  160. m.`query`,
  161. m.visible,
  162. m.status,
  163. ifnull(m.perms, '') as perms,
  164. m.is_frame,
  165. m.is_cache,
  166. m.menu_type,
  167. m.icon,
  168. m.order_num,
  169. m.create_time
  170. from sys_tenant_menu tm
  171. left join sys_menu m on
  172. tm.menu_id = m.menu_id
  173. where m.menu_type in ('M', 'C')
  174. and m.status = 0
  175. and tm.tenant_id = #{tenantId}
  176. and m.parent_id in (select menu_id
  177. from sys_menu
  178. where menu_name in ("数据引擎", "流程引擎", "表单引擎"))
  179. </select>
  180. <select id="selectMenuListByUserId" parameterType="SysMenu" resultMap="SysMenuResult">
  181. select distinct m.menu_id, m.parent_id, m.menu_name, m.path, m.component, m.`query`, m.visible, m.status,
  182. ifnull(m.perms,'') as perms, m.is_frame, m.is_cache, m.menu_type, m.icon, m.order_num,
  183. m.create_time,t.tenant_name
  184. from sys_menu m
  185. left join sys_role_menu rm on m.menu_id = rm.menu_id
  186. left join sys_user_role ur on rm.role_id = ur.role_id
  187. left join sys_role ro on ur.role_id = ro.role_id
  188. LEFT JOIN sys_user u on m.create_by = u.user_name
  189. LEFT JOIN sys_tenant t on t.tenant_id = u.tenant_id
  190. where ur.user_id = #{params.userId}
  191. <if test="menuName != null and menuName != ''">
  192. AND m.menu_name like concat('%', #{menuName}, '%')
  193. </if>
  194. <if test="visible != null and visible != ''">
  195. AND m.visible = #{visible}
  196. </if>
  197. <if test="status != null and status != ''">
  198. AND m.status = #{status}
  199. </if>
  200. <if test="tenantName != null and tenantName != ''">
  201. AND t.tenant_name like concat('%', #{tenantName}, '%')
  202. </if>
  203. order by m.parent_id, m.order_num
  204. </select>
  205. <select id="selectMenuTreeByUserId" parameterType="Long" resultMap="SysMenuResult">
  206. select distinct m.menu_id,
  207. m.parent_id,
  208. m.menu_name,
  209. m.path,
  210. m.component,
  211. m.`query`,
  212. m.visible,
  213. m.status,
  214. ifnull(m.perms, '') as perms,
  215. m.is_frame,
  216. m.is_cache,
  217. m.menu_type,
  218. m.icon,
  219. m.order_num,
  220. m.create_time
  221. from sys_menu m
  222. left join sys_role_menu rm on m.menu_id = rm.menu_id
  223. left join sys_user_role ur on rm.role_id = ur.role_id
  224. left join sys_role ro on ur.role_id = ro.role_id
  225. left join sys_user u on ur.user_id = u.user_id
  226. where u.user_id = #{userId}
  227. and m.menu_type in ('M', 'C')
  228. and m.status = 0
  229. AND ro.status = 0
  230. order by m.parent_id, m.order_num
  231. </select>
  232. <select id="selectMenuListByRoleId" resultType="Long">
  233. select m.menu_id
  234. from sys_menu m
  235. left join sys_role_menu rm on m.menu_id = rm.menu_id
  236. where rm.role_id = #{roleId}
  237. <if test="menuCheckStrictly">
  238. and m.menu_id not in (select m.parent_id from sys_menu m inner join sys_role_menu rm on m.menu_id =
  239. rm.menu_id and rm.role_id = #{roleId})
  240. </if>
  241. order by m.parent_id, m.order_num
  242. </select>
  243. <select id="selectMenuPerms" resultType="String">
  244. select distinct m.perms
  245. from sys_menu m
  246. left join sys_role_menu rm on m.menu_id = rm.menu_id
  247. left join sys_user_role ur on rm.role_id = ur.role_id
  248. </select>
  249. <select id="selectMenuPermsByUserId" parameterType="Long" resultType="String">
  250. select distinct m.perms
  251. from sys_menu m
  252. left join sys_role_menu rm on m.menu_id = rm.menu_id
  253. left join sys_user_role ur on rm.role_id = ur.role_id
  254. left join sys_role r on r.role_id = ur.role_id
  255. where m.status = '0'
  256. and r.status = '0'
  257. and ur.user_id = #{userId}
  258. </select>
  259. <select id="selectMenuPermsByRoleId" parameterType="Long" resultType="String">
  260. select distinct m.perms
  261. from sys_menu m
  262. left join sys_role_menu rm on m.menu_id = rm.menu_id
  263. where m.status = '0'
  264. and rm.role_id = #{roleId}
  265. </select>
  266. <select id="selectMenuById" parameterType="Long" resultMap="SysMenuResult">
  267. <include refid="selectMenuVo"/>
  268. where menu_id = #{menuId}
  269. </select>
  270. <select id="hasChildByMenuId" resultType="Integer">
  271. select count(1)
  272. from sys_menu
  273. where parent_id = #{menuId}
  274. </select>
  275. <select id="hasChildByMenuIdBatchRemove" resultType="Integer" parameterType="java.util.List">
  276. select count(1) from sys_menu where parent_id in
  277. <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
  278. #{item}
  279. </foreach>
  280. </select>
  281. <!-- <include refid="selectMenuVo"/>-->
  282. <select id="checkMenuNameUnique" parameterType="SysMenu" resultMap="SysMenuResult">
  283. SELECT sys.menu_id,
  284. sys.menu_name,
  285. sys.parent_id,
  286. sys.order_num,
  287. sys.path,
  288. sys.component,
  289. sys.`query`,
  290. sys.is_frame,
  291. sys.is_cache,
  292. sys.menu_type,
  293. sys.visible,
  294. sys.STATUS,
  295. ifnull(sys.perms, '') AS perms,
  296. sys.icon,
  297. sys.create_time
  298. FROM sys_menu AS sys
  299. LEFT JOIN sys_tenant_menu AS tenant ON sys.menu_id = tenant.menu_id
  300. WHERE sys.menu_name = #{menuName}
  301. AND sys.parent_id = #{parentId}
  302. <if test="tenantId != null and tenantId != ''">
  303. AND tenant.tenant_id = #{tenantId}
  304. </if>
  305. LIMIT 1
  306. </select>
  307. <update id="updateMenu" parameterType="SysMenu">
  308. update sys_menu
  309. <set>
  310. <if test="menuName != null and menuName != ''">menu_name = #{menuName},</if>
  311. <if test="parentId != null">parent_id = #{parentId},</if>
  312. <if test="orderNum != null">order_num = #{orderNum},</if>
  313. <if test="path != null and path != ''">path = #{path},</if>
  314. <if test="component != null">component = #{component},</if>
  315. <if test="query != null">`query` = #{query},</if>
  316. <if test="isFrame != null and isFrame != ''">is_frame = #{isFrame},</if>
  317. <if test="isCache != null and isCache != ''">is_cache = #{isCache},</if>
  318. <if test="menuType != null and menuType != ''">menu_type = #{menuType},</if>
  319. <if test="visible != null">visible = #{visible},</if>
  320. <if test="status != null">status = #{status},</if>
  321. <if test="perms !=null">perms = #{perms},</if>
  322. <if test="icon !=null and icon != ''">icon = #{icon},</if>
  323. <if test="remark != null and remark != ''">remark = #{remark},</if>
  324. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  325. update_time = sysdate()
  326. </set>
  327. where menu_id = #{menuId}
  328. </update>
  329. <insert id="insertMenu" parameterType="SysMenu" useGeneratedKeys="true" keyProperty="menuId">
  330. insert into sys_menu(
  331. <if test="menuId != null and menuId != 0">menu_id,</if>
  332. <if test="parentId != null and parentId != 0">parent_id,</if>
  333. <if test="menuName != null and menuName != ''">menu_name,</if>
  334. <if test="orderNum != null">order_num,</if>
  335. <if test="path != null and path != ''">path,</if>
  336. <if test="component != null and component != ''">component,</if>
  337. <if test="query != null and query != ''">`query`,</if>
  338. <if test="isFrame != null and isFrame != ''">is_frame,</if>
  339. <if test="isCache != null and isCache != ''">is_cache,</if>
  340. <if test="menuType != null and menuType != ''">menu_type,</if>
  341. <if test="visible != null">visible,</if>
  342. <if test="status != null">status,</if>
  343. <if test="perms !=null and perms != ''">perms,</if>
  344. <if test="icon != null and icon != ''">icon,</if>
  345. <if test="remark != null and remark != ''">remark,</if>
  346. <if test="createBy != null and createBy != ''">create_by,</if>
  347. create_time
  348. )values(
  349. <if test="menuId != null and menuId != 0">#{menuId},</if>
  350. <if test="parentId != null and parentId != 0">#{parentId},</if>
  351. <if test="menuName != null and menuName != ''">#{menuName},</if>
  352. <if test="orderNum != null">#{orderNum},</if>
  353. <if test="path != null and path != ''">#{path},</if>
  354. <if test="component != null and component != ''">#{component},</if>
  355. <if test="query != null and query != ''">#{query},</if>
  356. <if test="isFrame != null and isFrame != ''">#{isFrame},</if>
  357. <if test="isCache != null and isCache != ''">#{isCache},</if>
  358. <if test="menuType != null and menuType != ''">#{menuType},</if>
  359. <if test="visible != null">#{visible},</if>
  360. <if test="status != null">#{status},</if>
  361. <if test="perms !=null and perms != ''">#{perms},</if>
  362. <if test="icon != null and icon != ''">#{icon},</if>
  363. <if test="remark != null and remark != ''">#{remark},</if>
  364. <if test="createBy != null and createBy != ''">#{createBy},</if>
  365. sysdate()
  366. )
  367. </insert>
  368. <delete id="deleteMenuById" parameterType="Long">
  369. delete
  370. from sys_menu
  371. where menu_id = #{menuId}
  372. </delete>
  373. <delete id="batchDeleteMenuById" parameterType="java.util.List">
  374. delete from sys_menu where menu_id in
  375. <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
  376. #{item}
  377. </foreach>
  378. </delete>
  379. <select id="getMenuList" resultMap="SysMenuResult">
  380. SELECT m.menu_id,
  381. m.menu_name,
  382. m.parent_id,
  383. m.order_num,
  384. m.path,
  385. m.component,
  386. m.`query`,
  387. m.is_frame,
  388. m.is_cache,
  389. m.menu_type,
  390. m.visible,
  391. m.STATUS,
  392. ifnull(m.perms, '') AS perms,
  393. m.icon,
  394. m.create_time
  395. FROM sys_menu m
  396. join sys_tenant_menu tm on m.menu_id = tm.menu_id
  397. where m.menu_type != 'F' and m.STATUS = '0' and tm.tenant_id = #{tenantId}
  398. </select>
  399. <select id="selectMenuByPath" parameterType="string" resultMap="SysMenuResult">
  400. <include refid="selectMenuVo"/>
  401. where path = #{path}
  402. </select>
  403. <select id="selectMenusByIds" resultMap="SysMenuResult">
  404. <include refid="selectMenuVo"></include>
  405. where menu_id in
  406. <foreach collection="list" item="id" open="(" close=")" separator=",">
  407. #{id}
  408. </foreach>
  409. </select>
  410. <insert id="insertMenuBatch" parameterType="java.util.List">
  411. INSERT INTO sys_menu (
  412. menu_id,
  413. parent_id,
  414. menu_name,
  415. order_num,
  416. path,
  417. component,
  418. `query`,
  419. is_frame,
  420. is_cache,
  421. menu_type,
  422. visible,
  423. status,
  424. perms,
  425. icon,
  426. remark,
  427. create_by,
  428. create_time
  429. ) VALUES
  430. <foreach collection="list" item="item" separator=",">
  431. (
  432. #{item.menuId},
  433. #{item.parentId},
  434. #{item.menuName},
  435. #{item.orderNum},
  436. #{item.path},
  437. #{item.component},
  438. #{item.query},
  439. #{item.isFrame},
  440. #{item.isCache},
  441. #{item.menuType},
  442. #{item.visible},
  443. #{item.status},
  444. #{item.perms},
  445. #{item.icon},
  446. #{item.remark},
  447. #{item.createBy},
  448. sysdate()
  449. )
  450. </foreach>
  451. </insert>
  452. </mapper>