<?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.book.mapper.BookSwitchMapper">
  <resultMap id="BaseResultMap" type="com.pcloud.book.book.entity.BookSwitch">
    <id column="book_id" jdbcType="BIGINT" property="bookId" />
    <result column="is_black_box_enable" jdbcType="INTEGER" property="isBlackBoxEnable" />
    <result column="is_res_share_enable" jdbcType="INTEGER" property="isResShareEnable" />
    <result column="update_user" jdbcType="BIGINT" property="updateUser" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_user" jdbcType="BIGINT" property="createUser" />
  </resultMap>
  <sql id="Base_Column_List">
    book_id, is_black_box_enable, is_res_share_enable, update_user, update_time, create_time, 
    create_user
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from book_switch
    where book_id = #{bookId,jdbcType=BIGINT}
  </select>
  <select id="listByBookIds" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from book_switch
    where book_id in
    <foreach collection="list" separator="," item="item" open="(" close=")">#{item}</foreach>
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from book_switch
    where book_id = #{bookId,jdbcType=BIGINT}
  </delete>
  <insert id="insert"  parameterType="com.pcloud.book.book.entity.BookSwitch">
    insert into book_switch (book_id,is_black_box_enable, is_res_share_enable,
      update_user, update_time, create_time,
      create_user)
    values (#{bookId,jdbcType=BIGINT},#{isBlackBoxEnable,jdbcType=INTEGER}, #{isResShareEnable,jdbcType=INTEGER},
      #{updateUser,jdbcType=BIGINT}, now(), now(),
      #{createUser,jdbcType=BIGINT})
    on duplicate key update
        is_black_box_enable=values(is_black_box_enable),
        is_res_share_enable=values(is_res_share_enable),
        update_time=now(),
      update_user=values(update_user)

  </insert>
  <insert id="insertSelective" keyColumn="book_id" keyProperty="bookId" parameterType="com.pcloud.book.book.entity.BookSwitch" useGeneratedKeys="true">
    insert into book_switch
    <trim prefix="(" suffix=")" suffixOverrides=",">
      book_id,
      <if test="isBlackBoxEnable != null">
        is_black_box_enable,
      </if>
      <if test="isResShareEnable != null">
        is_res_share_enable,
      </if>
        update_user,
        update_time,
        create_time,
        create_user
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
        #{bookId},
      <if test="isBlackBoxEnable != null">
        #{isBlackBoxEnable,jdbcType=INTEGER},
      </if>
      <if test="isResShareEnable != null">
        #{isResShareEnable,jdbcType=INTEGER},
      </if>
        #{updateUser,jdbcType=BIGINT},
        now(),
        now(),
        #{createUser,jdbcType=BIGINT}
    </trim>
    on duplicate key update
    <if test="isBlackBoxEnable != null">
    is_black_box_enable=values(is_black_box_enable),
    </if>
    <if test="isResShareEnable != null">
    is_res_share_enable=values(is_res_share_enable),
    </if>
    update_time=now(),
    update_user=values(update_user)
  </insert>
  <insert id="batchInsert" parameterType="com.pcloud.book.book.entity.BookSwitch">
    insert into book_switch (book_id,is_black_box_enable, is_res_share_enable,
                             update_user, update_time, create_time,
                             create_user)
    values
    <foreach collection="list" separator="," item="item">
      (#{item.bookId,jdbcType=BIGINT},#{item.isBlackBoxEnable,jdbcType=INTEGER}, #{item.isResShareEnable,jdbcType=INTEGER},
      #{item.updateUser,jdbcType=BIGINT}, now(), now(),
      #{item.createUser,jdbcType=BIGINT})
    </foreach>
      on duplicate key update
      is_black_box_enable=values(is_black_box_enable),
        is_res_share_enable=values(is_res_share_enable),
      update_time=now(),
        update_user=values(update_user)
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.pcloud.book.book.entity.BookSwitch">
    update book_switch
    <set>
      <if test="isBlackBoxEnable != null">
        is_black_box_enable = #{isBlackBoxEnable,jdbcType=INTEGER},
      </if>
      <if test="isResShareEnable != null">
        is_res_share_enable = #{isResShareEnable,jdbcType=INTEGER},
      </if>
      <if test="updateUser != null">
        update_user = #{updateUser,jdbcType=BIGINT},
      </if>
      <if test="updateTime != null">
        update_time = #{updateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createUser != null">
        create_user = #{createUser,jdbcType=BIGINT},
      </if>
    </set>
    where book_id = #{bookId,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.pcloud.book.book.entity.BookSwitch">
    update book_switch
    set is_black_box_enable = #{isBlackBoxEnable,jdbcType=INTEGER},
      is_res_share_enable = #{isResShareEnable,jdbcType=INTEGER},
      update_user = #{updateUser,jdbcType=BIGINT},
      update_time = #{updateTime,jdbcType=TIMESTAMP},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      create_user = #{createUser,jdbcType=BIGINT}
    where book_id = #{bookId,jdbcType=BIGINT}
  </update>
</mapper>