<?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.model.mapper.ExaminationMapper">
    
    <resultMap type="Examination" id="ExaminationResult">
        <result property="examinationId"    column="examination_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="examinationQuestions"    column="examination_questions"    />
        <result property="examinationTypeId"    column="examination_type_id"    />
        <result property="reamk"    column="reamk"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <resultMap id="ExaminationVoResult" type="com.ruoyi.model.vo.ExaminationVo">
        <result property="examinationId"    column="examination_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="examinationQuestions"    column="examination_questions"    />
        <result property="examinationTypeId"    column="examination_type_id"    />
        <result property="reamk"    column="reamk"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <collection property="children" ofType="com.ruoyi.model.domain.Answer">
            <result property="answerId"    column="answer_id"    />
            <result property="answerCorrect"    column="answer_correct"    />
            <result property="answerExaminationId"    column="answer_examination_id"    />
            <result property="answerRed"    column="answer_red"    />
            <result property="createBy"    column="create_by"    />
            <result property="createTime"    column="create_time"    />
            <result property="delFlag"    column="del_flag"    />
            <result property="reamk"    column="reamk"    />
            <result property="updateBy"    column="update_by"    />
            <result property="updateTime"    column="update_time"    />
        </collection>
    </resultMap>

    <sql id="selectExaminationVo">
        select examination_id, create_by, create_time, del_flag, examination_questions, examination_type_id, reamk, update_by, update_time from examination
    </sql>

    <select id="selectExaminationList" parameterType="Examination" resultMap="ExaminationResult">
        <include refid="selectExaminationVo"/>
        <where>  
            <if test="examinationQuestions != null  and examinationQuestions != ''"> and examination_questions = #{examinationQuestions}</if>
            <if test="examinationTypeId != null "> and examination_type_id = #{examinationTypeId}</if>
            <if test="reamk != null  and reamk != ''"> and reamk = #{reamk}</if>
        </where>
    </select>
    
    <select id="selectExaminationByExaminationId" parameterType="Long" resultMap="ExaminationResult">
        <include refid="selectExaminationVo"/>
        where examination_id = #{examinationId}
    </select>
    <select id="getExaminationType" resultMap="ExaminationVoResult">
        select
            *
        from
            examination ex
        left join answer an on ex.examination_id = an.answer_examination_id
        where ex.examination_type_id = #{examinationTypeId}
    </select>

    <insert id="insertExamination" parameterType="Examination">
        insert into examination
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="examinationId != null">examination_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="examinationQuestions != null">examination_questions,</if>
            <if test="examinationTypeId != null">examination_type_id,</if>
            <if test="reamk != null">reamk,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="examinationId != null">#{examinationId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="examinationQuestions != null">#{examinationQuestions},</if>
            <if test="examinationTypeId != null">#{examinationTypeId},</if>
            <if test="reamk != null">#{reamk},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateExamination" parameterType="Examination">
        update examination
        <trim prefix="SET" suffixOverrides=",">
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="examinationQuestions != null">examination_questions = #{examinationQuestions},</if>
            <if test="examinationTypeId != null">examination_type_id = #{examinationTypeId},</if>
            <if test="reamk != null">reamk = #{reamk},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where examination_id = #{examinationId}
    </update>

    <delete id="deleteExaminationByExaminationId" parameterType="Long">
        delete from examination where examination_id = #{examinationId}
    </delete>

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