<?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.srs.teacher.mapper.SysTeacherKpiFillingStuEmergencyMapper">

    <resultMap type="SysTeacherKpiFillingStuEmergency" id="SysTeacherKpiFillingStuEmergencyResult">
        <result property="id" column="id"/>
        <result property="eventDescription" column="event_description"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="eventLevel" column="event_level"/>
        <result property="fdyName" column="fdy_name"/>
        <result property="fillingYear" column="filling_year"/>
        <result property="fillingMonth" column="filling_month"/>
    </resultMap>

    <sql id="selectSysTeacherKpiFillingStuEmergencyVo">
        select id,
               event_description,
               start_time,
               end_time,
               event_level,
               fdy_name,
               filling_year,
               filling_month
        from sys_teacher_kpi_filling_stu_emergency
    </sql>

    <select id="selectSysTeacherKpiFillingStuEmergencyList" parameterType="SysTeacherKpiFillingStuEmergency"
            resultMap="SysTeacherKpiFillingStuEmergencyResult">
        <include refid="selectSysTeacherKpiFillingStuEmergencyVo"/>
        <where>
            <if test="eventDescription != null  and eventDescription != ''">and event_description =
                #{eventDescription}
            </if>
            <if test="startTime != null ">and start_time = #{startTime}</if>
            <if test="endTime != null ">and end_time = #{endTime}</if>
            <if test="eventLevel != null ">and event_level = #{eventLevel}</if>
            <if test="fdyName != null  and fdyName != ''">and fdy_name like concat('%', #{fdyName}, '%')</if>
            <if test="fillingYear != null  and fillingYear != ''">and filling_year = #{fillingYear}</if>
            <if test="fillingMonth != null  and fillingMonth != ''">and filling_month = #{fillingMonth}</if>
        </where>
        order by id desc
    </select>

    <select id="selectSysTeacherKpiFillingStuEmergencyById" parameterType="Long"
            resultMap="SysTeacherKpiFillingStuEmergencyResult">
        <include refid="selectSysTeacherKpiFillingStuEmergencyVo"/>
        where id = #{id}
    </select>

    <!--根据名称、年份、月份查询-->
    <select id="selectSysTeacherKpiFillingStuEmergencyByFdyName" parameterType="String"
            resultMap="SysTeacherKpiFillingStuEmergencyResult">
        <include refid="selectSysTeacherKpiFillingStuEmergencyVo"/>
        <where>
            <if test="fdyName != null and fdyName != ''">
                and fdy_name = #{fdyName}
            </if>
            <if test="fillingYear != null and fillingYear != ''">
                and filling_year = #{fillingYear}
            </if>
            <if test="fillingMonth != null and fillingMonth != ''">
                and filling_month = #{fillingMonth}
            </if>
        </where>
        order by id desc
    </select>

    <insert id="insertSysTeacherKpiFillingStuEmergency" parameterType="SysTeacherKpiFillingStuEmergency"
            useGeneratedKeys="true" keyProperty="id">
        insert into sys_teacher_kpi_filling_stu_emergency
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="eventDescription != null and eventDescription != ''">event_description,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="eventLevel != null">event_level,</if>
            <if test="fdyName != null and fdyName != ''">fdy_name,</if>
            <if test="fillingYear != null and fillingYear != ''">filling_year,</if>
            <if test="fillingMonth != null and fillingMonth != ''">filling_month,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="eventDescription != null and eventDescription != ''">#{eventDescription},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="eventLevel != null">#{eventLevel},</if>
            <if test="fdyName != null and fdyName != ''">#{fdyName},</if>
            <if test="fillingYear != null and fillingYear != ''">#{fillingYear},</if>
            <if test="fillingMonth != null and fillingMonth != ''">#{fillingMonth},</if>
        </trim>
    </insert>

    <update id="updateSysTeacherKpiFillingStuEmergency" parameterType="SysTeacherKpiFillingStuEmergency">
        update sys_teacher_kpi_filling_stu_emergency
        <trim prefix="SET" suffixOverrides=",">
            <if test="eventDescription != null and eventDescription != ''">event_description = #{eventDescription},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="eventLevel != null">event_level = #{eventLevel},</if>
            <if test="fdyName != null and fdyName != ''">fdy_name = #{fdyName},</if>
            <if test="fillingYear != null and fillingYear != ''">filling_year = #{fillingYear},</if>
            <if test="fillingMonth != null and fillingMonth != ''">filling_month = #{fillingMonth},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysTeacherKpiFillingStuEmergencyById" parameterType="Long">
        delete
        from sys_teacher_kpi_filling_stu_emergency
        where id = #{id}
    </delete>

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