<?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="cn.reghao.tnb.content.app.exam.db.mapper.PaperAnswerMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert into exam_paper_answer
        (`result_id`,`pos`,`pid`,`question_id`,`question_type`,`answer`,`correct`,`score`,`review`)
        values
        (#{resultId},#{pos},#{pid},#{questionId},#{questionType},#{answer},#{correct},#{score},#{review})
    </insert>
    <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
        insert ignore into exam_paper_answer
        (`result_id`,`pos`,`pid`,`question_id`,`question_type`,`answer`,`correct`,`score`,`review`)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.resultId},#{item.pos},#{item.pid},#{item.questionId},#{item.questionType},#{item.answer},#{item.correct},#{item.score},#{item.review})
        </foreach>
    </insert>

    <update id="updatePaperAnswer">
        update exam_paper_answer
        set score=#{score},review=#{review}
        where result_id=#{resultId} and question_id=#{questionId}
    </update>

    <delete id="deleteByResultId">
        delete from exam_paper_answer
        where result_id=#{resultId}
    </delete>

    <select id="findByResultId" resultType="cn.reghao.tnb.content.app.exam.model.po.PaperAnswer">
        select *
        from exam_paper_answer
        where result_id=#{resultId}
    </select>
</mapper>