<?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.custom.mapper.CustomTimeControlBookMapper" >
  <resultMap id="BaseResultMap" type="com.pcloud.book.custom.entity.CustomTimeControlBook" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="custom_time_control_id" property="customTimeControlId" jdbcType="INTEGER" />
    <result column="book_id" property="bookId" jdbcType="VARCHAR" />
    <result column="read_type" property="readType" jdbcType="TINYINT" />
    <result column="create_time" property="createTime" jdbcType="TIMESTAMP" />
    <result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, custom_time_control_id, book_id, read_type, create_time, update_time
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" />
    from custom_time_control_book
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
    delete from custom_time_control_book
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.pcloud.book.custom.entity.CustomTimeControlBook" >
    insert into custom_time_control_book (id, custom_time_control_id, book_id, 
      read_type, create_time, update_time
      )
    values (#{id,jdbcType=INTEGER}, #{customTimeControlId,jdbcType=INTEGER}, #{bookId,jdbcType=VARCHAR},
      #{readType,jdbcType=TINYINT}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.pcloud.book.custom.entity.CustomTimeControlBook" >
    insert into custom_time_control_book
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="id != null" >
        id,
      </if>
      <if test="customTimeControlId != null" >
        custom_time_control_id,
      </if>
      <if test="bookId != null" >
        book_id,
      </if>
      <if test="readType != null" >
        read_type,
      </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=INTEGER},
      </if>
      <if test="customTimeControlId != null" >
        #{customTimeControlId,jdbcType=INTEGER},
      </if>
      <if test="bookId != null" >
        #{bookId,jdbcType=VARCHAR},
      </if>
      <if test="readType != null" >
        #{readType,jdbcType=TINYINT},
      </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.custom.entity.CustomTimeControlBook">
    insert into custom_time_control_book (custom_time_control_id, book_id,
    read_type, create_time, update_time
    )
    values
    <foreach collection="list" item="item" index="index" separator=",">
    (#{item.customTimeControlId,jdbcType=INTEGER}, #{item.bookId,jdbcType=VARCHAR},
    #{item.readType,jdbcType=TINYINT}, now(), #{item.updateTime,jdbcType=TIMESTAMP}
    )
    </foreach>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.pcloud.book.custom.entity.CustomTimeControlBook" >
    update custom_time_control_book
    <set >
      <if test="customTimeControlId != null" >
        custom_time_control_id = #{customTimeControlId,jdbcType=INTEGER},
      </if>
      <if test="bookId != null" >
        book_id = #{bookId,jdbcType=VARCHAR},
      </if>
      <if test="readType != null" >
        read_type = #{readType,jdbcType=TINYINT},
      </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=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.pcloud.book.custom.entity.CustomTimeControlBook" >
    update custom_time_control_book
    set custom_time_control_id = #{customTimeControlId,jdbcType=INTEGER},
      book_id = #{bookId,jdbcType=VARCHAR},
      read_type = #{readType,jdbcType=TINYINT},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      update_time = #{updateTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <select id="getCountByCustomTimeControlId" parameterType="integer" resultType="integer">
    select
    count(id)
    from
    custom_time_control_book
    where
    custom_time_control_id  = #{_parameter}
  </select>

  <select id="getBookListByCustomTimeControlId" parameterType="integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from
    custom_time_control_book
    where
    custom_time_control_id  = #{_parameter}
  </select>

  <delete id="deleteByCustomTimeControlId" parameterType="integer">
    delete
    from
    custom_time_control_book
    where
    custom_time_control_id  = #{id}
  </delete>

  <select id="getBooKCountMap"  parameterType="list" resultType="com.pcloud.book.custom.dto.CustomTimeControlPageDTO" >
    select
    custom_time_control_id id
    count(id)  relatedBookCount
    from
    custom_time_control_book
    where
    custom_time_control_id  in
    <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
      #{item}
    </foreach>
  </select>

  <select id="getBooKCountList"  parameterType="list" resultType="com.pcloud.book.custom.dto.CustomTimeControlPageDTO" >
    select
    custom_time_control_id id,
    count(id)  relatedBookCount
    from
    custom_time_control_book
    where
    custom_time_control_id  in
    <foreach collection="list" index="index" item="item" open="(" separator="," close=")">
      #{item}
    </foreach>
    group by custom_time_control_id
  </select>

</mapper>