<?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.zehong.system.mapper.TEmergencyDrillsMapper">
    
    <resultMap type="TEmergencyDrills" id="TEmergencyDrillsResult">
        <result property="fDrillsId"    column="f_drills_id"    />
        <result property="fDrillsTime"    column="f_drills_time"    />
        <result property="fEvent"    column="f_event"    />
        <result property="fPlace"    column="f_place"    />
        <result property="fPerDep"    column="f_per_dep"    />
        <result property="fDrillsContent"    column="f_drills_content"    />
        <result property="fDrillDepartment"    column="f_drill_department"    />
        <result property="fCreateTime"    column="f_create_time"    />
        <result property="fUpdateTime"    column="f_update_time"    />
        <result property="fIsDel"    column="f_is_del"    />
        <result property="fRemarks"    column="f_remarks"    />
    </resultMap>

    <sql id="selectTEmergencyDrillsVo">
        select f_drills_id, f_drills_time, f_event, f_place, f_per_dep, f_drills_content, f_drill_department, f_create_time, f_update_time, f_is_del, f_remarks from t_emergency_drills
    </sql>

    <select id="selectTEmergencyDrillsList" parameterType="TEmergencyDrills" resultMap="TEmergencyDrillsResult">
        <include refid="selectTEmergencyDrillsVo"/>
        <where>  
            <if test="fDrillsId != null "> and f_drills_id = #{fDrillsId}</if>
            <if test="fDrillsTime != null  and fDrillsTime != ''"> and f_drills_time = #{fDrillsTime}</if>
            <if test="fEvent != null  and fEvent != ''"> and f_event like concat('%', #{fEvent}, '%')</if>
            <if test="fPlace != null  and fPlace != ''"> and f_place like concat('%', #{fPlace}, '%')</if>
            <if test="fPerDep != null  and fPerDep != ''"> and f_per_dep = #{fPerDep}</if>
            <if test="fDrillsContent != null  and fDrillsContent != ''"> and f_drills_content = #{fDrillsContent}</if>
            <if test="fDrillDepartment != null  and fDrillDepartment != ''"> and f_drill_department = #{fDrillDepartment}</if>
            <if test="fCreateTime != null "> and f_create_time = #{fCreateTime}</if>
            <if test="fUpdateTime != null "> and f_update_time = #{fUpdateTime}</if>
            <if test="fIsDel != null  and fIsDel != ''"> and f_is_del = #{fIsDel}</if>
            <if test="fRemarks != null  and fRemarks != ''"> and f_remarks = #{fRemarks}</if>
        </where>
    </select>
    
    <select id="selectTEmergencyDrillsById" parameterType="Long" resultMap="TEmergencyDrillsResult">
        <include refid="selectTEmergencyDrillsVo"/>
        where f_drills_id = #{fDrillsId}
    </select>
        
    <insert id="insertTEmergencyDrills" parameterType="TEmergencyDrills">
        insert into t_emergency_drills
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fDrillsId != null">f_drills_id,</if>
            <if test="fDrillsTime != null">f_drills_time,</if>
            <if test="fEvent != null">f_event,</if>
            <if test="fPlace != null">f_place,</if>
            <if test="fPerDep != null">f_per_dep,</if>
            <if test="fDrillsContent != null">f_drills_content,</if>
            <if test="fDrillDepartment != null">f_drill_department,</if>
            <if test="fCreateTime != null">f_create_time,</if>
            <if test="fUpdateTime != null">f_update_time,</if>
            <if test="fIsDel != null">f_is_del,</if>
            <if test="fRemarks != null">f_remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fDrillsId != null">#{fDrillsId},</if>
            <if test="fDrillsTime != null">#{fDrillsTime},</if>
            <if test="fEvent != null">#{fEvent},</if>
            <if test="fPlace != null">#{fPlace},</if>
            <if test="fPerDep != null">#{fPerDep},</if>
            <if test="fDrillsContent != null">#{fDrillsContent},</if>
            <if test="fDrillDepartment != null">#{fDrillDepartment},</if>
            <if test="fCreateTime != null">#{fCreateTime},</if>
            <if test="fUpdateTime != null">#{fUpdateTime},</if>
            <if test="fIsDel != null">#{fIsDel},</if>
            <if test="fRemarks != null">#{fRemarks},</if>
         </trim>
    </insert>

    <update id="updateTEmergencyDrills" parameterType="TEmergencyDrills">
        update t_emergency_drills
        <trim prefix="SET" suffixOverrides=",">
            <if test="fDrillsTime != null">f_drills_time = #{fDrillsTime},</if>
            <if test="fEvent != null">f_event = #{fEvent},</if>
            <if test="fPlace != null">f_place = #{fPlace},</if>
            <if test="fPerDep != null">f_per_dep = #{fPerDep},</if>
            <if test="fDrillsContent != null">f_drills_content = #{fDrillsContent},</if>
            <if test="fDrillDepartment != null">f_drill_department = #{fDrillDepartment},</if>
            <if test="fCreateTime != null">f_create_time = #{fCreateTime},</if>
            <if test="fUpdateTime != null">f_update_time = #{fUpdateTime},</if>
            <if test="fIsDel != null">f_is_del = #{fIsDel},</if>
            <if test="fRemarks != null">f_remarks = #{fRemarks},</if>
        </trim>
        where f_drills_id = #{fDrillsId}
    </update>

    <delete id="deleteTEmergencyDrillsById" parameterType="Long">
        delete from t_emergency_drills where f_drills_id = #{fDrillsId}
    </delete>

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