<?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.TElExamRepoMapper">

    <resultMap type="TElExamRepo" id="TElExamRepoResult">
        <result property="id"    column="id"    />
        <result property="examId"    column="exam_id"    />
        <result property="repoId"    column="repo_id"    />
        <result property="radioCount"    column="radio_count"    />
        <result property="radioScore"    column="radio_score"    />
        <result property="multiCount"    column="multi_count"    />
        <result property="multiScore"    column="multi_score"    />
        <result property="judgeCount"    column="judge_count"    />
        <result property="judgeScore"    column="judge_score"    />
        <result property="saqCount"    column="saq_count"    />
        <result property="saqScore"    column="saq_score"    />
    </resultMap>

    <sql id="selectTElExamRepoVo">
        select d.id, d.exam_id, d.repo_id, d.radio_count, d.radio_score, d.multi_count, d.multi_score, d.judge_count, d.judge_score, d.saq_count, d.saq_score
            ,(SELECT COUNT(0) FROM t_el_qu_repo WHERE repo_id=d.repo_id AND qu_type=1) AS totalRadio,
               (SELECT COUNT(0) FROM t_el_qu_repo WHERE repo_id=d.repo_id AND qu_type=2) AS totalMulti,
               (SELECT COUNT(0) FROM t_el_qu_repo WHERE repo_id=d.repo_id AND qu_type=3) AS totalJudge
        from t_el_exam_repo d
    </sql>

    <select id="selectTElExamRepoList" parameterType="TElExamRepo" resultMap="TElExamRepoResult">
        <include refid="selectTElExamRepoVo"/>
        <where>
            <if test="examId != null "> and exam_id = #{examId}</if>
            <if test="repoId != null "> and repo_id = #{repoId}</if>
            <if test="radioCount != null "> and radio_count = #{radioCount}</if>
            <if test="radioScore != null "> and radio_score = #{radioScore}</if>
            <if test="multiCount != null "> and multi_count = #{multiCount}</if>
            <if test="multiScore != null "> and multi_score = #{multiScore}</if>
            <if test="judgeCount != null "> and judge_count = #{judgeCount}</if>
            <if test="judgeScore != null "> and judge_score = #{judgeScore}</if>
            <if test="saqCount != null "> and saq_count = #{saqCount}</if>
            <if test="saqScore != null "> and saq_score = #{saqScore}</if>
        </where>
        <!-- 数据范围过滤 -->
    </select>

    <select id="selectTElExamRepoById" parameterType="Long" resultMap="TElExamRepoResult">
        <include refid="selectTElExamRepoVo"/>
        where id = #{id}
    </select>

    <insert id="insertTElExamRepo" parameterType="TElExamRepo">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_el_exam_repo.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_el_exam_repo
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="examId != null">exam_id,</if>
            <if test="repoId != null">repo_id,</if>
            <if test="radioCount != null">radio_count,</if>
            <if test="radioScore != null">radio_score,</if>
            <if test="multiCount != null">multi_count,</if>
            <if test="multiScore != null">multi_score,</if>
            <if test="judgeCount != null">judge_count,</if>
            <if test="judgeScore != null">judge_score,</if>
            <if test="saqCount != null">saq_count,</if>
            <if test="saqScore != null">saq_score,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="examId != null">#{examId},</if>
            <if test="repoId != null">#{repoId},</if>
            <if test="radioCount != null">#{radioCount},</if>
            <if test="radioScore != null">#{radioScore},</if>
            <if test="multiCount != null">#{multiCount},</if>
            <if test="multiScore != null">#{multiScore},</if>
            <if test="judgeCount != null">#{judgeCount},</if>
            <if test="judgeScore != null">#{judgeScore},</if>
            <if test="saqCount != null">#{saqCount},</if>
            <if test="saqScore != null">#{saqScore},</if>
         </trim>
    </insert>

    <update id="updateTElExamRepo" parameterType="TElExamRepo">
        update t_el_exam_repo
        <trim prefix="SET" suffixOverrides=",">
            <if test="examId != null">exam_id = #{examId},</if>
            <if test="repoId != null">repo_id = #{repoId},</if>
            <if test="radioCount != null">radio_count = #{radioCount},</if>
            <if test="radioScore != null">radio_score = #{radioScore},</if>
            <if test="multiCount != null">multi_count = #{multiCount},</if>
            <if test="multiScore != null">multi_score = #{multiScore},</if>
            <if test="judgeCount != null">judge_count = #{judgeCount},</if>
            <if test="judgeScore != null">judge_score = #{judgeScore},</if>
            <if test="saqCount != null">saq_count = #{saqCount},</if>
            <if test="saqScore != null">saq_score = #{saqScore},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTElExamRepoById" parameterType="Long">
        delete from t_el_exam_repo  where id = #{id}
    </delete>


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

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

</mapper>
