<?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.system.mapper.TdExamnumMapper">
    
    <resultMap type="TdExamnum" id="TdExamnumResult">
        <result property="id"    column="id"    />
        <result property="userName"    column="userName"    />
        <result property="examResult"    column="examResult"    />
        <result property="startTime"    column="startTime"    />
        <result property="endTime"    column="endTime"    />
        <result property="dept"    column="dept"    />
        <result property="type"    column="type"    />
    </resultMap>

    <sql id="selectTdExamnumVo">
        select id, userName, examResult, startTime, endTime, dept, type from td_examnum
    </sql>

    <select id="selectTdExamnumList" parameterType="TdExamnum" resultMap="TdExamnumResult">
        <include refid="selectTdExamnumVo"/>
        <where>  
            <if test="userName != null  and userName != ''"> and userName like concat('%', #{userName}, '%')</if>
            <if test="examResult != null "> and examResult = #{examResult}</if>
            <if test="startTime != null "> and startTime = #{startTime}</if>
            <if test="endTime != null "> and endTime = #{endTime}</if>
            <if test="dept != null  and dept != ''"> and dept = #{dept}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
        </where>
        order by startTime desc
    </select>
    
    <select id="selectTdExamnumById" parameterType="Long" resultMap="TdExamnumResult">
        <include refid="selectTdExamnumVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTdExamnum" parameterType="TdExamnum" useGeneratedKeys="true" keyProperty="id">
        insert into td_examnum
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userName != null">userName,</if>
            <if test="examResult != null">examResult,</if>
            <if test="startTime != null">startTime,</if>
            <if test="endTime != null">endTime,</if>
            <if test="dept != null">dept,</if>
            <if test="type != null">type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userName != null">#{userName},</if>
            <if test="examResult != null">#{examResult},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="dept != null">#{dept},</if>
            <if test="type != null">#{type},</if>
         </trim>
    </insert>

    <update id="updateTdExamnum" parameterType="TdExamnum">
        update td_examnum
        <trim prefix="SET" suffixOverrides=",">
            <if test="userName != null">userName = #{userName},</if>
            <if test="examResult != null">examResult = #{examResult},</if>
            <if test="startTime != null">startTime = #{startTime},</if>
            <if test="endTime != null">endTime = #{endTime},</if>
            <if test="dept != null">dept = #{dept},</if>
            <if test="type != null">type = #{type},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTdExamnumById" parameterType="Long">
        delete from td_examnum where id = #{id}
    </delete>

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

</mapper>