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

    <resultMap type="com.pcloud.book.book.entity.SeriesBookRecord" id="SeriesBookRecordMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="userId" column="user_id" jdbcType="INTEGER"/>
        <result property="seriesBookId" column="series_book_id" jdbcType="INTEGER"/>
        <result property="bookId" column="book_id" jdbcType="INTEGER"/>
        <result property="channelId" column="channel_id" jdbcType="INTEGER"/>
        <result property="adviserId" column="adviser_id" jdbcType="INTEGER"/>
        <result property="recordType" column="record_type" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <!--查询单个-->
    <select id="getById" resultMap="SeriesBookRecordMap">
        select
          id, user_id, series_book_id, book_id, channel_id, adviser_id, record_type, create_time
        from book.series_book_record
        where id = #{id}
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into book.series_book_record(user_id, series_book_id, book_id, channel_id, adviser_id, record_type, create_time)
        values (#{userId}, #{seriesBookId}, #{bookId}, #{channelId}, #{adviserId}, #{recordType}, now())
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update book.series_book_record
        <set>
            <if test="userId != null">
                user_id = #{userId},
            </if>
            <if test="seriesBookId != null">
                series_book_id = #{seriesBookId},
            </if>
            <if test="bookId != null">
                book_id = #{bookId},
            </if>
            <if test="channelId != null">
                channel_id = #{channelId},
            </if>
            <if test="adviserId != null">
                adviser_id = #{adviserId},
            </if>
            <if test="recordType != null">
                record_type = #{recordType},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
        </set>
        where id = #{id}
    </update>

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

</mapper>