<?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.PaperQuestionMapper">
    <insert id="save" useGeneratedKeys="true" keyProperty="id">
        insert into exam_paper_question
        (`paper_id`,`pos`,`question_id`,`score`,`pid`,`child`)
        values
        (#{paperId},#{pos},#{questionId},#{score},#{pid},#{child})
    </insert>
    <insert id="saveAll" useGeneratedKeys="true" keyProperty="id">
        insert ignore into exam_paper_question
        (`paper_id`,`pos`,`question_id`,`score`,`pid`,`child`)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.paperId},#{item.pos},#{item.questionId},#{item.score},#{item.pid},#{item.child})
        </foreach>
    </insert>

    <delete id="deleteByPaperId">
        delete from exam_paper_question
        where paper_id=#{paperId}
    </delete>

    <select id="findByPaperId" resultType="cn.reghao.tnb.content.app.exam.model.po.PaperQuestion">
        select *
        from exam_paper_question
        where paper_id=#{paperId} and pid=0
    </select>
    <select id="findByPaperIdAndPid" resultType="cn.reghao.tnb.content.app.exam.model.po.PaperQuestion">
        select *
        from exam_paper_question
        where paper_id=#{paperId} and pid=#{pid}
    </select>
</mapper>