<?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
		)
		VALUES
			(#{bookId,jdbcType=BIGINT}, #{channelId,jdbcType=BIGINT}, #{adviserId,jdbcType=BIGINT},
			#{fileName,jdbcType=VARCHAR},#{fileUrl,jdbcType=VARCHAR},#{createUser,jdbcType=BIGINT},
			NOW())
	</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}
    </select>

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

</mapper>