<?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.BookOtherDaoImpl">

    <resultMap id="BaseResultMap" type="com.pcloud.book.book.entity.BookOther">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="book_id" property="bookId" jdbcType="BIGINT"/>
        <result column="adviser_id" property="adviserId" jdbcType="BIGINT"/>
        <result column="channel_id" property="channelId" jdbcType="BIGINT"/>
        <result column="book_name" property="bookName" jdbcType="VARCHAR"/>
        <result column="rights_setting_id" property="rightsSettingId" jdbcType="BIGINT"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, book_id, adviser_id, channel_id, book_name, rights_setting_id, create_time, update_time
    </sql>

    <select id="getById" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM book_other
        WHERE id = #{id}
    </select>

    <select id="getList" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM book_other
    </select>

    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        INSERT INTO book_other(
            book_id, 
            adviser_id, 
            channel_id, 
            book_name,
            rights_setting_id,
            create_time, 
            update_time
        ) VALUES (
            #{bookId, jdbcType=BIGINT}, 
            #{adviserId, jdbcType=BIGINT}, 
            #{channelId, jdbcType=BIGINT}, 
            #{bookName, jdbcType=VARCHAR},
            #{rightsSettingId, jdbcType=BIGINT},
            #{createTime, jdbcType=TIMESTAMP}, 
            #{updateTime, jdbcType=TIMESTAMP}
        )
    </insert>

    <insert id="batchInsert">
        INSERT INTO book_other (
        book_id,
        adviser_id,
        channel_id,
        book_name,
        create_time,
        update_time
        ) VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.bookId, jdbcType=BIGINT},
            #{item.adviserId, jdbcType=BIGINT},
            #{item.channelId, jdbcType=BIGINT},
            #{item.bookName, jdbcType=VARCHAR},
           now(),
           now()
            )
        </foreach>
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        UPDATE book_other
        <set>
            <if test="bookId != null">
                book_id = #{bookId},
            </if>
            <if test="adviserId != null">
                adviser_id = #{adviserId},
            </if>
            <if test="channelId != null">
                channel_id = #{channelId},
            </if>
            <if test="bookName != null and bookName != ''">
                book_name = #{bookName},
            </if>
            <if test="rightsSettingId != null">
                rights_setting_id = #{rightsSettingId},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
        </set>
        WHERE id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        DELETE FROM book_other where id = #{id}
    </delete>


</mapper>