<?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.advertising.dao.impl.AdvertisingBrandBookDaoImpl">

    <resultMap id="BaseResultMap" type="com.pcloud.book.advertising.entity.AdvertisingBrandBook" >
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="bookId" column="book_id" jdbcType="BIGINT"/>
        <result property="advertisingBrandId" column="advertising_brand_id" jdbcType="BIGINT"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List" >
      id,book_id,advertising_brand_id,create_time
  </sql>

    <!--新增所有列-->
    <insert id="insert" parameterType="com.pcloud.book.advertising.entity.AdvertisingBrandBook" useGeneratedKeys="true" keyProperty="id">
        insert into advertising_brand_book (book_id, advertising_brand_id,create_time)
        values (#{bookId}, #{advertisingBrandId},NOW())
    </insert>

    <delete id="deleteByBookId" parameterType="long">
        delete  from advertising_brand_book
        where book_id=#{bookId}
    </delete>

    <insert id="batchInsert"  parameterType="com.pcloud.book.advertising.entity.AdvertisingBrandBook" useGeneratedKeys="true" keyProperty="id">
        insert into advertising_brand_book (
        book_id, advertising_brand_id,create_time
        ) values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.bookId}, #{item.advertisingBrandId},NOW()
            )
        </foreach>
    </insert>

    <delete id="deleteByBookIds" parameterType="long">
        delete  from advertising_brand_book
        where book_id in
        <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
            ${item}
        </foreach>
    </delete>

    <select id="getByBookIds" parameterType="long" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/> from advertising_brand_book
        where book_id in
        <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
            ${item}
        </foreach>
    </select>

    <select id="getBookIdsByAdvertisingBrandId" parameterType="long" resultType="long">
        select book_id from advertising_brand_book
        where advertising_brand_id=#{advertisingBrandId}
    </select>

    <delete id="deleteByAdvertisingBrandId" parameterType="long">
        delete  from advertising_brand_book
        where advertising_brand_id=#{advertisingBrandId}
    </delete>

</mapper>