You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
4.4 KiB

4 months ago
3 weeks ago
4 months ago
3 weeks ago
3 weeks ago
3 weeks ago
4 months ago
3 weeks ago
4 months ago
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.example.demo.mapper.coin.RoleMapper">
  4. <update id="updateRole">
  5. UPDATE role
  6. <set>
  7. <if test="roleName != null">
  8. role_name = #{roleName},
  9. </if>
  10. <if test="market != null">
  11. market = #{market},
  12. </if>
  13. <if test="channel != null">
  14. channel = #{channel},
  15. </if>
  16. <if test="fatherId != null">
  17. father_id = #{fatherId},
  18. </if>
  19. </set>
  20. WHERE id = #{id}
  21. </update>
  22. <select id="selectByRoleName" resultType="com.example.demo.domain.entity.Role">
  23. SELECT id FROM role
  24. <where>
  25. role_name = #{roleName}
  26. </where>
  27. limit 1
  28. </select>
  29. <select id="selectByRoleId" resultType="com.example.demo.domain.entity.Role">
  30. SELECT role_name FROM role
  31. <where>
  32. id = #{id}
  33. </where>
  34. </select>
  35. <select id="selectAllRole" resultType="com.example.demo.domain.vo.coin.RoleVo">
  36. SELECT id,role_name,market,channel FROM role
  37. <where>
  38. <!-- 判断 market 是否不为总部且 markets 不为空 -->
  39. <if test="markets != null and markets.size() > 0 and '总部' not in markets and '研发部' not in markets">
  40. AND market IN
  41. <foreach collection="markets" item="market" open="(" close=")" separator=",">
  42. #{market}
  43. </foreach>
  44. </if>
  45. </where>
  46. </select>
  47. <select id="selectByFatherId" resultType="com.example.demo.domain.vo.coin.RoleVo">
  48. SELECT id,role_name,market,channel FROM role
  49. <where>
  50. father_id = #{id}
  51. </where>
  52. ORDER BY update_time desc
  53. </select>
  54. <!-- 插入角色信息 -->
  55. <insert id="addRole" parameterType="com.example.demo.domain.vo.coin.RoleVo" useGeneratedKeys="true" keyProperty="id">
  56. INSERT INTO role
  57. (role_name,father_id, market,channel)
  58. VALUES (#{roleName}, #{fatherId}, #{market},#{channel})
  59. </insert>
  60. <!-- 删除 role_menu 表中对应角色的数据 -->
  61. <delete id="deleteRoleMenu" parameterType="Integer">
  62. DELETE FROM role_menu WHERE role_id = #{id};
  63. </delete>
  64. <!-- 删除 role 表中对应的数据 -->
  65. <delete id="deleteRole" parameterType="Integer">
  66. DELETE FROM role WHERE id = #{id};
  67. </delete>
  68. <!-- 查询筛选后角色记录 -->
  69. <select id="selectBy" resultType="com.example.demo.domain.vo.coin.RoleVo">
  70. SELECT r.id AS id,
  71. r.role_name AS roleName,
  72. r.father_id AS fatherId,
  73. r.market AS market,
  74. r.create_time AS createTime,
  75. r.update_time AS updateTime,
  76. r.channel AS channel,
  77. -- 通过自连接查询父角色名称
  78. father.role_name AS fatherName
  79. FROM role r
  80. -- 自连接,通过 father_id 关联父角色
  81. LEFT JOIN role father ON r.father_id = father.id
  82. <where>
  83. <if test="roleName != null and roleName != ''">
  84. r.role_name LIKE CONCAT('%', #{roleName}, '%')
  85. </if>
  86. <if test="market != null and market != ''">
  87. r.market LIKE CONCAT('%', #{market}, '%')
  88. </if>
  89. <!-- 判断 market 是否不为总部且 markets 不为空 -->
  90. <if test="markets != null and markets.size() > 0 and '总部' not in markets and '研发部' not in markets">
  91. AND r.market IN
  92. <foreach collection="markets" item="market" open="(" close=")" separator=",">
  93. #{market}
  94. </foreach>
  95. </if>
  96. </where>
  97. ORDER BY r.update_time DESC
  98. </select>
  99. <!--获取当前角色的上级角色-->
  100. <select id="selectFather" resultType="com.example.demo.domain.vo.coin.RoleVo">
  101. select r.id as id,
  102. r.role_name as roleName,
  103. r.market as market,
  104. r.father_id as fatherId,
  105. father.market as fatherMarket,
  106. father.role_name as fatherName
  107. from role as r
  108. -- 自连接,通过 father_id 关联父角色
  109. LEFT JOIN role as father ON r.father_id = father.id
  110. where r.id = #{id}
  111. </select>
  112. </mapper>