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

    <resultMap type="TElPaper" id="TElPaperResult">
        <result property="paperId"    column="paper_id"    />
        <result property="userId"    column="user_id"    />
        <result property="staffId"    column="staff_id"    />
        <result property="examId"    column="exam_id"    />
        <result property="title"    column="title"    />
        <result property="totalTime"    column="total_time"    />
        <result property="userTime"    column="user_time"    />
        <result property="totalScore"    column="total_score"    />
        <result property="qualifyScore"    column="qualify_score"    />
        <result property="objScore"    column="obj_score"    />
        <result property="subjScore"    column="subj_score"    />
        <result property="userScore"    column="user_score"    />
        <result property="hasSaq"    column="has_saq"    />
        <result property="state"    column="state"    />
        <result property="limitTime"    column="limit_time"    />
        <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" />
    </resultMap>

    <sql id="selectTElPaperVo">
        select d.paper_id, d.user_id, d.staff_id, d.exam_id, d.title, d.total_time, d.user_time, d.total_score, d.qualify_score, d.obj_score, d.subj_score, d.user_score, d.has_saq, d.state, d.limit_time, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks ,s.dept_name from t_el_paper d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTElPaperList" parameterType="TElPaper" resultMap="TElPaperResult">
        <include refid="selectTElPaperVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="staffId != null and staffId != '' "> and staff_id = #{staffId}</if>
            <if test="examId != null "> and exam_id = #{examId}</if>
            <if test="title != null  and title != ''"> and title like concat(concat('%', #{title}), '%')</if>
            <if test="totalTime != null "> and total_time = #{totalTime}</if>
            <if test="userTime != null "> and user_time = #{userTime}</if>
            <if test="totalScore != null "> and total_score = #{totalScore}</if>
            <if test="qualifyScore != null "> and qualify_score = #{qualifyScore}</if>
            <if test="objScore != null "> and obj_score = #{objScore}</if>
            <if test="subjScore != null "> and subj_score = #{subjScore}</if>
            <if test="userScore != null "> and user_score = #{userScore}</if>
            <if test="hasSaq != null "> and has_saq = #{hasSaq}</if>
            <if test="state != null "> and state = #{state}</if>
            <if test="limitTime != null "> and limit_time = #{limitTime}</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>
        <!-- 数据范围过滤 -->
        order by d.createdate desc
    </select>

    <select id="selectTElPaperById" parameterType="Long" resultMap="TElPaperResult">
        <include refid="selectTElPaperVo"/>
        where paper_id = #{paperId}
    </select>

    <insert id="insertTElPaper" parameterType="TElPaper">
        <selectKey keyProperty="paperId" resultType="long" order="BEFORE">
            SELECT seq_t_el_paper.NEXTVAL as paperId FROM DUAL
        </selectKey>
        insert into t_el_paper
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="paperId != null">paper_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="staffId != null">staff_id,</if>
            <if test="examId != null">exam_id,</if>
            <if test="title != null">title,</if>
            <if test="totalTime != null">total_time,</if>
            <if test="userTime != null">user_time,</if>
            <if test="totalScore != null">total_score,</if>
            <if test="qualifyScore != null">qualify_score,</if>
            <if test="objScore != null">obj_score,</if>
            <if test="subjScore != null">subj_score,</if>
            <if test="userScore != null">user_score,</if>
            <if test="hasSaq != null">has_saq,</if>
            <if test="state != null">state,</if>
            <if test="limitTime != null">limit_time,</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="paperId != null">#{paperId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="staffId != null">#{staffId},</if>
            <if test="examId != null">#{examId},</if>
            <if test="title != null">#{title},</if>
            <if test="totalTime != null">#{totalTime},</if>
            <if test="userTime != null">#{userTime},</if>
            <if test="totalScore != null">#{totalScore},</if>
            <if test="qualifyScore != null">#{qualifyScore},</if>
            <if test="objScore != null">#{objScore},</if>
            <if test="subjScore != null">#{subjScore},</if>
            <if test="userScore != null">#{userScore},</if>
            <if test="hasSaq != null">#{hasSaq},</if>
            <if test="state != null">#{state},</if>
            <if test="limitTime != null">#{limitTime},</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="updateTElPaper" parameterType="TElPaper">
        update t_el_paper
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="staffId != null">staff_id = #{staffId},</if>
            <if test="examId != null">exam_id = #{examId},</if>
            <if test="title != null">title = #{title},</if>
            <if test="totalTime != null">total_time = #{totalTime},</if>
            <if test="userTime != null">user_time = #{userTime},</if>
            <if test="totalScore != null">total_score = #{totalScore},</if>
            <if test="qualifyScore != null">qualify_score = #{qualifyScore},</if>
            <if test="objScore != null">obj_score = #{objScore},</if>
            <if test="subjScore != null">subj_score = #{subjScore},</if>
            <if test="userScore != null">user_score = #{userScore},</if>
            <if test="hasSaq != null">has_saq = #{hasSaq},</if>
            <if test="state != null">state = #{state},</if>
            <if test="limitTime != null">limit_time = #{limitTime},</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 paper_id = #{paperId}
    </update>

    <update id="deleteTElPaperById" parameterType="Long">
        update t_el_paper set del_flag = 2 where paper_id = #{paperId}
    </update>

    <update id="deleteTElPaperByIds" parameterType="String">
        update t_el_paper set del_flag = 2 where paper_id in
        <foreach item="paperId" collection="array" open="(" separator="," close=")">
            #{paperId}
        </foreach>
    </update>

</mapper>
