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

    <resultMap id="BaseResultMap" type="com.pcloud.book.book.entity.NoviceGuideDelete">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="adviser_id" property="adviserId" jdbcType="BIGINT"/>
        <result column="book_id" property="bookId" 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, adviser_id, book_id, create_time, update_time        
    </sql>

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

    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        INSERT INTO novice_guide_delete(
            adviser_id,
            book_id,
            create_time,
            update_time
        ) VALUES (
            #{adviserId, jdbcType=BIGINT},
            #{bookId, jdbcType=BIGINT},
            now(),
            now()
        )
    </insert>
    
    <insert id="batchInsert" keyProperty="id" useGeneratedKeys="true">
        INSERT INTO novice_guide_delete (
            adviser_id,
            book_id,
            create_time,
            update_time
        ) VALUES 
        <foreach collection="list" item="item" separator=",">
        (
            #{item.adviserId, jdbcType=BIGINT},
            #{item.bookId, jdbcType=BIGINT},
            now(),
            now()
        )
        </foreach>
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        UPDATE novice_guide_delete
        <set>
            <if test="adviserId != null">
                adviser_id = #{adviserId},
            </if>
            <if test="bookId != null">
                book_id = #{bookId},
            </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 novice_guide_delete WHERE id = #{id}
    </delete>

    <select id="getDeleteBookIds" parameterType="map" resultType="Long">
        select distinct book_id
        from novice_guide_delete
        where adviser_id=#{adviserId}
    </select>

</mapper>