<?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.yanzhu.manage.mapper.BusExamInfoQuesMapper">
    
    <resultMap type="BusExamInfoQues" id="BusExamInfoQuesResult">
        <result property="examId"    column="exam_id"    />
        <result property="questionId"    column="question_id"    />
        <result property="marks"    column="marks"    />
        <result property="sortBy"    column="sort_by"    />
    </resultMap>

    <sql id="selectBusExamInfoQuesVo">
        select exam_id, question_id, marks, sort_by from bus_exam_info_ques
    </sql>

    <select id="selectBusExamInfoQuesList" parameterType="BusExamInfoQues" resultMap="BusExamInfoQuesResult">
        <include refid="selectBusExamInfoQuesVo"/>
        <where>  
            <if test="examId != null "> and exam_id = #{examId}</if>
            <if test="questionId != null "> and question_id = #{questionId}</if>
            <if test="marks != null "> and marks = #{marks}</if>
            <if test="sortBy != null "> and sort_by = #{sortBy}</if>
        </where>
    </select>
    
    <select id="selectBusExamInfoQuesByExamId" parameterType="Long" resultMap="BusExamInfoQuesResult">
        <include refid="selectBusExamInfoQuesVo"/>
        where exam_id = #{examId}
    </select>
        
    <insert id="insertBusExamInfoQues" parameterType="BusExamInfoQues">
        insert into bus_exam_info_ques
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="examId != null">exam_id,</if>
            <if test="questionId != null">question_id,</if>
            <if test="marks != null">marks,</if>
            <if test="sortBy != null">sort_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="examId != null">#{examId},</if>
            <if test="questionId != null">#{questionId},</if>
            <if test="marks != null">#{marks},</if>
            <if test="sortBy != null">#{sortBy},</if>
         </trim>
    </insert>

    <update id="updateBusExamInfoQues" parameterType="BusExamInfoQues">
        update bus_exam_info_ques
        <trim prefix="SET" suffixOverrides=",">
            <if test="questionId != null">question_id = #{questionId},</if>
            <if test="marks != null">marks = #{marks},</if>
            <if test="sortBy != null">sort_by = #{sortBy},</if>
        </trim>
        where exam_id = #{examId}
    </update>

    <delete id="deleteBusExamInfoQuesByExamId" parameterType="Long">
        delete from bus_exam_info_ques where exam_id = #{examId}
    </delete>

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