<?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.LearnTestPaperMapper">
    
    <resultMap type="LearnTestPaper" id="LearnTestPaperResult">
        <result property="id"    column="id"    />
        <result property="batchId"    column="batch_id"    />
        <result property="buildType"    column="build_type"    />
        <result property="subjectId"    column="subject_id"    />
        <result property="examType"    column="exam_type"    />
        <result property="teacherId"    column="teacher_id"    />
        <result property="universityId"    column="university_id"    />
        <result property="directKey"    column="direct_key"    />
        <result property="paperId"    column="paper_id"    />
        <result property="conditions"    column="conditions"    />
        <result property="creatorId"    column="creator_id"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectLearnTestPaperVo">
        select id, batch_id, build_type, subject_id, exam_type, teacher_id, university_id, direct_key, paper_id, conditions, creator_id, create_time from learn_test_paper
    </sql>

    <select id="selectLearnTestPaperList" parameterType="LearnTestPaper" resultMap="LearnTestPaperResult">
        <include refid="selectLearnTestPaperVo"/>
        <where>  
            <if test="batchId != null "> and batch_id = #{batchId}</if>
            <if test="buildType != null "> and build_type = #{buildType}</if>
            <if test="subjectId != null "> and subject_id = #{subjectId}</if>
            <if test="examType != null "> and exam_type = #{examType}</if>
            <if test="teacherId != null "> and teacher_id = #{teacherId}</if>
            <if test="universityId != null "> and university_id = #{universityId}</if>
            <if test="directKey != null  and directKey != ''"> and direct_key = #{directKey}</if>
            <if test="paperId != null "> and paper_id = #{paperId}</if>
            <if test="conditions != null  and conditions != ''"> and conditions = #{conditions}</if>
            <if test="creatorId != null "> and creator_id = #{creatorId}</if>
        </where>
    </select>

    <select id="selectByBatchAndUniversityIds" resultMap="LearnTestPaperResult">
        <include refid="selectLearnTestPaperVo"/>
        <where> batch_id = #{batchId} and build_type = #{buildType} and subject_id = #{subjectId}
         <if test="null != teacherId">and teacher_id = #{teacherId}</if>
         <if test="null != universityIds">and university_id in <foreach item="id" collection="universityIds" open="(" separator="," close=")">#{id}</foreach></if>
        </where>
    </select>

    <select id="selectLearnTestPaperById" parameterType="String" resultMap="LearnTestPaperResult">
        <include refid="selectLearnTestPaperVo"/>
        where id = #{id}
    </select>

    <insert id="insertLearnTestPaper" parameterType="LearnTestPaper" useGeneratedKeys="true" keyProperty="id">
        insert into learn_test_paper
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="batchId != null">batch_id,</if>
            <if test="buildType != null">build_type,</if>
            <if test="subjectId != null">subject_id,</if>
            <if test="examType != null">exam_type,</if>
            <if test="teacherId != null">teacher_id,</if>
            <if test="universityId != null">university_id,</if>
            <if test="directKey != null ">direct_key,</if>
            <if test="paperId != null">paper_id,</if>
            <if test="conditions != null">conditions,</if>
            <if test="creatorId != null">creator_id,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="batchId != null">#{batchId},</if>
            <if test="buildType != null">#{buildType},</if>
            <if test="subjectId != null">#{subjectId},</if>
            <if test="examType != null">#{examType},</if>
            <if test="teacherId != null">#{teacherId},</if>
            <if test="universityId != null">#{universityId},</if>
            <if test="directKey != null">#{directKey},</if>
            <if test="paperId != null">#{paperId},</if>
            <if test="conditions != null">#{conditions},</if>
            <if test="creatorId != null">#{creatorId},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateLearnTestPaper" parameterType="LearnTestPaper">
        update learn_test_paper
        <trim prefix="SET" suffixOverrides=",">
            <if test="batchId != null">batch_id = #{batchId},</if>
            <if test="buildType != null">build_type = #{buildType},</if>
            <if test="subjectId != null">subject_id = #{subjectId},</if>
            <if test="examType != null">exam_type = #{examType},</if>
            <if test="teacherId != null">teacher_id = #{teacherId},</if>
            <if test="universityId != null">university_id = #{universityId},</if>
            <if test="directKey != null">direct_key = #{directKey},</if>
            <if test="paperId != null">paper_id = #{paperId},</if>
            <if test="conditions != null">conditions = #{conditions},</if>
            <if test="creatorId != null">creator_id = #{creatorId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteLearnTestPaperById" parameterType="String">
        delete from learn_test_paper where id = #{id}
    </delete>

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