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

	<insert id="insert" useGeneratedKeys="true"  keyProperty="id" parameterType="BookAuthCodeImportRecord">
		INSERT INTO BOOK_AUTH_CODE_IMPORT_RECORD (
		BOOK_ID, CHANNEL_ID,ADVISER_ID,FILE_NAME,FILE_URL,CREATE_USER, CREATE_TIME, is_paper_book, is_group_book
		)
		VALUES
			(#{bookId,jdbcType=BIGINT}, #{channelId,jdbcType=BIGINT}, #{adviserId,jdbcType=BIGINT},
			#{fileName,jdbcType=VARCHAR},#{fileUrl,jdbcType=VARCHAR},#{createUser,jdbcType=BIGINT},
			NOW(), #{isPaperBook}, #{isGroupBook})
	</insert>

	<select id="importCodeRecord" resultType="importRecordVO" parameterType="map">
        SELECT
           ID, BOOK_ID bookId, CHANNEL_ID channelId,ADVISER_ID adviserId,FILE_NAME fileName,FILE_URL fileUrl,CREATE_TIME createTime, is_finish isFinish
        FROM
           BOOK_AUTH_CODE_IMPORT_RECORD
        WHERE
           BOOK_ID = #{bookId, jdbcType=BIGINT}
        AND
           CHANNEL_ID = #{channelId, jdbcType=BIGINT}
        AND
           ADVISER_ID = #{adviserId, jdbcType=BIGINT}
        <if test="isPaperBook != null">
            AND
            is_paper_book = #{isPaperBook}
        </if>
        <if test="isGroupBook!=null">
            AND
            is_group_book = #{isGroupBook}
        </if>
    </select>

    <update id="updateState" parameterType="map">
        UPDATE
          BOOK_AUTH_CODE_IMPORT_RECORD
        SET
            is_finish = #{state},
            update_time = now()
        WHERE
            ID = #{id}
    </update>

</mapper>