MenuMapper.xml 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4. <mapper namespace="com.tld.mapper.MenuMapper">
  5. <sql id="field">
  6. id,name,url,p_id,order_by,type,img
  7. </sql>
  8. <!-- 查询菜单 -->
  9. <select id="getMenu" resultType="com.tld.model.Menu">
  10. select
  11. <include refid="field"/>
  12. from tld_menu
  13. <trim prefix="WHERE" prefixOverrides="and |or">
  14. <if test="pId != null and pId != ''">
  15. and p_id = #{pId}
  16. </if>
  17. and type = "PC"
  18. </trim>
  19. order by order_by desc
  20. </select>
  21. <!-- 查询列表 -->
  22. <select id="getPage" resultType="com.tld.model.Menu">
  23. select
  24. a.id,
  25. a.name,
  26. a.url,
  27. a.p_id,
  28. a.order_by,
  29. a.type,
  30. a.img,
  31. a.modify_time as modifyTime,
  32. b.user_name as modifyUser
  33. from tld_menu a
  34. left join tld_user b on a.modify_user = b.id
  35. <trim prefix="WHERE" prefixOverrides="and |or">
  36. <if test="pId != null and pId != ''">
  37. and a.p_id = #{pId}
  38. </if>
  39. <if test="name != null and name != ''">
  40. and a.name like CONCAT(CONCAT('%', #{name}), '%')
  41. </if>
  42. <if test="type != null and type != ''">
  43. and a.type = #{type}
  44. </if>
  45. <if test="id != null and id != ''">
  46. and a.id = #{id}
  47. </if>
  48. </trim>
  49. order by a.order_by
  50. </select>
  51. <!-- 新增菜单 -->
  52. <insert id="addMenu">
  53. insert into tld_menu(name,url,p_id,order_by,type,img,modify_user,modify_time) values(#{name},#{url},#{pId},#{orderBy},#{type},#{img},#{modifyUser},NOW())
  54. </insert>
  55. <!-- 修改菜单 -->
  56. <update id="updateMenu">
  57. update tld_menu
  58. <set>
  59. <trim suffixOverrides=",">
  60. <if test="name != null">
  61. name = #{name},
  62. </if>
  63. <if test="url != null">
  64. url = #{url},
  65. </if>
  66. <if test="pId != null">
  67. p_id = #{pId},
  68. </if>
  69. <if test="orderBy != null">
  70. order_by = #{orderBy},
  71. </if>
  72. <if test="type != null">
  73. type = #{type},
  74. </if>
  75. <if test="img != null">
  76. img = #{img},
  77. </if>
  78. modify_user = #{modifyUser},modify_time=now(),
  79. </trim>
  80. </set>
  81. where id = #{id}
  82. </update>
  83. <!-- 删除菜单 -->
  84. <delete id="delMenu">
  85. delete from tld_menu where id = #{id}
  86. </delete>
  87. <!-- 根据角色查询菜单内容 -->
  88. <select id="getUserMenu" resultType="com.tld.model.Menu">
  89. SELECT a.id,
  90. a.name,
  91. a.url,
  92. a.img,
  93. a.p_id,
  94. c.menu
  95. FROM tld_menu a
  96. JOIN tld_user b ON b.id = #{userId}
  97. JOIN tld_role c ON b.role = c.id
  98. WHERE c.menu LIKE CONCAT('%', CONCAT(a.id, ','), '%')
  99. ORDER BY a.order_by
  100. </select>
  101. <!-- 根据角色查询菜单内容PDA -->
  102. <select id="getUserMenuPDA" resultType="com.tld.model.Menu">
  103. SELECT a.id,
  104. a.name,
  105. a.url,
  106. a.p_id,
  107. c.menu_pda
  108. FROM tld_menu a
  109. JOIN tld_user b ON b.id = #{userId}
  110. JOIN tld_role c ON b.role = c.id
  111. WHERE c.menu_pda LIKE CONCAT('%', CONCAT(a.id, ','), '%')
  112. ORDER BY a.order_by
  113. </select>
  114. </mapper>