<?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.FloodEmergencyPlanMapper">
    
    <resultMap type="FloodEmergencyPlan" id="FloodEmergencyPlanResult">
        <result property="planId"         column="plan_id"         />
        <result property="planLevel"     column="plan_level"     />
        <result property="planName"      column="plan_name"      />
        <result property="planUrl"       column="plan_url"       />
        <result property="planDesc"      column="plan_desc"      />
        <result property="status"        column="status"         />
        <result property="createBy"      column="create_by"      />
        <result property="createTime"    column="create_time"     />
        <result property="updateBy"      column="update_by"       />
        <result property="updateTime"    column="update_time"     />
        <result property="remark"        column="remark"         />
    </resultMap>

    <sql id="selectFloodEmergencyPlanVo">
        select plan_id, plan_level, plan_name, plan_url, plan_desc, status, create_by, create_time, update_by, update_time, remark 
        from flood_emergency_plan
    </sql>

    <select id="selectFloodEmergencyPlanList" parameterType="FloodEmergencyPlan" resultMap="FloodEmergencyPlanResult">
        <include refid="selectFloodEmergencyPlanVo"/>
        <where>  
            <if test="planLevel != null and planLevel != ''">
                and plan_level = #{planLevel}
            </if>
            <if test="planName != null and planName != ''">
                and plan_name like concat('%', #{planName}, '%')
            </if>
            <if test="status != null and status != ''">
                and status = #{status}
            </if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectFloodEmergencyPlanByPlanId" parameterType="Long" resultMap="FloodEmergencyPlanResult">
        <include refid="selectFloodEmergencyPlanVo"/>
        where plan_id = #{planId}
    </select>
        
    <insert id="insertFloodEmergencyPlan" parameterType="FloodEmergencyPlan" useGeneratedKeys="true" keyProperty="planId">
        insert into flood_emergency_plan
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="planLevel != null">plan_level,</if>
            <if test="planName != null and planName != ''">plan_name,</if>
            <if test="planUrl != null and planUrl != ''">plan_url,</if>
            <if test="planDesc != null">plan_desc,</if>
            <if test="status != null">status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="planLevel != null">#{planLevel},</if>
            <if test="planName != null and planName != ''">#{planName},</if>
            <if test="planUrl != null and planUrl != ''">#{planUrl},</if>
            <if test="planDesc != null">#{planDesc},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateFloodEmergencyPlan" parameterType="FloodEmergencyPlan">
        update flood_emergency_plan
        <trim prefix="SET" suffixOverrides=",">
            <if test="planLevel != null">plan_level = #{planLevel},</if>
            <if test="planName != null and planName != ''">plan_name = #{planName},</if>
            <if test="planUrl != null and planUrl != ''">plan_url = #{planUrl},</if>
            <if test="planDesc != null">plan_desc = #{planDesc},</if>
            <if test="status != null">status = #{status},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where plan_id = #{planId}
    </update>

    <delete id="deleteFloodEmergencyPlanByPlanId" parameterType="Long">
        delete from flood_emergency_plan where plan_id = #{planId}
    </delete>

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

    <select id="countFloodEmergencyPlan" resultType="int">
        select count(*) from flood_emergency_plan where status = '0'
    </select>
</mapper>
