<?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.FloodCaseMapper">
    
    <resultMap type="FloodCase" id="FloodCaseResult">
        <result property="caseId"                column="case_id"                />
        <result property="caseType"              column="case_type"              />
        <result property="caseName"              column="case_name"              />
        <result property="caseTime"              column="case_time"              />
        <result property="caseLocation"          column="case_location"          />
        <result property="caseDescription"       column="case_description"       />
        <result property="disasterType"          column="disaster_type"          />
        <result property="affectedArea"           column="affected_area"          />
        <result property="economicLoss"          column="economic_loss"          />
        <result property="casualties"            column="casualties"              />
        <result property="rainfall"              column="rainfall"              />
        <result property="waterLevel"             column="water_level"            />
        <result property="duration"               column="duration"               />
        <result property="responseMeasures"      column="response_measures"      />
        <result property="riverBasin"            column="river_basin"            />
        <result property="floodScale"            column="flood_scale"            />
        <result property="peakFlow"              column="peak_flow"              />
        <result property="affectedPopulation"    column="affected_population"    />
        <result property="damagedHouses"         column="damaged_houses"         />
        <result property="damagedCrops"          column="damaged_crops"           />
        <result property="infrastructureDamage"  column="infrastructure_damage"  />
        <result property="rescueSituation"       column="rescue_situation"       />
        <result property="preventionMeasures"    column="prevention_measures"    />
        <result property="lessonsLearned"        column="lessons_learned"         />
        <result property="weatherCondition"      column="weather_condition"       />
        <result property="floodCause"            column="flood_cause"            />
        <result property="warningLevel"          column="warning_level"          />
        <result property="evacuationNumber"      column="evacuation_number"      />
        <result property="rescueTeams"           column="rescue_teams"           />
        <result property="materialSupport"       column="material_support"       />
        <result property="caseData"              column="case_data"              />
        <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="selectFloodCaseVo">
        select case_id, case_type, case_name, case_time, case_location, case_description, 
               disaster_type, affected_area, economic_loss, casualties, rainfall, water_level, 
               duration, response_measures, river_basin, flood_scale, peak_flow, affected_population, 
               damaged_houses, damaged_crops, infrastructure_damage, rescue_situation, 
               prevention_measures, lessons_learned, weather_condition, flood_cause, warning_level, 
               evacuation_number, rescue_teams, material_support, case_data, status, 
               create_by, create_time, update_by, update_time, remark 
        from flood_case
    </sql>

    <select id="selectFloodCaseList" parameterType="FloodCase" resultMap="FloodCaseResult">
        <include refid="selectFloodCaseVo"/>
        <where>  
            <if test="caseType != null and caseType != ''">
                and case_type = #{caseType}
            </if>
            <if test="caseName != null and caseName != ''">
                and (case_name like concat('%', #{caseName}, '%') or case_description like concat('%', #{caseName}, '%') or case_location like concat('%', #{caseName}, '%'))
            </if>
            <if test="caseTime != null and caseTime != ''">
                and case_time like concat('%', #{caseTime}, '%')
            </if>
            <if test="caseLocation != null and caseLocation != ''">
                and case_location like concat('%', #{caseLocation}, '%')
            </if>
            <if test="status != null and status != ''">
                and status = #{status}
            </if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectFloodCaseByCaseId" parameterType="Long" resultMap="FloodCaseResult">
        <include refid="selectFloodCaseVo"/>
        where case_id = #{caseId}
    </select>
        
    <insert id="insertFloodCase" parameterType="FloodCase" useGeneratedKeys="true" keyProperty="caseId">
        insert into flood_case
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="caseType != null and caseType != ''">case_type,</if>
            <if test="caseName != null">case_name,</if>
            <if test="caseTime != null">case_time,</if>
            <if test="caseLocation != null">case_location,</if>
            <if test="caseDescription != null">case_description,</if>
            <if test="disasterType != null">disaster_type,</if>
            <if test="affectedArea != null">affected_area,</if>
            <if test="economicLoss != null">economic_loss,</if>
            <if test="casualties != null">casualties,</if>
            <if test="rainfall != null">rainfall,</if>
            <if test="waterLevel != null">water_level,</if>
            <if test="duration != null">duration,</if>
            <if test="responseMeasures != null">response_measures,</if>
            <if test="riverBasin != null">river_basin,</if>
            <if test="floodScale != null">flood_scale,</if>
            <if test="peakFlow != null">peak_flow,</if>
            <if test="affectedPopulation != null">affected_population,</if>
            <if test="damagedHouses != null">damaged_houses,</if>
            <if test="damagedCrops != null">damaged_crops,</if>
            <if test="infrastructureDamage != null">infrastructure_damage,</if>
            <if test="rescueSituation != null">rescue_situation,</if>
            <if test="preventionMeasures != null">prevention_measures,</if>
            <if test="lessonsLearned != null">lessons_learned,</if>
            <if test="weatherCondition != null">weather_condition,</if>
            <if test="floodCause != null">flood_cause,</if>
            <if test="warningLevel != null">warning_level,</if>
            <if test="evacuationNumber != null">evacuation_number,</if>
            <if test="rescueTeams != null">rescue_teams,</if>
            <if test="materialSupport != null">material_support,</if>
            <if test="caseData != null">case_data,</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="caseType != null and caseType != ''">#{caseType},</if>
            <if test="caseName != null">#{caseName},</if>
            <if test="caseTime != null">#{caseTime},</if>
            <if test="caseLocation != null">#{caseLocation},</if>
            <if test="caseDescription != null">#{caseDescription},</if>
            <if test="disasterType != null">#{disasterType},</if>
            <if test="affectedArea != null">#{affectedArea},</if>
            <if test="economicLoss != null">#{economicLoss},</if>
            <if test="casualties != null">#{casualties},</if>
            <if test="rainfall != null">#{rainfall},</if>
            <if test="waterLevel != null">#{waterLevel},</if>
            <if test="duration != null">#{duration},</if>
            <if test="responseMeasures != null">#{responseMeasures},</if>
            <if test="riverBasin != null">#{riverBasin},</if>
            <if test="floodScale != null">#{floodScale},</if>
            <if test="peakFlow != null">#{peakFlow},</if>
            <if test="affectedPopulation != null">#{affectedPopulation},</if>
            <if test="damagedHouses != null">#{damagedHouses},</if>
            <if test="damagedCrops != null">#{damagedCrops},</if>
            <if test="infrastructureDamage != null">#{infrastructureDamage},</if>
            <if test="rescueSituation != null">#{rescueSituation},</if>
            <if test="preventionMeasures != null">#{preventionMeasures},</if>
            <if test="lessonsLearned != null">#{lessonsLearned},</if>
            <if test="weatherCondition != null">#{weatherCondition},</if>
            <if test="floodCause != null">#{floodCause},</if>
            <if test="warningLevel != null">#{warningLevel},</if>
            <if test="evacuationNumber != null">#{evacuationNumber},</if>
            <if test="rescueTeams != null">#{rescueTeams},</if>
            <if test="materialSupport != null">#{materialSupport},</if>
            <if test="caseData != null">#{caseData},</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="updateFloodCase" parameterType="FloodCase">
        update flood_case
        <trim prefix="SET" suffixOverrides=",">
            <if test="caseType != null and caseType != ''">case_type = #{caseType},</if>
            <if test="caseName != null">case_name = #{caseName},</if>
            <if test="caseTime != null">case_time = #{caseTime},</if>
            <if test="caseLocation != null">case_location = #{caseLocation},</if>
            <if test="caseDescription != null">case_description = #{caseDescription},</if>
            <if test="disasterType != null">disaster_type = #{disasterType},</if>
            <if test="affectedArea != null">affected_area = #{affectedArea},</if>
            <if test="economicLoss != null">economic_loss = #{economicLoss},</if>
            <if test="casualties != null">casualties = #{casualties},</if>
            <if test="rainfall != null">rainfall = #{rainfall},</if>
            <if test="waterLevel != null">water_level = #{waterLevel},</if>
            <if test="duration != null">duration = #{duration},</if>
            <if test="responseMeasures != null">response_measures = #{responseMeasures},</if>
            <if test="riverBasin != null">river_basin = #{riverBasin},</if>
            <if test="floodScale != null">flood_scale = #{floodScale},</if>
            <if test="peakFlow != null">peak_flow = #{peakFlow},</if>
            <if test="affectedPopulation != null">affected_population = #{affectedPopulation},</if>
            <if test="damagedHouses != null">damaged_houses = #{damagedHouses},</if>
            <if test="damagedCrops != null">damaged_crops = #{damagedCrops},</if>
            <if test="infrastructureDamage != null">infrastructure_damage = #{infrastructureDamage},</if>
            <if test="rescueSituation != null">rescue_situation = #{rescueSituation},</if>
            <if test="preventionMeasures != null">prevention_measures = #{preventionMeasures},</if>
            <if test="lessonsLearned != null">lessons_learned = #{lessonsLearned},</if>
            <if test="weatherCondition != null">weather_condition = #{weatherCondition},</if>
            <if test="floodCause != null">flood_cause = #{floodCause},</if>
            <if test="warningLevel != null">warning_level = #{warningLevel},</if>
            <if test="evacuationNumber != null">evacuation_number = #{evacuationNumber},</if>
            <if test="rescueTeams != null">rescue_teams = #{rescueTeams},</if>
            <if test="materialSupport != null">material_support = #{materialSupport},</if>
            <if test="caseData != null">case_data = #{caseData},</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 case_id = #{caseId}
    </update>

    <delete id="deleteFloodCaseByCaseId" parameterType="Long">
        delete from flood_case where case_id = #{caseId}
    </delete>

    <delete id="deleteFloodCaseByCaseIds" parameterType="String">
        delete from flood_case where case_id in 
        <foreach item="caseId" collection="array" open="(" separator="," close=")">
            #{caseId}
        </foreach>
    </delete>

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