<?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.pcloud.book.rightsSetting.mapper.RightsSettingBookRelationMapper" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.rightsSetting.entity.RightsSettingBookRelation" >
    <id column="id" property="id" jdbcType="BIGINT" />
    <result column="rights_setting_id" property="rightsSettingId" jdbcType="BIGINT" />
    <result column="book_id" property="bookId" jdbcType="BIGINT" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
    <result column="book_name" property="bookName" jdbcType="VARCHAR" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, rights_setting_id, book_id, create_time, update_time
  </sql>
  <sql id="Base_Column_List_owm" >
    r.id, r.rights_setting_id, r.book_id, r.create_time, r.update_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
    select 
    <include refid="Base_Column_List" />
    from rights_setting_book_relation
    where id = #{id,jdbcType=BIGINT}
  </select>
  <select id="selectByRithsSettingId" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from rights_setting_book_relation
    where rights_setting_id = #{rightsSettingId,jdbcType=BIGINT}
  </select>
  <select id="getAllBookIds" resultType="java.lang.Long">
    select book_id
    from
    rights_setting_book_relation
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
    delete from rights_setting_book_relation
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByRightsSettingId" parameterType="long">
    delete from rights_setting_book_relation
    where rights_setting_id = #{rightsSettingId,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.pcloud.book.rightsSetting.entity.RightsSettingBookRelation" >
    insert into rights_setting_book_relation (id, rights_setting_id, book_id, 
      create_time, update_time)
    values (#{id,jdbcType=BIGINT}, #{rightsSettingId,jdbcType=BIGINT}, #{bookId,jdbcType=BIGINT}, 
      #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.pcloud.book.rightsSetting.entity.RightsSettingBookRelation" >
    insert into rights_setting_book_relation
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="rightsSettingId != null" >
        rights_setting_id,
      </if>
      <if test="bookId != null" >
        book_id,
      </if>
      <if test="createTime != null" >
        create_time,
      </if>
      <if test="updateTime != null" >
        update_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        #{id,jdbcType=BIGINT},
      </if>
      <if test="rightsSettingId != null" >
        #{rightsSettingId,jdbcType=BIGINT},
      </if>
      <if test="bookId != null" >
        #{bookId,jdbcType=BIGINT},
      </if>
      <if test="createTime != null" >
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null" >
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <insert id="batchInsert" parameterType="com.pcloud.book.rightsSetting.entity.RightsSettingBookRelation">
    insert into rights_setting_book_relation (rights_setting_id, book_id,
    create_time, update_time)
    values
    <foreach collection="list" index="index" item="item" separator=",">
    (#{item.rightsSettingId,jdbcType=BIGINT}, #{item.bookId,jdbcType=BIGINT},
    now(),now())
    </foreach>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.pcloud.book.rightsSetting.entity.RightsSettingBookRelation" >
    update rights_setting_book_relation
    <set >
      <if test="rightsSettingId != null" >
        rights_setting_id = #{rightsSettingId,jdbcType=BIGINT},
      </if>
      <if test="bookId != null" >
        book_id = #{bookId,jdbcType=BIGINT},
      </if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="updateTime != null" >
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.pcloud.book.rightsSetting.entity.RightsSettingBookRelation" >
    update rights_setting_book_relation
    set rights_setting_id = #{rightsSettingId,jdbcType=BIGINT},
      book_id = #{bookId,jdbcType=BIGINT},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <select id="selectBookByRithsSettingId" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List_owm" />,b.book_name
    from rights_setting_book_relation r
    left join book b on r.book_id = b.book_Id
    where rights_setting_id = #{_parameter}
  </select>
</mapper>