<?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.ruoyi.learn.mapper.LearnPaperQuestionMapper">
    
    <resultMap type="LearnPaperQuestion" id="LearnPaperQuestionResult">
        <result property="id"    column="id"    />
        <result property="paperId"    column="paper_id"    />
        <result property="questionId"    column="question_id"    />
        <result property="knowledgeId"    column="knowledge_id"    />
        <result property="seq"    column="seq"    />
        <result property="score"    column="score"    />
        <result property="createTime"    column="createTime"    />
    </resultMap>

    <sql id="selectLearnPaperQuestionVo">
        select id, paper_id, question_id, seq, score, createTime from learn_paper_question
    </sql>

    <select id="selectLearnPaperQuestionList" parameterType="LearnPaperQuestion" resultMap="LearnPaperQuestionResult">
        <include refid="selectLearnPaperQuestionVo"/>
        <where>  
            <if test="paperId != null "> and paper_id = #{paperId}</if>
            <if test="questionId != null "> and question_id = #{questionId}</if>
            <if test="knowledgeId != null "> and knowledge_id = #{knowledgeId}</if>
            <if test="seq != null "> and seq = #{seq}</if>
            <if test="score != null "> and score = #{score}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
        </where>
    </select>
    
    <select id="selectLearnPaperQuestionById" parameterType="Long" resultMap="LearnPaperQuestionResult">
        <include refid="selectLearnPaperQuestionVo"/>
        where id = #{id}
    </select>

    <insert id="insertLearnPaperQuestion" parameterType="LearnPaperQuestion" useGeneratedKeys="true" keyProperty="id">
        insert into learn_paper_question
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="paperId != null">paper_id,</if>
            <if test="questionId != null">question_id,</if>
            <if test="knowledgeId != null">knowledge_id,</if>
            <if test="seq != null">seq,</if>
            <if test="score != null">score,</if>
            <if test="createTime != null">createTime,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="paperId != null">#{paperId},</if>
            <if test="questionId != null">#{questionId},</if>
            <if test="knowledgeId != null">#{knowledgeId},</if>
            <if test="seq != null">#{seq},</if>
            <if test="score != null">#{score},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <insert id="batchInsert" parameterType="LearnPaperQuestion" useGeneratedKeys="true" keyProperty="id">
        insert into learn_paper_question(paper_id, question_id, knowledge_id, seq, score, createTime) VALUES
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.paperId}, #{item.questionId}, #{item.knowledgeId}, #{item.seq}, #{item.score}, #{item.createTime})
        </foreach>
    </insert>

    <update id="updateLearnPaperQuestion" parameterType="LearnPaperQuestion">
        update learn_paper_question
        <trim prefix="SET" suffixOverrides=",">
            <if test="paperId != null">paper_id = #{paperId},</if>
            <if test="questionId != null">question_id = #{questionId},</if>
            <if test="knowledgeId != null">knowledge_id = #{knowledgeId},</if>
            <if test="seq != null">seq = #{seq},</if>
            <if test="score != null">score = #{score},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteLearnPaperQuestionById" parameterType="Long">
        delete from learn_paper_question where id = #{id}
    </delete>

    <delete id="deleteLearnPaperQuestionByIds" parameterType="String">
        delete from learn_paper_question where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>