<?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.BusExamUserResultMapper">
    
    <resultMap type="BusExamUserResult" id="BusExamUserResultResult">
        <result property="examUserId"    column="exam_user_id"    />
        <result property="questionId"    column="question_id"    />
        <result property="answers"    column="answers"    />
        <result property="sortBy"    column="sort_by"    />
        <result property="useRes"    column="use_res"    />
        <result property="useMark"    column="use_mark"    />
    </resultMap>

    <sql id="selectBusExamUserResultVo">
        select exam_user_id, question_id, answers, sort_by, use_res, use_mark from bus_exam_user_result
    </sql>

    <select id="selectBusExamUserResultList" parameterType="BusExamUserResult" resultMap="BusExamUserResultResult">
        <include refid="selectBusExamUserResultVo"/>
        <where>  
            <if test="examUserId != null "> and exam_user_id = #{examUserId}</if>
            <if test="questionId != null "> and question_id = #{questionId}</if>
            <if test="answers != null  and answers != ''"> and answers = #{answers}</if>
            <if test="sortBy != null "> and sort_by = #{sortBy}</if>
            <if test="useRes != null  and useRes != ''"> and use_res = #{useRes}</if>
            <if test="useMark != null  and useMark != ''"> and use_mark = #{useMark}</if>
        </where>
    </select>
    
    <select id="selectBusExamUserResultByExamUserId" parameterType="Long" resultMap="BusExamUserResultResult">
        <include refid="selectBusExamUserResultVo"/>
        where exam_user_id = #{examUserId}
    </select>
        
    <insert id="insertBusExamUserResult" parameterType="BusExamUserResult">
        insert into bus_exam_user_result
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="examUserId != null">exam_user_id,</if>
            <if test="questionId != null">question_id,</if>
            <if test="answers != null">answers,</if>
            <if test="sortBy != null">sort_by,</if>
            <if test="useRes != null">use_res,</if>
            <if test="useMark != null">use_mark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="examUserId != null">#{examUserId},</if>
            <if test="questionId != null">#{questionId},</if>
            <if test="answers != null">#{answers},</if>
            <if test="sortBy != null">#{sortBy},</if>
            <if test="useRes != null">#{useRes},</if>
            <if test="useMark != null">#{useMark},</if>
         </trim>
    </insert>

    <update id="updateBusExamUserResult" parameterType="BusExamUserResult">
        update bus_exam_user_result
        <trim prefix="SET" suffixOverrides=",">
            <if test="questionId != null">question_id = #{questionId},</if>
            <if test="answers != null">answers = #{answers},</if>
            <if test="sortBy != null">sort_by = #{sortBy},</if>
            <if test="useRes != null">use_res = #{useRes},</if>
            <if test="useMark != null">use_mark = #{useMark},</if>
        </trim>
        where exam_user_id = #{examUserId}
    </update>

    <delete id="deleteBusExamUserResultByExamUserId" parameterType="Long">
        delete from bus_exam_user_result where exam_user_id = #{examUserId}
    </delete>

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