<?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.project.training.elearn.mapper.TElExamMapper">

    <resultMap type="TElExam" id="TElExamResult">
        <result property="examId"    column="exam_id"    />
        <result property="title"    column="title"    />
        <result property="content"    column="content"    />
        <result property="openType"    column="open_type"    />
        <result property="state"    column="state"    />
        <result property="timeLimit"    column="time_limit"    />
        <result property="examStartTime"    column="exam_start_time"    />
        <result property="examEndTime"    column="exam_end_time"    />
        <result property="totalScore"    column="total_score"    />
        <result property="totalTime"    column="total_time"    />
        <result property="qualifyScore"    column="qualify_score"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="deptId"    column="dept_id"    />
        <result property="remarks"    column="remarks"    />
        <result property="deptName" column="dept_name" />
        <result property="examType"    column="exam_type"    />
    </resultMap>

    <sql id="selectTElExamVo">
        select d.exam_id,d.exam_type, d.title, d.content, d.open_type, d.state, d.time_limit, d.exam_start_time, d.exam_end_time, d.total_score, d.total_time, d.qualify_score, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks from t_el_exam d
    </sql>

    <select id="selectTElExamList" parameterType="TElExam" resultMap="TElExamResult">
        <include refid="selectTElExamVo"/>
        <where>
            <if test="examId != null "> and exam_id = #{examId}</if>
            <if test="title != null  and title != ''"> and title like concat(concat('%', #{title}), '%')</if>
            <if test="content != null  and content != ''"> and content = #{content}</if>
            <if test="openType != null "> and open_type = #{openType}</if>
            <if test="examType != null "> and exam_type = #{examType}</if>
            <if test="state != null "> and state = #{state}</if>
            <if test="timeLimit != null "> and time_limit = #{timeLimit}</if>
            <if test="examStartTime != null "> and exam_start_time = #{examStartTime}</if>
            <if test="examEndTime != null "> and exam_end_time = #{examEndTime}</if>
            <if test="totalScore != null "> and total_score = #{totalScore}</if>
            <if test="totalTime != null "> and total_time = #{totalTime}</if>
            <if test="qualifyScore != null "> and qualify_score = #{qualifyScore}</if>
            <if test="createrCode != null  and createrCode != ''"> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null  and updaterCode != ''"> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTElExamById" parameterType="Long" resultMap="TElExamResult">
        <include refid="selectTElExamVo"/>
        where exam_id = #{examId}
    </select>

    <insert id="insertTElExam" parameterType="TElExam">
        <selectKey keyProperty="examId" resultType="long" order="BEFORE">
            SELECT seq_t_el_exam.NEXTVAL as examId FROM DUAL
        </selectKey>
        insert into t_el_exam
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="examId != null">exam_id,</if>
            <if test="title != null">title,</if>
            <if test="content != null">content,</if>
            <if test="openType != null">open_type,</if>
            <if test="examType != null">exam_type,</if>
            <if test="state != null">state,</if>
            <if test="timeLimit != null">time_limit,</if>
            <if test="examStartTime != null">exam_start_time,</if>
            <if test="examEndTime != null">exam_end_time,</if>
            <if test="totalScore != null">total_score,</if>
            <if test="totalTime != null">total_time,</if>
            <if test="qualifyScore != null">qualify_score,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="examId != null">#{examId},</if>
            <if test="title != null">#{title},</if>
            <if test="content != null">#{content},</if>
            <if test="openType != null">#{openType},</if>
            <if test="examType != null">#{examType},</if>
            <if test="state != null">#{state},</if>
            <if test="timeLimit != null">#{timeLimit},</if>
            <if test="examStartTime != null">#{examStartTime},</if>
            <if test="examEndTime != null">#{examEndTime},</if>
            <if test="totalScore != null">#{totalScore},</if>
            <if test="totalTime != null">#{totalTime},</if>
            <if test="qualifyScore != null">#{qualifyScore},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTElExam" parameterType="TElExam">
        update t_el_exam
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null">title = #{title},</if>
            <if test="content != null">content = #{content},</if>
            <if test="openType != null">open_type = #{openType},</if>
            <if test="examType != null">exam_type = #{examType},</if>
            <if test="state != null">state = #{state},</if>
            <if test="timeLimit != null">time_limit = #{timeLimit},</if>
            <if test="examStartTime != null">exam_start_time = #{examStartTime},</if>
            <if test="examEndTime != null">exam_end_time = #{examEndTime},</if>
            <if test="totalScore != null">total_score = #{totalScore},</if>
            <if test="totalTime != null">total_time = #{totalTime},</if>
            <if test="qualifyScore != null">qualify_score = #{qualifyScore},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where exam_id = #{examId}
    </update>

    <update id="deleteTElExamById" parameterType="Long">
        update t_el_exam set del_flag = 2 where exam_id = #{examId}
    </update>

    <update id="deleteTElExamByIds" parameterType="String">
        update t_el_exam set del_flag = 2 where exam_id in
        <foreach item="examId" collection="array" open="(" separator="," close=")">
            #{examId}
        </foreach>
    </update>

</mapper>
