<?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.huijy.management.mapper.EarlyWarningMapper">

    <resultMap type="EarlyWarning" id="EarlyWarningResult">
        <result property="earlyWarningId"    column="early_warning_id"    />
        <result property="earlyWarningType"    column="early_warning_type"    />
        <result property="title"    column="title"    />
        <result property="rangeText"    column="range_text"    />
        <result property="content"    column="content"    />
        <result property="remarks"    column="remarks"    />
        <result property="sendFlag"    column="send_flag"    />
        <result property="sendAt"    column="send_at"    />
        <result property="sendTime"    column="send_time"    />
        <result property="createAt"    column="create_at"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectEarlyWarningVo">
        select early_warning_id, early_warning_type, title, range_text, content, remarks, send_flag, send_at, send_time, create_at, create_time from t_early_warning
    </sql>

    <select id="selectEarlyWarningList" parameterType="EarlyWarning" resultMap="EarlyWarningResult">
        <include refid="selectEarlyWarningVo"/>
        <where>
            <if test="earlyWarningType != null  and earlyWarningType != ''"> and early_warning_type = #{earlyWarningType}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="sendFlag != null  and sendFlag != ''"> and send_flag = #{sendFlag}</if>
        </where>
    </select>

    <select id="selectEarlyWarningByEarlyWarningId" parameterType="Long" resultMap="EarlyWarningResult">
        <include refid="selectEarlyWarningVo"/>
        where early_warning_id = #{earlyWarningId}
    </select>

    <insert id="insertEarlyWarning" parameterType="EarlyWarning" useGeneratedKeys="true" keyProperty="earlyWarningId">
        insert into t_early_warning
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="earlyWarningType != null">early_warning_type,</if>
            <if test="title != null">title,</if>
            <if test="rangeText != null">range_text,</if>
            <if test="content != null">content,</if>
            <if test="remarks != null">remarks,</if>
            <if test="sendFlag != null">send_flag,</if>
            <if test="sendAt != null">send_at,</if>
            <if test="sendTime != null">send_time,</if>
            <if test="createAt != null">create_at,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="earlyWarningType != null">#{earlyWarningType},</if>
            <if test="title != null">#{title},</if>
            <if test="rangeText != null">#{rangeText},</if>
            <if test="content != null">#{content},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="sendFlag != null">#{sendFlag},</if>
            <if test="sendAt != null">#{sendAt},</if>
            <if test="sendTime != null">#{sendTime},</if>
            <if test="createAt != null">#{createAt},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateEarlyWarning" parameterType="EarlyWarning">
        update t_early_warning
        <trim prefix="SET" suffixOverrides=",">
            <if test="earlyWarningType != null">early_warning_type = #{earlyWarningType},</if>
            <if test="title != null">title = #{title},</if>
            <if test="rangeText != null">range_text = #{rangeText},</if>
            <if test="content != null">content = #{content},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="sendFlag != null">send_flag = #{sendFlag},</if>
            <if test="sendAt != null">send_at = #{sendAt},</if>
            <if test="sendTime != null">send_time = #{sendTime},</if>
            <if test="createAt != null">create_at = #{createAt},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where early_warning_id = #{earlyWarningId}
    </update>

    <delete id="deleteEarlyWarningByEarlyWarningId" parameterType="Long">
        delete from t_early_warning where early_warning_id = #{earlyWarningId}
    </delete>

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