RoleMapper.xml 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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.goafanti.common.dao.RoleMapper">
  4. <resultMap id="BaseResultMap" type="com.goafanti.common.model.Role">
  5. <id column="id" jdbcType="VARCHAR" property="id" />
  6. <result column="role_name" jdbcType="VARCHAR" property="roleName" />
  7. <result column="role_type" jdbcType="INTEGER" property="roleType" />
  8. </resultMap>
  9. <sql id="Base_Column_List">
  10. id, role_name, role_type ,creater,create_time as createTime
  11. </sql>
  12. <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
  13. select
  14. <include refid="Base_Column_List" />
  15. from role
  16. where id = #{id,jdbcType=VARCHAR}
  17. </select>
  18. <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
  19. delete from role
  20. where id = #{id,jdbcType=VARCHAR}
  21. </delete>
  22. <insert id="insert" parameterType="com.goafanti.common.model.Role">
  23. insert into role (id, role_name,creater,create_time
  24. <if test="roleType!=null">
  25. ,role_type
  26. </if>
  27. )
  28. values (#{id,jdbcType=VARCHAR}, #{roleName,jdbcType=VARCHAR},
  29. #{creater,jdbcType=VARCHAR},#{createTime,jdbcType=VARCHAR}
  30. <if test="roleType!=null">
  31. ,#{roleType}
  32. </if>
  33. )
  34. ON DUPLICATE KEY UPDATE
  35. role_name = values(role_name)
  36. <if test="roleType!=null">
  37. ,role_type=#{roleType}
  38. </if>
  39. </insert>
  40. <insert id="insertSelective" parameterType="com.goafanti.common.model.Role">
  41. insert into role
  42. <trim prefix="(" suffix=")" suffixOverrides=",">
  43. <if test="id != null">
  44. id,
  45. </if>
  46. <if test="roleName != null">
  47. role_name,
  48. </if>
  49. <if test="roleType != null">
  50. role_type,
  51. </if>
  52. </trim>
  53. <trim prefix="values (" suffix=")" suffixOverrides=",">
  54. <if test="id != null">
  55. #{id,jdbcType=VARCHAR},
  56. </if>
  57. <if test="roleName != null">
  58. #{roleName,jdbcType=VARCHAR},
  59. </if>
  60. <if test="roleType != null">
  61. #{roleType,jdbcType=INTEGER},
  62. </if>
  63. </trim>
  64. </insert>
  65. <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.Role">
  66. update role
  67. <set>
  68. <if test="roleName != null">
  69. role_name = #{roleName,jdbcType=VARCHAR},
  70. </if>
  71. <if test="roleType != null">
  72. role_type = #{roleType,jdbcType=INTEGER},
  73. </if>
  74. </set>
  75. where id = #{id,jdbcType=VARCHAR}
  76. </update>
  77. <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.Role">
  78. update role
  79. set role_name = #{roleName,jdbcType=VARCHAR},
  80. role_type = #{roleType,jdbcType=INTEGER}
  81. where id = #{id,jdbcType=VARCHAR}
  82. </update>
  83. <insert id="insertBatch" parameterType="com.goafanti.common.model.Role">
  84. insert into role (id, name)
  85. values
  86. <foreach item="item" index="index" collection="list" separator=",">
  87. (#{item.id,jdbcType=VARCHAR}, #{item.name,jdbcType=VARCHAR})
  88. </foreach>
  89. ON DUPLICATE KEY UPDATE
  90. name = values(name)
  91. </insert>
  92. <select id="findRolePermissions" resultType="com.goafanti.permission.bo.RolePermissionBo">
  93. select tr.id as rid, tr.role_name as rname, tr.role_type,tp.id as pid,tp.name as pname,tp.url
  94. from role tr
  95. left join role_permission trp on trp.rid=tr.id
  96. left join permission tp on tp.id=trp.pid
  97. where tr.role_type <![CDATA[ < ]]> 999999
  98. </select>
  99. <select id="findRolePermissionsExceptAreaManager" resultType="com.goafanti.permission.bo.RolePermissionBo">
  100. select tr.id as rid, tr.role_name as rname, tr.role_type,tp.id as pid,tp.name as pname,tp.url
  101. from role tr
  102. left join role_permission trp on trp.rid=tr.id
  103. left join permission tp on tp.id=trp.pid
  104. where tr.role_type <![CDATA[ < ]]> 99999
  105. </select>
  106. <select id="findRoleByUserId" resultType="java.lang.String">
  107. select tr.role_type from role tr
  108. left join user_role tur on tur.rid=tr.id
  109. where tur.uid = #{userId,jdbcType=VARCHAR}
  110. </select>
  111. <select id="selectByAid" resultType="com.goafanti.common.model.Role">
  112. select tr.id, tr.role_name roleName, tr.role_type roleType ,tr.creater,tr.create_time as createTime
  113. from role tr
  114. left join user_role tur on tur.rid=tr.id
  115. where tur.uid = #{userId,jdbcType=VARCHAR}
  116. </select>
  117. <delete id="deleteByPrimaryKeys" parameterType="java.lang.String">
  118. delete from role
  119. where id in
  120. <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
  121. #{item,jdbcType=VARCHAR}
  122. </foreach>
  123. </delete>
  124. <!-- ******************************************************************** -->
  125. <select id="selectRoleList" resultType="com.goafanti.permission.bo.RoleBo">
  126. select id,role_name as roleName,role_type as roleType,creater,create_time as createTime
  127. from role
  128. where role_type <![CDATA[ < ]]> 999999
  129. <if test="roleName !=null">
  130. AND role_name like CONCAT('%',#{roleName,jdbcType=VARCHAR},'%')
  131. </if>
  132. <if test="page_sql != null">
  133. ${page_sql}
  134. </if>
  135. </select>
  136. <select id="selectRoleCount" resultType="java.lang.Integer">
  137. select
  138. count(0)
  139. from role
  140. where
  141. 1=1
  142. <if test="roleName !=null">
  143. AND role_name like CONCAT('%',#{roleName,jdbcType=VARCHAR},'%')
  144. </if>
  145. </select>
  146. <select id="selectRolePList" resultType="com.goafanti.permission.bo.RolePermissionBo">
  147. select tr.id as rid, tr.role_name as rname, tr.role_type,tp.id as pid,tp.name as pname,tp.url
  148. from role tr
  149. left join role_permission trp on trp.rid=tr.id
  150. left join permission tp on tp.id=trp.pid
  151. where
  152. tr.id=#{id,jdbcType=VARCHAR}
  153. </select>
  154. <select id="selectCountByRoleId" parameterType="java.lang.String" resultType="java.lang.Integer">
  155. select
  156. count(0)
  157. from user_role
  158. where
  159. rid in
  160. <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
  161. #{item,jdbcType=VARCHAR}
  162. </foreach>
  163. </select>
  164. <select id="selectIdByName" parameterType="java.lang.String" resultType="java.lang.String">
  165. select
  166. id
  167. from role
  168. where
  169. role_name=#{roleName,jdbcType=VARCHAR}
  170. </select>
  171. <select id="selectNameById" parameterType="java.lang.String" resultType="java.lang.String">
  172. select
  173. role_name as roleName
  174. from role
  175. where
  176. id=#{id,jdbcType=VARCHAR}
  177. </select>
  178. <select id="selectIdByNamei" parameterType="com.goafanti.common.model.Role" resultType="java.lang.String">
  179. select
  180. id
  181. from role
  182. where
  183. role_name=#{roleName,jdbcType=VARCHAR}
  184. and
  185. id!=#{id,jdbcType=VARCHAR}
  186. </select>
  187. <select id="selectByIdList" resultMap="BaseResultMap">
  188. select
  189. <include refid="Base_Column_List" />
  190. from role where id in
  191. <foreach item="item" index="index" collection="list" open="(" separator="," close=")">
  192. #{item,jdbcType=VARCHAR}
  193. </foreach>
  194. </select>
  195. </mapper>