<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.tmerclub.cloud.user.mapper.UserLevelRightsMapper">
  <resultMap id="userLevelRightsMap" type="com.tmerclub.cloud.user.model.UserLevelRights">
    <id column="level_rights_id" property="levelRightsId" />
    <result column="create_time" property="createTime"/>
    <result column="user_level_id" property="userLevelId"/>
    <result column="rights_id" property="rightsId"/>
  </resultMap>
  <sql id="Vo_Column_List">
    `level_rights_id`,`create_time`,`user_level_id`,`rights_id`
  </sql>
  <insert id="saveBatch">
    <foreach collection="rightIds" item="rightId">
      insert into user_level_rights (`user_level_id`,`rights_id`)
      values (#{userLevelId},#{rightId});
    </foreach>
  </insert>
  <delete id="deleteByUserLevelId">
    delete from user_level_rights where user_level_id = #{userLevelId}
  </delete>
  <delete id="deleteByRightId">
    delete from user_level_rights where rights_id = #{rightId}
  </delete>

  <select id="listUserLevelIdByRightId" resultType="com.tmerclub.cloud.user.model.UserLevel">
    select ul.* from user_level_rights ulr
    left join user_level ul on ulr.user_level_id = ul.user_level_id
    where ulr.rights_id = #{rightId}
  </select>
</mapper>
