<?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.TEmergencyDrillMapper">
    
    <resultMap type="TEmergencyDrill" id="TEmergencyDrillResult">
        <result property="drillId"    column="drill_id"    />
        <result property="drillName"    column="drill_name"    />
        <result property="drillAddress"    column="drill_address"    />
        <result property="drillUnit"    column="drill_unit"    />
        <result property="drillTime"    column="drill_time"    />
        <result property="drillType"    column="drill_type"    />
        <result property="drillForm"    column="drill_form"    />
        <result property="drillObjective"    column="drill_objective"    />
        <result property="drillPeople"    column="drill_people"    />
        <result property="drillContent"    column="drill_content"    />
        <result property="assessment"    column="assessment"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="isDel"    column="is_del"    />
    </resultMap>

    <sql id="selectTEmergencyDrillVo">
        select drill_id, drill_name, drill_address, drill_unit, drill_time, drill_type, drill_form, drill_objective, drill_people, drill_content, assessment, create_time, create_by, is_del from t_emergency_drill
    </sql>

    <select id="selectTEmergencyDrillList" parameterType="TEmergencyDrill" resultMap="TEmergencyDrillResult">
        <include refid="selectTEmergencyDrillVo"/>
        <where>
            AND is_del = 0
            <if test="drillName != null  and drillName != ''"> and drill_name like concat('%', #{drillName}, '%')</if>
            <if test="drillType != null "> and drill_type = #{drillType}</if>
            <if test="drillForm != null "> and drill_form = #{drillForm}</if>
        </where>
    </select>
    
    <select id="selectTEmergencyDrillById" parameterType="Long" resultMap="TEmergencyDrillResult">
        <include refid="selectTEmergencyDrillVo"/>
        where drill_id = #{drillId}
    </select>
        
    <insert id="insertTEmergencyDrill" parameterType="TEmergencyDrill" useGeneratedKeys="true" keyProperty="drillId">
        insert into t_emergency_drill
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="drillName != null">drill_name,</if>
            <if test="drillAddress != null">drill_address,</if>
            <if test="drillUnit != null">drill_unit,</if>
            <if test="drillTime != null">drill_time,</if>
            <if test="drillType != null">drill_type,</if>
            <if test="drillForm != null">drill_form,</if>
            <if test="drillObjective != null">drill_objective,</if>
            <if test="drillPeople != null">drill_people,</if>
            <if test="drillContent != null">drill_content,</if>
            <if test="assessment != null">assessment,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="isDel != null">is_del,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="drillName != null">#{drillName},</if>
            <if test="drillAddress != null">#{drillAddress},</if>
            <if test="drillUnit != null">#{drillUnit},</if>
            <if test="drillTime != null">#{drillTime},</if>
            <if test="drillType != null">#{drillType},</if>
            <if test="drillForm != null">#{drillForm},</if>
            <if test="drillObjective != null">#{drillObjective},</if>
            <if test="drillPeople != null">#{drillPeople},</if>
            <if test="drillContent != null">#{drillContent},</if>
            <if test="assessment != null">#{assessment},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="isDel != null">#{isDel},</if>
         </trim>
    </insert>

    <update id="updateTEmergencyDrill" parameterType="TEmergencyDrill">
        update t_emergency_drill
        <trim prefix="SET" suffixOverrides=",">
            <if test="drillName != null">drill_name = #{drillName},</if>
            <if test="drillAddress != null">drill_address = #{drillAddress},</if>
            <if test="drillUnit != null">drill_unit = #{drillUnit},</if>
            <if test="drillTime != null">drill_time = #{drillTime},</if>
            <if test="drillType != null">drill_type = #{drillType},</if>
            <if test="drillForm != null">drill_form = #{drillForm},</if>
            <if test="drillObjective != null">drill_objective = #{drillObjective},</if>
            <if test="drillPeople != null">drill_people = #{drillPeople},</if>
            <if test="drillContent != null">drill_content = #{drillContent},</if>
            <if test="assessment != null">assessment = #{assessment},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
        </trim>
        where drill_id = #{drillId}
    </update>

    <delete id="deleteTEmergencyDrillById" parameterType="Long">
        delete from t_emergency_drill where drill_id = #{drillId}
    </delete>

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