<?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.inspect.patrol.mapper.PatrolPresetParamMapper">
    
    <resultMap type="PatrolPresetParam" id="PatrolPresetParamResult">
        <result property="presetParamId"    column="pos_param_id"    />
        <result property="presetPosId"    column="preset_pos_id"    />
        <result property="measureAreaType"    column="measure_area_type"    />
        <result property="measureName"    column="measure_name"    />
        <result property="measureDistance"    column="measure_distance"    />
        <result property="radioRate"    column="radio_rate"    />
        <result property="warnMaxTemp"    column="warn_max_temp"    />
        <result property="warnMinTemp"    column="warn_min_temp"    />
        <result property="alarmMaxTemp"    column="alarm_max_temp"    />
        <result property="alarmMinTemp"    column="alarm_min_temp"    />
        <result property="warnAverageTemp"    column="warn_average_temp"    />
        <result property="alarmAverageTemp"    column="alarm_average_temp"    />
        <result property="warnDifferenceTemp"    column="warn_difference_temp"    />
        <result property="alarmDifferenceTemp"    column="alarm_difference_temp"    />
        <result property="coordinate"    column="coordinate"    />
        <result property="isEnable"    column="is_enable"    />
        <result property="createTime"    column="create_time"    />
        <result property="reflexTemp"    column="reflex_temp"    />
        <result property="presetParamCode"    column="preset_param_code"    />
    </resultMap>

    <sql id="selectPatrolPresetParamVo">
        select preset_param_id, preset_pos_id, measure_area_type, measure_name, measure_distance, radio_rate, warn_max_temp, warn_min_temp, alarm_max_temp, alarm_min_temp, warn_average_temp, alarm_average_temp, warn_difference_temp, alarm_difference_temp, coordinate, is_enable, create_time,reflex_temp,preset_param_code from patrol_preset_param
    </sql>

    <select id="selectPatrolPresetParamList" parameterType="PatrolPresetParam" resultMap="PatrolPresetParamResult">
        <include refid="selectPatrolPresetParamVo"/>
        <where>  
            <if test="presetPosId != null "> and preset_pos_id = #{presetPosId}</if>
            <if test="measureAreaType != null  and measureAreaType != ''"> and measure_area_type = #{measureAreaType}</if>
            <if test="measureName != null  and measureName != ''"> and measure_name like concat('%', #{measureName}, '%')</if>
            <if test="measureDistance != null  and measureDistance != ''"> and measure_distance = #{measureDistance}</if>
            <if test="radioRate != null  and radioRate != ''"> and radio_rate = #{radioRate}</if>
            <if test="warnMaxTemp != null  and warnMaxTemp != ''"> and warn_max_temp = #{warnMaxTemp}</if>
            <if test="warnMinTemp != null  and warnMinTemp != ''"> and warn_min_temp = #{warnMinTemp}</if>
            <if test="alarmMaxTemp != null  and alarmMaxTemp != ''"> and alarm_max_temp = #{alarmMaxTemp}</if>
            <if test="alarmMinTemp != null  and alarmMinTemp != ''"> and alarm_min_temp = #{alarmMinTemp}</if>
            <if test="warnAverageTemp != null  and warnAverageTemp != ''"> and warn_average_temp = #{warnAverageTemp}</if>
            <if test="alarmAverageTemp != null  and alarmAverageTemp != ''"> and alarm_average_temp = #{alarmAverageTemp}</if>
            <if test="warnDifferenceTemp != null  and warnDifferenceTemp != ''"> and warn_difference_temp = #{warnDifferenceTemp}</if>
            <if test="alarmDifferenceTemp != null  and alarmDifferenceTemp != ''"> and alarm_difference_temp = #{alarmDifferenceTemp}</if>
            <if test="coordinate != null  and coordinate != ''"> and coordinate = #{coordinate}</if>
            <if test="isEnable != null  and isEnable != ''"> and is_enable = #{isEnable}</if>
            <if test="reflexTemp != null  and reflexTemp != ''"> and reflex_temp = #{reflexTemp}</if>
            <if test="presetParamCode != null  and presetParamCode != ''"> and preset_param_code = #{presetParamCode}</if>
        </where>
    </select>
    
    <select id="selectPatrolPresetParamByPosId" parameterType="Long" resultMap="PatrolPresetParamResult">
        <include refid="selectPatrolPresetParamVo"/>
        where preset_pos_id = #{presetPosId}
    </select>
        
    <insert id="insertPatrolPresetParam" parameterType="PatrolPresetParam" useGeneratedKeys="true" keyProperty="presetParamId">
        insert into patrol_preset_param
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="presetPosId != null and presetPosId!= ''">preset_pos_id,</if>
            <if test="measureAreaType != null">measure_area_type,</if>
            <if test="measureName != null">measure_name,</if>
            <if test="measureDistance != null">measure_distance,</if>
            <if test="radioRate != null">radio_rate,</if>
            <if test="warnMaxTemp != null">warn_max_temp,</if>
            <if test="warnMinTemp != null">warn_min_temp,</if>
            <if test="alarmMaxTemp != null">alarm_max_temp,</if>
            <if test="alarmMinTemp != null">alarm_min_temp,</if>
            <if test="warnAverageTemp != null">warn_average_temp,</if>
            <if test="alarmAverageTemp != null">alarm_average_temp,</if>
            <if test="warnDifferenceTemp != null">warn_difference_temp,</if>
            <if test="alarmDifferenceTemp != null">alarm_difference_temp,</if>
            <if test="coordinate != null">coordinate,</if>
            <if test="isEnable != null">is_enable,</if>
            <if test="createTime != null">create_time,</if>
            <if test="reflexTemp != null">reflex_temp,</if>
            <if test="presetParamCode != null">preset_param_code,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="presetPosId != null and presetPosId!= ''">#{presetPosId},</if>
            <if test="measureAreaType != null">#{measureAreaType},</if>
            <if test="measureName != null">#{measureName},</if>
            <if test="measureDistance != null">#{measureDistance},</if>
            <if test="radioRate != null">#{radioRate},</if>
            <if test="warnMaxTemp != null">#{warnMaxTemp},</if>
            <if test="warnMinTemp != null">#{warnMinTemp},</if>
            <if test="alarmMaxTemp != null">#{alarmMaxTemp},</if>
            <if test="alarmMinTemp != null">#{alarmMinTemp},</if>
            <if test="warnAverageTemp != null">#{warnAverageTemp},</if>
            <if test="alarmAverageTemp != null">#{alarmAverageTemp},</if>
            <if test="warnDifferenceTemp != null">#{warnDifferenceTemp},</if>
            <if test="alarmDifferenceTemp != null">#{alarmDifferenceTemp},</if>
            <if test="coordinate != null">#{coordinate},</if>
            <if test="isEnable != null">#{isEnable},</if>
            <if test="reflexTemp != null">#{reflexTemp},</if>
            <if test="presetParamCode != null">#{presetParamCode},</if>
         </trim>
    </insert>

    <insert id="insertPatrolPresetParamList" parameterType="List">
        insert into patrol_preset_param (preset_pos_id, measure_area_type, measure_name, measure_distance, radio_rate, warn_max_temp, warn_min_temp, alarm_max_temp, alarm_min_temp, warn_average_temp, alarm_average_temp, warn_difference_temp, alarm_difference_temp, coordinate, create_time,reflex_temp,preset_param_code,is_enable) values
        <foreach item="item" collection="list" separator="," >
            (#{item.presetPosId},#{item.measureAreaType},#{item.measureName},#{item.measureDistance},#{item.radioRate},#{item.warnMaxTemp},#{item.warnMinTemp},#{item.alarmMaxTemp},#{item.alarmMinTemp},#{item.warnAverageTemp},#{item.alarmAverageTemp},#{item.warnDifferenceTemp},#{item.alarmDifferenceTemp},#{item.coordinate},#{item.createTime},#{item.reflexTemp},#{item.presetParamCode},#{item.isEnable})
        </foreach>
    </insert>
    <update id="updatePatrolPresetParam" parameterType="PatrolPresetParam">
        update patrol_preset_param
        <trim prefix="SET" suffixOverrides=",">
            <if test="presetPosId != null">preset_pos_id = #{presetPosId},</if>
            <if test="measureAreaType != null">measure_area_type = #{measureAreaType},</if>
            <if test="measureName != null">measure_name = #{measureName},</if>
            <if test="measureDistance != null">measure_distance = #{measureDistance},</if>
            <if test="radioRate != null">radio_rate = #{radioRate},</if>
            <if test="warnMaxTemp != null">warn_max_temp = #{warnMaxTemp},</if>
            <if test="warnMinTemp != null">warn_min_temp = #{warnMinTemp},</if>
            <if test="alarmMaxTemp != null">alarm_max_temp = #{alarmMaxTemp},</if>
            <if test="alarmMinTemp != null">alarm_min_temp = #{alarmMinTemp},</if>
            <if test="warnAverageTemp != null">warn_average_temp = #{warnAverageTemp},</if>
            <if test="alarmAverageTemp != null">alarm_average_temp = #{alarmAverageTemp},</if>
            <if test="warnDifferenceTemp != null">warn_difference_temp = #{warnDifferenceTemp},</if>
            <if test="alarmDifferenceTemp != null">alarm_difference_temp = #{alarmDifferenceTemp},</if>
            <if test="coordinate != null">coordinate = #{coordinate},</if>
            <if test="isEnable != null">is_enable = #{isEnable},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="reflexTemp != null">reflex_temp = #{reflexTemp},</if>
            <if test="presetParamCode != null">preset_param_code = #{presetParamCode},</if>
        </trim>
        where preset_param_id = #{presetParamId}
    </update>

    <delete id="deletePatrolPresetParamByPosParamId" parameterType="Long">
        delete from patrol_preset_param where preset_param_id = #{presetParamId}
    </delete>
    <delete id="deletePatrolPresetParamByPatrolPresetPosId" parameterType="String">
        delete from patrol_preset_param where preset_pos_id = #{presetParamId}
    </delete>

    <delete id="deletePatrolPresetParamByPresetPosIds" parameterType="String">
        delete from patrol_preset_param where preset_pos_id in
        <foreach item="presetParamId" collection="array" open="(" separator="," close=")">
            #{presetParamId}
        </foreach>
    </delete>
</mapper>