<?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.yinlihupo.enlish.service.domain.mapper.StudentExamWordsDOMapper">
    <resultMap id="BaseResultMap" type="com.yinlihupo.enlish.service.domain.dataobject.StudentExamWordsDO">
        <id column="id" jdbcType="INTEGER" property="id" />
        <result column="student_id" jdbcType="INTEGER" property="studentId" />
        <result column="exam_words_id" jdbcType="INTEGER" property="examWordsId" />
        <result column="is_completed" jdbcType="INTEGER" property="isCompleted" />
        <result column="start_data" jdbcType="TIMESTAMP" property="startData" />
    </resultMap>

    <insert id="insertStudentsExam">
        insert into student_exam_words
            (student_id, exam_words_id, is_completed, start_data)
        values
            (#{studentId}, #{examWordsId}, 0, now())
    </insert>

    <select id="selectByStudentIdAndExamWordsId" resultMap="BaseResultMap">
        select *
        from student_exam_words
        where student_id = #{studentId}
        and exam_words_id = #{examWordsId}
        and is_completed = 0
    </select>

    <update id="updateStudentExamWordsFinished">
        update student_exam_words
        set is_completed = 1
        where student_id = #{studentId}
            and exam_words_id = #{examWordsId}
            and is_completed = 0
    </update>

</mapper>