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

    <resultMap type="com.pcloud.book.book.entity.BookLabelTrimRelate" id="BookLabelTrimRelateMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="bookId" column="book_id" jdbcType="INTEGER"/>
        <result property="label1" column="label1" jdbcType="VARCHAR"/>
        <result property="label2" column="label2" jdbcType="VARCHAR"/>
        <result property="label3" column="label3" jdbcType="VARCHAR"/>
        <result property="label4" column="label4" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <!--查询单个-->
    <select id="getById" resultMap="BookLabelTrimRelateMap">
        select
          id, book_id, label1, label2, label3, label4, create_time, update_time
        from book.book_label_trim_relate
        where id = #{id}
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into book.book_label_trim_relate(book_id, label1, label2, label3, label4, create_time, update_time)
        values (#{bookId}, #{label1}, #{label2}, #{label3}, #{label4}, now(), now())
    </insert>

    <insert id="batchInsert" keyProperty="id" useGeneratedKeys="true">
        insert into book.book_label_trim_relate(book_id, label1, label2, label3, label4, create_time, update_time)
        values
        <foreach collection="list" item="item" separator="," index="index">
            (#{item.bookId}, #{item.label1}, #{item.label2}, #{item.label3}, #{item.label4}, now(), now())
        </foreach>
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update book.book_label_trim_relate
        <set>
            <if test="bookId != null">
                book_id = #{bookId},
            </if>
            <if test="label1 != null">
                label1 = #{label1},
            </if>
            <if test="label2 != null">
                label2 = #{label2},
            </if>
            <if test="label3 != null">
                label3 = #{label3},
            </if>
            <if test="label4 != null">
                label4 = #{label4},
            </if>
                update_time = now(),
        </set>
        where id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from book.book_label_trim_relate where id = #{id}
    </delete>

    <select id="mapBookTrimLabel" resultMap="BookLabelTrimRelateMap" parameterType="map">
         select
          id, book_id, label1, label2, label3, label4
        from book.book_label_trim_relate
        where book_id IN
        <foreach collection="bookIds" index="index" separator="," item="item" open="(" close=")">
            #{item}
        </foreach>
    </select>
</mapper>